types

package
v0.0.0-...-1bc71c5 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidChainID = errors.New("invalid chain id for signer")
	ErrInvalidSig     = errors.New("invalid transaction v, r, s values")
)

sign tx errors

Functions

func Sender

func Sender(signer Signer, tx *Transaction) (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.

func ToBlockNumArg

func ToBlockNumArg(number *big.Int) string

ToBlockNumArg to block number arg

func ToFilterArg

func ToFilterArg(q *FilterQuery) (interface{}, error)

ToFilterArg query to filter arg

Types

type EIP155Signer

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

EIP155Signer implements Signer using the EIP155 rules.

func NewEIP155Signer

func NewEIP155Signer(chainID *big.Int) EIP155Signer

NewEIP155Signer new EIP155Signer

func (EIP155Signer) Equal

func (s EIP155Signer) Equal(s2 Signer) bool

Equal compare signer

func (EIP155Signer) Hash

func (s EIP155Signer) Hash(tx *Transaction) common.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 *Transaction) (common.Address, error)

Sender get sender

func (EIP155Signer) SignatureValues

func (s EIP155Signer) SignatureValues(tx *Transaction, sig []byte) (rsvR, rsvS, rsvV *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 FilterQuery

type FilterQuery struct {
	BlockHash *common.Hash
	FromBlock *big.Int
	ToBlock   *big.Int
	Addresses []common.Address
	Topics    [][]common.Hash
}

FilterQuery struct

type FrontierSigner

type FrontierSigner struct{}

FrontierSigner frontier signer

func (FrontierSigner) Equal

func (fs FrontierSigner) Equal(s2 Signer) bool

Equal compare signer

func (FrontierSigner) Hash

func (fs FrontierSigner) Hash(tx *Transaction) common.Hash

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

func (FrontierSigner) Sender

func (fs FrontierSigner) Sender(tx *Transaction) (common.Address, error)

Sender get sender

func (FrontierSigner) SignatureValues

func (fs FrontierSigner) SignatureValues(tx *Transaction, 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 }

HomesteadSigner implements TransactionInterface using the homestead rules.

func (HomesteadSigner) Equal

func (hs HomesteadSigner) Equal(s2 Signer) bool

Equal compare signer

func (HomesteadSigner) Sender

func (hs HomesteadSigner) Sender(tx *Transaction) (common.Address, error)

Sender get sender

func (HomesteadSigner) SignatureValues

func (hs HomesteadSigner) SignatureValues(tx *Transaction, 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 RPCBlock

type RPCBlock struct {
	Hash            *common.Hash    `json:"hash"`
	ParentHash      *common.Hash    `json:"parentHash"`
	UncleHash       *common.Hash    `json:"sha3Uncles"`
	Coinbase        *common.Address `json:"miner"`
	Root            *common.Hash    `json:"stateRoot"`
	TxHash          *common.Hash    `json:"transactionsRoot"`
	ReceiptHash     *common.Hash    `json:"receiptsRoot"`
	Bloom           *hexutil.Bytes  `json:"logsBloom"`
	Difficulty      *hexutil.Big    `json:"difficulty"`
	Number          *hexutil.Big    `json:"number"`
	GasLimit        *hexutil.Uint64 `json:"gasLimit"`
	GasUsed         *hexutil.Uint64 `json:"gasUsed"`
	Time            *hexutil.Big    `json:"timestamp"`
	Extra           *hexutil.Bytes  `json:"extraData"`
	MixDigest       *common.Hash    `json:"mixHash"`
	Nonce           *hexutil.Bytes  `json:"nonce"`
	Size            interface{}     `json:"size"` // unexpect maybe string or number
	TotalDifficulty *hexutil.Big    `json:"totalDifficulty"`
	Transactions    []*common.Hash  `json:"transactions"`
	Uncles          []*common.Hash  `json:"uncles"`
}

RPCBlock struct

type RPCLog

type RPCLog struct {
	Address     *common.Address `json:"address"`
	Topics      []common.Hash   `json:"topics"`
	Data        *hexutil.Bytes  `json:"data"`
	BlockNumber *hexutil.Uint64 `json:"blockNumber"`
	TxHash      *common.Hash    `json:"transactionHash"`
	TxIndex     *hexutil.Uint   `json:"transactionIndex"`
	BlockHash   *common.Hash    `json:"blockHash"`
	Index       *hexutil.Uint   `json:"logIndex"`
	Removed     *bool           `json:"removed"`
}

RPCLog struct

type RPCTransaction

type RPCTransaction struct {
	Hash             *common.Hash    `json:"hash"`
	TransactionIndex *hexutil.Uint   `json:"transactionIndex"`
	BlockNumber      *hexutil.Big    `json:"blockNumber,omitempty"`
	BlockHash        *common.Hash    `json:"blockHash,omitempty"`
	From             *common.Address `json:"from,omitempty"`
	AccountNonce     interface{}     `json:"nonce"` // unexpect RSK has leading zero (eg. 0x01)
	Price            *hexutil.Big    `json:"gasPrice"`
	GasLimit         *hexutil.Uint64 `json:"gas"`
	Recipient        *common.Address `json:"to"`
	Amount           *hexutil.Big    `json:"value"`
	Payload          *hexutil.Bytes  `json:"input"`
	V                *hexutil.Big    `json:"v"`
	R                *hexutil.Big    `json:"r"`
	S                *hexutil.Big    `json:"s"`
}

RPCTransaction struct

type RPCTxAndReceipt

type RPCTxAndReceipt struct {
	FsnTxInput   interface{}     `json:"fsnTxInput,omitempty"`
	Tx           *RPCTransaction `json:"tx"`
	Receipt      *RPCTxReceipt   `json:"receipt"`
	ReceiptFound *bool           `json:"receiptFound"`
}

RPCTxAndReceipt struct

type RPCTxReceipt

type RPCTxReceipt struct {
	TxHash            *common.Hash    `json:"transactionHash"`
	TxIndex           *hexutil.Uint   `json:"transactionIndex"`
	BlockNumber       *hexutil.Big    `json:"blockNumber"`
	BlockHash         *common.Hash    `json:"blockHash"`
	PostState         *hexutil.Bytes  `json:"root"`
	Status            *hexutil.Uint64 `json:"status"`
	From              *common.Address `json:"from"`
	Recipient         *common.Address `json:"to"`
	GasUsed           *hexutil.Uint64 `json:"gasUsed"`
	CumulativeGasUsed *hexutil.Uint64 `json:"cumulativeGasUsed"`
	ContractAddress   *common.Address `json:"contractAddress,omitempty"`
	Bloom             *hexutil.Bytes  `json:"logsBloom"`
	FsnLogTopic       *string         `json:"fsnLogTopic,omitempty"`
	FsnLogData        interface{}     `json:"fsnLogData,omitempty"`
	Logs              []*RPCLog       `json:"logs"`
}

RPCTxReceipt struct

type Signer

type Signer interface {
	// Sender returns the sender address of the transaction.
	Sender(tx *Transaction) (common.Address, error)
	// SignatureValues returns the raw R, S, V values corresponding to the
	// given signature.
	SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error)
	// Hash returns the hash to be signed.
	Hash(tx *Transaction) common.Hash
	// Equal returns true if the given signer is the same as the receiver.
	Equal(Signer) 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(signType string, chainID *big.Int) Signer

MakeSigner make signer

type StorageSize

type StorageSize float64

StorageSize type

type Transaction

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

Transaction struct

func NewContractCreation

func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction

NewContractCreation new contract creation

func NewTransaction

func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction

NewTransaction new tx

func SignTx

func SignTx(tx *Transaction, s Signer, prv *ecdsa.PrivateKey) (*Transaction, error)

SignTx signs the transaction using the given signer and private key

func (*Transaction) ChainID

func (tx *Transaction) ChainID() *big.Int

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

func (*Transaction) CheckNonce

func (tx *Transaction) CheckNonce() bool

CheckNonce check nonce

func (*Transaction) Cost

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

Cost returns amount + gasprice * gaslimit.

func (*Transaction) Data

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

Data tx data

func (*Transaction) DecodeRLP

func (tx *Transaction) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder

func (*Transaction) EncodeRLP

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

EncodeRLP implements rlp.Encoder

func (*Transaction) Gas

func (tx *Transaction) Gas() uint64

Gas tx gas

func (*Transaction) GasPrice

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

GasPrice tx gas price

func (*Transaction) Hash

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

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

func (*Transaction) MarshalJSON

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

MarshalJSON encodes the web3 RPC transaction format.

func (*Transaction) Nonce

func (tx *Transaction) Nonce() uint64

Nonce tx nonce

func (*Transaction) PrintPretty

func (tx *Transaction) PrintPretty()

PrintPretty print pretty (json)

func (*Transaction) PrintRaw

func (tx *Transaction) PrintRaw()

PrintRaw print raw encoded (hex string)

func (*Transaction) Protected

func (tx *Transaction) Protected() bool

Protected returns whether the transaction is protected from replay protection.

func (*Transaction) RawSignatureValues

func (tx *Transaction) 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 (*Transaction) RawStr

func (tx *Transaction) RawStr() string

RawStr return raw encoded (hex string)

func (*Transaction) SetGasPrice

func (tx *Transaction) SetGasPrice(gasPrice *big.Int)

SetGasPrice tx gas price

func (*Transaction) Size

func (tx *Transaction) Size() 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 (*Transaction) To

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

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

func (*Transaction) UnmarshalJSON

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

UnmarshalJSON decodes the web3 RPC transaction format.

func (*Transaction) Value

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

Value tx value

func (*Transaction) WithSignature

func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, 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.

Jump to

Keyboard shortcuts

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