mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-07 11:32:20 +00:00
2e81cdbfd9
* adding eth_getLogs functionality for contract events for the devnet tool * Made changes to fix double hashing * Fixed lint errors * Changed strings.Replace to strings.ReplaceAll for replacing strings * Cleaned up print statements across files * Fixed logs not being populated in result typee.go Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package requests
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/ledgerwatch/erigon/cmd/rpctest/rpctest"
|
|
"github.com/ledgerwatch/erigon/common"
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
)
|
|
|
|
func parseResponse(resp interface{}) string {
|
|
result, err := json.Marshal(resp)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return string(result)
|
|
}
|
|
|
|
func GetBalance(reqId int, address common.Address, blockNum string) {
|
|
reqGen := initialiseRequestGenerator(reqId)
|
|
var b rpctest.EthBalance
|
|
|
|
res := reqGen.Erigon("eth_getBalance", reqGen.getBalance(address, blockNum), &b)
|
|
if res.Err != nil {
|
|
fmt.Printf("Error getting balance: %v\n", res.Err)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Balance retrieved: %v\n", parseResponse(b))
|
|
}
|
|
|
|
func SendTx(reqId int, signedTx *types.Transaction) (*common.Hash, error) {
|
|
reqGen := initialiseRequestGenerator(reqId)
|
|
var b rpctest.EthSendRawTransaction
|
|
|
|
var buf bytes.Buffer
|
|
err := (*signedTx).MarshalBinary(&buf)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res := reqGen.Erigon("eth_sendRawTransaction", reqGen.sendRawTransaction(buf.Bytes()), &b)
|
|
if res.Err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
fmt.Printf("Submitted transaction successfully: %v\n", parseResponse(b))
|
|
return &b.TxnHash, nil
|
|
}
|
|
|
|
func TxpoolContent(reqId int) {
|
|
reqGen := initialiseRequestGenerator(reqId)
|
|
var b rpctest.EthTxPool
|
|
|
|
res := reqGen.Erigon("txpool_content", reqGen.txpoolContent(), &b)
|
|
if res.Err != nil {
|
|
fmt.Printf("Error fetching txpool: %v\n", res.Err)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Txpool content: %v\n", parseResponse(b))
|
|
}
|
|
|
|
func ParityList(reqId int, account common.Address, quantity int, offset []byte, blockNum string) {
|
|
reqGen := initialiseRequestGenerator(reqId)
|
|
var b rpctest.ParityListStorageKeysResult
|
|
|
|
res := reqGen.Erigon("parity_listStorageKeys", reqGen.parityStorageKeyListContent(account, quantity, offset, blockNum), &b)
|
|
if res.Err != nil {
|
|
fmt.Printf("Error fetching storage keys: %v\n", res.Err)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Storage keys: %v\n", parseResponse(b))
|
|
|
|
}
|
|
|
|
func GetLogs(reqId int, fromBlock, toBlock uint64, address common.Address) error {
|
|
reqGen := initialiseRequestGenerator(reqId)
|
|
var b rpctest.EthGetLogs
|
|
|
|
res := reqGen.Erigon("eth_getLogs", reqGen.getLogs(fromBlock, toBlock, address), &b)
|
|
if res.Err != nil {
|
|
return fmt.Errorf("Error fetching logs: %v\n", res.Err)
|
|
}
|
|
|
|
fmt.Printf("Logs: %v\n", parseResponse(b))
|
|
return nil
|
|
}
|