pub struct ErgoBox {
    pub value: BoxValue,
    pub ergo_tree: ErgoTree,
    pub tokens: Vec<Token, Global>,
    pub additional_registers: NonMandatoryRegisters,
    pub creation_height: u32,
    pub transaction_id: TxId,
    pub index: u16,
    /* private fields */
}
Expand description

Box (aka coin, or an unspent output) is a basic concept of a UTXO-based cryptocurrency. In Bitcoin, such an object is associated with some monetary value (arbitrary, but with predefined precision, so we use integer arithmetic to work with the value), and also a guarding script (aka proposition) to protect the box from unauthorized opening.

In other way, a box is a state element locked by some proposition (ErgoTree).

In Ergo, box is just a collection of registers, some with mandatory types and semantics, others could be used by applications in any way. We add additional fields in addition to amount and proposition~(which stored in the registers R0 and R1). Namely, register R2 contains additional tokens (a sequence of pairs (token identifier, value)). Register R3 contains height specified by user (protocol checks if it was <= current height when transaction was accepted) and also transaction identifier and box index in the transaction outputs. Registers R4-R9 are free for arbitrary usage.

A transaction is unsealing a box. As a box can not be open twice, any further valid transaction can not be linked to the same box.

Fields

value: BoxValue

amount of money associated with the box

ergo_tree: ErgoTree

guarding script, which should be evaluated to true in order to open this box

tokens: Vec<Token, Global>

secondary tokens the box contains

additional_registers: NonMandatoryRegisters

additional registers the box can carry over

creation_height: u32

height when a transaction containing the box was created. This height is declared by user and should not exceed height of the block, containing the transaction with this box.

transaction_id: TxId

id of transaction which created the box

index: u16

number of box (from 0 to total number of boxes the transaction with transactionId created - 1)

Implementations

Maximum number of tokens in the box

Crate new box

Box id (Blake2b256 hash of serialized box)

Create ErgoBox from ErgoBoxCandidate by adding transaction id and index of the box in the transaction

Get register value

Returns tokens as tuple of byte array and amount as primitive types

Returns serialized ergo_tree guarding this box

Tuple of height when block got included into the blockchain and transaction identifier with box index in the transaction outputs serialized to the byte array.

Returns serialized ErgoBox without tx_id and index

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Box value

Tokens (ids and amounts)

Id of the ergo box

Performs the conversion.

Performs the conversion.

get SType

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Write self to the given writer. This function has a sigma_ prefix to alert the reader that the serialization in use is consensus-critical serialization Read more

Try to read self from the given reader. sigma- prefix to alert the reader that the serialization in use is consensus-critical Read more

Serialize any SigmaSerializable value into bytes

Parse self from the bytes

Extract the value or return an error if type does not match

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Compare self to key and return true if they are equal.

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Should always be Self

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Attempts to convert self into T using TryInto<T>. Read more

Extract the value or return an error if type does not match

Extract value of the given type from any type (e.g. [‘Constant’], [super::value::Value]) on which [TryExtractFrom] is implemented Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.