Documentation
¶
Index ¶
- Variables
- func Equal(t, other ContractCall) bool
- func Invalidate(cc ContractCall)
- func IsMockInvalid(cc ContractCall) bool
- func MTransaction(r *rusk.Transaction, f *Transaction) error
- func Marshal(r *bytes.Buffer, f ContractCall) error
- func MarshalCrossover(r *bytes.Buffer, f *Crossover) error
- func MarshalFee(r *bytes.Buffer, f *Fee) error
- func MarshalNote(r *bytes.Buffer, f *Note) error
- func MarshalTransaction(r *bytes.Buffer, f *Transaction) error
- func MarshalTransactionPayload(r *bytes.Buffer, f *TransactionPayload) error
- func MockKeys() (*keys.SecretKey, *keys.PublicKey)
- func Rand32Bytes() []byte
- func RandBool() bool
- func RandBytes(size int) []byte
- func RandKeys() (keys.SecretKey, keys.PublicKey)
- func RandUint64() uint64
- func RuskPublicKey() *rusk.PublicKey
- func RuskSecretKey() *rusk.SecretKey
- func RuskTx() *rusk.Transaction
- func UMember(r *rusk.Provisioner, t *user.Member)
- func UTransaction(r *rusk.Transaction, f *Transaction) error
- func Unmarshal(r *bytes.Buffer, f ContractCall) error
- func UnmarshalCrossover(r *bytes.Buffer, f *Crossover) error
- func UnmarshalFee(r *bytes.Buffer, f *Fee) error
- func UnmarshalNote(r *bytes.Buffer, f *Note) error
- func UnmarshalTransaction(r *bytes.Buffer, f *Transaction) error
- func UnmarshalTransactionPayload(r *bytes.Buffer, f *TransactionPayload) error
- type ContractCall
- type Crossover
- type Executor
- type Fee
- type KeyMaster
- type MockProxy
- type Note
- type PermissiveExecutor
- func (p *PermissiveExecutor) Accept(context.Context, []ContractCall, []byte, uint64, uint64) (user.Provisioners, []byte, error)
- func (p *PermissiveExecutor) ExecuteStateTransition(ctx context.Context, cc []ContractCall, blockGasLimit uint64, ...) ([]ContractCall, []byte, error)
- func (p *PermissiveExecutor) Finalize(context.Context, []ContractCall, []byte, uint64, uint64) (user.Provisioners, []byte, error)
- func (p *PermissiveExecutor) GetProvisioners(ctx context.Context) (user.Provisioners, error)
- func (p *PermissiveExecutor) GetStateRoot(ctx context.Context) ([]byte, error)
- func (p *PermissiveExecutor) VerifyStateTransition(context.Context, []ContractCall, uint64, uint64) error
- type Provider
- type Proxy
- type Transaction
- func MockBidTx(expiration uint64, edPk, seed []byte, randomized bool) *Transaction
- func MockDeterministicBid(expiration uint64, edPk, seed []byte) *Transaction
- func MockInvalidTx() *Transaction
- func MockStakeTx(expiration uint64, blsKey []byte, randomized bool) *Transaction
- func MockTx(obfuscated bool, blindingFactor []byte, randomized bool) *Transaction
- func NewTransaction() *Transaction
- func RandBidTx(expiration uint64) *Transaction
- func RandDistributeTx(reward uint64, provisionerNr int) *Transaction
- func RandStakeTx(expiration uint64) *Transaction
- func RandTx() *Transaction
- type TransactionPayload
- type TxRequest
- type TxType
- type UnconfirmedTxProber
Constants ¶
This section is empty.
Variables ¶
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 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 ¶
MarshalCrossover writes the Crossover struct into a bytes.Buffer.
func MarshalFee ¶
MarshalFee writes the Fee struct into a bytes.Buffer.
func MarshalNote ¶
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 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 UnmarshalCrossover ¶
UnmarshalCrossover reads a Crossover struct from a bytes.Buffer.
func UnmarshalFee ¶
UnmarshalFee reads a Fee struct from a bytes.Buffer.
func UnmarshalNote ¶
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 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 ¶
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) error
// ExecuteStateTransition performs dry-run state transition to return valid-only set of txs and state hash.
ExecuteStateTransition(context.Context, []ContractCall, uint64, uint64) ([]ContractCall, []byte, error)
// Accept creates an ephemeral state transition.
Accept(context.Context, []ContractCall, []byte, uint64, uint64) (user.Provisioners, []byte, error)
// Finalize creates a finalized state transition.
Finalize(context.Context, []ContractCall, []byte, uint64, uint64) (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)
}
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.
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 MockProxy ¶
type MockProxy struct {
Pr Provider
V UnconfirmedTxProber
KM KeyMaster
E Executor
}
MockProxy mocks a proxy for ease of testing.
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 {
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 ¶
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 ¶
MockTransparentNote is a transparent note.
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
func (p *PermissiveExecutor) Accept(context.Context, []ContractCall, []byte, uint64, uint64) (user.Provisioners, []byte, error)
Accept ...
func (*PermissiveExecutor) ExecuteStateTransition ¶
func (p *PermissiveExecutor) ExecuteStateTransition(ctx context.Context, cc []ContractCall, blockGasLimit uint64, blockHeight uint64) ([]ContractCall, []byte, error)
ExecuteStateTransition ...
func (*PermissiveExecutor) Finalize ¶ added in v0.4.4
func (p *PermissiveExecutor) Finalize(context.Context, []ContractCall, []byte, uint64, uint64) (user.Provisioners, []byte, error)
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) VerifyStateTransition ¶
func (p *PermissiveExecutor) VerifyStateTransition(context.Context, []ContractCall, uint64, uint64) error
VerifyStateTransition ...
type Provider ¶
type Provider interface {
// NewStake creates a staking transaction.
NewStake(context.Context, []byte, uint64) (*Transaction, 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 Proxy ¶
type Proxy interface {
Provider() Provider
Prober() UnconfirmedTxProber
KeyMaster() KeyMaster
Executor() Executor
}
Proxy toward the rusk client.
func NewProxy ¶
func NewProxy(stateClient rusk.StateClient, keysClient rusk.KeysClient, transferClient rusk.TransferClient, stakeClient rusk.StakeServiceClient, 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) 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 ¶
func (t *TransactionPayload) Copy() *TransactionPayload
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.
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 )
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).