nearprotocolnear

what is ContractPromise? near-sdk-as to near-sdk-rs comparison


I've found this function in an assemblyscript project for a NEAR contract:

export function assert_single_promise_success(): void {
  const x = ContractPromise.getResults()
  assert(x.length == 1, "Expected exactly one promise result")
  assert(x[0].succeeded, "Expected PromiseStatus to be successful")
}

What does ContractPromise.getResults() do exactly? How should implement the same thing in rust?


Solution

  • I'm going to give an answer, comments taken directly from the implementation of ContractPromise.getResults(), which can be found here. The implementation also has an example on how to use the function, which may be useful.

    Method to receive async (one or multiple) results from the remote contract in the callback.

    @returns An array of results based on the number of promises the callback was created on. If the callback using then was scheduled only on one result, then one result will be returned.