mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 17:44:29 +00:00
f5bd806b84
Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro-2.local>
280 lines
9.4 KiB
Go
280 lines
9.4 KiB
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
|
"github.com/ledgerwatch/erigon/accounts/abi/bind/backends"
|
|
"github.com/ledgerwatch/erigon/common/hexutil"
|
|
"github.com/ledgerwatch/erigon/core"
|
|
"github.com/ledgerwatch/erigon/crypto"
|
|
"github.com/ledgerwatch/erigon/p2p"
|
|
"github.com/ledgerwatch/erigon/rpc"
|
|
)
|
|
|
|
type EthError struct {
|
|
Code int `json:"code"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type CommonResponse struct {
|
|
Version string `json:"jsonrpc"`
|
|
RequestId int `json:"id"`
|
|
Error *EthError `json:"error"`
|
|
}
|
|
|
|
// Log represents a contract log event. These events are generated by the LOG opcode and
|
|
// stored/indexed by the node.
|
|
type Log struct { //nolint
|
|
// Consensus fields:
|
|
// address of the contract that generated the event
|
|
Address libcommon.Address `json:"address" gencodec:"required"`
|
|
// list of topics provided by the contract.
|
|
Topics []libcommon.Hash `json:"topics" gencodec:"required"`
|
|
// supplied by the contract, usually ABI-encoded
|
|
Data hexutility.Bytes `json:"data" gencodec:"required"`
|
|
|
|
// Derived fields. These fields are filled in by the node
|
|
// but not secured by consensus.
|
|
// block in which the transaction was included
|
|
BlockNumber hexutil.Uint64 `json:"blockNumber"`
|
|
// hash of the transaction
|
|
TxHash libcommon.Hash `json:"transactionHash" gencodec:"required"`
|
|
// index of the transaction in the block
|
|
TxIndex hexutil.Uint `json:"transactionIndex" gencodec:"required"`
|
|
// hash of the block in which the transaction was included
|
|
BlockHash libcommon.Hash `json:"blockHash"`
|
|
// index of the log in the receipt
|
|
Index hexutil.Uint `json:"logIndex" gencodec:"required"`
|
|
|
|
// The Removed field is true if this log was reverted due to a chain reorganisation.
|
|
// You must pay attention to this field if you receive logs through a filter query.
|
|
Removed bool `json:"removed"`
|
|
}
|
|
|
|
type EthBlockNumber struct {
|
|
CommonResponse
|
|
Number hexutil.Uint64 `json:"result"`
|
|
}
|
|
|
|
type EthGetLogs struct {
|
|
CommonResponse
|
|
Result []Log `json:"result"`
|
|
}
|
|
|
|
type EthBalance struct {
|
|
CommonResponse
|
|
Balance hexutil.Big `json:"result"`
|
|
}
|
|
|
|
type EthTxPool struct {
|
|
CommonResponse
|
|
Result interface{} `json:"result"`
|
|
}
|
|
|
|
type EthGetTransactionCount struct {
|
|
CommonResponse
|
|
Result hexutil.Uint64 `json:"result"`
|
|
}
|
|
|
|
type EthTransaction struct {
|
|
From libcommon.Address `json:"from"`
|
|
To *libcommon.Address `json:"to"` // Pointer because it might be missing
|
|
Hash string `json:"hash"`
|
|
Gas hexutil.Big `json:"gas"`
|
|
GasPrice hexutil.Big `json:"gasPrice"`
|
|
Input hexutility.Bytes `json:"input"`
|
|
Value hexutil.Big `json:"value"`
|
|
}
|
|
|
|
type EthSendRawTransaction struct {
|
|
CommonResponse
|
|
TxnHash libcommon.Hash `json:"result"`
|
|
}
|
|
|
|
type EthBlockByNumberResult struct {
|
|
Difficulty hexutil.Big `json:"difficulty"`
|
|
Miner libcommon.Address `json:"miner"`
|
|
Transactions []EthTransaction `json:"transactions"`
|
|
TxRoot libcommon.Hash `json:"transactionsRoot"`
|
|
Hash libcommon.Hash `json:"hash"`
|
|
}
|
|
|
|
type EthBlockByNumber struct {
|
|
CommonResponse
|
|
Result *EthBlockByNumberResult `json:"result"`
|
|
}
|
|
|
|
type (
|
|
// TransactionType is the type of transaction attempted to be made, can be regular or contract
|
|
TransactionType string
|
|
// BlockNumber represents the block number type
|
|
BlockNumber string
|
|
|
|
// RPCMethod is the type for rpc methods used
|
|
RPCMethod string
|
|
// SubMethod is the type for sub methods used in subscriptions
|
|
SubMethod string
|
|
)
|
|
|
|
const (
|
|
// BuildDirArg is the build directory for the devnet executable
|
|
BuildDirArg = "./build/bin/devnet"
|
|
// DataDirArg is the datadir flag
|
|
DataDirArg = "--datadir"
|
|
// ChainArg is the chain flag
|
|
ChainArg = "--chain"
|
|
// DevPeriodArg is the dev.period flag
|
|
DevPeriodArg = "--dev.period"
|
|
// ConsoleVerbosityArg is the log.console.verbosity flag
|
|
ConsoleVerbosityArg = "--log.console.verbosity"
|
|
// LogDirArg is the log.dir.path flag
|
|
LogDirArg = "--log.dir.path"
|
|
// TorrentPortArg is the --torrent.port flag argument
|
|
TorrentPortArg = "--torrent.port"
|
|
// Mine is the mine flag
|
|
Mine = "--mine"
|
|
// NoDiscover is the nodiscover flag
|
|
NoDiscover = "--nodiscover"
|
|
// PrivateApiAddrArg is the private.api.addr flag
|
|
PrivateApiAddrArg = "--private.api.addr"
|
|
// StaticPeersArg is the staticpeers flag
|
|
StaticPeersArg = "--staticpeers"
|
|
// HttpApiArg is the http.api flag
|
|
HttpApiArg = "--http.api"
|
|
// WSArg is the --ws flag for rpcdaemon
|
|
WSArg = "--ws"
|
|
|
|
// DataDirParam is the datadir parameter
|
|
DataDirParam = "./dev"
|
|
// ChainParam is the chain parameter
|
|
ChainParam = "dev"
|
|
// DevPeriodParam is the dev.period parameter
|
|
DevPeriodParam = "30"
|
|
// ConsoleVerbosityParam is the verbosity parameter for the console logs
|
|
ConsoleVerbosityParam = "0"
|
|
// LogDirParam is the log directory parameter for logging to disk
|
|
LogDirParam = "./cmd/devnet/debug_logs"
|
|
// TorrentPortParam is the port parameter for the second node
|
|
TorrentPortParam = "42070"
|
|
// PrivateApiParamMine is the private.api.addr parameter for the mining node
|
|
PrivateApiParamMine = "localhost:9092"
|
|
// PrivateApiParamNoMine is the private.api.addr parameter for the non-mining node
|
|
PrivateApiParamNoMine = "localhost:9091"
|
|
// HttpApiParam is the http.api default parameter for rpcdaemon
|
|
HttpApiParam = "admin,eth,erigon,web3,net,debug,trace,txpool,parity,ots"
|
|
|
|
// ErigonUrl is the default url for rpc connections
|
|
ErigonUrl = "http://localhost:8545"
|
|
// Localhost is the default localhost endpoint for web socket attachments
|
|
Localhost = "127.0.0.1:8545"
|
|
|
|
// MaxNumberOfBlockChecks is the max number of blocks to look for a transaction in
|
|
MaxNumberOfBlockChecks = 3
|
|
|
|
// Latest is the parameter for the latest block
|
|
Latest BlockNumber = "latest"
|
|
// Earliest is the parameter for the earliest block
|
|
Earliest BlockNumber = "earliest"
|
|
// Pending is the parameter for the pending block
|
|
Pending BlockNumber = "pending"
|
|
|
|
// hexPrivateKey is the hex value for the private key
|
|
hexPrivateKey = "26e86e45f6fc45ec6e2ecd128cec80fa1d1505e5507dcd2ae58c3130a7a97b48"
|
|
// DevAddress is the developer address for sending
|
|
DevAddress = "0x67b1d87101671b127f5f8714789C7192f7ad340e"
|
|
|
|
// NonContractTx is the transaction type for sending ether
|
|
NonContractTx TransactionType = "non-contract"
|
|
// ContractTx is the transaction type for sending ether
|
|
ContractTx TransactionType = "contract"
|
|
// DynamicFee is the transaction type for dynamic fee
|
|
DynamicFee TransactionType = "dynamic-fee"
|
|
|
|
// SolContractMethodSignature is the function signature for the event in the solidity contract definition
|
|
SolContractMethodSignature = "SubscriptionEvent()"
|
|
|
|
// ETHGetTransactionCount represents the eth_getTransactionCount method
|
|
ETHGetTransactionCount RPCMethod = "eth_getTransactionCount"
|
|
// ETHGetBalance represents the eth_getBalance method
|
|
ETHGetBalance RPCMethod = "eth_getBalance"
|
|
// ETHSendRawTransaction represents the eth_sendRawTransaction method
|
|
ETHSendRawTransaction RPCMethod = "eth_sendRawTransaction"
|
|
// ETHGetBlockByNumber represents the eth_getBlockByNumber method
|
|
ETHGetBlockByNumber RPCMethod = "eth_getBlockByNumber"
|
|
// ETHGetBlock represents the eth_getBlock method
|
|
ETHGetBlock RPCMethod = "eth_getBlock"
|
|
// ETHGetLogs represents the eth_getLogs method
|
|
ETHGetLogs RPCMethod = "eth_getLogs"
|
|
// ETHBlockNumber represents the eth_blockNumber method
|
|
ETHBlockNumber RPCMethod = "eth_blockNumber"
|
|
// AdminNodeInfo represents the admin_nodeInfo method
|
|
AdminNodeInfo RPCMethod = "admin_nodeInfo"
|
|
// TxpoolContent represents the txpool_content method
|
|
TxpoolContent RPCMethod = "txpool_content"
|
|
|
|
// OTSGetBlockDetails represents the ots_getBlockDetails method
|
|
OTSGetBlockDetails RPCMethod = "ots_getBlockDetails"
|
|
|
|
// ETHNewHeads represents the eth_newHeads sub method
|
|
ETHNewHeads SubMethod = "eth_newHeads"
|
|
)
|
|
|
|
var (
|
|
// DevSignedPrivateKey is the signed private key for signing transactions
|
|
DevSignedPrivateKey, _ = crypto.HexToECDSA(hexPrivateKey)
|
|
// gspec is the geth dev genesis block
|
|
gspec = core.DeveloperGenesisBlock(uint64(0), libcommon.HexToAddress(DevAddress))
|
|
// ContractBackend is a simulated backend created using a simulated blockchain
|
|
ContractBackend = backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, 1_000_000)
|
|
|
|
// MethodSubscriptionMap is a container for all the subscription methods
|
|
MethodSubscriptionMap *map[SubMethod]*MethodSubscription
|
|
|
|
// NewHeadsChan is the block cache the eth_NewHeads
|
|
NewHeadsChan chan interface{}
|
|
|
|
//QuitNodeChan is the channel for receiving a quit signal on all nodes
|
|
QuitNodeChan chan bool
|
|
)
|
|
|
|
type (
|
|
// AdminNodeInfoResponse is the response for calls made to admin_nodeInfo
|
|
AdminNodeInfoResponse struct {
|
|
CommonResponse
|
|
Result p2p.NodeInfo `json:"result"`
|
|
}
|
|
)
|
|
|
|
// MethodSubscription houses the client subscription, name and channel for its delivery
|
|
type MethodSubscription struct {
|
|
Client *rpc.Client
|
|
ClientSub *rpc.ClientSubscription
|
|
Name SubMethod
|
|
SubChan chan interface{}
|
|
}
|
|
|
|
// NewMethodSubscription returns a new MethodSubscription instance
|
|
func NewMethodSubscription(name SubMethod) *MethodSubscription {
|
|
return &MethodSubscription{
|
|
Name: name,
|
|
SubChan: make(chan interface{}),
|
|
}
|
|
}
|
|
|
|
// Block represents a simple block for queries
|
|
type Block struct {
|
|
Number *hexutil.Big
|
|
Transactions []libcommon.Hash
|
|
BlockHash libcommon.Hash
|
|
}
|
|
|
|
// ParameterFromArgument merges the argument and parameter and returns a flag input string
|
|
func ParameterFromArgument(arg, param string) (string, error) {
|
|
if arg == "" {
|
|
return "", ErrInvalidArgument
|
|
}
|
|
return fmt.Sprintf("%s=%s", arg, param), nil
|
|
}
|