Product Note: Transactions Related API Usage Patterns (Spacemesh 0.2)
- Client should locally store the ids of all transactions it is interested in, and transaction data for these transactions.
- Clients should update these data based on api results.
Stateful clients such as Smapp should use the following api patterns for working with transactions:
- Read
transaction ids set
from local store. - Call
TransactionService::TransactionsState(ids)
with thetransactions ids set
as input. The goal is to get the currentTransactionState
. Update local transaction data store based on results of call (see below for more info). - Call
MeshService::AccountMeshDataQuery(accountId)
for each of the client's user accounts in order to get mesh transactions the client doesn't know about yet that touch any of the user's accounts, e.g., inbound transactions from another account/user. Update the local transaction data store with the transaction ids in the results (including their layer numbers). - Subscribe to
Transaction::TransactionsStateStream(ids)
usingtransactions ids set
. Update the locally stored transactions store with new streaming data. This is required to receive updated TransactionState for all transactions that the client is interested in. - Subscribe to
MeshService:: AccountMeshDataStream(accountId)
for all local accounts of interest. Update the locally stored transactions based new streaming results. This is required to updateLayerId
for transactions the user cares about. This happens when transactions get included in the mesh or when the mesh is reorganized.
Note: in practice it may make sense to do this in reverse order, i.e., to subscribe to the streams before running the queries, to ensure that no data are missed between the initial queries and the stream subscription.
- Store should include
transactions ids set
and transaction data for each transaction. - When a new transaction is added to the store, its id should be added to the
transactions ids set
. - Transactions created and submitted by the client should be added to the store.
- Store should be updated with new results from
TransactionService
andMeshService
api calls. - If
TransactionState
isTRANSACTION_STATE_MESH
orTRANSACTION_STATE_PROCESSED
in data returned for a transaction from aTransactionService
api, then client should callMeshService:: AccountMeshDataQuery()
for that transaction in order to get its layer id from the node and update layer id in the local store.