From 46e2be1c8be6058528dc3a69f02594305761b193 Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Fri, 28 Jul 2023 13:01:51 +0200 Subject: [PATCH] update --- proxy/blocks.go | 17 ++++++++--------- rpc/rpc.go | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/proxy/blocks.go b/proxy/blocks.go index dba20f5..031f033 100644 --- a/proxy/blocks.go +++ b/proxy/blocks.go @@ -7,7 +7,6 @@ import ( "strings" "sync" - "github.com/ethereum/go-ethereum/common" "github.com/yuriy0803/open-etc-pool-friends/rpc" "github.com/yuriy0803/open-etc-pool-friends/util" ) @@ -26,24 +25,24 @@ type BlockTemplate struct { Target string Difficulty *big.Int Height uint64 - GetPendingBlockCache *rpc.GetBlockReplyPart + GetPendingBlockCache *rpc.GetBlockReplyPart // Assuming this type is defined elsewhere nonces map[string]bool headers map[string]heightDiffPair } type Block struct { difficulty *big.Int - hashNoNonce common.Hash + hashNoNonce string // Replacing common.Hash with string nonce uint64 - mixDigest common.Hash + mixDigest string // Replacing common.Hash with string number uint64 } -func (b Block) Difficulty() *big.Int { return b.difficulty } -func (b Block) HashNoNonce() common.Hash { return b.hashNoNonce } -func (b Block) Nonce() uint64 { return b.nonce } -func (b Block) MixDigest() common.Hash { return b.mixDigest } -func (b Block) NumberU64() uint64 { return b.number } +func (b Block) Difficulty() *big.Int { return b.difficulty } +func (b Block) HashNoNonce() string { return b.hashNoNonce } +func (b Block) Nonce() uint64 { return b.nonce } +func (b Block) MixDigest() string { return b.mixDigest } +func (b Block) NumberU64() uint64 { return b.number } func (s *ProxyServer) fetchBlockTemplate() { rpc := s.rpc() diff --git a/rpc/rpc.go b/rpc/rpc.go index 9a4f1b0..b1850f5 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -13,10 +13,27 @@ import ( "sync" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/yuriy0803/open-etc-pool-friends/util" ) +const ( + // RPC method "eth_getWork" + RPCEthGetWork = "eth_getWork" + + // RPC method "eth_getBlockByNumber" + RPCEthGetBlockByNumber = "eth_getBlockByNumber" + + // RPC method "eth_getBlockByHash" + RPCEthGetBlockByHash = "eth_getBlockByHash" + + // Additional RPC method constants can be added here + RPCMethodFoo = "foo" + RPCMethodBar = "bar" + + RPCMethodBaz = "baz" + RPCMethodQux = "qux" +) + type RPCClient struct { sync.RWMutex Url string @@ -34,8 +51,8 @@ type GetBlockReply struct { Miner string `json:"miner"` Difficulty string `json:"difficulty"` GasLimit string `json:"gasLimit"` - BaseFeePerGas string `json:"baseFeePerGas"` GasUsed string `json:"gasUsed"` + BaseFeePerGas string `json:"baseFeePerGas"` Timestamp string `json:"timestamp"` Transactions []Tx `json:"transactions"` Uncles []string `json:"uncles"` @@ -207,6 +224,19 @@ func (r *RPCClient) GetPeerCount() (int64, error) { return strconv.ParseInt(strings.Replace(reply, "0x", "", -1), 16, 64) } +func (r *RPCClient) GetGasPrice() (int64, error) { + rpcResp, err := r.doPost(r.Url, "eth_gasPrice", nil) + if err != nil { + return 0, err + } + var reply string + err = json.Unmarshal(*rpcResp.Result, &reply) + if err != nil { + return 0, err + } + return strconv.ParseInt(strings.Replace(reply, "0x", "", -1), 16, 64) +} + func (r *RPCClient) SendTransaction(from, to, gas, gasPrice, value string, autoGas bool) (string, error) { params := map[string]string{ "from": from, @@ -214,7 +244,6 @@ func (r *RPCClient) SendTransaction(from, to, gas, gasPrice, value string, autoG "value": value, } if !autoGas { - // Sends as Legacy TX params["gas"] = gas params["gasPrice"] = gasPrice }