Provides external public gateway interface (like JSON over HTTP) to the network which is normally used by clients. Since responses are synchronous, maintains a list of all active client sessions.
Currently a single instance per virtual chain per node.
BlockStorage
- Gets the latest committed block height from it and queries old transactions from it.VirtualMachine
- Uses it to execute methods.TransactionPool
- Provides it with new transactions.
- Requests are HTTP POST with JSON body and JSON response.
- See request and response encoding.
- Requests are HTTP GET with all parameters encoded on the URL.
- See request and response encoding.
- Limited to
CallMethod
requests.
Public interface: Run a read only service method without consensus based on the current block height. The call is synchronous.
- Correct request format.
- Correct protocol version.
- Correct virtual chain.
- Get block height for the call by calling
BlockStorage.GetLastCommittedBlockHeight
.- Note that method calls are asynchronous to block creation so execution may end up a few blocks behind the last.
- Optimization: The call to
BlockStorage.GetLastCommittedBlockHeight
can be cached based on time.
- Execute call on the virtual machine by calling
VirtualMachine.RunLocalMethod
. - Return the result.
Public interface: Execute a transaction on a service under consensus that may change state (write). The call is synchronous.
- Correct request format.
- Correct protocol version.
- Correct virtual chain.
- Calculate the transaction
tx_id
(see transaction format for structure). - Send transaction to the network by calling
TransactionPool.AddNewTransaction
. - Block until
ReturnTransactionResults
is called with the relevanttx_id
. - If a configurable timeout expires during the block, fail.
- Note: Beware of having the forwarded transaction fail somewhere else and swallowed without calling
ReturnTransactionResults
.
- Note: Beware of having the forwarded transaction fail somewhere else and swallowed without calling
Called by transaction pool on committed blocks to let public api respond to their waiting clients.
- For every transaction:
- Locate the relevant blocking
SendTransaction
contexts based on thetx_id
. - Unblock them to respond to the client using the data from the transaction receipt.
- Locate the relevant blocking
Public interface: Query the status of previously sent transaction.
- Correct request format.
- Correct protocol version.
- Correct virtual chain.
- Check the transaction timestamp, verifying that it's not a future transaction plus configurable grace (eg. 5 sec).
- Query the transactions pool by calling
TransactionPool.GetTransactionReceipt
.- If found return status
PENDING
, if committed return statusCOMMITTED
with the receipt.
- If found return status
- If not found in transaction pool, it might be an older transaction, widen our search.
- Query the block storage by calling
BlockStorage.GetTransactionReceipt
.- If found return status
COMMITTED
with the receipt, else return statusNO_RECORD_FOUND
.
- If found return status