Categorygithub.com/anchorageoss/tezosprotocol/v3
modulepackage
3.1.0
Repository: https://github.com/anchorageoss/tezosprotocol.git
Documentation: pkg.go.dev

# README

tezosprotocol

godoc CircleCI codecov

An implementation of the Tezos peer-to-peer communications protocol.

Supports offline fee calculation and the parsing, signing, and encoding of Tezos operations.

Installation

$ go get github.com/anchorageoss/tezosprotocol/v3
import "github.com/anchorageoss/tezosprotocol/v3"

Examples

Operation Parsing

Parsing a Tezos wire-format operation:

signedOperationBytes, _ := hex.DecodeString("e655948a282fcfc31b98abe9b37a82038c4c0e9b8e11f60ea0c7b33e6ecc625f6b0002298c03ed7d454a101eb7022bc95f7e5f41ac78e90901904e00004798d2cc98473d7e250c898885718afd2e4efbcb1a1595ab9730761ed830de0f6c0002298c03ed7d454a101eb7022bc95f7e5f41ac78d0860302c8010080c2d72f0000e7670f32038107a59a2b9cfefae36ea21f5aa63c0065667ade71f0c28dcd8c6f443be8b2ff9ebe9f3d2bd8a95d8a29df74319ef24e46bb8abe3e2553dec2a81353f059093861229869ad3c468ade4d9366be3e1308")
var signedOperation tezosprotocol.SignedOperation
_ = signedOperation.UnmarshalBinary(signedOperationBytes)

fmt.Printf("%v\n", signedOperation)
operationHash, _ := signedOperation.GetHash()
fmt.Println(operationHash)

Operation Signing and Encoding

Creating, signing, and encoding a Tezos wire-format operation:

operation := &tezosprotocol.Operation{
	Branch: tezosprotocol.BranchID("BMTiv62VhjkVXZJL9Cu5s56qTAJxyciQB2fzA9vd2EiVMsaucWB"),
	Contents: []tezosprotocol.OperationContents{
		&tezosprotocol.Revelation{
			Source:       tezosprotocol.ContractID("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"),
			Fee:          big.NewInt(1257),
			Counter:      big.NewInt(1),
			GasLimit:     big.NewInt(10000),
			StorageLimit: big.NewInt(0),
			PublicKey:    tezosprotocol.PublicKey("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"),
		},
		&tezosprotocol.Transaction{
			Source:       tezosprotocol.ContractID("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"),
			Fee:          big.NewInt(50000),
			Counter:      big.NewInt(2),
			GasLimit:     big.NewInt(200),
			StorageLimit: big.NewInt(0),
			Amount:       big.NewInt(100000000),
			Destination:  tezosprotocol.ContractID("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN"),
		},
	},
}
privateKey := tezosprotocol.PrivateKey("edskRwAubEVzMEsaPYnTx3DCttC8zYrGjzPMzTfDr7jfDaihYuh95CFrrYj6kyJoqYhycQPXMZHsZR5mPQRtDgjY6KHJxpeKnZ")
signedOperation, _ := tezosprotocol.SignOperation(operation, privateKey)
signedOperationBytes, _ := signedOperation.MarshalBinary()
fmt.Printf("%x\n", signedOperationBytes)

Protocol Upgrades

All backwards-incompatible changes will be handled via standard semantic versioning conventions. Separate tags for the latest stable release for each Tezos protocol will be maintained in parallel.

A separate go module will be published for each Tezos protocol upgrade to support applications migrating between the two.

import (
	babylon "github.com/anchorageoss/tezosprotocol/v3"
	athens "github.com/anchorageoss/tezosprotocol"
)

# Packages

No description provided by the author

# Functions

Base58CheckDecode decodes the given base58check string and returns the payload and prefix.
Base58CheckEncode encodes the given binary payload to base58check.
ComputeMinimumFee returns the minimum fee required according to the constraint: fees >= (minimal_fees + minimal_nanotez_per_byte * size + minimal_nanotez_per_gas_unit * gas) Amount returned is in units of mutez.
NewContractIDFromOrigination returns the address (contract ID) of an account that would be originated by this operation.
NewContractIDFromPublicKey creates a new contract ID from a public key.
NewNamedEntrypoint creates a named entrypoint.
NewPrivateKeyFromCryptoPrivateKey creates a new PrivateKey from a crypto.PrivateKey.
NewPublicKeyFromCryptoPublicKey creates a new PublicKey from a crypto.PublicKey.
SignMessage signs the given text based message using the provided signing key.
SignOperation signs the given tezos operation using the provided signing key.
VerifyMessage verifies the signature on a human readable message.

# Constants

AccountTypeImplicit indicates an implicit account.
AccountTypeOriginated indicates an originated account.
BlockHashLen is the length in bytes of a serialized block hash.
BlockHeaderWatermark is the special byte prepended to serialized block headers before signing.
ContentsTagDelegation is the tag for delegations.
ContentsTagEndorsement is the tag for endorsements.
ContentsTagOrigination is the tag for originations.
ContentsTagRevelation is the tag for revelations.
ContentsTagTransaction is the tag for transactions.
ContractHashLen is the length in bytes of a serialized contract hash.
ContractIDLen is the length in bytes of a serialized contract ID.
ContractIDTagImplicit is the tag for implicit accounts.
ContractIDTagOriginated is the tag for originated accounts.
CustomWatermark is for custom purposes.
DefaultMinimalFees is a flat fee that represents the cost of broadcasting an operation to the network.
DefaultMinimalMutezPerByte is the default fee rate in mutez that nodes expect per byte of a serialized, signed operation -- including header and all contents.
DefaultMinimalMutezPerGasUnit is the default fee rate in mutez that nodes expect per unit gas spent by an operation (and all its contents).
DelegationGasLimit is the gas consumed by a delegation.
DelegationStorageBurn is the amount burned by an account as a consequence of signing a delegation.
DelegationStorageLimitBytes is the storage limit required for delegations.
EndorsementWatermark is the special byte prepended to serialized endorsements before signing.
EntrypointTag values.
EntrypointTag values.
EntrypointTag values.
EntrypointTag values.
EntrypointTag values.
EntrypointTag values.
MinimumTransactionGasLimit is the gas consumed by a transaction with no parameters that does not result in any Michelson code execution.
NewAccountCreationBurn is the cost in mutez burned from an account that signs an operation creating a new account, either by a transferring to a new implicit address or by originating a KT1 address.
NewAccountStorageLimitBytes is the storage needed to create a new account, either implicit or originated.
OperationHashLen is the length in bytes of a serialized operation hash.
OperationSignatureLen is the length in bytes of a serialized operation signature.
OperationWatermark is the special byte prepended to serialized operations before signing.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PrimK_parameter and the remaining constants are adapted from Adapted from https://gitlab.com/tezos/tezos/blob/master/src%2Fproto_alpha%2Flib_protocol%2Fmichelson_v1_primitives.ml They don't follow go's name conventions in order to preserve easy comparison with the original ocaml code and easy updates to keep up with protocol changes The right order is defined in prim_encoding.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PubKeyHashLen is the length in bytes of a serialized public key hash.
PubKeyHashTagEd25519 is the tag for Ed25519 pubkey hashes.
PubKeyHashTagP256 is the tag for P256 pubkey hashes.
PubKeyHashTagSecp256k1 is the tag for Secp256k1 pubkey hashes.
PubKeyLenEd25519 is the length in bytes of a serialized Ed25519 public key.
PubKeyLenP256 is the length in bytes of a serialized P256 public key.
PubKeyLenSecp256k1 is the length in bytes of a serialized Secp256k1 public key.
PubKeyTagEd25519 is the tag for Ed25519 pubkeys.
PubKeyTagP256 is the tag for P256 pubkeys.
PubKeyTagSecp256k1 is the tag for Secp256k1 pubkeys.
RevelationGasLimit is the gas consumed by a revelation.
RevelationStorageBurn is the amount burned by an account as a consequence of signing a revelation.
RevelationStorageLimitBytes is the storage limit required for revelations.
StorageCostPerByte is the amount of mutez burned per byte of storage used.
TaggedPubKeyHashLen is the length in bytes of a serialized, tagged public key hash.
TextWatermark is the special byte prepended to plaintext messages before signing.

# Variables

AllBase58CheckPrefixes is the list of all defined base58check prefixes.
Preset entrypoints (those with an implicit name).
Preset entrypoints (those with an implicit name).
Preset entrypoints (those with an implicit name).
Preset entrypoints (those with an implicit name).
Preset entrypoints (those with an implicit name).
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
PrefixContractHash is referenced from https://gitlab.com/tezos/tezos/blob/master/src/proto_alpha/lib_protocol/contract_hash.ml#L26.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.
Base58Check prefixes.

# Structs

ContractScript models $scripted.contracts.
Delegation models the tezos delegation operation type.
Endorsement models the tezos endorsement operation type.
Entrypoint models $entrypoint.
MichelinePrim likely represents a Michelson primitive in a Micheline expression.
Operation models a tezos operation with variable length contents.
Origination models the tezos origination operation type.
Revelation models the revelation operation type.
SignedOperation represents a signed operation.
Transaction models the tezos transaction type.
TransactionParameters models $X_o.

# Interfaces

MichelineNode represents one node in the tree of Micheline expressions.
OperationContents models one of multiple contents of a tezos operation.
TransactionParametersValue models $X_o.value.

# Type aliases

AccountType is either an implicit account or an originated account.
Base58CheckPrefix in an enum that models a base58check prefix used specifically by tezos.
BranchID encodes a tezos branch ID in base58check encoding.
ContentsTag captures the possible tag values for operation contents.
ContractID encodes a tezos contract ID (either implicit or originated) in base58check encoding.
ContractIDTag captures the possible tag values for $contract_id.
EntrypointTag captures the possible tag values for $entrypoint.Tag.
MichelineBytes represents a byte array in a Micheline expression.
MichelineInt represents an integer in a Micheline expression.
MichelineSeq represents a sequence of nodes in a Micheline expression.
MichelineString represents a string in a Micheline expression.
OperationHash encodes an operation hash in base58check encoding.
PrivateKey encodes a tezos private key in base58check encoding.
PrivateKeySeed encodes a tezos private key seed in base58check encoding.
PubKeyHashTag captures the possible tag values for $public_key_hash.
PubKeyTag captures the possible tag values for $public_key.
PublicKey encodes a tezos public key in base58check encoding.
Signature is a tezos base58check encoded signature.
TransactionParametersValueRawBytes is an interim way to provide the value for transaction parameters, until support for Michelson is added.
Watermark is the first byte of a signable payload that indicates the type of data represented.