Documentation ¶
Index ¶
- Constants
- 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 Rand32Bytes() []byte
- func RandBool() bool
- func RandBytes(size int) []byte
- 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 UnmarshalCall(r *bytes.Buffer, c *Call) error
- func UnmarshalCrossover(r *bytes.Buffer, f *Crossover) error
- func UnmarshalFee(r *bytes.Buffer, f *Fee) error
- func UnmarshalNote(r *bytes.Buffer, f *Note) (err error)
- func UnmarshalTransaction(r *bytes.Buffer, f *Transaction) error
- func UnmarshalTransactionPayload(r *bytes.Buffer, f *TransactionPayload) error
- func UnmarshalTransactionPayloadDecoded(r *bytes.Buffer, f *TransactionPayloadDecoded, txType TxType) error
- type Call
- type ContractCall
- func MockTxWithParams(txtype TxType, gasSpent uint64) ContractCall
- func RandContractCall() ContractCall
- func RandContractCalls(amount, invalid int, includeCoinbase bool) []ContractCall
- func UpdateHash(t ContractCall, hash []byte) (ContractCall, error)
- func UpdateTransaction(t ContractCall, gasSpent uint64, err *rusk.ExecutedTransaction_Error) (ContractCall, error)
- type Crossover
- type Executor
- type Fee
- type MockProxy
- type Note
- type PermissiveExecutor
- func (p *PermissiveExecutor) Accept(context.Context, []ContractCall, []byte, uint64, uint64, []byte, ...) ([]ContractCall, 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, []byte, ...) ([]ContractCall, 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) Persist(context.Context, []byte) error
- func (p *PermissiveExecutor) Revert(ctx context.Context) ([]byte, error)
- func (p *PermissiveExecutor) VerifyStateTransition(context.Context, []ContractCall, uint64, uint64, []byte) ([]byte, error)
- type Proxy
- type Transaction
- func (t Transaction) CalculateHash() ([]byte, error)
- func (t Transaction) Copy() payload.Safe
- func (t Transaction) Decode() (*TransactionPayloadDecoded, error)
- func (t Transaction) Fee() (uint64, error)
- func (t Transaction) GasSpent() uint64
- func (t Transaction) StandardTx() *TransactionPayload
- func (t Transaction) TxError() *rusk.ExecutedTransaction_Error
- func (t Transaction) Type() TxType
- type TransactionPayload
- type TransactionPayloadDecoded
- type TxType
- type UnconfirmedTxProber
Constants ¶
const ( NoteTypeTransparent uint8 = 0 NoteTypeObfuscated uint8 = 1 )
Note types.
Variables ¶
var RandBlind = Rand32Bytes
RandBlind returns a random BlindingFactor (it is just an alias for Rand32Bytes).
Functions ¶
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 UnmarshalCall ¶ added in v0.5.0
UnmarshalCall reads a Call 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.
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.
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 ¶
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.
type MockProxy ¶
type MockProxy struct { V UnconfirmedTxProber 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 { 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 ¶
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.
func (*Note) DecodeTxAmount ¶ added in v0.5.0
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
func (p *PermissiveExecutor) Accept(context.Context, []ContractCall, []byte, uint64, uint64, []byte, *user.Provisioners) ([]ContractCall, user.Provisioners, []byte, error)
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
func (p *PermissiveExecutor) Finalize(context.Context, []ContractCall, []byte, uint64, uint64, []byte, *user.Provisioners) ([]ContractCall, 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) 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.
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 MockInvalidTx ¶
func MockInvalidTx() *Transaction
MockInvalidTx creates an invalid transaction.
func NewTransaction ¶
func NewTransaction() *Transaction
NewTransaction returns a new empty Transaction struct.
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
func (t Transaction) Decode() (*TransactionPayloadDecoded, error)
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
func (t Transaction) TxError() *rusk.ExecutedTransaction_Error
TxError returns the execution error, if set.
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 ¶
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 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.
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).