tx_ver2

package
v0.0.0-...-7ece11e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitConversion

func InitConversion(tx *Tx, params *TxConvertVer1ToVer2InitParams) error

func InitTokenConversion

func InitTokenConversion(txToken *TxToken, params *TxTokenConvertVer1ToVer2InitParams) error

Types

type CustomTokenConversionParams

type CustomTokenConversionParams struct {
	// contains filtered or unexported fields
}

type SigPubKey

type SigPubKey struct {
	Indexes [][]*big.Int
}

SigPubKey defines the public key to sign ring signatures in version 2. It is an array of coin indexes.

func (SigPubKey) Bytes

func (sigPub SigPubKey) Bytes() ([]byte, error)

func (*SigPubKey) SetBytes

func (sigPub *SigPubKey) SetBytes(b []byte) error

type Tx

type Tx struct {
	tx_generic.TxBase
}

Tx struct for version 2 contains the same fields as before

func (*Tx) CheckData

func (tx *Tx) CheckData(transactionStateDB *statedb.StateDB) error

Retrieve ring from database using sigpubkey and last column commitment (last column = sumOutputCoinCommitment + fee)

func (*Tx) GetReceiverData

func (tx *Tx) GetReceiverData() ([]privacy.Coin, error)

GetReceiverData returns output coins for this function

func (Tx) GetTxActualSize

func (tx Tx) GetTxActualSize() uint64

GetTxActualSize returns the size of this TX. It is the length of its JSON form.

func (Tx) GetTxBurnData

func (tx Tx) GetTxBurnData() (bool, privacy.Coin, *common.Hash, error)

func (Tx) GetTxFullBurnData

func (tx Tx) GetTxFullBurnData() (bool, privacy.Coin, privacy.Coin, *common.Hash, error)

func (Tx) GetTxMintData

func (tx Tx) GetTxMintData() (bool, privacy.Coin, *common.Hash, error)

func (Tx) Hash

func (tx Tx) Hash() *common.Hash

nolint:revive // skip linter since this function modifies a value receiver Hash returns the hash of this transaction. All non-signature fields are marshalled into JSON before hashing

func (Tx) HashWithoutMetadataSig

func (tx Tx) HashWithoutMetadataSig() *common.Hash

HashWithoutMetadataSig returns the hash of this transaction, but it leaves out the metadata's own signature field. It is used to verify that metadata signature.

func (*Tx) Init

func (tx *Tx) Init(paramsInterface interface{}) error

Init uses the information in parameter to create a valid, signed Tx.

func (*Tx) InitTxSalary

func (tx *Tx) InitTxSalary(otaCoin *privacy.CoinV2, privateKey *privacy.PrivateKey, stateDB *statedb.StateDB, metaData metadata.Metadata) error

InitTxSalary is used to create a "mint" transaction of version 2. The minting rule is covered inside the metadata.

func (Tx) IsSalaryTx

func (tx Tx) IsSalaryTx() bool

func (Tx) ListOTAHashH

func (tx Tx) ListOTAHashH() []common.Hash

func (*Tx) LoadData

func (tx *Tx) LoadData(transactionStateDB *statedb.StateDB) error

Retrieve ring from database using sigpubkey and last column commitment (last column = sumOutputCoinCommitment + fee)

func (Tx) ValidateSanityData

func (tx Tx) ValidateSanityData(chainRetriever metadata.ChainRetriever, shardViewRetriever metadata.ShardViewRetriever, beaconViewRetriever metadata.BeaconViewRetriever, beaconHeight uint64) (bool, error)

func (*Tx) ValidateSanityDataByItSelf

func (tx *Tx) ValidateSanityDataByItSelf() (bool, error)

func (*Tx) ValidateSanityDataWithBlockchain

func (tx *Tx) ValidateSanityDataWithBlockchain(
	chainRetriever metadata.ChainRetriever,
	shardViewRetriever metadata.ShardViewRetriever,
	beaconViewRetriever metadata.BeaconViewRetriever,
	beaconHeight uint64,
) (
	bool,
	error,
)

func (Tx) ValidateTransaction

func (tx Tx) ValidateTransaction(boolParams map[string]bool, transactionStateDB *statedb.StateDB, bridgeStateDB *statedb.StateDB, shardID byte, tokenID *common.Hash) (bool, []privacy.Proof, error)

func (Tx) ValidateTxByItself

func (tx Tx) ValidateTxByItself(boolParams map[string]bool, transactionStateDB *statedb.StateDB, bridgeStateDB *statedb.StateDB, chainRetriever metadata.ChainRetriever, shardID byte, shardViewRetriever metadata.ShardViewRetriever, beaconViewRetriever metadata.BeaconViewRetriever) (bool, error)

func (*Tx) ValidateTxCorrectness

func (tx *Tx) ValidateTxCorrectness(transactionStateDB *statedb.StateDB) (bool, error)

func (*Tx) ValidateTxSalary

func (tx *Tx) ValidateTxSalary(db *statedb.StateDB) (bool, error)

ValidateTxSalary checks the following conditions for salary transactions (s, rs):

  • the signature is valid
  • the number of output coins is 1
  • all fields of the output coins are valid
  • the commitment has been calculated correctly
  • the ota has not existed

func (*Tx) ValidateTxWithBlockChain

func (tx *Tx) ValidateTxWithBlockChain(chainRetriever metadata.ChainRetriever, shardViewRetriever metadata.ShardViewRetriever, beaconViewRetriever metadata.BeaconViewRetriever, shardID byte, stateDB *statedb.StateDB) error

func (Tx) ValidateTxWithCurrentMempool

func (tx Tx) ValidateTxWithCurrentMempool(mr metadata.MempoolRetriever) error

func (*Tx) Verify

func (tx *Tx) Verify(boolParams map[string]bool, transactionStateDB *statedb.StateDB, bridgeStateDB *statedb.StateDB, shardID byte, tokenID *common.Hash) (bool, error)

Verify is the sub-function for ValidateTransaction. It is called in the verification flow of most transactions, excluding some special TX types. It takes in boolParams to reflect some big differences across code versions; and db pointer, shard ID & token ID to get coins from the chain database.

func (Tx) VerifyMinerCreatedTxBeforeGettingInBlock

func (tx Tx) VerifyMinerCreatedTxBeforeGettingInBlock(mintdata *metadata.MintData, shardID byte, bcr metadata.ChainRetriever, accumulatedValues *metadata.AccumulatedValues, retriever metadata.ShardViewRetriever, viewRetriever metadata.BeaconViewRetriever) (bool, error)

VerifyMinerCreatedTxBeforeGettingInBlock checks that a transaction was created by a miner

func (*Tx) VerifySigTx

func (tx *Tx) VerifySigTx(transactionStateDB *statedb.StateDB) (bool, error)

type TxConvertVer1ToVer2InitParams

type TxConvertVer1ToVer2InitParams struct {
	// contains filtered or unexported fields
}

func NewTxConvertVer1ToVer2InitParams

func NewTxConvertVer1ToVer2InitParams(senderSK *privacy.PrivateKey,
	paymentInfo []*privacy.PaymentInfo,
	inputCoins []privacy.PlainCoin,
	fee uint64,
	stateDB *statedb.StateDB,
	tokenID *common.Hash,
	metaData metadata.Metadata,
	info []byte) *TxConvertVer1ToVer2InitParams

type TxToken

type TxToken struct {
	Tx        Tx                  `json:"Tx"`
	TokenData TxTokenDataVersion2 `json:"TxTokenPrivacyData"`
	// contains filtered or unexported fields
}

TxToken is the struct for pToken transaction. Its attributes:

- Tx describes a PRV transfer (typically the fee payment) - TokenData describes a pToken transfer / creation

func (*TxToken) CalculateTxValue

func (txToken *TxToken) CalculateTxValue() uint64

func (*TxToken) CheckData

func (txToken *TxToken) CheckData(transactionStateDB *statedb.StateDB) error

func (TxToken) CheckTxVersion

func (txToken TxToken) CheckTxVersion(maxTxVersion int8) bool

func (TxToken) GetCachedActualSize

func (txToken TxToken) GetCachedActualSize() *uint64

not supported

func (TxToken) GetCachedHash

func (txToken TxToken) GetCachedHash() *common.Hash

not supported

func (TxToken) GetInfo

func (txToken TxToken) GetInfo() []byte

GetInfo returns the transaction's extra information. A pToken transaction only has one Info.

func (TxToken) GetLockTime

func (txToken TxToken) GetLockTime() int64

GetLockTime returns the transaction's time. A pToken transaction only has one LockTime.

func (TxToken) GetMetadata

func (txToken TxToken) GetMetadata() metadata.Metadata

GetMetadataType returns the transaction's metadata. A pToken transaction only has one metadata.

func (TxToken) GetMetadataType

func (txToken TxToken) GetMetadataType() int

GetMetadataType returns the metadata type. A pToken transaction only has one metadata.

func (TxToken) GetPrivateKey

func (txToken TxToken) GetPrivateKey() []byte

GetPrivateKey returns the private key being used to sign this TxToken. The private key is always cleared after signing.

func (TxToken) GetProof

func (txToken TxToken) GetProof() privacy.Proof

not supported

func (*TxToken) GetReceiverData

func (txToken *TxToken) GetReceiverData() ([]privacy.Coin, error)

func (TxToken) GetReceivers

func (txToken TxToken) GetReceivers() ([][]byte, []uint64)

func (TxToken) GetSenderAddrLastByte

func (txToken TxToken) GetSenderAddrLastByte() byte

GetSenderAddrLastByte returns the SHARD ID of this transaction sender. It uses this legacy function name for compatibility purposes.

func (TxToken) GetSig

func (txToken TxToken) GetSig() []byte

not supported

func (TxToken) GetSigPubKey

func (txToken TxToken) GetSigPubKey() []byte

not supported

func (TxToken) GetTokenID

func (txToken TxToken) GetTokenID() *common.Hash

GetTokenID returns the token ID for this TxToken.

func (*TxToken) GetTransferData

func (txToken *TxToken) GetTransferData() (bool, []byte, uint64, *common.Hash)

func (TxToken) GetTxActualSize

func (txToken TxToken) GetTxActualSize() uint64

GetTxActualSize returns the size of this TxToken. It is the length of its JSON form.

func (*TxToken) GetTxBase

func (txToken *TxToken) GetTxBase() metadata.Transaction

GetTxBase returns the Tx field in this TxToken as a generic Transaction.

func (*TxToken) GetTxBurnData

func (txToken *TxToken) GetTxBurnData() (bool, privacy.Coin, *common.Hash, error)

func (TxToken) GetTxFee

func (txToken TxToken) GetTxFee() uint64

GetTxFee returns the fee of this TxToken (fee is in PRV). A pToken transaction only has one Fee.

func (TxToken) GetTxFeeToken

func (txToken TxToken) GetTxFeeToken() uint64

GetTxFeeToken is a filler function to satisfy the interface. It returns zero since paying fee in pToken is no longer supported.

func (*TxToken) GetTxFullBurnData

func (txToken *TxToken) GetTxFullBurnData() (bool, privacy.Coin, privacy.Coin, *common.Hash, error)

func (*TxToken) GetTxMintData

func (txToken *TxToken) GetTxMintData() (bool, privacy.Coin, *common.Hash, error)

func (*TxToken) GetTxNormal

func (txToken *TxToken) GetTxNormal() metadata.Transaction

GetTxNormal returns a Transaction describing the "token" part of this TxToken.

func (*TxToken) GetTxTokenData

func (txToken *TxToken) GetTxTokenData() tx_generic.TxTokenData

func (TxToken) GetType

func (txToken TxToken) GetType() string

GetType returns the transaction type. A pToken transaction only has one Type (TokenData's Type is a separate enum).

func (*TxToken) GetValidationEnv

func (txToken *TxToken) GetValidationEnv() metadata.ValidationEnviroment

func (TxToken) GetVersion

func (txToken TxToken) GetVersion() int8

-- OVERRIDE--

func (*TxToken) Hash

func (txToken *TxToken) Hash() *common.Hash

Hash returns the hash of this object. For TxToken, we just concatenate the hash of its fields, then hash that again.

func (TxToken) HashWithoutMetadataSig

func (txToken TxToken) HashWithoutMetadataSig() *common.Hash

func (*TxToken) Init

func (txToken *TxToken) Init(paramsInterface interface{}) error

Init uses the information in the parameter to create a valid, signed pToken transaction.

func (*TxToken) InitTxTokenSalary

func (txToken *TxToken) InitTxTokenSalary(otaCoin *privacy.CoinV2, privKey *privacy.PrivateKey, stateDB *statedb.StateDB, metaData metadata.Metadata, coinID *common.Hash, coinName string) error

InitTxTokenSalary creates a transaction that "mints" some pToken. The minting rule is covered by the metadata.

func (*TxToken) IsCoinsBurning

func (txToken *TxToken) IsCoinsBurning(bcr metadata.ChainRetriever, retriever metadata.ShardViewRetriever, viewRetriever metadata.BeaconViewRetriever, beaconHeight uint64) bool

func (TxToken) IsPrivacy

func (txToken TxToken) IsPrivacy() bool

func (TxToken) IsSalaryTx

func (txToken TxToken) IsSalaryTx() bool

IsSalaryTx checks if the transaction is a token salary transaction. A token salary transaction is a transaction produced by shard committees with the following conditions:

- mintable is true, tokenType is CustomTokenInit - PRV proof is nil - no input token - only output token

func (TxToken) ListOTAHashH

func (txToken TxToken) ListOTAHashH() []common.Hash

func (TxToken) ListSerialNumbersHashH

func (txToken TxToken) ListSerialNumbersHashH() []common.Hash

func (*TxToken) LoadData

func (txToken *TxToken) LoadData(transactionStateDB *statedb.StateDB) error

func (*TxToken) SetCachedActualSize

func (txToken *TxToken) SetCachedActualSize(sz *uint64)

func (*TxToken) SetCachedHash

func (txToken *TxToken) SetCachedHash(h *common.Hash)

not supported

func (*TxToken) SetGetSenderAddrLastByte

func (txToken *TxToken) SetGetSenderAddrLastByte(b byte)

func (*TxToken) SetInfo

func (txToken *TxToken) SetInfo(info []byte)

func (*TxToken) SetLockTime

func (txToken *TxToken) SetLockTime(locktime int64)

func (*TxToken) SetMetadata

func (txToken *TxToken) SetMetadata(meta metadata.Metadata)

func (*TxToken) SetPrivateKey

func (txToken *TxToken) SetPrivateKey(sk []byte)

func (*TxToken) SetProof

func (txToken *TxToken) SetProof(proof privacy.Proof)

not supported

func (*TxToken) SetSig

func (txToken *TxToken) SetSig(sig []byte)

not supported

func (*TxToken) SetSigPubKey

func (txToken *TxToken) SetSigPubKey(sigPubkey []byte)

not supported

func (*TxToken) SetTxBase

func (txToken *TxToken) SetTxBase(inTx metadata.Transaction) error

SetTxBase tries to set the Tx field to inTx. It can fail when inTx has the wrong version.

func (*TxToken) SetTxFee

func (txToken *TxToken) SetTxFee(fee uint64)

func (*TxToken) SetTxNormal

func (txToken *TxToken) SetTxNormal(inTx metadata.Transaction) error

SetTxNormal extracts the data in inTx & puts it in the TokenData of this TxToken

func (*TxToken) SetTxTokenData

func (txToken *TxToken) SetTxTokenData(data tx_generic.TxTokenData) error

func (*TxToken) SetType

func (txToken *TxToken) SetType(t string)

func (*TxToken) SetValidationEnv

func (txToken *TxToken) SetValidationEnv(valEnv metadata.ValidationEnviroment)

func (*TxToken) SetVersion

func (txToken *TxToken) SetVersion(version int8)

func (TxToken) String

func (txToken TxToken) String() string

func (*TxToken) UnmarshalJSON

func (txToken *TxToken) UnmarshalJSON(data []byte) error

func (*TxToken) ValidateDoubleSpendWithBlockchain

func (txToken *TxToken) ValidateDoubleSpendWithBlockchain(shardID byte, stateDB *statedb.StateDB, tokenID *common.Hash) error

func (TxToken) ValidateSanityData

func (txToken TxToken) ValidateSanityData(chainRetriever metadata.ChainRetriever, shardViewRetriever metadata.ShardViewRetriever, beaconViewRetriever metadata.BeaconViewRetriever, beaconHeight uint64) (bool, error)

ValidateSanityData performs sanity checks for this TxToken (including its descendant fields & metadata)

func (*TxToken) ValidateSanityDataByItSelf

func (txToken *TxToken) ValidateSanityDataByItSelf() (bool, error)

func (*TxToken) ValidateSanityDataWithBlockchain

func (txToken *TxToken) ValidateSanityDataWithBlockchain(
	chainRetriever metadata.ChainRetriever,
	shardViewRetriever metadata.ShardViewRetriever,
	beaconViewRetriever metadata.BeaconViewRetriever,
	beaconHeight uint64,
) (
	bool,
	error,
)

func (*TxToken) ValidateSanityDataWithMetadata

func (txToken *TxToken) ValidateSanityDataWithMetadata() (bool, error)

func (TxToken) ValidateTransaction

func (txToken TxToken) ValidateTransaction(boolParams map[string]bool, transactionStateDB *statedb.StateDB, bridgeStateDB *statedb.StateDB, shardID byte, tokenID *common.Hash) (bool, []privacy.Proof, error)

ValidateTransaction does the same verification as ValidateTxByItself, but it works with Bulletproof batching.

func (TxToken) ValidateTxByItself

func (txToken TxToken) ValidateTxByItself(boolParams map[string]bool, transactionStateDB *statedb.StateDB, bridgeStateDB *statedb.StateDB, chainRetriever metadata.ChainRetriever, shardID byte, shardViewRetriever metadata.ShardViewRetriever, beaconViewRetriever metadata.BeaconViewRetriever) (bool, error)

ValidateTxByItself does most of the verification for TxToken, including bulletproofs, signatures & metadata. This depends on the chain state defined by shard ID & db pointer, as well as boolParams (which handles code version differences)

func (*TxToken) ValidateTxCorrectness

func (txToken *TxToken) ValidateTxCorrectness(transactionStateDB *statedb.StateDB) (bool, error)

func (*TxToken) ValidateTxSalary

func (txToken *TxToken) ValidateTxSalary(db *statedb.StateDB) (bool, error)

ValidateTxSalary checks the following conditions for minteable transactions:

  • the signature is valid
  • all fields of the output coins are valid: commitment, assetTag, etc,.
  • the commitment has been calculated correctly
  • the ota has not existed

func (*TxToken) ValidateTxWithBlockChain

func (txToken *TxToken) ValidateTxWithBlockChain(chainRetriever metadata.ChainRetriever, shardViewRetriever metadata.ShardViewRetriever, beaconViewRetriever metadata.BeaconViewRetriever, shardID byte, stateDB *statedb.StateDB) error

func (*TxToken) ValidateTxWithCurrentMempool

func (txToken *TxToken) ValidateTxWithCurrentMempool(mr metadata.MempoolRetriever) error

func (TxToken) ValidateType

func (txToken TxToken) ValidateType() bool

func (*TxToken) Verify

func (txToken *TxToken) Verify(boolParams map[string]bool, transactionStateDB *statedb.StateDB, bridgeStateDB *statedb.StateDB, shardID byte, tokenID *common.Hash) (bool, error)

Verify is the sub-function for ValidateTransaction. This is in the verification flow of most TXs (excluding some special types).

func (*TxToken) VerifyMinerCreatedTxBeforeGettingInBlock

func (txToken *TxToken) VerifyMinerCreatedTxBeforeGettingInBlock(mintData *metadata.MintData, shardID byte, bcr metadata.ChainRetriever, accumulatedValues *metadata.AccumulatedValues, retriever metadata.ShardViewRetriever, viewRetriever metadata.BeaconViewRetriever) (bool, error)

type TxTokenConvertVer1ToVer2InitParams

type TxTokenConvertVer1ToVer2InitParams struct {
	// contains filtered or unexported fields
}

func NewTxTokenConvertVer1ToVer2InitParams

func NewTxTokenConvertVer1ToVer2InitParams(senderSK *privacy.PrivateKey,
	feeInputs []privacy.PlainCoin,
	feePayments []*privacy.PaymentInfo,
	tokenInputs []privacy.PlainCoin,
	tokenPayments []*privacy.PaymentInfo,
	fee uint64,
	stateDB *statedb.StateDB,
	bridgeStateDB *statedb.StateDB,
	tokenID *common.Hash,
	metaData metadata.Metadata,
	info []byte) *TxTokenConvertVer1ToVer2InitParams

type TxTokenDataVersion2

type TxTokenDataVersion2 struct {
	PropertyID     common.Hash
	PropertyName   string
	PropertySymbol string
	SigPubKey      []byte `json:"SigPubKey,omitempty"` // 33 bytes
	Sig            []byte `json:"Sig,omitempty"`       //
	Proof          privacy.Proof

	Type     int
	Mintable bool
}

TxTokenDataVersion2 contains the token data for a pToken transaction (input / output coins, signature, token ID, type of transfer, ...). Unlike the previous version, this does not have a *Tx field in it; this avoids duplication of data.

func (TxTokenDataVersion2) Hash

func (td TxTokenDataVersion2) Hash() (*common.Hash, error)

Hash returns the hash of this object. All non-signature fields are marshalled to JSON beforehand.

func (TxTokenDataVersion2) ToCompatTokenData

ToCompatTokenData uses the data from TxToken to construct a TxTokenData of the previous version (for compatibility).

Jump to

Keyboard shortcuts

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