Trait exonum::blockchain::Transaction
[−]
[src]
pub trait Transaction: Message + 'static { fn verify(&self) -> bool; fn execute(&self, fork: &mut Fork); fn info(&self) -> Value { ... } }
A trait that describes transaction processing rules (a group of sequential operations
with the Exonum storage) for the given Message
.
Required Methods
fn verify(&self) -> bool
Verifies the transaction, which includes the message signature verification and other specific internal constraints. verify is intended to check the internal consistency of a transaction; it has no access to the blockchain state. If a transaction fails verify, it is considered incorrect and cannot be included into any correct block proposal. Incorrect transactions are never included into the blockchain.
This method should not use external data, that is, it must be a pure function.
fn execute(&self, fork: &mut Fork)
Takes the current blockchain state via fork
and can modify it if certain conditions
are met.
Notes
- When programming
execute
, you should perform state-related checks before any changes to the state and return early if these checks fail. - If the execute method of a transaction raises a
panic
, the changes made by the transactions are discarded, but the transaction itself is still considered committed.
Provided Methods
fn info(&self) -> Value
Returns the useful information about the transaction in the JSON format. The returned value
is used to fill the TxInfo.content
field in the blockchain explorer.
Notes
The default implementation returns null
. For transactions defined with
the message!
macro, you may redefine info()
as
extern crate serde_json; message! { struct MyTransaction { // Transaction definition... } } impl Transaction for MyTransaction { // Other methods... fn info(&self) -> serde_json::Value { serde_json::to_value(self).expect("Cannot serialize transaction to JSON") } }