Error on returning environmental account id's

眉间皱痕 提交于 2019-12-24 06:31:19

问题


If I have the following method to test predecessor_account_id behaviour

pub fn get_pred_acc(&self) -> (String {
    let prev_acc = env::predecessor_account_id().to_string();
    return prev_acc;
}

And try to call this from frontend

const contract = await this.near.loadContract(window.nearConfig.contractName, {
  viewMethods: ["get_pred_acc", ],
  changeMethods: [],
  sender: this.accountId,
});

const acc = await contract.get_pred_acc();

I get the following error:

Uncaught (in promise) Error: Querying call/flux-protocol/get_account_id failed: wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView("predecessor_account_id"))).
{ "error": "wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView(\"predecessor_account_id\")))",
"logs": []
}


回答1:


That's expected behavior for the view calls.

The view calls don't have certain context information such calls are not part of an actual transaction.

Currently, the best option to see which methods are prohibited in the view calls is to take a look at the test: https://github.com/nearprotocol/nearcore/blob/master/runtime/near-vm-logic/tests/test_view_method.rs#L19-L43

To summarize:

  • previous account information and keys (signer, predecessor and signer_public_key)
  • gas information
  • all promise methods, cause they involve other contracts


来源:https://stackoverflow.com/questions/58642732/error-on-returning-environmental-account-ids

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!