TzGo
Search…
Codec
Construct and serialize Tezos operations
Visit the Go Doc docu or read the source code on Github.
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().
ForNetwork(Mainnet).
ForProtocol(ProtoV012_2).
Mixin(&Params{
OperationTagsVersion: 2,
MaxOperationsTTL: 120,
HardGasLimitPerOperation: 1040000,
HardGasLimitPerBlock: 5200000,
OriginationSize: 257,
CostPerByte: 250,
HardStorageLimitPerOperation: 60000,
MinimalBlockDelay: 30 * time.Second,
})
)

Assembling Operations

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. 1.
    Create a new operation group container NewOp()
  2. 2.
    Add contents, i.e. concrete operations
    • WithContents() adds a generic operation at the end
    • WithContentsFront() adds a generic operation at the front (useful for reveal)
    • WithTransfer() adds a tez transfer
    • WithCall() / WithCallExt() adds a contract call
    • WithOrigination()/ WithOriginationExt() adds a contract origination
    • WithDelegation() / WithUndelegation() / WithRegisterBaker() adds a delegation
    • WithRegisterConstant() adds a constant registration
  3. 3.
    Add configuration options
    • WithParams() defines protocol and network to use for encoding
    • WithTTL() defines a maximum TTL
    • WithBranch()adds a branch for direct TTL control
    • WithSource() sets a common source for all manager operations
  4. 4.
    Read and apply limits from simulation
    • Limits() returns an array or current limits for each contained manager operation
    • WithLimits()adds gas/storage/fee limits to manager operations
  5. 5.
    Sign the operation group
    • Sign() to directly sign the operation with a provided private key, or
    • Digest() to get watermarked bytes for external signing
    • WithSignature() to add the externally created signature
  6. 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().
Copy link