Skip to content

#[callback_vec] argument includes other args with #[callback_unwrap] #1320

Open
@dj8yfo

Description

@dj8yfo

A sample contract method

pub fn handle_callbacks(
&self,
#[callback_unwrap] a: Pair,
#[callback_unwrap] b: Pair,
#[callback_vec] others: Vec<Pair>,
) -> CompositeCallbacksResult {
log!("a : {:#?}", a);
log!("b : {:#?}", b);
log!("others : {:#?}", others);
CompositeCallbacksResult { a, b, others }

behaves very strange with respect to handling arguments: an argument annotated with #[callback_vec]
comprises the values of previous arguments annotated with #[callback_unwrap]:

let res = contract
.call("call_all")
.args_json(())
.gas(near_sdk::Gas::from_tgas(300))
.transact()
.await?;
println!("res: {:#?}", res);
let composite_result = res.json::<CompositeCallbacksResult>()?;
assert_eq!(composite_result.a, Pair(0, 0));
assert_eq!(composite_result.b, Pair(2, 2));
assert_eq!(composite_result.others, vec![Pair(0, 0), Pair(2, 2), Pair(3, 3), Pair(4, 4),]);

One would probably expect this argument to behave as a var-arg parameter with respect to Promise-s:

// pseudo-code
fn handle_callbacks(a_promise, b_promise, *rest_of_the_promises)

=>

assert_eq!(composite_result.others, vec![Pair(3, 3), Pair(4, 4),]);

Possible changes/fixes:

  1. Simple
    1. disallow using #[callback_vec] with #[callback_unwrap]/#[callback_result] on other arguments
    2. disallow using #[callback_vec] more that once on all of the arguments
  2. Less simple
    1. adjust starting promise idx computing for #[callback_vec]
    2. disallow using #[callback_vec] more that once on all of the arguments
    3. require #[callback_vec] to be used after all of the #[callback_unwrap]/#[callback_result]-s

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status

      NEW❗

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions