transactions

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

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. TODO: implement.

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 MBidTransaction

func MBidTransaction(r *rusk.BidTransaction, f *BidTransaction) error

MBidTransaction copies the BidTransaction structure into the Rusk equivalent.

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 MarshalBidTransaction

func MarshalBidTransaction(r *bytes.Buffer, f *BidTransaction) error

MarshalBidTransaction writes the BidTransaction struct into 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 MockKeys

func MockKeys() (*keys.SecretKey, *keys.PublicKey)

MockKeys mocks the keys.

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 RandKeys

func RandKeys() (keys.SecretKey, keys.PublicKey)

RandKeys returns a syntactically correct (but semantically rubbish) keypair.

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 UBidTransaction

func UBidTransaction(r *rusk.BidTransaction, f *BidTransaction) error

UBidTransaction copies the Rusk BidTransaction structure into the native equivalent.

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 UnmarshalBidTransaction

func UnmarshalBidTransaction(r *bytes.Buffer, f *BidTransaction) error

UnmarshalBidTransaction reads a BidTransaction 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) 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.

Types

type BidTransaction

type BidTransaction struct {
	BidTreeStorageIndex uint64
	Tx                  *Transaction `json:"tx"`
}

BidTransaction is used to perform a blind bid.

func NewBidTransaction

func NewBidTransaction() *BidTransaction

NewBidTransaction creates a new empty BidTransaction struct.

func (*BidTransaction) Copy

func (b *BidTransaction) Copy() *BidTransaction

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

type BlockGenerator

type BlockGenerator interface {
	// GenerateScore to participate in the block generation lottery.
	GenerateScore(context.Context, blindbid.GenerateScoreRequest) (blindbid.GenerateScoreResponse, error)
}

BlockGenerator encapsulates the operations performed by the BlockGenerator.

type ContractCall

type ContractCall interface {
	payload.Safe
	merkletree.Payload

	// StandardTx returns the payload.
	StandardTx() *TransactionPayload

	// Type indicates the transaction.
	Type() TxType

	// Obfuscated returns true if the TransactionOutputs consists of Obfuscated
	// Notes, false if they are transparent.
	Obfuscated() bool

	// Values returns a tuple where the first element is the sum of all transparent
	// outputs' note values and the second is the fee.
	Values() (amount uint64, fee uint64)
}

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

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.

type Crossover

type Crossover struct {
	ValueComm     []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.

func (*Crossover) Copy

func (c *Crossover) Copy() *Crossover

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

func (*Crossover) Equal

func (c *Crossover) Equal(other *Crossover) bool

Equal returns whether or not two Crossovers are equal.

type Executor

type Executor interface {
	// VerifyStateTransition takes a bunch of ContractCalls and the block
	// height. It returns those ContractCalls deemed valid.
	VerifyStateTransition(context.Context, []ContractCall, uint64) ([]ContractCall, error)

	// ExecuteStateTransition performs a global state mutation and steps the
	// block-height up.
	ExecuteStateTransition(context.Context, []ContractCall, uint64) (user.Provisioners, error)

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

Executor encapsulate the Global State operations.

type Fee

type Fee struct {
	GasLimit uint64 `json:"gas_limit"`
	GasPrice uint64 `json:"gas_price"`
	R        []byte `json:"r"`
	PkR      []byte `json:"pk_r"`
}

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 whether or not two Fees are equal.

type KeyMaster

type KeyMaster interface {
	// GenerateKeys creates a SecretKey using a []byte as Seed.
	GenerateKeys(context.Context, []byte) (keys.SecretKey, keys.PublicKey, keys.ViewKey, error)
}

KeyMaster Encapsulates the Key creation and retrieval operations.

type MockBlockGenerator

type MockBlockGenerator struct{}

MockBlockGenerator mocks a blockgenerator.

func (MockBlockGenerator) GenerateScore

GenerateScore obeys the BlockGenerator interface.

type MockProxy

type MockProxy struct {
	P  Provisioner
	Pr Provider
	V  UnconfirmedTxProber
	KM KeyMaster
	E  Executor
	BG BlockGenerator
}

MockProxy mocks a proxy for ease of testing.

func (MockProxy) BlockGenerator

func (m MockProxy) BlockGenerator() BlockGenerator

BlockGenerator ...

func (MockProxy) Executor

func (m MockProxy) Executor() Executor

Executor ...

func (MockProxy) KeyMaster

func (m MockProxy) KeyMaster() KeyMaster

KeyMaster ...

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.

func (MockProxy) Provider

func (m MockProxy) Provider() Provider

Provider ...

func (MockProxy) Provisioner

func (m MockProxy) Provisioner() Provisioner

Provisioner ...

type Note

type Note struct {
	Randomness    []byte `json:"randomness"`
	PkR           []byte `json:"pk_r"`
	Commitment    []byte `json:"commitment"`
	Nonce         []byte `json:"nonce"`
	EncryptedData []byte `json:"encrypted_data"`
}

Note represents a Phoenix note.

func MockObfuscatedOutput

func MockObfuscatedOutput(blindingFactor []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) Copy

func (n *Note) Copy() *Note

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

func (*Note) Equal

func (n *Note) Equal(other *Note) bool

Equal returns whether or not two Notes are equal.

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) ExecuteStateTransition

func (p *PermissiveExecutor) ExecuteStateTransition(ctx context.Context, cc []ContractCall, height uint64) (user.Provisioners, error)

ExecuteStateTransition performs a global state mutation and steps the block-height up.

func (*PermissiveExecutor) GetProvisioners

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

GetProvisioners returns current state of provisioners.

func (*PermissiveExecutor) VerifyStateTransition

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

VerifyStateTransition returns all ContractCalls passed height. It returns those ContractCalls deemed valid.

type PermissiveProvisioner

type PermissiveProvisioner struct{}

PermissiveProvisioner mocks verification of scores.

func (PermissiveProvisioner) VerifyScore

VerifyScore returns nil all the time.

type Provider

type Provider interface {
	// GetBalance returns the balance of the client expressed in (unit?) of
	// DUSK. It accepts the ViewKey as parameter.
	GetBalance(context.Context, keys.ViewKey) (uint64, uint64, error)

	// NewStake creates a staking transaction.
	NewStake(context.Context, []byte, uint64) (*Transaction, error)

	// NewBid creates a new bidding transaction.
	NewBid(context.Context, []byte, uint64, []byte, *keys.StealthAddress, []byte, uint64, uint64) (*BidTransaction, error)

	// NewTransaction creates a new transaction using the user's PrivateKey
	// It accepts the PublicKey of the recipient, a value, a fee and whether
	// the transaction should be obfuscated or otherwise.
	NewTransfer(context.Context, uint64, *keys.StealthAddress) (*Transaction, error)
}

Provider encapsulates the common Wallet and transaction operations.

type Provisioner

type Provisioner interface {
	// VerifyScore created by the BlockGenerator.
	VerifyScore(context.Context, uint64, uint8, blindbid.VerifyScoreRequest) error
}

Provisioner encapsulates the operations common to a Provisioner during the consensus.

type Proxy

type Proxy interface {
	Provisioner() Provisioner
	Provider() Provider
	Prober() UnconfirmedTxProber
	KeyMaster() KeyMaster
	Executor() Executor
	BlockGenerator() BlockGenerator
}

Proxy toward the rusk client.

func NewProxy

func NewProxy(stateClient rusk.StateClient, keysClient rusk.KeysClient, blindbidClient rusk.BlindBidServiceClient,
	bidClient rusk.BidServiceClient, transferClient rusk.TransferClient, stakeClient rusk.StakeServiceClient, walletClient rusk.WalletClient,
	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"`
}

Transaction is a Phoenix transaction.

func MockBidTx

func MockBidTx(expiration uint64, edPk, seed []byte, randomized bool) *Transaction

MockBidTx creates a BidTransaction.

func MockDeterministicBid

func MockDeterministicBid(expiration uint64, edPk, seed []byte) *Transaction

MockDeterministicBid creates a deterministic bid, where none of the fields are subject to randomness. This creates predictability in the output of the hash calculation, and is useful for testing purposes.

func MockInvalidTx

func MockInvalidTx() *Transaction

MockInvalidTx creates an invalid transaction.

func MockStakeTx

func MockStakeTx(expiration uint64, blsKey []byte, randomized bool) *Transaction

MockStakeTx creates a StakeTransaction.

func MockTx

func MockTx(obfuscated bool, blindingFactor []byte, randomized bool) *Transaction

MockTx mocks a transfer transaction. For simplicity it includes a single output with the amount specified. The blinding factor can be left to nil if the test is not interested in Transaction equality/differentiation. Otherwise it can be used to identify/differentiate the transaction.

func NewTransaction

func NewTransaction() *Transaction

NewTransaction returns a new empty Transaction struct.

func RandBidTx

func RandBidTx(expiration uint64) *Transaction

RandBidTx creates a random bid transaction. If the expiration is <1, then it is randomly set.

func RandDistributeTx

func RandDistributeTx(reward uint64, provisionerNr int) *Transaction

RandDistributeTx creates a random distribute transaction.

func RandStakeTx

func RandStakeTx(expiration uint64) *Transaction

RandStakeTx creates a random stake transaction. If the expiration is <1, then it is randomly set.

func RandTx

func RandTx() *Transaction

RandTx returns a random transaction. The randomization includes the amount, the fee, the blinding factor and whether the transaction is obfuscated or otherwise.

func (Transaction) CalculateHash

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

CalculateHash returns the SHA3-256 hash digest of the transaction. TODO: this needs to correspond with how rusk hashes transactions.

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) Obfuscated

func (t Transaction) Obfuscated() bool

Obfuscated returns whether or not the outputs of this transaction are obfuscated. TODO: implement.

func (Transaction) StandardTx

func (t Transaction) StandardTx() *TransactionPayload

StandardTx returns the transaction payload.

func (Transaction) Type

func (t Transaction) Type() TxType

Type returns the transaction type.

func (Transaction) Values

func (t Transaction) Values() (amount uint64, fee uint64)

Values returns the amount and fee spent in this transaction. TODO: add amount calculation.

type TransactionPayload

type TransactionPayload struct {
	Anchor        []byte   `json:"anchor"`
	Nullifiers    [][]byte `json:"nullifier"`
	*Crossover    `json:"crossover"`
	Notes         []*Note `json:"notes"`
	*Fee          `json:"fee"`
	SpendingProof []byte `json:"spending_proof"`
	CallData      []byte `json:"call_data"`
}

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 whether or not two TransactionPayloads are equal.

type TxRequest

type TxRequest struct {
	SK         keys.SecretKey
	PK         keys.PublicKey
	Amount     uint64
	Fee        uint64
	Obfuscated bool
}

TxRequest is a convenient struct to group all parameters needed to create a transaction.

func MakeTxRequest

func MakeTxRequest(sk keys.SecretKey, pk keys.PublicKey, amount uint64, fee uint64, isObfuscated bool) TxRequest

MakeTxRequest populates a TxRequest with all needed data ContractCall. As such, it does not need the Public Key.

type TxType

type TxType uint32

TxType is the type identifier for a transaction.

const (
	// Tx indicates the phoenix transaction type.
	Tx TxType = iota
	// Distribute indicates the coinbase and reward distribution contract call.
	Distribute
	// WithdrawFees indicates the Provisioners' withdraw contract call.
	WithdrawFees
	// Bid transaction propagated by the Block Generator.
	Bid
	// Stake transaction propagated by the Provisioners.
	Stake
	// Slash transaction propagated by the consensus to punish the Committee
	// members when they turn byzantine.
	Slash
	// WithdrawStake transaction propagated by the Provisioners to withdraw
	// their stake.
	WithdrawStake
	// WithdrawBid transaction propagated by the Block Generator to withdraw
	// their bids.
	WithdrawBid
)

func RandTxType

func RandTxType() TxType

RandTxType returns a random TxType.

type UnconfirmedTxProber

type UnconfirmedTxProber interface {
	// VerifyTransaction verifies a contract call transaction.
	VerifyTransaction(context.Context, ContractCall) error
	// CalculateBalance for transactions on demand. This functionality is used
	// primarily by the mempool which can order RUSK to calculate balance for
	// transactions even if they are unconfirmed.
	CalculateBalance(context.Context, []byte, []ContractCall) (uint64, 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