transactions

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoteTypeTransparent uint8 = 0
	NoteTypeObfuscated  uint8 = 1
)

Note types.

Variables

View Source
var RandBlind = Rand32Bytes

RandBlind returns a random BlindingFactor (it is just an alias for Rand32Bytes).

Functions

func Equal

func Equal(t, other ContractCall) bool

Equal checks equality between two transactions.

func Invalidate

func Invalidate(cc ContractCall)

Invalidate a transaction by marking its Proof field as "INVALID".

func IsMockInvalid

func IsMockInvalid(cc ContractCall) bool

IsMockInvalid checks whether a ContractCall mock is invalid or not.

func MTransaction

func MTransaction(r *rusk.Transaction, f *Transaction) error

MTransaction copies the Transaction structure into the Rusk equivalent.

func Marshal

func Marshal(r *bytes.Buffer, f ContractCall) error

Marshal a Contractcall to a bytes.Buffer.

func MarshalCrossover

func MarshalCrossover(r *bytes.Buffer, f *Crossover) error

MarshalCrossover writes the Crossover struct into a bytes.Buffer.

func MarshalFee

func MarshalFee(r *bytes.Buffer, f *Fee) error

MarshalFee writes the Fee struct into a bytes.Buffer.

func MarshalNote

func MarshalNote(r *bytes.Buffer, f *Note) error

MarshalNote writes the Note struct into a bytes.Buffer.

func MarshalTransaction

func MarshalTransaction(r *bytes.Buffer, f *Transaction) error

MarshalTransaction writes the Transaction struct into a bytes.Buffer.

func MarshalTransactionPayload

func MarshalTransactionPayload(r *bytes.Buffer, f *TransactionPayload) error

MarshalTransactionPayload writes the TransactionPayload struct into a bytes.Buffer.

func Rand32Bytes

func Rand32Bytes() []byte

Rand32Bytes returns random 32 bytes.

func RandBool

func RandBool() bool

RandBool returns a random boolean.

func RandBytes

func RandBytes(size int) []byte

RandBytes returns a random byte slice of the desired size.

func RandUint64

func RandUint64() uint64

RandUint64 returns a random uint64.

func RuskPublicKey

func RuskPublicKey() *rusk.PublicKey

RuskPublicKey mocks rusk pk.

func RuskSecretKey

func RuskSecretKey() *rusk.SecretKey

RuskSecretKey mocks rusk sk.

func RuskTx

func RuskTx() *rusk.Transaction

RuskTx is the mock of a ContractCallTx.

func UMember

func UMember(r *rusk.Provisioner, t *user.Member)

UMember deep copies from the rusk.Provisioner.

func UTransaction

func UTransaction(r *rusk.Transaction, f *Transaction) error

UTransaction copies the Rusk Transaction structure into the native equivalent.

func Unmarshal

func Unmarshal(r *bytes.Buffer, f ContractCall) error

Unmarshal a ContractCall from a bytes.Buffer.

func UnmarshalCall added in v0.5.0

func UnmarshalCall(r *bytes.Buffer, c *Call) error

UnmarshalCall reads a Call struct from a bytes.Buffer.

func UnmarshalCrossover

func UnmarshalCrossover(r *bytes.Buffer, f *Crossover) error

UnmarshalCrossover reads a Crossover struct from a bytes.Buffer.

func UnmarshalFee

func UnmarshalFee(r *bytes.Buffer, f *Fee) error

UnmarshalFee reads a Fee struct from a bytes.Buffer.

func UnmarshalNote

func UnmarshalNote(r *bytes.Buffer, f *Note) (err error)

UnmarshalNote reads a Note struct from a bytes.Buffer.

func UnmarshalTransaction

func UnmarshalTransaction(r *bytes.Buffer, f *Transaction) error

UnmarshalTransaction reads a Transaction struct from a bytes.Buffer.

func UnmarshalTransactionPayload

func UnmarshalTransactionPayload(r *bytes.Buffer, f *TransactionPayload) error

UnmarshalTransactionPayload reads a TransactionPayload struct from a bytes.Buffer.

func UnmarshalTransactionPayloadDecoded added in v0.5.0

func UnmarshalTransactionPayloadDecoded(r *bytes.Buffer, f *TransactionPayloadDecoded, txType TxType) error

UnmarshalTransactionPayloadDecoded reads a TransactionPayloadDecoded struct from a bytes.Buffer.

Types

type Call added in v0.5.0

type Call struct {
	// ContractID are 32 bytes representing the address of a contract. It is a valid BlsScalar.
	ContractID []byte
	// The data to call the contract with.
	CallData []byte
}

Call represents a contract call.

func NewCall added in v0.5.0

func NewCall() *Call

NewCall returns a new empty Call struct.

type ContractCall

type ContractCall interface {
	payload.Safe
	merkletree.Payload

	// StandardTx returns the payload.
	StandardTx() *TransactionPayload
	Decode() (*TransactionPayloadDecoded, error)

	// Type indicates the transaction.
	Type() TxType

	Fee() (uint64, error)
	GasSpent() uint64

	TxError() *rusk.ExecutedTransaction_Error
}

ContractCall is the transaction that embodies the execution parameter for a smart contract method invocation.

func MockTxWithParams added in v0.5.0

func MockTxWithParams(txtype TxType, gasSpent uint64) ContractCall

MockTxWithParams mocks a transactions with specified params.

func RandContractCall

func RandContractCall() ContractCall

RandContractCall returns a random ContractCall.

func RandContractCalls

func RandContractCalls(amount, invalid int, includeCoinbase bool) []ContractCall

RandContractCalls creates random but syntactically valid amount of transactions and an "invalid" amount of invalid transactions. The invalid transactions are marked as such since they carry "INVALID" in the proof. This because we actually have no way to know if a transaction is valid or not without RUSK, since syntactically wrong transactions would be discarded when Unmarshalling. The set is composed of Stake, Bid and normal Transactions. If a coinbase is included, an additional Distribute transaction is added at the top. A coinbase is never invalid.

func UpdateHash added in v0.5.0

func UpdateHash(t ContractCall, hash []byte) (ContractCall, error)

UpdateHash creates a deep copy of t and sets new hash value.

func UpdateTransaction added in v0.5.0

func UpdateTransaction(t ContractCall, gasSpent uint64, err *rusk.ExecutedTransaction_Error) (ContractCall, error)

UpdateTransaction creates a deep copy of t and sets new gas spent value and tx error.

type Crossover

type Crossover struct {
	ValueCommitment []byte `json:"value_comm"`
	Nonce           []byte `json:"nonce"`
	EncryptedData   []byte `json:"encrypted_data"`
}

Crossover is the crossover note used in a Phoenix transaction.

func MockCrossover

func MockCrossover(randomized bool) *Crossover

MockCrossover returns a mocked Crossover struct.

func NewCrossover

func NewCrossover() *Crossover

NewCrossover returns a new empty Crossover struct.

type Executor

type Executor interface {
	// VerifyStateTransition performs dry-run state transition to ensure all txs are valid.
	VerifyStateTransition(context.Context, []ContractCall, uint64, uint64, []byte) ([]byte, error)

	// ExecuteStateTransition performs dry-run state transition to return valid-only set of txs and state hash.
	ExecuteStateTransition(context.Context, []ContractCall, uint64, uint64, []byte) ([]ContractCall, []byte, error)

	// Accept creates an ephemeral state transition.
	Accept(context.Context, []ContractCall, []byte, uint64, uint64, []byte, *user.Provisioners) ([]ContractCall, user.Provisioners, []byte, error)

	// Finalize creates a finalized state transition.
	Finalize(context.Context, []ContractCall, []byte, uint64, uint64, []byte, *user.Provisioners) ([]ContractCall, user.Provisioners, []byte, error)

	// GetProvisioners returns the current set of provisioners.
	GetProvisioners(ctx context.Context) (user.Provisioners, error)

	// GetStateRoot returns root hash of the finalized state.
	GetStateRoot(ctx context.Context) ([]byte, error)

	// Persist instructs Rusk to persist the state if in-sync with provided stateRoot.
	Persist(ctx context.Context, stateRoot []byte) error

	// Revert instructs Rusk to revert to the most recent finalized state. Returns stateRoot, if no error.
	Revert(ctx context.Context) ([]byte, error)
}

Executor encapsulate the Global State operations.

type Fee

type Fee struct {
	GasLimit    uint64 `json:"gas_limit"`
	GasPrice    uint64 `json:"gas_price"`
	StealthAddr []byte `json:"stealth_addr"`
}

Fee is a Phoenix fee note.

func MockFee

func MockFee(randomized bool) *Fee

MockFee returns a mocked Fee struct.

func NewFee

func NewFee() *Fee

NewFee returns a new empty Fee struct.

func (*Fee) Copy

func (f *Fee) Copy() *Fee

Copy complies with message.Safe interface. It returns a deep copy of the message safe to publish to multiple subscribers.

func (*Fee) Equal

func (f *Fee) Equal(other *Fee) bool

Equal returns if the two Fees are equal.

type MockProxy

type MockProxy struct {
	V UnconfirmedTxProber

	E Executor
}

MockProxy mocks a proxy for ease of testing.

func (MockProxy) Executor

func (m MockProxy) Executor() Executor

Executor ...

func (MockProxy) Prober

func (m MockProxy) Prober() UnconfirmedTxProber

Prober returns a UnconfirmedTxProber that is capable of checking invalid mocked up transactions.

func (MockProxy) ProberWithParams added in v0.4.1

func (m MockProxy) ProberWithParams(verifyTransactionLatency time.Duration) UnconfirmedTxProber

ProberWithParams instantiates a mockVerifier with a latency value for VerifyTransaction.

type Note

type Note struct {
	Type            uint8  `json:"note_type"`
	ValueCommitment []byte `json:"value_commitment"`
	Nonce           []byte `json:"nonce"`
	StealthAddress  []byte `json:"stealth_address"`
	Pos             uint64 `json:"pos"`
	EncryptedData   []byte `json:"encrypted_data"`
}

Note represents a Phoenix note.

func MockObfuscatedOutput

func MockObfuscatedOutput(valueCommitment []byte) *Note

MockObfuscatedOutput returns a Note with the amount hashed. To allow for equality checking and retrieval, an encrypted blinding factor can also be provided. Despite the unsofisticated mocking, the hashing should be enough since the node has no way to decode obfuscation as this is delegated to RUSK.

func MockTransparentNote

func MockTransparentNote(blindingFactor []byte) *Note

MockTransparentNote is a transparent note.

func NewNote

func NewNote() *Note

NewNote returns a new empty Note struct.

func (*Note) DecodeTxAmount added in v0.5.0

func (f *Note) DecodeTxAmount() uint64

DecodeTxAmount return the amount of the tx (if transparent).

type PermissiveExecutor

type PermissiveExecutor struct {
	P *user.Provisioners
	// contains filtered or unexported fields
}

PermissiveExecutor implements the transactions.Executor interface. It simulates successful Validation and Execution of State transitions all Validation and simulates.

func MockExecutor

func MockExecutor(height uint64) *PermissiveExecutor

MockExecutor returns an instance of PermissiveExecutor.

func (*PermissiveExecutor) Accept added in v0.4.4

Accept ...

func (*PermissiveExecutor) ExecuteStateTransition

func (p *PermissiveExecutor) ExecuteStateTransition(ctx context.Context, cc []ContractCall, blockGasLimit uint64, blockHeight uint64, generator []byte) ([]ContractCall, []byte, error)

ExecuteStateTransition ...

func (*PermissiveExecutor) Finalize added in v0.4.4

Finalize ...

func (*PermissiveExecutor) GetProvisioners

func (p *PermissiveExecutor) GetProvisioners(ctx context.Context) (user.Provisioners, error)

GetProvisioners ...

func (*PermissiveExecutor) GetStateRoot added in v0.4.4

func (p *PermissiveExecutor) GetStateRoot(ctx context.Context) ([]byte, error)

GetStateRoot ...

func (*PermissiveExecutor) Persist added in v0.5.0

func (p *PermissiveExecutor) Persist(context.Context, []byte) error

Persist ...

func (*PermissiveExecutor) Revert added in v0.5.0

func (p *PermissiveExecutor) Revert(ctx context.Context) ([]byte, error)

Revert ...

func (*PermissiveExecutor) VerifyStateTransition

func (p *PermissiveExecutor) VerifyStateTransition(context.Context, []ContractCall, uint64, uint64, []byte) ([]byte, error)

VerifyStateTransition ...

type Proxy

type Proxy interface {
	Prober() UnconfirmedTxProber
	Executor() Executor
}

Proxy toward the rusk client.

func NewProxy

func NewProxy(stateClient rusk.StateClient, txTimeout, defaultTimeout time.Duration) Proxy

NewProxy creates a new Proxy.

type Transaction

type Transaction struct {
	Version uint32 `json:"version"`
	TxType  `json:"type"`
	Payload *TransactionPayload `json:"payload"`

	// Extended
	Hash          [32]byte
	GasSpentValue uint64

	Error *rusk.ExecutedTransaction_Error
}

Transaction is a Phoenix transaction.

func EmptyTx added in v0.6.0

func EmptyTx() *Transaction

EmptyTx creates an zero-ed transaction.

func MockInvalidTx

func MockInvalidTx() *Transaction

MockInvalidTx creates an invalid transaction.

func MockTx

func MockTx() *Transaction

MockTx mocks a transaction.

func NewTransaction

func NewTransaction() *Transaction

NewTransaction returns a new empty Transaction struct.

func RandTx

func RandTx() *Transaction

RandTx mocks a transaction.

func (Transaction) CalculateHash

func (t Transaction) CalculateHash() ([]byte, error)

CalculateHash returns hash of transaction, if set.

func (Transaction) Copy

func (t Transaction) Copy() payload.Safe

Copy complies with message.Safe interface. It returns a deep copy of the message safe to publish to multiple subscribers.

func (Transaction) Decode added in v0.5.0

Decode returns a TransactionPayloadDecoded.

func (Transaction) Fee added in v0.5.0

func (t Transaction) Fee() (uint64, error)

Fee returns GasPrice.

func (Transaction) GasSpent added in v0.5.0

func (t Transaction) GasSpent() uint64

GasSpent returns gas spent on transaction execution.

func (Transaction) StandardTx

func (t Transaction) StandardTx() *TransactionPayload

StandardTx returns the transaction payload.

func (Transaction) TxError added in v0.5.0

TxError returns the execution error, if set.

func (Transaction) Type

func (t Transaction) Type() TxType

Type returns the transaction type.

type TransactionPayload

type TransactionPayload struct {
	Data []byte `json:"payload"`
}

TransactionPayload carries the common data contained in all transaction types.

func NewTransactionPayload

func NewTransactionPayload() *TransactionPayload

NewTransactionPayload returns a new empty TransactionPayload struct.

func (*TransactionPayload) Copy

Copy complies with message.Safe interface. It returns a deep copy of the message safe to publish to multiple subscribers.

func (*TransactionPayload) Equal

func (t *TransactionPayload) Equal(other *TransactionPayload) bool

Equal returns true when two TransactionPayloads are equal.

type TransactionPayloadDecoded added in v0.5.0

type TransactionPayloadDecoded struct {
	Anchor     []byte     `json:"anchor"`
	Nullifiers [][]byte   `json:"nullifier"`
	Crossover  *Crossover `json:"crossover"`
	Notes      []*Note    `json:"notes"`
	Fee        *Fee       `json:"fee"`
	SpendProof []byte     `json:"spend_proof"`
	Call       *Call      `json:"call"`
}

TransactionPayloadDecoded carries data for an execute transaction (type 1).

func NewTransactionPayloadDecoded added in v0.5.0

func NewTransactionPayloadDecoded() *TransactionPayloadDecoded

NewTransactionPayloadDecoded returns a new empty TransactionPayloadDecoded struct.

func (*TransactionPayloadDecoded) EstimatedGasSpent added in v0.6.0

func (p *TransactionPayloadDecoded) EstimatedGasSpent() uint64

EstimatedGasSpent return the estimated amount of Gas that a transaction will spend. For now it uses `t.Call` to determine if it's a normal transfer or it is an intercontract call. TODO: further improvement should take care of the contractAddress to compare it against historical data.

func (*TransactionPayloadDecoded) Hash added in v0.5.0

func (p *TransactionPayloadDecoded) Hash(txType TxType) ([]byte, error)

Hash the decoded payload in the same way as the transaction is hashed in `dusk-wallet-core`.

type TxType

type TxType uint32

TxType is the type identifier for a transaction.

const (
	// Tx indicates the phoenix transaction type.
	Tx TxType = iota
	// Transfer transaction id.
	Transfer = 1
)

func RandTxType

func RandTxType() TxType

RandTxType returns a random TxType.

type UnconfirmedTxProber

type UnconfirmedTxProber interface {
	// VerifyTransaction verifies a contract call transaction.
	Preverify(context.Context, ContractCall) ([]byte, Fee, error)
}

UnconfirmedTxProber performs verification of contract calls (transactions).

Jump to

Keyboard shortcuts

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