polygon

package
v0.0.0-...-46a0b90 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NodeVersion is the version of geth we are using.
	NodeVersion = "1.9.24"

	// Blockchain is Polygon.
	Blockchain string = "polygon"

	// MainnetNetwork is the value of the network
	// in MainnetNetworkIdentifier.
	MainnetNetwork string = "mainnet"

	// TestnetNetwork is the value of the network
	// in TestnetNetworkIdentifier.
	TestnetNetwork string = "testnet"

	// Symbol is the symbol value
	// used in Currency.
	Symbol = "MATIC"

	// Decimals is the decimals value
	// used in Currency.
	Decimals = 18

	// MinerRewardOpType is used to describe
	// a miner block reward.
	MinerRewardOpType = "MINER_REWARD"

	// UncleRewardOpType is used to describe
	// an uncle block reward.
	UncleRewardOpType = "UNCLE_REWARD"

	// FeeOpType is used to represent fee operations.
	FeeOpType = "FEE"

	// PaymentOpType is used to represent payment/transfer operations
	PaymentOpType = "PAYMENT"

	// CallOpType is used to represent CALL trace operations.
	CallOpType = "CALL"

	// CreateOpType is used to represent CREATE trace operations.
	CreateOpType = "CREATE"

	// Create2OpType is used to represent CREATE2 trace operations.
	Create2OpType = "CREATE2"

	// SelfDestructOpType is used to represent SELFDESTRUCT trace operations.
	SelfDestructOpType = "SELFDESTRUCT"

	// CallCodeOpType is used to represent CALLCODE trace operations.
	CallCodeOpType = "CALLCODE"

	// DelegateCallOpType is used to represent DELEGATECALL trace operations.
	DelegateCallOpType = "DELEGATECALL"

	// StaticCallOpType is used to represent STATICCALL trace operations.
	StaticCallOpType = "STATICCALL"

	// DestructOpType is a synthetic operation used to represent the
	// deletion of suicided accounts that still have funds at the end
	// of a transaction.
	DestructOpType = "DESTRUCT"

	// SuccessStatus is the status of any
	// Ethereum operation considered successful.
	SuccessStatus = "SUCCESS"

	// FailureStatus is the status of any
	// Ethereum operation considered unsuccessful.
	FailureStatus = "FAILURE"

	// HistoricalBalanceSupported is whether
	// historical balance is supported.
	HistoricalBalanceSupported = true

	// UnclesRewardMultiplier is the uncle reward
	// multiplier.
	UnclesRewardMultiplier = 32

	// MaxUncleDepth is the maximum depth for
	// an uncle to be rewarded.
	MaxUncleDepth = 8

	// GenesisBlockIndex is the index of the
	// genesis block.
	GenesisBlockIndex = int64(0)

	// TransferGasLimit is the gas limit
	// of a transfer.
	TransferGasLimit = uint64(21000) //nolint:gomnd

	// IncludeMempoolCoins does not apply to polygon-rosetta as it is not UTXO-based.
	IncludeMempoolCoins = false

	// ContractAddressKey is the key used to denote the contract address
	// for a token, provided via Currency metadata.
	ContractAddressKey string = "token_address"
)

Variables

View Source
var (
	ErrBlockOrphaned         = errors.New("block orphaned")
	ErrCallParametersInvalid = errors.New("call parameters invalid")
	ErrCallOutputMarshal     = errors.New("call output marshal")
	ErrCallMethodInvalid     = errors.New("call method invalid")
)

Client errors

View Source
var (
	// MainnetGenesisBlockIdentifier is the *types.BlockIdentifier
	// of the mainnet genesis block.
	MainnetGenesisBlockIdentifier = &types.BlockIdentifier{
		Hash:  "0xa9c28ce2141b56c474f1dc504bee9b01eb1bd7d1a507580d5519d4437a97de1b",
		Index: GenesisBlockIndex,
	}

	// MumbaiGenesisBlockIdentifier is the *types.BlockIdentifier
	// of the Mumbai genesis block.
	MumbaiGenesisBlockIdentifier = &types.BlockIdentifier{
		Hash:  "0x7b66506a9ebdbf30d32b43c5f15a3b1216269a1ec3a75aa3182b86176a2b1ca7",
		Index: GenesisBlockIndex,
	}

	// Currency is the *types.Currency for all
	// Polygon networks.
	Currency = &types.Currency{
		Symbol:   Symbol,
		Decimals: Decimals,
	}

	// OperationTypes are all supported operation types.
	OperationTypes = []string{
		MinerRewardOpType,
		UncleRewardOpType,
		FeeOpType,
		PaymentOpType,
		CallOpType,
		CreateOpType,
		Create2OpType,
		SelfDestructOpType,
		CallCodeOpType,
		DelegateCallOpType,
		StaticCallOpType,
		DestructOpType,
	}

	// OperationStatuses are all supported operation statuses.
	OperationStatuses = []*types.OperationStatus{
		{
			Status:     SuccessStatus,
			Successful: true,
		},
		{
			Status:     FailureStatus,
			Successful: false,
		},
	}

	// CallMethods are all supported call methods.
	CallMethods = []string{
		"eth_getTransactionReceipt",
	}
)

Functions

func CallType

func CallType(t string) bool

CallType returns a boolean indicating if the provided trace type is a call type.

func ChecksumAddress

func ChecksumAddress(address string) (string, bool)

ChecksumAddress ensures an Polygon hex address is in Checksum Format. If the address cannot be converted, it returns !ok.

func CreateType

func CreateType(t string) bool

CreateType returns a boolean indicating if the provided trace type is a create type.

func GenerateBootstrapFile

func GenerateBootstrapFile(genesisFile string, outputFile string) error

GenerateBootstrapFile creates the bootstrap balances file for a particular genesis file.

func MustChecksum

func MustChecksum(address string) string

MustChecksum ensures an address can be converted into a valid checksum. If it does not, the program will exit.

Types

type Call

type Call struct {
	Type         string         `json:"type"`
	From         common.Address `json:"from"`
	To           common.Address `json:"to"`
	Value        *big.Int       `json:"value"`
	GasUsed      *big.Int       `json:"gasUsed"`
	Revert       bool
	ErrorMessage string  `json:"error"`
	Calls        []*Call `json:"calls"`
}

Call is an Ethereum debug trace.

func (*Call) UnmarshalJSON

func (t *Call) UnmarshalJSON(input []byte) error

UnmarshalJSON is a custom unmarshaler for Call.

type Client

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

Client allows for querying a set of specific Ethereum endpoints in an idempotent manner. Client relies on the eth_*, debug_*, and admin_* methods and on the graphql endpoint.

Client borrows HEAVILY from https://github.com/ethereum/go-ethereum/tree/master/ethclient.

func NewClient

func NewClient(cfg *ClientConfig) (*Client, error)

NewClient creates a Client that from the provided url and params.

func (*Client) Balance

Balance returns the balance of a *RosettaTypes.AccountIdentifier at a *RosettaTypes.PartialBlockIdentifier.

Note: If the currencies field is populated, only balances for the specified currencies will be returned. If not populated, the native balance (MATIC) will be returned. See: https://www.rosetta-api.org/docs/models/AccountBalanceRequest.html For each specified ERC20 token, we make a graphql call to its respective contract address in order to query the account's balance.

We must use graphql to get the balance atomically (the rpc method for balance does not allow for querying by block hash nor return the block hash where the balance was fetched).

func (*Client) Block

func (ec *Client) Block(
	ctx context.Context,
	blockIdentifier *RosettaTypes.PartialBlockIdentifier,
) (*RosettaTypes.Block, error)

Block returns a populated block at the *RosettaTypes.PartialBlockIdentifier. If neither the hash or index is populated in the *RosettaTypes.PartialBlockIdentifier, the current block is returned.

func (*Client) BlockHeader

func (ec *Client) BlockHeader(ctx context.Context, number *big.Int) (*types.Header, error)

BlockHeader returns a block header from the current canonical chain. If number is nil, the latest known header is returned.

func (*Client) CalculateBurntContract

func (ec *Client) CalculateBurntContract(blockNum uint64) string

CalculateBurntContract implementation is taken from: https://github.com/maticnetwork/bor/blob/c227a072418626dd758ceabffd2ea7dadac6eecb/params/config.go#L527

TODO: Depend on maticnetwork fork of go-ethereum instead of stock geth so we don't need to copy/paste this.

func (*Client) Call

Call handles calls to the /call endpoint.

func (*Client) Close

func (ec *Client) Close()

Close shuts down the RPC client connection.

func (*Client) EstimateGas

func (ec *Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

EstimateGas retrieves the currently gas limit

func (*Client) PendingNonceAt

func (ec *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

PendingNonceAt returns the account nonce of the given account in the pending state. This is the nonce that should be used for the next transaction.

func (*Client) SendTransaction

func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction injects a signed transaction into the pending pool for execution.

If the transaction was a contract creation use the TransactionReceipt method to get the contract address after the transaction has been mined.

func (*Client) Status

Status returns geth status information for determining node healthiness.

func (*Client) SuggestGasTipCap

func (ec *Client) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

SuggestGasTipCap retrieves the currently suggested gas tip cap after 1559 to allow a timely execution of a transaction.

type ClientConfig

type ClientConfig struct {
	URL            string
	ChainConfig    *params.ChainConfig
	SkipAdminCalls bool
	Headers        []*HTTPHeader
	BurntContract  map[string]string
}

ClientConfig holds asset config information

type CurrencyFetcher

type CurrencyFetcher interface {
	// contains filtered or unexported methods
}

CurrencyFetcher interface describes a struct that can fetch the details of an Ethereum-based token given its contract address.

type ERC20CurrencyFetcher

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

ERC20CurrencyFetcher type has a global currencyCache (lru) to cache results of fetching currency details, as well as a GraphQL client (required for getting currency details).

type GetTransactionReceiptInput

type GetTransactionReceiptInput struct {
	TxHash string `json:"tx_hash"`
}

GetTransactionReceiptInput is the input to the call method "eth_getTransactionReceipt".

type GraphQL

type GraphQL interface {
	Query(ctx context.Context, input string) (string, error)
}

GraphQL is the interface for accessing go-ethereum's GraphQL endpoint.

type GraphQLClient

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

GraphQLClient is a client used to make graphQL queries to geth's graphql endpoint.

func (*GraphQLClient) Query

func (g *GraphQLClient) Query(ctx context.Context, input string) (string, error)

Query makes a query to the graphQL endpoint.

type HTTPHeader

type HTTPHeader struct {
	Key   string
	Value string
}

HTTPHeader is key, value pair to be set on the HTTP and GraphQL client.

type JSONRPC

type JSONRPC interface {
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
	BatchCallContext(ctx context.Context, b []rpc.BatchElem) error
	Close()
}

JSONRPC is the interface for accessing go-ethereum's JSON RPC endpoint.

Directories

Path Synopsis
utilities

Jump to

Keyboard shortcuts

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