Documentation ¶
Index ¶
- Constants
- Variables
- func CallType(t string) bool
- func ChecksumAddress(address string) (string, bool)
- func CreateType(t string) bool
- func GenerateBootstrapFile(genesisFile string, outputFile string) error
- func MustChecksum(address string) string
- func StartKlaytnNode(ctx context.Context, arguments string, g *errgroup.Group) error
- type Call
- type Client
- func (kc *Client) Balance(ctx context.Context, accountIdf *RosettaTypes.AccountIdentifier, ...) (*RosettaTypes.AccountBalanceResponse, error)
- func (kc *Client) Block(ctx context.Context, blockIdentifier *RosettaTypes.PartialBlockIdentifier) (*RosettaTypes.Block, error)
- func (kc *Client) Call(ctx context.Context, request *RosettaTypes.CallRequest) (*RosettaTypes.CallResponse, error)
- func (kc *Client) Close()
- func (kc *Client) GasPriceAt(ctx context.Context, blockNumber int64) (*big.Int, error)
- func (kc *Client) GetAccount(ctx context.Context, address, blockQuery string) (map[string]interface{}, error)
- func (kc *Client) GetMempool(ctx context.Context) (*RosettaTypes.MempoolResponse, error)
- func (kc *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
- func (kc *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (kc *Client) Status(ctx context.Context) (*RosettaTypes.BlockIdentifier, int64, *RosettaTypes.SyncStatus, ...)
- func (kc *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error)
- func (kc *Client) Transaction(ctx context.Context, blockIdentifier *RosettaTypes.BlockIdentifier, ...) (*RosettaTypes.Transaction, error)
- type GetBlockByNumberInput
- type GetCallInput
- type GetTransactionReceiptInput
- type GraphQL
- type JSONRPC
Constants ¶
const ( // NodeVersion is the version of klaytn we are using. NodeVersion = "1.8.4" // Blockchain is Klaytn. Blockchain string = "Klaytn" // MainnetNetwork is the value of the network // in MainnetNetworkIdentifier (which is Cypress). MainnetNetwork string = "Mainnet" // TestnetNetwork is the value of the network // in TestnetNetworkIdentifier. TestnetNetwork string = "Testnet" // LocalNetwork is the value of the network // in LocalNetworkIdentifier. LocalNetwork string = "Local" // Symbol is the symbol value // used in Currency. Symbol = "KLAY" // Decimals is the decimals value // used in Currency. Decimals = 18 // BlockRewardOpType is used to describe // a block reward. BlockRewardOpType = "BLOCK_REWARD" // FeeOpType is used to represent fee operations. FeeOpType = "FEE" // 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 // Klaytn operation considered successful. SuccessStatus = "SUCCESS" // FailureStatus is the status of any // Klaytn operation considered unsuccessful. FailureStatus = "FAILURE" // HistoricalBalanceSupported is whether // historical balance is supported. HistoricalBalanceSupported = true // GenesisBlockIndex is the index of the // genesis block. GenesisBlockIndex = int64(0) // TransferGasLimit is the gas limit // of a transfer. TransferGasLimit = int64(21000) //nolint:gomnd // KlaytnNodeArguments are the arguments to start a klaytn node instance. KlaytnNodeArguments = `--conf /app/klaytn/ken.yaml --gcmode archive --rpc --rpcapi debug,admin,txpool,klay,governance --rpcport 8551` // IncludeMempoolCoins does not apply to rosetta-klaytn as it is not UTXO-based. IncludeMempoolCoins = false )
Variables ¶
var ( ErrCallParametersInvalid = errors.New("call parameters invalid") ErrCallOutputMarshal = errors.New("call output marshal") ErrCallMethodInvalid = errors.New("call method invalid") )
Client errors
var ( // MainnetKlaytnNodeArguments are the arguments to start a Mainnet(Cypress) Klaytn node // instance. MainnetKlaytnNodeArguments = fmt.Sprintf("%s --cypress", KlaytnNodeArguments) // TestnetKlaytnNodeArguments are the arguments to start a Testnet(Baobab) Klaytn node instance. TestnetKlaytnNodeArguments = fmt.Sprintf("%s --baobab", KlaytnNodeArguments) // MainnetGenesisBlockIdentifier is the *types.BlockIdentifier // of the cypress genesis block. MainnetGenesisBlockIdentifier = &types.BlockIdentifier{ Hash: params.CypressGenesisHash.Hex(), Index: GenesisBlockIndex, } // TestnetGenesisBlockIdentifier is the *types.BlockIdentifier // of the Testnet(Baobab) genesis block. TestnetGenesisBlockIdentifier = &types.BlockIdentifier{ Hash: params.BaobabGenesisHash.Hex(), Index: GenesisBlockIndex, } // LocalGenesisBlockIdentifier is the *types.BlockIdentifier // of the Local network genesis block. LocalGenesisBlockIdentifier = &types.BlockIdentifier{ Hash: "0xb9d1d87259d7c7badd0a4ce2268a2fce81c7fe944905ac04dd2e7872a20b2087", Index: GenesisBlockIndex, } // Currency is the *types.Currency for all // Klaytn networks. Currency = &types.Currency{ Symbol: Symbol, Decimals: Decimals, } // OperationTypes are all suppoorted operation types. OperationTypes = []string{ BlockRewardOpType, FeeOpType, 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{ "klay_getBlockByNumber", "klay_getTransactionReceipt", "klay_call", "klay_estimateGas", } )
Functions ¶
func ChecksumAddress ¶
ChecksumAddress ensures an Klaytn hex address is in Checksum Format. If the address cannot be converted, it returns !ok.
func CreateType ¶
CreateType returns a boolean indicating if the provided trace type is a create type.
func GenerateBootstrapFile ¶
GenerateBootstrapFile creates the bootstrap balances file for a particular genesis file.
func MustChecksum ¶
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"` Gas *big.Int `json:"gas"` Revert bool ErrorMessage string `json:"error"` Calls []*Call `json:"calls"` }
Call is an Klaytn debug trace.
func (*Call) UnmarshalJSON ¶
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 klay_*, debug_*, admin_*, governance_*, and txpool_* methods.
Client borrows HEAVILY from https://github.com/klaytn/klaytn/blob/dev/client/klay_client.go
func (*Client) Balance ¶
func (kc *Client) Balance( ctx context.Context, accountIdf *RosettaTypes.AccountIdentifier, block *RosettaTypes.PartialBlockIdentifier, ) (*RosettaTypes.AccountBalanceResponse, error)
Balance returns the balance of a *RosettaTypes.AccountIdentifier at a *RosettaTypes.PartialBlockIdentifier.
Currently, Klaytn does not support graphQL, so it uses multiple RPC calls. Since Balance RPC Call supports block information as a parameter, there is no need to use graphQL.
func (*Client) Block ¶
func (kc *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) Call ¶
func (kc *Client) Call( ctx context.Context, request *RosettaTypes.CallRequest, ) (*RosettaTypes.CallResponse, error)
Call handles calls to the /call endpoint.
func (*Client) GasPriceAt ¶
GasPriceAt retrieves the suggested gas price to allow a timely execution of a transaction at the given block height.
func (*Client) GetAccount ¶
func (kc *Client) GetAccount(ctx context.Context, address, blockQuery string) (map[string]interface{}, error)
GetAccount calls `klay_getAccount` API and returns an account.
func (*Client) GetMempool ¶
func (kc *Client) GetMempool(ctx context.Context) (*RosettaTypes.MempoolResponse, error)
GetMempool get and returns all the transactions on Ethereum TxPool (pending and queued).
func (*Client) PendingNonceAt ¶
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 ¶
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 ¶
func (kc *Client) Status(ctx context.Context) ( *RosettaTypes.BlockIdentifier, int64, *RosettaTypes.SyncStatus, []*RosettaTypes.Peer, error, )
Status returns klaytn client status information for determining node healthiness.
func (*Client) SuggestGasPrice ¶
SuggestGasPrice retrieves the currently suggested gas price to allow a timely execution of a transaction.
func (*Client) Transaction ¶
func (kc *Client) Transaction( ctx context.Context, blockIdentifier *RosettaTypes.BlockIdentifier, transactionIdentifier *RosettaTypes.TransactionIdentifier, ) (*RosettaTypes.Transaction, error)
Transaction returns the transaction response of the Transaction identified by *RosettaTypes.TransactionIdentifier hash
type GetBlockByNumberInput ¶
type GetBlockByNumberInput struct { Index *int64 `json:"index,omitempty"` ShowTxDetails bool `json:"show_transaction_details"` }
GetBlockByNumberInput is the input to the call method "klay_getBlockByNumber".
type GetCallInput ¶
type GetCallInput struct { BlockIndex int64 `json:"index,omitempty"` BlockHash string `json:"hash,omitempty"` From string `json:"from"` To string `json:"to"` Gas int64 `json:"gas"` GasPrice int64 `json:"gas_price"` Value int64 `json:"value"` Data string `json:"data"` }
GetCallInput is the input to the call method "klay_call", "klay_estimateGas".
type GetTransactionReceiptInput ¶
type GetTransactionReceiptInput struct {
TxHash string `json:"tx_hash"`
}
GetTransactionReceiptInput is the input to the call method "klay_getTransactionReceipt".