The Transaction type
Table of contents |
---|
Deploy |
Version1 |
A transaction is an tagged-union type whose variants represent atomic units of work that can be sent to the node for execution.
Currently it consists of two possible variants:
- Deploy
- Version1
Deploy
The Transaction::Deploy variant is equivalent to the 1.x Deploy.
Serializing a Transaction
of variant Deploy
:
- The first byte is a
0
- Next bytes are binary representation of a Deploy
Version1
Transaction::Version1 is the new way that work can be proposed to a node. It's nature is more amorphic than Transaction::Deploy. This type of Transaction uses a self-describing binary serialization scheme (comparing to other Binary Serialization Standard types). The self-describing scheme is called Calltable serialization
in this document. In general, the layout of this new style of transaction is "tagged-union" oriented. An in-depth description of how this self-describing standard works is in the calltable serialization document.
In the scope of this documentation, for abbreviation, we will call these "tagged-unions". Tagged unions are data structures that can define very different internal fields depending on which variant is currently being used. For serialization we denote the variant (effectively - "which variant of the union was created for this instance of the union type") and serialize it alongside the fields. This "variant marking" is stored as a one byte unsigned number and will be referred to in this document as variant discriminator
. The terms serialization_index
and variant discriminator
(which we use in this document) are also explained in the calltable serialization document also.
Serializing a Transaction
of variant Version1
:
- The first byte is a
1
- Next bytes are binary representation of a TransactionV1
TransactionV1
TransactionV1
(serialized using calltable scheme) consists of:
hash
- hash calculated over binary serialization ofpayload
. It'sserialization_index
is0
. In the sense of binary serialization it is a Digestpayload
- of typeTransactionV1Payload
, contains all the actual data that the transaction sends to node. It'sserialization_index
is1
approvals
- collection of Approvals being signatures overhash
. It'sserialization_index
is2
TransactionV1Payload
TransactionV1Payload
(serialized using calltable scheme) consists of:
initiator_addr
- of type InitiatorAddr identifies the initiator of this Transaction. It'sserialization_index
is0
timestamp
- Timestamp identifying the self-declared time of creation for this transaction. It'sserialization_index
is1
ttl
- TimeDiff self-declared period in which the transaction should be included in a block and executed. It'sserialization_index
is2
chain_name
-String
identifying the network name on which this transaction should be executed. It'sserialization_index
is3
pricing_mode
- PricingMode declaration of how the transaction should be payed for. It'sserialization_index
is4
fields
- please see v1.payload.fields section. It'sserialization_index
is5
InitiatorAddr
InitiatorAddr
(serialized using calltable scheme) consists of:
- in variant InitiatorAddr::PublicKey
- variant discriminator of value
0
PublicKey
serialized under serialization key1
- variant discriminator of value
- in variant InitiatorAddr::AccountHash
- variant discriminator of value
1
AccountHash
serialized under serialization key1
- variant discriminator of value
PricingMode
PricingMode
(serialized using calltable scheme) consists of:
- in variant
PaymentLimited
- in variant
Fixed
- in variant
Prepaid
- variant discriminator of value
2
- field
receipt
of type Digest with serialization index1
- variant discriminator of value
Version1.payload.fields
This is an amorphous data holder. It is serialized as a map of key u16
and value Byte
. By u16 we understand an unsigned 2 byte number (see numeric). Byte
a collection of bytes.
The invariants for this field are:
- keys (first tuple entries) are unique
- the collection is ordered ascending by first element of the tuple (u16)
Breaking the above invariants will cause the node to reject the the transaction as malformed.
This field is design in this amorphous way to facilitate the possibility of reshaping (adding, removing) fields in the future while keeping the byte serialization structure compatible. First tuple entries of this collection discern internal fields, second tuple entries are Binary Serialization Standard compliant serializations of data.
Currently the "keys" (first tuple entries) of the fields
map are interpreted as:
- payload with key
0
: an instance ofTransactionArgs
- payload with key
1
: an instance ofTransactionTarget
- payload with key
2
: an instance ofTransactionEntryPoint
- payload with key
3
: an instance ofTransactionScheduling
TransactionTarget
TransactionTarget
(serialized using calltable scheme) consists of:
- in variant
Native
- variant discriminator of value
0
- variant discriminator of value
- in variant
Stored
- variant discriminator of value
1
- field
id
of type TransactionInvocationTarget with serialization index1
- field
runtime
of type TransactionRuntimeParams with serialization index2
- variant discriminator of value
- in variant
Session
- variant discriminator of value
2
- field
is_install_upgrade
of typebool
with serialization index1
- field
module_bytes
of typeBytes
with serialization index2
- field
runtime
of type TransactionRuntimeParams with serialization index2
- variant discriminator of value
TransactionInvocationTarget
TransactionInvocationTarget
(serialized using calltable scheme) consists of:
- in variant
ByHash
- variant discriminator of value
0
HashAddr
with serialization index1
- variant discriminator of value
- in variant
ByName
- variant discriminator of value
1
String
with serialization index1
- variant discriminator of value
- in variant
ByPackageHash
- variant discriminator of value
2
- field
addr
which is a 32 bytes hash digest with serialization index1
- field
version
of typeOption<u32>
(option of 4 bytes unsigned number) with serialization index2
- field
protocol_version_major
of typeu32
(4 bytes unsigned number). It's serialization index is3
. This field is not mandatory - in fact in the reference rust implementation it is defined asOption<u32>
. If it is present it should be serialized asu32
under index3
. But if it's not present, there will be no entry for it at all (both in the calltable section ofTransactionInvocationTarget
or payload)
- variant discriminator of value
- in variant
ByPackageName
- variant discriminator of value
3
- field
name
of typeString
with serialization index1
- field
version
of typeOption<u32>
(option of 4 bytes unsigned number) with serialization index2
- field
protocol_version_major
of typeu32
(4 bytes unsigned number). It's serialization index is3
. This field is not mandatory - in fact in the reference rust implementation it is defined asOption<u32>
. If it is present it should be serialized asu32
under index3
. But if it's not present, there will be no entry for it at all (both in the calltable section ofTransactionInvocationTarget
or payload)
- variant discriminator of value
TransactionRuntimeParams
TransactionRuntimeParams
(serialized using calltable scheme) consists of:
- in variant
VmCasperV1
:- variant discriminator of value
0
- variant discriminator of value
- in variant
VmCasperV2
:- variant discriminator of value
1
- field
transferred_value
of typeu64
(8 bytes unsigned number) with serialization index1
- field
seed
of typeOption<[u8; 32]>
(option of 32 bytes Byte array) with serialization index2
- variant discriminator of value
TransactionEntryPoint
TransactionEntryPoint
(serialized using calltable scheme) consists of:
- in variant
Call
:- variant discriminator of value
0
- variant discriminator of value
- in variant
Custom
:- variant discriminator of value
1
String
with serialization index1
- variant discriminator of value
- in variant
Transfer
:- variant discriminator of value
2
- variant discriminator of value
- in variant
AddBid
:- variant discriminator of value
3
- variant discriminator of value
- in variant
WithdrawBid
:- variant discriminator of value
4
- variant discriminator of value
- in variant
Delegate
:- variant discriminator of value
5
- variant discriminator of value
- in variant
Undelegate
:- variant discriminator of value
6
- variant discriminator of value
- in variant
Redelegate
:- variant discriminator of value
7
- variant discriminator of value
- in variant
ActivateBid
:- variant discriminator of value
8
- variant discriminator of value
- in variant
ChangeBidPublicKey
- variant discriminator of value
9
- variant discriminator of value
- in variant
AddReservations
:- variant discriminator of value
10
- variant discriminator of value
- in variant
CancelReservations
:- variant discriminator of value
11
- variant discriminator of value
- in variant
Burn
:- variant discriminator of value
12
- variant discriminator of value
TransactionScheduling
TransactionScheduling
(serialized using calltable scheme) consists of:
- in variant
Standard
:- variant discriminator of value
0
- variant discriminator of value
Serialization example
Please see this document to see an in-depth step-by-step example of deserializing a transaction
Deserialization example
Please see this document to see an in-depth step-by-step example of deserializing a transaction