txsystem

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: AGPL-3.0, ISC Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTransactionExpired      = errors.New("transaction timeout must be greater than current block height")
	ErrInvalidSystemIdentifier = errors.New("error invalid system identifier")
	ErrInvalidDataType         = errors.New("invalid data type")
	ErrInvalidBacklink         = errors.New("transaction backlink must be equal to bill backlink")
)
View Source
var ErrStateContainsUncommittedChanges = errors.New("state contains uncommitted changes")
View Source
var File_transaction_proto protoreflect.FileDescriptor

Functions

func ValidateGenericTransaction

func ValidateGenericTransaction(ctx *TxValidationContext) error

Types

type DefaultGenericTransaction

type DefaultGenericTransaction struct {
	// contains filtered or unexported fields
}

DefaultGenericTransaction is a default implementation of GenericTransaction interface. NB! Only suitable for transactions that contains systemID, unitID, timeout, and OwnerProof. If the transaction contains more attributes then the transaction system developer must provide its own implementation.

func (*DefaultGenericTransaction) AddToHasher added in v0.1.1

func (d *DefaultGenericTransaction) AddToHasher(hasher hash.Hash)

func (*DefaultGenericTransaction) Hash

func (d *DefaultGenericTransaction) Hash(hashFunc crypto.Hash) []byte

func (*DefaultGenericTransaction) IsPrimary added in v0.1.1

func (d *DefaultGenericTransaction) IsPrimary() bool

func (*DefaultGenericTransaction) OwnerProof

func (d *DefaultGenericTransaction) OwnerProof() []byte

func (*DefaultGenericTransaction) SigBytes

func (d *DefaultGenericTransaction) SigBytes() []byte

func (*DefaultGenericTransaction) SystemID

func (d *DefaultGenericTransaction) SystemID() []byte

func (*DefaultGenericTransaction) TargetUnits added in v0.1.1

func (d *DefaultGenericTransaction) TargetUnits(_ crypto.Hash) []*uint256.Int

func (*DefaultGenericTransaction) Timeout

func (d *DefaultGenericTransaction) Timeout() uint64

func (*DefaultGenericTransaction) ToProtoBuf

func (d *DefaultGenericTransaction) ToProtoBuf() *Transaction

func (*DefaultGenericTransaction) UnitID

func (d *DefaultGenericTransaction) UnitID() *uint256.Int

type GenericTransaction

type GenericTransaction interface {
	SystemID() []byte
	UnitID() *uint256.Int
	Timeout() uint64
	OwnerProof() []byte
	Hash(hashFunc crypto.Hash) []byte
	AddToHasher(hasher hash.Hash)
	ToProtoBuf() *Transaction
	SigBytes() []byte
	IsPrimary() bool
	TargetUnits(hashFunc crypto.Hash) []*uint256.Int
}

func NewDefaultGenericTransaction

func NewDefaultGenericTransaction(transaction *Transaction) (GenericTransaction, error)

NewDefaultGenericTransaction creates a new DefaultGenericTransaction from the given Transaction.

type State

type State interface {
	// Root returns the root hash of the TransactionSystem.
	Root() []byte
	// Summary returns the summary value of the state.
	Summary() []byte
}

State represents the root hash and summary value of the transaction system.

type StateSummary

type StateSummary struct {
	// contains filtered or unexported fields
}

StateSummary is a default implementation of State interface.

func NewStateSummary

func NewStateSummary(rootHash []byte, summary []byte) StateSummary

func (StateSummary) Root

func (s StateSummary) Root() []byte

func (StateSummary) Summary

func (s StateSummary) Summary() []byte

type Transaction

type Transaction struct {
	SystemId              []byte     `protobuf:"bytes,1,opt,name=system_id,json=systemId,proto3" json:"system_id,omitempty"`
	UnitId                []byte     `protobuf:"bytes,2,opt,name=unit_id,json=unitId,proto3" json:"unit_id,omitempty"`
	TransactionAttributes *anypb.Any `protobuf:"bytes,3,opt,name=transaction_attributes,json=transactionAttributes,proto3" json:"transaction_attributes,omitempty"`
	Timeout               uint64     `protobuf:"varint,4,opt,name=timeout,proto3" json:"timeout,omitempty"`
	OwnerProof            []byte     `protobuf:"bytes,5,opt,name=owner_proof,json=ownerProof,proto3" json:"owner_proof,omitempty"`
	// contains filtered or unexported fields
}

Transaction is a generic transaction order, same for all transaction systems.

func (*Transaction) Bytes

func (x *Transaction) Bytes() []byte

Bytes serializes the generic transaction order fields.

func (*Transaction) Descriptor deprecated

func (*Transaction) Descriptor() ([]byte, []int)

Deprecated: Use Transaction.ProtoReflect.Descriptor instead.

func (*Transaction) GetOwnerProof

func (x *Transaction) GetOwnerProof() []byte

func (*Transaction) GetSystemId

func (x *Transaction) GetSystemId() []byte

func (*Transaction) GetTimeout

func (x *Transaction) GetTimeout() uint64

func (*Transaction) GetTransactionAttributes

func (x *Transaction) GetTransactionAttributes() *anypb.Any

func (*Transaction) GetUnitId

func (x *Transaction) GetUnitId() []byte

func (*Transaction) ProtoMessage

func (*Transaction) ProtoMessage()

func (*Transaction) ProtoReflect

func (x *Transaction) ProtoReflect() protoreflect.Message

func (*Transaction) Reset

func (x *Transaction) Reset()

func (*Transaction) String

func (x *Transaction) String() string

type TransactionResponse

type TransactionResponse struct {

	// True if request passed initial validation.
	Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"`
	// Contains error message if ok is false.
	Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	// contains filtered or unexported fields
}

func (*TransactionResponse) Descriptor deprecated

func (*TransactionResponse) Descriptor() ([]byte, []int)

Deprecated: Use TransactionResponse.ProtoReflect.Descriptor instead.

func (*TransactionResponse) GetMessage

func (x *TransactionResponse) GetMessage() string

func (*TransactionResponse) GetOk

func (x *TransactionResponse) GetOk() bool

func (*TransactionResponse) ProtoMessage

func (*TransactionResponse) ProtoMessage()

func (*TransactionResponse) ProtoReflect

func (x *TransactionResponse) ProtoReflect() protoreflect.Message

func (*TransactionResponse) Reset

func (x *TransactionResponse) Reset()

func (*TransactionResponse) String

func (x *TransactionResponse) String() string

type TransactionSystem

type TransactionSystem interface {

	// State returns the current state of the transaction system or an ErrStateContainsUncommittedChanges if
	// current state contains uncommitted changes.
	State() (State, error)

	// BeginBlock signals the start of a new block and is invoked before any Execute method calls.
	BeginBlock(uint64)

	// Execute method executes the transaction. An error must be returned if the transaction execution was not
	// successful.
	Execute(tx GenericTransaction) error

	// EndBlock signals the end of the block and is called after all transactions have been delivered to the
	// transaction system.
	EndBlock() (State, error)

	// Revert signals the unsuccessful consensus round. When called the transaction system must revert all the changes
	// made during the BeginBlock, EndBlock, and Execute method calls.
	Revert()

	// Commit signals the successful consensus round. Called after the block was approved by the root chain. When called
	// the transaction system must commit all the changes made during the BeginBlock, EndBlock, and Execute method
	// calls.
	Commit()

	// ConvertTx converts protobuf transaction to a GenericTransaction.
	ConvertTx(tx *Transaction) (GenericTransaction, error)
}

TransactionSystem is a set of rules and logic for defining units and performing transactions with them. The following sequence of methods is executed for each block: BeginBlock, Execute (called once for each transaction in the block), EndBlock, and Commit (consensus round was successful) or Revert (consensus round was unsuccessful).

type TxValidationContext

type TxValidationContext struct {
	Tx               GenericTransaction
	Bd               *rma.Unit
	SystemIdentifier []byte
	BlockNumber      uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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