-
Notifications
You must be signed in to change notification settings - Fork 277
Open
Labels
Description
A sample contract method
near-sdk-rs/examples/adder/src/lib.rs
Lines 40 to 49 in 3bdbdd3
| 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]:
near-sdk-rs/examples/adder/src/lib.rs
Lines 112 to 123 in 3bdbdd3
| 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:
- Simple
- disallow using
#[callback_vec]with#[callback_unwrap]/#[callback_result]on other arguments - disallow using
#[callback_vec]more that once on all of the arguments
- disallow using
- Less simple
- adjust starting promise idx computing for
#[callback_vec] - disallow using
#[callback_vec]more that once on all of the arguments - require
#[callback_vec]to be used after all of the#[callback_unwrap]/#[callback_result]-s
- adjust starting promise idx computing for
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
NEW❗