Documentation ¶
Index ¶
- Variables
- func Equal(t, other ContractCall) bool
- func Invalidate(cc ContractCall)
- func IsMockInvalid(cc ContractCall) bool
- func MBidTransaction(r *rusk.BidTransaction, f *BidTransaction) error
- func MTransaction(r *rusk.Transaction, f *Transaction) error
- func Marshal(r *bytes.Buffer, f ContractCall) error
- func MarshalBidTransaction(r *bytes.Buffer, f *BidTransaction) 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 UBidTransaction(r *rusk.BidTransaction, f *BidTransaction) error
- 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 UnmarshalBidTransaction(r *bytes.Buffer, f *BidTransaction) 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 BidTransaction
- type BlockGenerator
- type ContractCall
- type Crossover
- type Executor
- type Fee
- type KeyMaster
- type MockBlockGenerator
- type MockProxy
- func (m MockProxy) BlockGenerator() BlockGenerator
- func (m MockProxy) Executor() Executor
- func (m MockProxy) KeyMaster() KeyMaster
- func (m MockProxy) Prober() UnconfirmedTxProber
- func (m MockProxy) ProberWithParams(verifyTransactionLatency time.Duration) UnconfirmedTxProber
- func (m MockProxy) Provider() Provider
- func (m MockProxy) Provisioner() Provisioner
- type Note
- type PermissiveExecutor
- func (p *PermissiveExecutor) ExecuteStateTransition(ctx context.Context, cc []ContractCall, height uint64) (user.Provisioners, error)
- func (p *PermissiveExecutor) GetProvisioners(ctx context.Context) (user.Provisioners, error)
- func (p *PermissiveExecutor) VerifyStateTransition(ctx context.Context, cc []ContractCall, height uint64) ([]ContractCall, error)
- type PermissiveProvisioner
- type Provider
- type Provisioner
- 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 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 ¶
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 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 ¶
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 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 ¶
MockCrossover returns a mocked Crossover struct.
func NewCrossover ¶
func NewCrossover() *Crossover
NewCrossover returns a new empty Crossover struct.
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.
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 ¶
func (b MockBlockGenerator) GenerateScore(context.Context, blindbid.GenerateScoreRequest) (blindbid.GenerateScoreResponse, error)
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) 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) 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 ¶
func (p PermissiveProvisioner) VerifyScore(context.Context, uint64, uint8, blindbid.VerifyScoreRequest) error
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) 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).