什么是ContractPromise? near-sdk-as 与 near-sdk-rs 比较

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

我在 NEAR 合约的汇编脚本项目中找到了这个函数:

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")
}

ContractPromise.getResults() 的具体作用是什么?应该如何在 Rust 中实现同样的东西?

这里有来自 examples in the SDK 存储库

之一的 Rust 中的类似内容
require!(env::promise_results_count() == 2);

let data0: Vec<u8> = match env::promise_result(0) {
  PromiseResult::Successful(x) => x,
  _ => env::panic_str("Promise with index 0 failed"),
};

我要给出一个答案,评论直接取自 ContractPromise.getResults()which can be found here 的实施。该实现还有一个关于如何使用该功能的示例,这可能很有用。

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.