interfaces

package
v0.0.0-...-020e20f Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package interfaces defines commonly used interfaces for block producers.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidContainerType represents invalid container type read from msgpack bytes.
	ErrInvalidContainerType = errors.New("invalid container type for TransactionWrapper")
	// ErrInvalidTransactionType represents invalid transaction type read from msgpack bytes.
	ErrInvalidTransactionType = errors.New("invalid transaction type, can not instantiate transaction")
	// ErrTransactionRegistration represents invalid transaction object type being registered.
	ErrTransactionRegistration = errors.New("transaction register failed")
	// ErrMsgPackVersionMismatch represents the msgpack library abi has changed.
	ErrMsgPackVersionMismatch = errors.New("msgpack library version mismatch")
)

Functions

func RegisterTransaction

func RegisterTransaction(t TransactionType, tx Transaction)

RegisterTransaction registers transaction type to wrapper.

Types

type AccountNonce

type AccountNonce uint32

AccountNonce defines the an account nonce.

type ContainsTransactionTypeMixin

type ContainsTransactionTypeMixin interface {
	SetTransactionType(TransactionType)
}

ContainsTransactionTypeMixin interface defines interface to detect transaction type mixin.

type Transaction

type Transaction interface {
	GetTransactionType() TransactionType
	GetAccountAddress() proto.AccountAddress
	GetAccountNonce() AccountNonce
	GetTimestamp() time.Time
	Hash() hash.Hash
	Sign(signer *asymmetric.PrivateKey) error
	Verify() error
	MarshalHash() ([]byte, error)
	Msgsize() int
}

Transaction is the interface implemented by an object that can be verified and processed by block producers.

func NewTransaction

func NewTransaction(t TransactionType) (tx Transaction, err error)

NewTransaction instantiates new transaction object.

type TransactionState

type TransactionState uint32

TransactionState defines a transaction state.

const (
	TransactionStatePending TransactionState = iota
	TransactionStatePacked
	TransactionStateConfirmed
	TransactionStateExpired
	TransactionStateNotFound
)

Transaction state transition: [o] ---[ Add ]--> Pending ---[ Produce Block ]--> Packed ---[ Irreversible ]--> Confirmed

|                     |                              x
|                     x                              +------[ Prune ]--> Not Found
x                     |
|                     +------------------------------------[ Expire ]--> Expired
|
+----------------------------------------------------------------------> Not Found.

func (TransactionState) String

func (s TransactionState) String() string

type TransactionType

type TransactionType uint32

TransactionType defines a transaction type.

const (
	// TransactionTypeDeprecated is a deprecated transaction type, do NOT use it.
	TransactionTypeDeprecated TransactionType = iota
	// TransactionTypeTransfer defines transfer transaction type.
	TransactionTypeTransfer
	// TransactionTypeCreateAccount defines account creation transaction type.
	TransactionTypeCreateAccount
	// TransactionTypeDeleteAccount defines account deletion transaction type.
	TransactionTypeDeleteAccount
	// TransactionTypeAddDatabaseUser defines database user addition transaction type.
	TransactionTypeAddDatabaseUser
	// TransactionTypeAlterDatabaseUser defines database user alteration transaction type.
	TransactionTypeAlterDatabaseUser
	// TransactionTypeDeleteDatabaseUser defines database user deletion transaction type.
	TransactionTypeDeleteDatabaseUser
	// TransactionTypeBaseAccount defines base account transaction type.
	TransactionTypeBaseAccount
	// TransactionTypeCreateDatabase defines database creation transaction type.
	TransactionTypeCreateDatabase
	// TransactionTypeProvideService defines miner providing database service type.
	TransactionTypeProvideService
	// TransactionTypeUpdatePermission defines admin user grant/revoke permission type.
	TransactionTypeUpdatePermission
	// TransactionTypeIssueKeys defines SQLChain owner assign symmetric key.
	TransactionTypeIssueKeys
	// TransactionTypeUpdateBilling defines SQLChain update billing information.
	TransactionTypeUpdateBilling
	// TransactionTypeNumber defines transaction types number.
	TransactionTypeNumber
)

func FromBytes

func FromBytes(b []byte) TransactionType

FromBytes decodes a TransactionType from a byte slice.

func (TransactionType) Bytes

func (t TransactionType) Bytes() (b []byte)

Bytes encodes a TransactionType to a byte slice.

func (TransactionType) String

func (t TransactionType) String() string

type TransactionTypeMixin

type TransactionTypeMixin struct {
	TxType    TransactionType
	Timestamp time.Time
}

TransactionTypeMixin provide type heuristic features to transaction wrapper.

func NewTransactionTypeMixin

func NewTransactionTypeMixin(txType TransactionType) *TransactionTypeMixin

NewTransactionTypeMixin returns new instance.

func (*TransactionTypeMixin) GetTimestamp

func (m *TransactionTypeMixin) GetTimestamp() time.Time

GetTimestamp implements Transaciton.GetTimestamp().

func (*TransactionTypeMixin) GetTransactionType

func (m *TransactionTypeMixin) GetTransactionType() TransactionType

GetTransactionType implements Transaction.GetTransactionType.

func (*TransactionTypeMixin) SetTimestamp

func (m *TransactionTypeMixin) SetTimestamp(t time.Time)

SetTimestamp is a helper function for derived types.

func (*TransactionTypeMixin) SetTransactionType

func (m *TransactionTypeMixin) SetTransactionType(t TransactionType)

SetTransactionType is a helper function for derived types.

type TransactionWrapper

type TransactionWrapper struct {
	Transaction
}

TransactionWrapper is the wrapper for Transaction interface for serialization/deserialization purpose.

func WrapTransaction

func WrapTransaction(tx Transaction) *TransactionWrapper

WrapTransaction wraps transaction in wrapper.

func (*TransactionWrapper) CodecDecodeSelf

func (w *TransactionWrapper) CodecDecodeSelf(d *codec.Decoder)

CodecDecodeSelf implements codec.Selfer interface.

func (*TransactionWrapper) CodecEncodeSelf

func (w *TransactionWrapper) CodecEncodeSelf(e *codec.Encoder)

CodecEncodeSelf implements codec.Selfer interface.

func (TransactionWrapper) MarshalJSON

func (w TransactionWrapper) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*TransactionWrapper) UnmarshalJSON

func (w *TransactionWrapper) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements json.Unmarshaler interface.

func (*TransactionWrapper) Unwrap

func (w *TransactionWrapper) Unwrap() Transaction

Unwrap returns transaction within wrapper.

Jump to

Keyboard shortcuts

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