transaction

package
v0.0.0-...-8d384ed Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: LGPL-3.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
	// ErrEthCompatibleTransactionIsntCompatible is returned if the transaction has EthCompatible: true
	// but has non-nil-or-0 values for some of the Celo-only fields
	ErrEthCompatibleTransactionIsntCompatible = errors.New("ethCompatible is true, but non-eth-compatible fields are present")
)
View Source
var (
	ErrInvalidChainId = errors.New("invalid chain id for signer")
)

Functions

func NewCeloTransaction

func NewCeloTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice []*big.Int, data []byte) (evmclient.CommonTransaction, error)

func Sender

func Sender(signer CeloSigner, tx *CeloTransaction) (common.Address, error)

Sender returns the address derived from the signature (V, R, S) using secp256k1 elliptic curve and an error if it failed deriving or upon an incorrect signature.

Sender may cache the address, allowing it to be used regardless of signing method. The cache is invalidated if the cached signer does not match the signer used in the current call.

Types

type CeloSigner

type CeloSigner interface {
	// Sender returns the sender address of the transaction.
	Sender(tx *CeloTransaction) (common.Address, error)
	// SignatureValues returns the raw R, S, V values corresponding to the
	// given signature.
	SignatureValues(tx *CeloTransaction, sig []byte) (r, s, v *big.Int, err error)
	// Hash returns the hash to be signed.
	Hash(tx *CeloTransaction) common.Hash
	// Equal returns true if the given signer is the same as the receiver.
	Equal(CeloSigner) bool
}

Signer encapsulates transaction signature handling. Note that this interface is not a stable API and may change at any time to accommodate new protocol rules.

func MakeSigner

func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) CeloSigner

MakeSigner returns a Signer based on the given chain config and block number.

type CeloTransaction

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

func SignTx

SignTx signs the transaction using the given signer and private key

func (*CeloTransaction) AsMessage

func (tx *CeloTransaction) AsMessage(s CeloSigner) (Message, error)

AsMessage returns the transaction as a core.Message.

AsMessage requires a signer to derive the sender.

XXX Rename message to something less arbitrary?

func (*CeloTransaction) ChainId

func (tx *CeloTransaction) ChainId() *big.Int

ChainId returns which chain id this transaction was signed for (if at all)

func (*CeloTransaction) CheckEthCompatibility

func (tx *CeloTransaction) CheckEthCompatibility() error

CheckEthCompatibility checks that the Celo-only fields are nil-or-0 if EthCompatible is true

func (*CeloTransaction) CheckNonce

func (tx *CeloTransaction) CheckNonce() bool

func (*CeloTransaction) Cost

func (tx *CeloTransaction) Cost() *big.Int

Cost returns amount + gasprice * gaslimit + gatewayfee.

func (*CeloTransaction) Data

func (tx *CeloTransaction) Data() []byte

func (*CeloTransaction) DecodeRLP

func (tx *CeloTransaction) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements celorlp.Decoder

func (*CeloTransaction) EncodeRLP

func (tx *CeloTransaction) EncodeRLP(w io.Writer) error

EncodeRLP implements celorlp.Encoder

func (*CeloTransaction) EthCompatible

func (tx *CeloTransaction) EthCompatible() bool

func (*CeloTransaction) Fee

func (tx *CeloTransaction) Fee() *big.Int

func (*CeloTransaction) FeeCurrency

func (tx *CeloTransaction) FeeCurrency() *common.Address

func (*CeloTransaction) Gas

func (tx *CeloTransaction) Gas() uint64

func (*CeloTransaction) GasPrice

func (tx *CeloTransaction) GasPrice() *big.Int

func (*CeloTransaction) GatewayFee

func (tx *CeloTransaction) GatewayFee() *big.Int

func (*CeloTransaction) GatewayFeeRecipient

func (tx *CeloTransaction) GatewayFeeRecipient() *common.Address

func (*CeloTransaction) Hash

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

Hash hashes the RLP encoding of tx. It uniquely identifies the transaction.

func (*CeloTransaction) MarshalJSON

func (tx *CeloTransaction) MarshalJSON() ([]byte, error)

MarshalJSON encodes the web3 RPC transaction format.

func (*CeloTransaction) Nonce

func (tx *CeloTransaction) Nonce() uint64

func (*CeloTransaction) Protected

func (tx *CeloTransaction) Protected() bool

Protected returns whether the transaction is protected from replay protection.

func (*CeloTransaction) RawSignatureValues

func (tx *CeloTransaction) RawSignatureValues() (v, r, s *big.Int)

RawSignatureValues returns the V, R, S signature values of the transaction. The return values should not be modified by the caller.

func (*CeloTransaction) RawWithSignature

func (tx *CeloTransaction) RawWithSignature(key *ecdsa.PrivateKey, chainID *big.Int) ([]byte, error)

func (*CeloTransaction) Size

func (tx *CeloTransaction) Size() common.StorageSize

Size returns the true RLP encoded storage size of the transaction, either by encoding and returning it, or returning a previsouly cached value.

func (*CeloTransaction) To

func (tx *CeloTransaction) To() *common.Address

To returns the recipient address of the transaction. It returns nil if the transaction is a contract creation.

func (*CeloTransaction) UnmarshalJSON

func (tx *CeloTransaction) UnmarshalJSON(input []byte) error

UnmarshalJSON decodes the web3 RPC transaction format.

func (*CeloTransaction) Value

func (tx *CeloTransaction) Value() *big.Int

func (*CeloTransaction) WithSignature

func (tx *CeloTransaction) WithSignature(signer CeloSigner, sig []byte) (*CeloTransaction, error)

WithSignature returns a new transaction with the given signature. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type CeloTransactions

type CeloTransactions []*CeloTransaction

Transactions is a Transaction slice type for basic sorting.

func TxDifference

func TxDifference(a, b CeloTransactions) CeloTransactions

TxDifference returns a new set which is the difference between a and b.

func (CeloTransactions) GetRlp

func (s CeloTransactions) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in celorlp.

func (CeloTransactions) Len

func (s CeloTransactions) Len() int

Len returns the length of s.

func (CeloTransactions) Swap

func (s CeloTransactions) Swap(i, j int)

Swap swaps the i'th and the j'th element in s.

type EIP155Signer

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

EIP155Transaction implements Signer using the EIP155 rules.

func NewEIP155Signer

func NewEIP155Signer(chainId *big.Int) EIP155Signer

func (EIP155Signer) Equal

func (s EIP155Signer) Equal(s2 CeloSigner) bool

func (EIP155Signer) Hash

Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.

func (EIP155Signer) Sender

func (s EIP155Signer) Sender(tx *CeloTransaction) (common.Address, error)

func (EIP155Signer) SignatureValues

func (s EIP155Signer) SignatureValues(tx *CeloTransaction, sig []byte) (R, S, V *big.Int, err error)

SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type FrontierSigner

type FrontierSigner struct{}

func (FrontierSigner) Equal

func (s FrontierSigner) Equal(s2 CeloSigner) bool

func (FrontierSigner) Hash

Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.

func (FrontierSigner) Sender

func (FrontierSigner) SignatureValues

func (fs FrontierSigner) SignatureValues(tx *CeloTransaction, sig []byte) (r, s, v *big.Int, err error)

SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type HomesteadSigner

type HomesteadSigner struct{ FrontierSigner }

HomesteadTransaction implements TransactionInterface using the homestead rules.

func (HomesteadSigner) Equal

func (s HomesteadSigner) Equal(s2 CeloSigner) bool

func (HomesteadSigner) Sender

func (HomesteadSigner) SenderData

func (hs HomesteadSigner) SenderData(data common.Hash, sig []byte) (common.Address, []byte, error)

func (HomesteadSigner) SignatureValues

func (hs HomesteadSigner) SignatureValues(tx *CeloTransaction, sig []byte) (r, s, v *big.Int, err error)

SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type Message

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

Message is a fully derived transaction and implements core.Message

NOTE: In a future PR this will be removed.

func NewMessage

func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, feeCurrency, gatewayFeeRecipient *common.Address, gatewayFee *big.Int, data []byte, ethCompatible, checkNonce bool) Message

func (Message) CheckNonce

func (m Message) CheckNonce() bool

func (Message) Data

func (m Message) Data() []byte

func (Message) EthCompatible

func (m Message) EthCompatible() bool

func (Message) Fee

func (m Message) Fee() *big.Int

func (Message) FeeCurrency

func (m Message) FeeCurrency() *common.Address

func (Message) From

func (m Message) From() common.Address

func (Message) Gas

func (m Message) Gas() uint64

func (Message) GasPrice

func (m Message) GasPrice() *big.Int

func (Message) GatewayFee

func (m Message) GatewayFee() *big.Int

func (Message) GatewayFeeRecipient

func (m Message) GatewayFeeRecipient() *common.Address

func (Message) Nonce

func (m Message) Nonce() uint64

func (Message) To

func (m Message) To() *common.Address

func (Message) Value

func (m Message) Value() *big.Int

type TransactOpts

type TransactOpts struct {
	From   common.Address // Ethereum account to send the transaction from
	Nonce  *big.Int       // Nonce to use for the transaction execution (nil = use pending state)
	Signer SignerFn       // Method to use for signing the transaction (mandatory)

	Value               *big.Int        // Funds to transfer along along the transaction (nil = 0 = no funds)
	GasPrice            *big.Int        // Gas price to use for the transaction execution (nil = gas price oracle)
	FeeCurrency         *common.Address // Fee currency to be used for transaction (nil = default currency = Celo Gold)
	GatewayFeeRecipient *common.Address // Address to which gateway fees should be paid (nil = no gateway fees are paid)
	GatewayFee          *big.Int        // Value of gateway fees to be paid (nil = no gateway fees are paid)
	GasLimit            uint64          // Gas limit to set for the transaction execution (0 = estimate)

	Context context.Context // Network context to support cancellation and timeouts (nil = no timeout)
}

TransactOpts is the collection of authorization data required to create a valid Ethereum transaction.

func NewKeyStoreTransactor

func NewKeyStoreTransactor(keystore *keystore.KeyStore, account accounts.Account) (*TransactOpts, error)

NewKeyStoreTransactor is a utility method to easily create a transaction signer from an decrypted key from a keystore

func NewKeyedTransactor

func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts

NewKeyedTransactor is a utility method to easily create a transaction signer from a single private key.

func NewTransactor

func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error)

NewTransactor is a utility method to easily create a transaction signer from an encrypted json key stream and the associated passphrase.

Jump to

Keyboard shortcuts

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