transactions

package
v0.171.10 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MPL-2.0 Imports: 28 Imported by: 14

Documentation

Index

Constants

View Source
const (
	WorkNotDone = false
	WorkDone    = true
)
View Source
const (
	// PendingTransactionUpdate is emitted when a pending transaction is updated (added or deleted)
	EventPendingTransactionUpdate walletevent.EventType = "pending-transaction-update"
	// Caries StatusChangedPayload in message
	EventPendingTransactionStatusChanged walletevent.EventType = "pending-transaction-status-changed"

	PendingCheckInterval = 10 * time.Second
)
View Source
const (
	ValidSignatureSize = 65
)

Variables

View Source
var (
	// ErrInvalidSendTxArgs is returned when the structure of SendTxArgs is ambigious.
	ErrInvalidSendTxArgs = errors.New("transaction arguments are invalid")
	// ErrUnexpectedArgs is returned when args are of unexpected length.
	ErrUnexpectedArgs = errors.New("unexpected args")
	//ErrInvalidTxSender is returned when selected account is different than From field.
	ErrInvalidTxSender = errors.New("transaction can only be send by its creator")
	//ErrAccountDoesntExist is sent when provided sub-account is not stored in database.
	ErrAccountDoesntExist = errors.New("account doesn't exist")
)
View Source
var ErrInvalidSignatureSize = errors.New("signature size must be 65")

ErrInvalidSignatureSize is returned if a signature is not 65 bytes to avoid panic from go-ethereum

View Source
var (
	ErrStillPending = errors.New("transaction is still pending")
)

Functions

This section is empty.

Types

type AddrLocker

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

AddrLocker provides locks for addresses

func (*AddrLocker) LockAddr

func (l *AddrLocker) LockAddr(address types.Address)

LockAddr locks an account's mutex. This is used to prevent another tx getting the same nonce until the lock is released. The mutex prevents the (an identical nonce) from being read again during the time that the first transaction is being signed.

func (*AddrLocker) UnlockAddr

func (l *AddrLocker) UnlockAddr(address types.Address)

UnlockAddr unlocks the mutex of the given account.

type AutoDeleteType added in v0.166.1

type AutoDeleteType = bool
const (
	AutoDelete AutoDeleteType = true
	Keep       AutoDeleteType = false
)

type ConditionalRepeater added in v0.166.1

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

ConditionalRepeater runs a task at regular intervals until the task returns true. It doesn't allow running task in parallel and can be triggered early by call to RunUntilDone.

func NewConditionalRepeater added in v0.166.1

func NewConditionalRepeater(interval time.Duration, task TaskFunc) *ConditionalRepeater

func (*ConditionalRepeater) IsRunning added in v0.166.6

func (t *ConditionalRepeater) IsRunning() bool

func (*ConditionalRepeater) RunUntilDone added in v0.166.1

func (t *ConditionalRepeater) RunUntilDone()

RunUntilDone starts the task immediately and continues to run it at the defined interval until the task returns true. Can be called multiple times but it does not allow multiple concurrent executions of the task.

func (*ConditionalRepeater) Stop added in v0.166.1

func (t *ConditionalRepeater) Stop()

Stop forcefully stops the running task by canceling its context.

type ErrBadNonce added in v0.35.0

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

func (*ErrBadNonce) Error added in v0.35.0

func (e *ErrBadNonce) Error() string

type GasCalculator

type GasCalculator interface {
	ethereum.GasEstimator
	ethereum.GasPricer
}

GasCalculator provides methods for estimating and pricing gas.

type Nonce added in v0.125.0

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

func NewNonce added in v0.125.0

func NewNonce() *Nonce

func (*Nonce) GetCurrent added in v0.125.0

func (n *Nonce) GetCurrent(rpcWrapper *rpcWrapper, from types.Address) (uint64, error)

func (*Nonce) Next added in v0.125.0

func (n *Nonce) Next(rpcWrapper *rpcWrapper, from types.Address) (uint64, UnlockNonceFunc, error)

type PendingNonceProvider

type PendingNonceProvider interface {
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
}

PendingNonceProvider provides information about nonces.

type PendingTransaction added in v0.161.6

type PendingTransaction struct {
	Hash               eth.Hash       `json:"hash"`
	Timestamp          uint64         `json:"timestamp"`
	Value              bigint.BigInt  `json:"value"`
	From               eth.Address    `json:"from"`
	To                 eth.Address    `json:"to"`
	Data               string         `json:"data"`
	Symbol             string         `json:"symbol"`
	GasPrice           bigint.BigInt  `json:"gasPrice"`
	GasLimit           bigint.BigInt  `json:"gasLimit"`
	Type               PendingTrxType `json:"type"`
	AdditionalData     string         `json:"additionalData"`
	ChainID            common.ChainID `json:"network_id"`
	MultiTransactionID int64          `json:"multi_transaction_id"`

	// nil will insert the default value (Pending) in DB
	Status *TxStatus `json:"status,omitempty"`
	// nil will insert the default value (true) in DB
	AutoDelete *bool `json:"autoDelete,omitempty"`
}

type PendingTrxType added in v0.161.6

type PendingTrxType string
const (
	RegisterENS               PendingTrxType = "RegisterENS"
	ReleaseENS                PendingTrxType = "ReleaseENS"
	SetPubKey                 PendingTrxType = "SetPubKey"
	BuyStickerPack            PendingTrxType = "BuyStickerPack"
	WalletTransfer            PendingTrxType = "WalletTransfer"
	DeployCommunityToken      PendingTrxType = "DeployCommunityToken"
	AirdropCommunityToken     PendingTrxType = "AirdropCommunityToken"
	RemoteDestructCollectible PendingTrxType = "RemoteDestructCollectible"
	BurnCommunityToken        PendingTrxType = "BurnCommunityToken"
	DeployOwnerToken          PendingTrxType = "DeployOwnerToken"
	SetSignerPublicKey        PendingTrxType = "SetSignerPublicKey"
)

func GetOwnedPendingStatus added in v0.166.9

func GetOwnedPendingStatus(tx *sql.Tx, chainID common.ChainID, hash eth.Hash, ownerAddress eth.Address) (txType *PendingTrxType, mTID *int64, err error)

GetOwnedPendingStatus returns sql.ErrNoRows if no pending transaction is found for the given identity

type PendingTxTracker added in v0.166.1

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

func NewPendingTxTracker added in v0.166.1

func NewPendingTxTracker(db *sql.DB, rpcClient rpc.ClientInterface, rpcFilter *rpcfilters.Service, eventFeed *event.Feed, checkInterval time.Duration) *PendingTxTracker

func (*PendingTxTracker) APIs added in v0.166.1

func (tm *PendingTxTracker) APIs() []ethrpc.API

APIs returns a list of new APIs.

func (*PendingTxTracker) Delete added in v0.166.1

func (tm *PendingTxTracker) Delete(ctx context.Context, chainID common.ChainID, transactionHash eth.Hash) error

Delete returns ErrStillPending if the deleted transaction was still pending The transactions are suppose to be deleted by the client only after they are confirmed

func (*PendingTxTracker) DeleteBySQLTx added in v0.166.1

func (tm *PendingTxTracker) DeleteBySQLTx(tx *sql.Tx, chainID common.ChainID, hash eth.Hash) (notify func(), err error)

DeleteBySQLTx returns ErrStillPending if the transaction is still pending

func (*PendingTxTracker) GetAllPending added in v0.166.1

func (tm *PendingTxTracker) GetAllPending() ([]*PendingTransaction, error)

func (*PendingTxTracker) GetPendingByAddress added in v0.166.1

func (tm *PendingTxTracker) GetPendingByAddress(chainIDs []uint64, address eth.Address) ([]*PendingTransaction, error)

func (*PendingTxTracker) GetPendingEntry added in v0.166.1

func (tm *PendingTxTracker) GetPendingEntry(chainID common.ChainID, hash eth.Hash) (*PendingTransaction, error)

GetPendingEntry returns sql.ErrNoRows if no pending transaction is found for the given identity

func (*PendingTxTracker) Protocols added in v0.166.1

func (tm *PendingTxTracker) Protocols() []p2p.Protocol

Protocols returns a new protocols list. In this case, there are none.

func (*PendingTxTracker) Start added in v0.166.1

func (tm *PendingTxTracker) Start() error

func (*PendingTxTracker) Stop added in v0.166.1

func (tm *PendingTxTracker) Stop() error

func (*PendingTxTracker) StoreAndTrackPendingTx added in v0.166.1

func (tm *PendingTxTracker) StoreAndTrackPendingTx(transaction *PendingTransaction) error

StoreAndTrackPendingTx store the details of a pending transaction and track it until it is mined

func (*PendingTxTracker) TrackPendingTransaction added in v0.166.1

func (tm *PendingTxTracker) TrackPendingTransaction(chainID common.ChainID, hash eth.Hash, from eth.Address, trType PendingTrxType, autoDelete AutoDeleteType) error

PendingTransaction called with autoDelete = false will keep the transaction in the database until it is confirmed by the caller using Delete

func (*PendingTxTracker) Watch added in v0.166.1

func (tm *PendingTxTracker) Watch(ctx context.Context, chainID common.ChainID, hash eth.Hash) (*TxStatus, error)

Watch returns sql.ErrNoRows if no pending transaction is found for the given identity tx.Status is not nill if err is nil

type SendTxArgs

type SendTxArgs struct {
	From                 types.Address   `json:"from"`
	To                   *types.Address  `json:"to"`
	Gas                  *hexutil.Uint64 `json:"gas"`
	GasPrice             *hexutil.Big    `json:"gasPrice"`
	Value                *hexutil.Big    `json:"value"`
	Nonce                *hexutil.Uint64 `json:"nonce"`
	MaxFeePerGas         *hexutil.Big    `json:"maxFeePerGas"`
	MaxPriorityFeePerGas *hexutil.Big    `json:"maxPriorityFeePerGas"`
	// We keep both "input" and "data" for backward compatibility.
	// "input" is a preferred field.
	// see `vendor/github.com/ethereum/go-ethereum/internal/ethapi/api.go:1107`
	Input types.HexBytes `json:"input"`
	Data  types.HexBytes `json:"data"`
}

SendTxArgs represents the arguments to submit a new transaction into the transaction pool. This struct is based on go-ethereum's type in internal/ethapi/api.go, but we have freedom over the exact layout of this struct.

func (SendTxArgs) GetInput

func (args SendTxArgs) GetInput() types.HexBytes

GetInput returns either Input or Data field's value dependent on what is filled.

func (SendTxArgs) IsDynamicFeeTx added in v0.82.0

func (args SendTxArgs) IsDynamicFeeTx() bool

IsDynamicFeeTx checks whether dynamic fee parameters are set for the tx

func (SendTxArgs) ToTransactOpts added in v0.93.2

func (args SendTxArgs) ToTransactOpts(signerFn bind.SignerFn) *bind.TransactOpts

func (SendTxArgs) Valid

func (args SendTxArgs) Valid() bool

Valid checks whether this structure is filled in correctly.

type StatusChangedPayload added in v0.166.1

type StatusChangedPayload struct {
	ChainID common.ChainID `json:"chainId"`
	Hash    eth.Hash       `json:"hash"`
	Status  *TxStatus      `json:"status,omitempty"`
}

type TaskFunc added in v0.166.1

type TaskFunc func(ctx context.Context) (done bool)

TaskFunc defines the task to be run. The context is canceled when Stop is called to early stop scheduled task.

type Transactor

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

Transactor validates, signs transactions. It uses upstream to propagate transactions to the Ethereum network.

func NewTransactor

func NewTransactor() *Transactor

NewTransactor returns a new Manager.

func (*Transactor) EstimateGas added in v0.171.10

func (t *Transactor) EstimateGas(network *params.Network, from common.Address, to common.Address, value *big.Int, input []byte) (uint64, error)

func (*Transactor) HashTransaction added in v0.35.0

func (t *Transactor) HashTransaction(args SendTxArgs) (validatedArgs SendTxArgs, hash types.Hash, err error)

func (*Transactor) NetworkID added in v0.161.6

func (t *Transactor) NetworkID() uint64

func (*Transactor) NextNonce added in v0.125.0

func (t *Transactor) NextNonce(rpcClient *rpc.Client, chainID uint64, from types.Address) (uint64, UnlockNonceFunc, error)

func (*Transactor) SendBuiltTransactionWithSignature added in v0.171.1

func (t *Transactor) SendBuiltTransactionWithSignature(chainID uint64, tx *gethtypes.Transaction, sig []byte) (hash types.Hash, err error)

func (*Transactor) SendTransaction

func (t *Transactor) SendTransaction(sendArgs SendTxArgs, verifiedAccount *account.SelectedExtKey) (hash types.Hash, err error)

SendTransaction is an implementation of eth_sendTransaction. It queues the tx to the sign queue.

func (*Transactor) SendTransactionWithChainID added in v0.101.1

func (t *Transactor) SendTransactionWithChainID(chainID uint64, sendArgs SendTxArgs, verifiedAccount *account.SelectedExtKey) (hash types.Hash, err error)

func (*Transactor) SendTransactionWithSignature added in v0.35.0

func (t *Transactor) SendTransactionWithSignature(chainID uint64, args SendTxArgs, sig []byte) (hash types.Hash, err error)

SendTransactionWithSignature receive a transaction and a signature, serialize them together and propage it to the network. It's different from eth_sendRawTransaction because it receives a signature and not a serialized transaction with signature. Since the transactions is already signed, we assume it was validated and used the right nonce.

func (*Transactor) SetNetworkID

func (t *Transactor) SetNetworkID(networkID uint64)

SetNetworkID selects a correct network.

func (*Transactor) SetRPC

func (t *Transactor) SetRPC(rpcClient *rpc.Client, timeout time.Duration)

SetRPC sets RPC params, a client and a timeout

func (*Transactor) ValidateAndBuildTransaction added in v0.171.1

func (t *Transactor) ValidateAndBuildTransaction(chainID uint64, sendArgs SendTxArgs) (tx *gethtypes.Transaction, unlock UnlockNonceFunc, err error)

type TxStatus added in v0.166.1

type TxStatus = string
const (
	Pending TxStatus = "Pending"
	Done    TxStatus = "Done"
)

Values for status column in pending_transactions

type UnlockNonceFunc added in v0.171.10

type UnlockNonceFunc func(inc bool, n uint64)

Directories

Path Synopsis
Package fake is a generated GoMock package.
Package fake is a generated GoMock package.

Jump to

Keyboard shortcuts

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