extrinsic

package
v0.0.0-...-ec75c2a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrEncodeToHex          = libErr.Error("encode to hex")
	ErrScaleEncode          = libErr.Error("scale encode")
	ErrInvalidVersion       = libErr.Error("invalid version")
	ErrPayloadCreation      = libErr.Error("payload creation")
	ErrPayloadMutation      = libErr.Error("payload mutation")
	ErrMultiAddressCreation = libErr.Error("multi address creation")
	ErrPayloadSigning       = libErr.Error("payload signing")
)
View Source
const (
	BitSigned   = 0x80
	BitUnsigned = 0

	UnmaskVersion = 0x7f

	DefaultVersion = 1
	VersionUnknown = 0 // v0 is unknown
	Version1       = 1
	Version2       = 2
	Version3       = 3
	Version4       = 4
)
View Source
const (
	ErrCallEncoding                    = libErr.Error("call encoding")
	ErrSignedFieldNotMutated           = libErr.Error("signed field not mutated")
	ErrPayloadSignedFieldEncoding      = libErr.Error("signed field encoding")
	ErrSignedExtraFieldNotMutated      = libErr.Error("signed extra field not mutated")
	ErrSignedExtraFieldEncoding        = libErr.Error("signed extra field encoding")
	ErrPayloadNil                      = libErr.Error("payload is nil")
	ErrPayloadEncoding                 = libErr.Error("payload encoding")
	ErrSignedExtensionTypeNotDefined   = libErr.Error("signed extension type not defined")
	ErrSignedExtensionTypeNotSupported = libErr.Error("signed extension type not supported")
)
View Source
const (
	ErrSignatureFieldEncoding = libErr.Error("signature field encoding failed")
)

Variables

View Source
var PayloadMutatorFns = map[extensions.SignedExtensionName]PayloadMutatorFn{
	extensions.CheckMortalitySignedExtension: func(payload *Payload) {
		payload.SignedFields = append(payload.SignedFields, &SignedField{
			Name:  EraSignedField,
			Value: &types.ExtrinsicEra{},
		})
		payload.SignedExtraFields = append(payload.SignedExtraFields, &SignedField{
			Name:  BlockHashSignedField,
			Value: &types.Hash{},
		})
	},
	extensions.CheckEraSignedExtension: func(payload *Payload) {
		payload.SignedFields = append(payload.SignedFields, &SignedField{
			Name:  EraSignedField,
			Value: &types.ExtrinsicEra{},
		})
		payload.SignedExtraFields = append(payload.SignedExtraFields, &SignedField{
			Name:  BlockHashSignedField,
			Value: &types.Hash{},
		})
	},
	extensions.CheckNonceSignedExtension: func(payload *Payload) {
		payload.SignedFields = append(payload.SignedFields, &SignedField{
			Name:  NonceSignedField,
			Value: types.U32(0),
		})
	},
	extensions.ChargeTransactionPaymentSignedExtension: func(payload *Payload) {
		payload.SignedFields = append(payload.SignedFields, &SignedField{
			Name:  TipSignedField,
			Value: types.NewUCompactFromUInt(0),
		})
	},
	extensions.ChargeAssetTxPaymentSignedExtension: func(payload *Payload) {
		payload.SignedFields = append(payload.SignedFields, &SignedField{
			Name:  TipSignedField,
			Value: types.NewUCompactFromUInt(0),
		})
		payload.SignedFields = append(payload.SignedFields, &SignedField{
			Name:  AssetIDSignedField,
			Value: types.NewEmptyOption[types.AssetID](),
		})
	},
	extensions.CheckMetadataHashSignedExtension: func(payload *Payload) {
		payload.SignedFields = append(payload.SignedFields, &SignedField{
			Name:  CheckMetadataHashModeSignedField,
			Value: extensions.CheckMetadataModeDisabled,
		})
		payload.SignedExtraFields = append(payload.SignedExtraFields, &SignedField{
			Name:  CheckMetadataHashSignedField,
			Value: &extensions.CheckMetadataHash{},
		})
	},
	extensions.CheckSpecVersionSignedExtension: func(payload *Payload) {
		payload.SignedExtraFields = append(payload.SignedExtraFields, &SignedField{
			Name:  SpecVersionSignedField,
			Value: types.U32(0),
		})
	},
	extensions.CheckTxVersionSignedExtension: func(payload *Payload) {
		payload.SignedExtraFields = append(payload.SignedExtraFields, &SignedField{
			Name:  TransactionVersionSignedField,
			Value: types.U32(0),
		})
	},
	extensions.CheckGenesisSignedExtension: func(payload *Payload) {
		payload.SignedExtraFields = append(payload.SignedExtraFields, &SignedField{
			Name:  GenesisHashSignedField,
			Value: &types.Hash{},
		})
	},

	extensions.CheckNonZeroSenderSignedExtension:          func(payload *Payload) {},
	extensions.CheckWeightSignedExtension:                 func(payload *Payload) {},
	extensions.PreBalanceTransferExtensionSignedExtension: func(payload *Payload) {},
	extensions.StorageWeightReclaimSignedExtension:        func(payload *Payload) {},
	extensions.PrevalidateAttestsSignedExtension:          func(payload *Payload) {},
	extensions.CheckNetworkMembershipSignedExtension:      func(payload *Payload) {},
}

PayloadMutatorFns is a map that holds a PayloadMutatorFn for each supported signed extension.

Functions

This section is empty.

Types

type Extrinsic

type Extrinsic struct {
	// Version is the encoded version flag (which encodes the raw transaction version
	// and signing information in one byte).
	Version byte
	// Signature is the extrinsic signature.
	Signature *Signature
	// Method is the call this extrinsic wraps
	Method types.Call
}

Extrinsic is an extrinsic type that can be used on chains that have a custom signed extension logic.

func NewExtrinsic

func NewExtrinsic(c types.Call) Extrinsic

NewExtrinsic creates a new Extrinsic from the provided Call.

func (Extrinsic) Encode

func (e Extrinsic) Encode(encoder scale.Encoder) error

func (Extrinsic) IsSigned

func (e Extrinsic) IsSigned() bool

IsSigned returns true if the extrinsic is signed

func (Extrinsic) MarshalJSON

func (e Extrinsic) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON encoded byte array of Extrinsic.

func (Extrinsic) Type

func (e Extrinsic) Type() uint8

Type returns the raw transaction version (not flagged with signing information)

type Payload

type Payload struct {
	EncodedCall       types.BytesBare
	SignedFields      []*SignedField
	SignedExtraFields []*SignedField
}

Payload holds the encoded types.Call and the fields that are used for generating the Extrinsic payload and signature.

Notes - the ordering of the SignedFields and SignedExtraFields is the order in which they are provided in the metadata.

func (*Payload) Encode

func (p *Payload) Encode(encoder scale.Encoder) error

Encode the call bytes and the signed fields in the order that is provided during creation from the metadata.

The function also performs an extra check to ensure that all required fields were mutated.

func (*Payload) MutateSignedFields

func (p *Payload) MutateSignedFields(vals SignedFieldValues) error

MutateSignedFields is mutating the payload's SignedFields and SignedExtraFields based on the provided SignedFieldValues.

type PayloadMutatorFn

type PayloadMutatorFn func(payload *Payload)

PayloadMutatorFn is the type used for mutating the Payload during creation.

type Signature

type Signature struct {
	Signer       types.MultiAddress
	Signature    types.MultiSignature
	SignedFields []*SignedField
}

Signature holds all the relevant fields for an extrinsic signature.

func (Signature) Encode

func (s Signature) Encode(encoder scale.Encoder) error

Encode is encoding the Signer, Signature, and SignedFields.

Note - the ordering of the SignedFields is the order in which they are provided in the metadata.

type SignedField

type SignedField struct {
	// Name of the field, this is omitted when the extrinsic is signed.
	Name SignedFieldName

	// Value of the field used when the extrinsic is signed.
	Value any

	// Mutated is used to keep track of changes done to the field.
	Mutated bool
}

SignedField represents a field used in the Payload.

type SignedFieldName

type SignedFieldName string

SignedFieldName is the type used for representing a field name.

const (
	EraSignedField                   SignedFieldName = "era"
	BlockHashSignedField             SignedFieldName = "block_hash"
	NonceSignedField                 SignedFieldName = "nonce"
	TipSignedField                   SignedFieldName = "tip"
	AssetIDSignedField               SignedFieldName = "asset_id"
	CheckMetadataHashModeSignedField SignedFieldName = "check_metadata_hash_mode"
	CheckMetadataHashSignedField     SignedFieldName = "check_metadata_hash"
	SpecVersionSignedField           SignedFieldName = "spec_version"
	TransactionVersionSignedField    SignedFieldName = "transaction_version"
	GenesisHashSignedField           SignedFieldName = "genesis_hash"
)

type SignedFieldValues

type SignedFieldValues map[SignedFieldName]any

SignedFieldValues is a map that holds a value for a particular SignedFieldName.

type SigningOption

type SigningOption func(vals SignedFieldValues)

SigningOption is the type used for providing values to a SignedFieldValues map.

func WithAssetID

func WithAssetID(assetID types.Option[types.AssetID]) SigningOption

WithAssetID returns a SigningOption that is used to add the asset ID to a Payload.

func WithEra

func WithEra(era types.ExtrinsicEra, blockHash types.Hash) SigningOption

WithEra returns a SigningOption that is used to add the era and block hash to a Payload.

func WithGenesisHash

func WithGenesisHash(genesisHash types.Hash) SigningOption

WithGenesisHash returns a SigningOption that is used to add the genesis hash to a Payload.

func WithMetadataMode

func WithMetadataMode(mode extensions.CheckMetadataMode, metadataHash extensions.CheckMetadataHash) SigningOption

WithMetadataMode returns a SigningOption that is used to add the check metadata mode and hash to a Payload.

func WithNonce

func WithNonce(nonce types.UCompact) SigningOption

WithNonce returns a SigningOption that is used to add the nonce to a Payload.

func WithSpecVersion

func WithSpecVersion(specVersion types.U32) SigningOption

WithSpecVersion returns a SigningOption that is used to add the spec version to a Payload.

func WithTip

func WithTip(tip types.UCompact) SigningOption

WithTip returns a SigningOption that is used to add the tip to a Payload.

func WithTransactionVersion

func WithTransactionVersion(transactionVersion types.U32) SigningOption

WithTransactionVersion returns a SigningOption that is used to add the transaction version to a Payload.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL