Tracking promise chains in NEAR smart contract protocol

240 Views Asked by At

NEAR protocol is sharded and transactions between cross-contract calls in shards are final. In some cases, it would make sense to identify longer transaction chains, especially if the promise chain hits the same contract twice (re-entrancy).

Let's imagine a chain of promises: Alice wants to buy a token and the trade is routed through multiple smart contracts and hits one contract in the chain twice.

Alice (user) (tx 1) -> 
exchange contract (triggers promise 1) -> 
aggregator contract (triggers promise 2) -> 
pool contact (triggers promise 3) -> 
exchange contract (again)

The exchange contract can identify Alice's account with signer_account_id. However can the exchange contract know about the re-entrancy, namely tx 1 or promise 1, and is it possible to resolve or infer this from the smart contract execution context, so that the exchange would know it is already processing trade for Alice?

Note that Alice may have two chain of promises being processed at the same time, so signer_account_id is not enough uniquely to identify the chain of promises.

I am looking in VMContext and trying to figure out how this is possible.

1

There are 1 best solutions below

0
On BEST ANSWER

In the contract environment, you have to pass all the necessary information through arguments.

Off-chain you can use NEAR Indexer or JSONRPC EXPERIMENTAL_tx_status method to get all the receipts and their outcomes