Node-side smart contract

The node could execute (or handle specifically) some types of smart contracts on the network, using the customized Java handlers. For example the storage contract is being executed on each node. Such a contract could be distinguished by analysing its definition.extended_type, which, if present, must contain the valid (approved by the node) smart-contract type, otherwise it must be declined.

The valid server-side smart contract implementation implements the NContract Java interface (see  UniversaBlockchain/universa/…/services/ for details).

The node executes such smart contracts in the following way:

If extends the local check:

  • before the check, if the definition.extended_type presents and not known, fail.
  • perform the usual contract check as with a regular contract.
  • call the interface beforeCreate(), beforeUpdate() or beforeRevoke() respectively, It it returns false, fail.

If the network approve the change or revoke the contract, call onCreate(), onUpdate() or onRevoke() respectively. First two return optional Binder with extra data to return to the client as ItemResult#extra#.

The interface implement a query: readonly method calls to get some information from a single node. This is readonly, immutable method that must not change nothing in such smart contract state and associated data and could be called separately on each node.