Codec
Construct and serialize Tezos operations
The
codec
package can produce compliant binary encodings of all Tezos operation types and for different protocols. The default setting will always use the most recent Mainnet protocol as defined in tezos.DefaultParams
. If necessary for use with a sandbox or an old testnet, you can use one of the alternative testnet params or even define your own and use them in op.WithParams()
package tezos
var (
// DefaultParams defines the blockchain configuration for Mainnet under the latest
// protocol. It is used to generate compliant transaction encodings. To change,
// either overwrite this default or set custom params per operation using
// op.WithParams().
DefaultParams = NewParams().
Network: "Mainnet",
ChainId: Mainnet,
Protocol: ProtoV016_2,
Version: 16,
OperationTagsVersion: 2,
MaxOperationsTTL: 240,
HardGasLimitPerOperation: 1040000,
HardGasLimitPerBlock: 2600000,
OriginationSize: 257,
CostPerByte: 250,
HardStorageLimitPerOperation: 60000,
MinimalBlockDelay: 15 * time.Second,
PreservedCycles: 5,
)
Codec defines a list of helpers to simplify the creation, configuration and concatenation of operation groups. The canonical way to use this package is to
- 1.Create a new operation group container
NewOp()
- 2.Add contents, i.e. concrete operations
WithContents()
adds a generic operation at the endWithContentsFront()
adds a generic operation at the front (useful for reveal)WithTransfer()
adds a tez transferWithCall()
/WithCallExt()
adds a contract callWithOrigination()
/WithOriginationExt()
adds a contract originationWithDelegation()
/WithUndelegation()
/WithRegisterBaker()
adds a delegationWithRegisterConstant()
adds a constant registration
- 3.Add configuration options
WithParams()
defines protocol and network to use for encodingWithTTL()
defines a maximum TTLWithBranch()
adds a branch for direct TTL controlWithSource()
sets a common source for all manager operations
- 4.Read and apply limits from simulation
Limits()
returns an array or current limits for each contained manager operationWithLimits()
adds gas/storage/fee limits to manager operations
- 5.Sign the operation group
Sign()
to directly sign the operation with a provided private key, orDigest()
to get watermarked bytes for external signingWithSignature()
to add the externally created signature
- 6.Get signed data for injection
Bytes()
returns encoded content of an unsigned or signed operation
For maximum control, all operation types can be constructed by allocating and filling their respective structs, then adding them as pointer to
op.WithContents()
.Last modified 5mo ago