Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dj8yfo opened this issue Mar 3, 2025 · 1 comment
Open

Comments

@dj8yfo
Copy link
Collaborator

dj8yfo commented Mar 3, 2025

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
@0xscharki
Copy link

I’d like to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: NEW❗
Development

No branches or pull requests

2 participants