2022-09-30 20:04:34 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2023-01-13 18:12:18 +00:00
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
2022-11-22 13:28:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/accounts/abi/bind/backends"
|
2023-06-04 19:53:05 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/requests"
|
2022-11-03 02:45:36 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common/hexutil"
|
2022-11-22 13:28:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/core"
|
2022-10-31 10:46:49 +00:00
|
|
|
"github.com/ledgerwatch/erigon/crypto"
|
2023-01-10 17:43:58 +00:00
|
|
|
"github.com/ledgerwatch/erigon/rpc"
|
2022-09-30 20:04:34 +00:00
|
|
|
)
|
|
|
|
|
2022-10-31 10:46:49 +00:00
|
|
|
type (
|
|
|
|
// TransactionType is the type of transaction attempted to be made, can be regular or contract
|
|
|
|
TransactionType string
|
|
|
|
)
|
|
|
|
|
2022-09-30 20:04:34 +00:00
|
|
|
const (
|
2022-11-03 02:45:36 +00:00
|
|
|
// MaxNumberOfBlockChecks is the max number of blocks to look for a transaction in
|
2023-01-10 17:43:58 +00:00
|
|
|
MaxNumberOfBlockChecks = 3
|
2022-10-11 12:34:32 +00:00
|
|
|
|
2022-10-31 10:46:49 +00:00
|
|
|
// 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"
|
2023-03-02 10:25:11 +00:00
|
|
|
// DynamicFee is the transaction type for dynamic fee
|
|
|
|
DynamicFee TransactionType = "dynamic-fee"
|
2022-10-31 10:46:49 +00:00
|
|
|
|
2023-01-10 17:43:58 +00:00
|
|
|
// SolContractMethodSignature is the function signature for the event in the solidity contract definition
|
|
|
|
SolContractMethodSignature = "SubscriptionEvent()"
|
2022-10-31 10:46:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// DevSignedPrivateKey is the signed private key for signing transactions
|
|
|
|
DevSignedPrivateKey, _ = crypto.HexToECDSA(hexPrivateKey)
|
2022-11-22 13:28:53 +00:00
|
|
|
// gspec is the geth dev genesis block
|
2023-01-13 18:12:18 +00:00
|
|
|
gspec = core.DeveloperGenesisBlock(uint64(0), libcommon.HexToAddress(DevAddress))
|
2022-11-22 13:28:53 +00:00
|
|
|
// ContractBackend is a simulated backend created using a simulated blockchain
|
|
|
|
ContractBackend = backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, 1_000_000)
|
2023-01-10 17:43:58 +00:00
|
|
|
|
|
|
|
// MethodSubscriptionMap is a container for all the subscription methods
|
2023-06-04 19:53:05 +00:00
|
|
|
MethodSubscriptionMap *map[requests.SubMethod]*MethodSubscription
|
2023-01-10 17:43:58 +00:00
|
|
|
|
|
|
|
// NewHeadsChan is the block cache the eth_NewHeads
|
|
|
|
NewHeadsChan chan interface{}
|
2023-01-16 18:59:01 +00:00
|
|
|
|
|
|
|
//QuitNodeChan is the channel for receiving a quit signal on all nodes
|
|
|
|
QuitNodeChan chan bool
|
2022-09-30 20:04:34 +00:00
|
|
|
)
|
|
|
|
|
2023-01-10 17:43:58 +00:00
|
|
|
// MethodSubscription houses the client subscription, name and channel for its delivery
|
|
|
|
type MethodSubscription struct {
|
|
|
|
Client *rpc.Client
|
|
|
|
ClientSub *rpc.ClientSubscription
|
2023-06-04 19:53:05 +00:00
|
|
|
Name requests.SubMethod
|
2023-01-10 17:43:58 +00:00
|
|
|
SubChan chan interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewMethodSubscription returns a new MethodSubscription instance
|
2023-06-04 19:53:05 +00:00
|
|
|
func NewMethodSubscription(name requests.SubMethod) *MethodSubscription {
|
2023-01-10 17:43:58 +00:00
|
|
|
return &MethodSubscription{
|
|
|
|
Name: name,
|
|
|
|
SubChan: make(chan interface{}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-03 02:45:36 +00:00
|
|
|
// Block represents a simple block for queries
|
|
|
|
type Block struct {
|
|
|
|
Number *hexutil.Big
|
2023-01-13 18:12:18 +00:00
|
|
|
Transactions []libcommon.Hash
|
|
|
|
BlockHash libcommon.Hash
|
2022-09-30 20:04:34 +00:00
|
|
|
}
|