Major Structures
Account
An Account is a structure that represented a user on a legacy Casper network. Alongside the Condor protocol release, Accounts were replaced with AddressableEntities of the type Account. The account structure consists of the following fields:
-
main_purse: The account's main purseURef. You may find information onURefserialization here.
AddressableEntity
An Addressable Entity is a structure that represents an entity on a Casper network. The addressable entity consists of the following fields:
-
main_purse: The entity's main purseURef. You may find information onURefserialization here.
Block
A block is the core component of the Casper linear blockchain, used in two contexts:
- A data structure containing a collection of transactions. Blocks form the primary structure of the blockchain.
- A message that is exchanged between nodes containing the data structure as explained in (1).
Each block has a globally unique ID, achieved by hashing the contents of the block.
Each block points to its parent. An exception is the first block, which has no parent.
A block is structurally defined as follows:
hash: A hash over the header of the block.header: The header of the block that contains information about the contents of the block with additional metadata.body: The block's body contains the proposer of the block and hashes of deploys and transfers contained within it.
Further, a block may consist of one of the following types:
-
Version1: A legacy block created prior to the Condor upgrade. -
Version2: A modern block.
BlockHash
The block hash is a Digest over the contents of the block Header. The BlockHash serializes as the byte representation of the hash itself.
BlockHeader
The header portion of a block, structurally, is defined as follows:
parent_hashis the hash of the parent block. It serializes to the byte representation of the parent hash. The serialized buffer of theparent_hashis 32 bytes long.state_root_hashis the global state root hash produced by executing this block's body. It serializes to the byte representation of thestate root hash. The serialized buffer of thestate_root_hashis 32 bytes long.body_hashthe hash of the block body. It serializes to the byte representation of the body hash. The serialized buffer of thebody_hashis 32 bytes long.random_bitis a boolean needed for initializing a future era. It is serialized as a single byte; true maps to 1, while false maps to 0.accumulated_seedis a seed needed for initializing a future era. It serializes to the byte representation of the parent Hash. The serialized buffer of theaccumulated_hashis 32 bytes long.era_endcontains equivocation and reward information to be included in the terminal finalized block. It is an optional field. Thus if the field is set asNone, it serializes to 0. The serialization of the other case is described in the EraEnd.timestampThe timestamp from when the block was proposed. It serializes as a singleu64value. The serialization of au64value is described in the CLValues section.era_idEra ID in which this block was created. It serializes as a singleu64value.heightThe height of this block, i.e., the number of ancestors. It serializes as a singleu64value.protocol_versionThe version of the Casper network when this block was proposed. It is 3-element tuple containingu32values. It serializes as a buffer containing the threeu32serialized values. Refer to the CLValues section on howu32values are serialized.
Both BlockHeaderV1 and BlockHeaderV2 serialize in the same way.
EraEndV1
EraEndV1 as represented within the block header, is a struct containing two fields.
era_report: The first field is termed asEraReportand contains information about equivocators and rewards for an era.next_era_validator_weights: The second field is map for the validators and their weights for the era to follow.
EraReport itself contains two fields:
equivocators: A vector ofPublicKey.rewards: A Binary Tree Map ofPublicKeyandu64.inactive_validators: A vector ofPublicKey.
When serializing an EraReport, the buffer is first filled with the individual serialization of the PublicKey contained within the vector.
- If the
PublicKeyis anEd25519key, the first byte within the buffer is a1followed by the individual bytes of the serialized key. - If the
PublicKeyis anSecp256k1key, the first byte within the buffer is a2followed by the individual bytes of the serialized key.
When serializing the overarching struct of EraEndV1, we first allocate a buffer, which contains the serialized representation of the EraReport as described above, followed by the serialized BTreeMap.
Note that EraEndV1 is an optional field. Thus the above scheme only applies if there is an EraEndV1; if there is no era end, the field simply serializes to 0.
EraEndV2
EraEndV1 as represented within the block header, is a struct containing four fields.
equivocators: A vector ofPublicKeylisting equivocators for the era.inactive_validators: A list of inactive validators for the era.next_era_validator_weights: A map of validators and their weights for the era to follow.rewards: A Binary Tree Map ofPublicKeyandu64.next_era_gas_price: The next era's gas price as au8.
Note that EraEndV2 is an optional field. Thus the above scheme only applies if there is an EraEndV2; if there is no era end, the field simply serializes to 0.
BlockBodyV1
The body portion of a block, prior to the Condor upgrade, is structurally defined as:
proposer: The PublicKey which proposed this block.deploy_hashes: Is a vector of hex-encoded hashes identifying Deploys included in this block.transfer_hashes: Is a vector of hex-encoded hashes identifying Transfers included in this block.
When we serialize the BlockBodyV1, we create a buffer that contains the serialized representations of the individual fields present within the block.
proposerserializes to the byte representation of thePublicKey. If thePublicKeyis anEd25519key, then the first byte within the serialized buffer is 1 followed by the bytes of the key itself; else, in the case ofSecp256k1, the first byte is 2.deploy_hashesserializes to the byte representation of all the deploy_hashes within the block header. Its length is32 * n, where n denotes the number of deploy hashes present within the body.transfer_hashesserializes to the byte representation of all the deploy_hashes within the block header. Its length is32 * n, where n denotes the number of transfers present within the body.
BlockBodyV2 {blockbodyv2}
A modern block is structurally defined as:
-
transactions: Is aBTreeMapof transaction hashes and their given categories. It is serialized as aBTreeMapwhere the first 4 bytes represent au32value describing the number of values held within. The remainder consists of a repeating pattern of transaction categories as au8value and then the associatedTransactionHashthe category tag describes. -
rewarded_signatures: A list of identifiers for finality signatures for a particular past block. It serializes as a vector ofSingleBlockRewardedSignatureswhich describes signatures for a single ancestor block. The first entry represents the signatures for the parent block, the second for the parent of the parent, and so on.
Contract
A contract struct containing the following fields:
ContractPackageHash
A blake2b hash of a contract package. The contract package hash serializes as a 32-byte buffer containing the bytes of the contract package hash.
ContractWasmHash
A blake2b hash of a contract's Wasm. The contract's Wasm hash serializes as a 32-byte buffer containing the bytes of the contract's Wasm hash.
ContractHash
A blake2b hash of a contract. The contract hash serializes as a 32-byte buffer containing the bytes of the contract hash.
ContractPackageStatus
The lock status of the contract package, serialized as a boolean where true indicates a locked contract and false indicates an unlocked contract package.
ContractVersion
The version of the contract.
-
contract_hash: The contract hash of the contract. -
contract_version: The version of the contract within the protocol major version. It serializes as au32value. -
protocol_version_major: The major element of the protocol version this contract is compatible with. It serializes as au32value.
ContractVersionKey
The major element of ProtocolVersion combined with Contract Version serialized as two u32 values.
ContractWasm
A container for a contract's Wasm bytes, serialized as the byte representation of itself.
Message
A message emitted by an addressable entity during execution. The message struct contains the following fields:
-
entity_hash: The identity of the entity that produced the message, serialized as anEntityAddr. -
message: The payload of the message, serialized as aMessagePayload. -
topic_name: The name of the topic on which the message was emitted, serialized as aString. -
topic_name_hash: The hash of the topic name, serialized as aTopicNameHash. -
topic_index: The message index in the topic, serialized as au32value. -
block_index: The message index in the block, serialized as au64value.
MessageAddr
A message topic address, a structure which consists of the following fields:
-
entity_addr: The entity address, serialized as anEntityAddr. -
topic_name_hash: The hash of the topic name, serialized as aTopicNameHash. -
message_index: The message index, serialized as anOptionofu32.
MessageChecksum
A newtype wrapping an array which contains the raw bytes of the hash of the message emitted. It serializes as a CLType u8 tag followed by a ByteArray.
MessageLimits
Configuration for message lists, serialized as three u32 values:
-
max_topic_name_size: Maximum size in bytes of a topic name string. -
max_message_size: Maximum message size in bytes. -
max_topics_per_contract: Maximum number of topics that a contract can register.
MessagePayload
The payload of a message emitted by an addressable entity during execution. It serializes as either a u8 tag of 0 followed by a a serialized version of a human-readable String, or as a u8 tag of 1 followed by serialized raw Bytes.
MessageTopicOperation
Operations that can be performed on message topics. Currently, serializes as a u8 of 0 representing the Add function.
TopicNameHash
The hash of the name of a message topic, serialized as a u8 describing the length of the string and the 32-byte serialized representation of the string itself.
Transaction
A versioned wrapper for a transaction or deploy. It serializes as a u8 tag of 0 followed by a Deploy or a u8 tag of 1 followed by a TransactionV1.
Deploy
A deploy is a data structure containing a smart contract and the requester's signature(s). Additionally, the deploy header contains additional metadata about the deploy itself. A deploy is structurally defined as follows:
hash: The hash of the deploy header.header: Contains metadata about the deploy. The structure of the header is detailed further in this document.payment: The payment code for contained smart contract.session: The stored contract itself.approvals: A list of signatures.
DeployHash
The deploy hash is a digest over the contents of the deploy header. The deploy hash serializes as the byte representation of the hash itself.
DeployHeader
account: A supported public key variant (currently eitherEd25519orSecp256k1). AnEd25519key is serialized as a buffer of bytes, with the leading byte being1forEd25519, with remainder of the buffer containing the byte representation of the signature. Correspondingly, aSecp256k1key is serialized as a buffer of bytes, with the leading byte being2.timestamp: A timestamp is a struct that is a unary tuple containing au64value. This value is a count of the milliseconds since the UNIX epoch. Thus the value1603994401469serializes as0xbd3a847575010000ttl: The Time to live is defined as the amount of time for which deploy is considered valid. Thettlserializes in the same manner as the timestamp.gas_price: The gas isu64value which is serialized asu64CLValue discussed below.body_hash: Body hash is a hash over the contents of the deploy body, which includes the payment, session, and approval fields. Its serialization is the byte representation of the hash itself.dependencies: Dependencies is a vector of deploy hashes referencing deploys that must execute before the current deploy can be executed. It serializes as a buffer containing the individual serialization of each DeployHash within the Vector.chain_name: Chain name is a human-readable string describing the name of the chain as detailed in the chainspec. It is serialized as a String CLValue described below.
Approval
Approval contains two fields:
signer: The public key of the approvals signer. It serializes to the byte representation of thePublicKey. If thePublicKeyis anEd25519key, then the first byte within the serialized buffer is 1 followed by the bytes of the key itself; else, in the case ofSecp256k1, the first byte is 2.signature: The approval signature, which serializes as the byte representation of theSignature. The first byte within the signature is 1 in the case of anEd25519signature or 2 in the case ofSecp256k1.
ApprovalsHash
The cryptographic hash of the bytesrepr-encoded set of approvals. It serializes as a digest.
DeployInfo
Information relating to a given deploy. The structure consists of the following fields:
-
deploy_hash: The hash of the relevant deploy, serialized as a byte representation of the hash itself. -
transfers: Transfers performed by the deploy, serialized as aList. -
from: The account identifier of the creator of the deploy, serialized as anaccount_hash. -
source: The source purse used for payment of the deploy, serialized as aURef. -
gas: The gas cost of executing the deploy, serialized as aU512.
DeployConfig
A struct containing configuration values associated with deploys. The structure contains the following fields:
-
max_payment_cost: The maximum amount any deploy can pay, serialized inMotes. -
max_dependencies: The maximum time to live any deploy can specify, serialized as au8. -
payment_args_max_length: The maximum length in bytes of payment args per deploy, serialized as au32 -
session_args_max_length: The maximum length in bytes of session args per deploy, serialized as au32
TransactionV1
A unit of work sent by a client to the network, which when executed can cause global state to be altered. It is structurally defined as follows:
-
approvals: A list of signatures.
TransactionV1Hash
The transaction hash is a digest over the contents of the transaction header. The transaction hash serializes as the byte representation of the hash itself.
TransactionV1Header
The header portion of a transaction, structurally, is defined as follows:
chain_name: Chain name is a human-readable string describing the name of the chain as detailed in the chainspec. It is serialized as a String.timestamp: A timestamp is a struct that is a unary tuple containing au64value. This value is a count of the milliseconds since the UNIX epoch. Thus the value1603994401469serializes as0xbd3a847575010000.ttl: The Time to live is defined as the amount of time for which the transaction is considered valid. Thettlserializes in the same manner as the timestamp.body_hash: Body hash is a hash over the contents of the transaction body. It serializes as the byte representation of the hash itself.pricing_modeinitator_addr
TransactionV1Body
The body of a TransactionV1, consisting of the following:
TransactionRuntime
The runtime used to execute a transaction, serialized as a u8. Currently, only the VmCasperV1 is available, which serializes as a 0.
TransactionEntryPoint
An entry point of a transaction, serialized as a u8 value based on the type of entry point. The following table outlines the available types:
| Tag | Entry Point |
|---|---|
| 0 | Custom |
| 1 | Transfer |
| 2 | Add_Bid |
| 3 | Withdraw_Bid |
| 4 | Delegate |
| 5 | Undelegate |
| 6 | Redelegate |
| 7 | Activate_Bid |
| 8 | ChangePublicKey |
| 9 | Call |
TransactionConfig
A struct containing configuration values associated with Transactions. The structure contains the following fields:
-
max_ttl: The maximum time to live any transaction can specify, serialized as aTimeDiff. -
block_max_approval_count: The maximum number of approvals (signatures) allowed in a block across all transactions, serialized as au32. -
max_block_size: The maximum possible size in bytes of a block, serialized as au32. -
block_gas_limit: The maximum sum of payment across al transactions included in a block, serialized as au64. -
native_transfer_minimum_motes: The minimum token amount for a native transfer deploy or transaction, serialized as au64. -
max_timestamp_leeway: The maximum value to which atransaction_acceptor.timestamp_leewaycan be set in the config.toml file. -
deploy_config: Configuration values specific to Deploy transactions. -
transaction_v1_config: Configuration values specific to V1 transactions.
TransactionV1Config
A struct containing configuration values associated with TransactionV1s. The structure contains the following fields:
-
native_mint_lane: The lane configuration for the native mint interaction, serializing as a vector ofu64values. -
native_auction_lane: The lane configuration for the native auction interaction, serializing as a vector ofu64values. -
wasm_lanes: The lane configuration for the Wasm-based lanes, serializing as a nested vector ofu64values.
TransactionHash
A versioned wrapper for transaction hash or deploy hash. It serializes as either a u8 tag of 0 followed by a DeployHash or a u8 tag of 1 followed by a TransactionV1Hash.
TransactionHeader
A versioned wrapper for transaction header or deploy header. It serializes as either a u8 tag of 0 followed by a DeployHeader or a u8 tag of 1 followed by a TransactionV1Header.
TransactionId
The unique identifier of a Transaction, serialized as its TransactionHash and ApprovalsHash.
TransactionScheduling
The scheduling mode of a transaction, serialized as a u8 tag identifying the type:
-
Standardserializes as a0. -
FutureEraserializes as a1followed by a futureera_id. -
FutureTimestampserializes as a2followed by a futuretimestamp.
TransactionInvocationTarget
The identifier of a stored transaction target, serialized as one of the following:
-
InvocableEntityserializes as au8tag of0followed by the hex-encoded entity address serialized as the byte representation of itself. -
InvocableEntityAliasserializes as au8tag of1followed by the alias serialized as astring. -
Packageserializes as au8tag of2followed by thepackage hashand optionally theentity_version. -
PackageAliasserializes as au8tag of3followed by the alias serialized as astringand optionally theentity_version.
TransactionTarget
The execution target of a transaction, serializing as a u8 that identifies the type, followed by any additional data.
-
nativeserializes as a0. -
sessionserializes as a2followed by thekind,module_bytesandruntime.
TransactionWithExecutionInfo
A struct containing aTransaction with execution info. It serializes as a Transaction followed by an Option of ExecutionInfo.