-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
107 lines (94 loc) · 3.25 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
_ "embed"
"encoding/hex"
"flag"
"log"
"os"
"strings"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/b-harvest/ethrpc-checker/config"
"github.com/b-harvest/ethrpc-checker/contracts"
"github.com/b-harvest/ethrpc-checker/report"
"github.com/b-harvest/ethrpc-checker/rpc"
"github.com/b-harvest/ethrpc-checker/types"
)
func main() {
verbose := flag.Bool("v", false, "Enable verbose output")
outputExcel := flag.Bool("xlsx", false, "Save output as xlsx")
flag.Parse()
// Load configuration from conf.yaml
conf := config.MustLoadConfig("config.yaml")
rCtx, err := rpc.NewContext(conf)
if err != nil {
log.Fatalf("Failed to create context: %v", err)
}
rCtx = MustLoadContractInfo(rCtx)
// Collect json rpc results
var results []*types.RpcResult
rpcs := []struct {
name types.RpcName
test rpc.CallRPC
}{
{rpc.SendRawTransaction, rpc.RpcSendRawTransactionTransferValue},
{rpc.SendRawTransaction, rpc.RpcSendRawTransactionDeployContract},
{rpc.SendRawTransaction, rpc.RpcSendRawTransactionTransferERC20},
{rpc.GetBlockNumber, rpc.RpcGetBlockNumber},
{rpc.GetGasPrice, rpc.RpcGetGasPrice},
{rpc.GetMaxPriorityFeePerGas, rpc.RpcGetMaxPriorityFeePerGas},
{rpc.GetChainId, rpc.RpcGetChainId},
{rpc.GetBalance, rpc.RpcGetBalance},
{rpc.GetTransactionCount, rpc.RpcGetTransactionCount},
{rpc.GetBlockByHash, rpc.RpcGetBlockByHash},
{rpc.GetBlockByNumber, rpc.RpcGetBlockByNumber},
{rpc.GetBlockReceipts, rpc.RpcGetBlockReceipts},
{rpc.GetTransactionByHash, rpc.RpcGetTransactionByHash},
{rpc.GetTransactionByBlockHashAndIndex, rpc.RpcGetTransactionByBlockHashAndIndex},
{rpc.GetTransactionByBlockNumberAndIndex, rpc.RpcGetTransactionByBlockNumberAndIndex},
{rpc.GetTransactionReceipt, rpc.RpcGetTransactionReceipt},
{rpc.GetTransactionCountByHash, rpc.RpcGetTransactionCountByHash},
{rpc.GetBlockTransactionCountByHash, rpc.RpcGetBlockTransactionCountByHash},
{rpc.GetCode, rpc.RpcGetCode},
{rpc.GetStorageAt, rpc.RpcGetStorageAt},
{rpc.NewFilter, rpc.RpcNewFilter},
{rpc.GetFilterLogs, rpc.RpcGetFilterLogs},
{rpc.NewBlockFilter, rpc.RpcNewBlockFilter},
{rpc.GetFilterChanges, rpc.RpcGetFilterChanges},
{rpc.UninstallFilter, rpc.RpcUninstallFilter},
{rpc.GetLogs, rpc.RpcGetLogs},
{rpc.EstimateGas, rpc.RpcEstimateGas},
{rpc.Call, rpc.RPCCall},
}
for _, r := range rpcs {
_, err := r.test(rCtx)
if err != nil {
// add error to results
results = append(results, &types.RpcResult{
Method: r.name,
Status: types.Error,
ErrMsg: err.Error(),
})
continue
}
}
results = append(results, rCtx.AlreadyTestedRPCs...)
report.ReportResults(results, *verbose, *outputExcel)
}
func MustLoadContractInfo(rCtx *rpc.RpcContext) *rpc.RpcContext {
// Read the ABI file
abiFile, err := os.ReadFile("contracts/ERC20Token.abi")
if err != nil {
log.Fatalf("Failed to read ABI file: %v", err)
}
// Parse the ABI
parsedABI, err := abi.JSON(strings.NewReader(string(abiFile)))
if err != nil {
log.Fatalf("Failed to parse ERC20 ABI: %v", err)
}
rCtx.ERC20Abi = &parsedABI
// Read the compiled contract bytecode
contractBytecode := common.FromHex(hex.EncodeToString(contracts.ContractByteCode))
rCtx.ERC20ByteCode = contractBytecode
return rCtx
}