Browse Source

update

master
yuriy0803 2 years ago
parent
commit
46e2be1c8b
  1. 17
      proxy/blocks.go
  2. 35
      rpc/rpc.go

17
proxy/blocks.go

@ -7,7 +7,6 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/ethereum/go-ethereum/common"
"github.com/yuriy0803/open-etc-pool-friends/rpc" "github.com/yuriy0803/open-etc-pool-friends/rpc"
"github.com/yuriy0803/open-etc-pool-friends/util" "github.com/yuriy0803/open-etc-pool-friends/util"
) )
@ -26,24 +25,24 @@ type BlockTemplate struct {
Target string Target string
Difficulty *big.Int Difficulty *big.Int
Height uint64 Height uint64
GetPendingBlockCache *rpc.GetBlockReplyPart GetPendingBlockCache *rpc.GetBlockReplyPart // Assuming this type is defined elsewhere
nonces map[string]bool nonces map[string]bool
headers map[string]heightDiffPair headers map[string]heightDiffPair
} }
type Block struct { type Block struct {
difficulty *big.Int difficulty *big.Int
hashNoNonce common.Hash hashNoNonce string // Replacing common.Hash with string
nonce uint64 nonce uint64
mixDigest common.Hash mixDigest string // Replacing common.Hash with string
number uint64 number uint64
} }
func (b Block) Difficulty() *big.Int { return b.difficulty } func (b Block) Difficulty() *big.Int { return b.difficulty }
func (b Block) HashNoNonce() common.Hash { return b.hashNoNonce } func (b Block) HashNoNonce() string { return b.hashNoNonce }
func (b Block) Nonce() uint64 { return b.nonce } func (b Block) Nonce() uint64 { return b.nonce }
func (b Block) MixDigest() common.Hash { return b.mixDigest } func (b Block) MixDigest() string { return b.mixDigest }
func (b Block) NumberU64() uint64 { return b.number } func (b Block) NumberU64() uint64 { return b.number }
func (s *ProxyServer) fetchBlockTemplate() { func (s *ProxyServer) fetchBlockTemplate() {
rpc := s.rpc() rpc := s.rpc()

35
rpc/rpc.go

@ -13,10 +13,27 @@ import (
"sync" "sync"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/yuriy0803/open-etc-pool-friends/util" "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 { type RPCClient struct {
sync.RWMutex sync.RWMutex
Url string Url string
@ -34,8 +51,8 @@ type GetBlockReply struct {
Miner string `json:"miner"` Miner string `json:"miner"`
Difficulty string `json:"difficulty"` Difficulty string `json:"difficulty"`
GasLimit string `json:"gasLimit"` GasLimit string `json:"gasLimit"`
BaseFeePerGas string `json:"baseFeePerGas"`
GasUsed string `json:"gasUsed"` GasUsed string `json:"gasUsed"`
BaseFeePerGas string `json:"baseFeePerGas"`
Timestamp string `json:"timestamp"` Timestamp string `json:"timestamp"`
Transactions []Tx `json:"transactions"` Transactions []Tx `json:"transactions"`
Uncles []string `json:"uncles"` Uncles []string `json:"uncles"`
@ -207,6 +224,19 @@ func (r *RPCClient) GetPeerCount() (int64, error) {
return strconv.ParseInt(strings.Replace(reply, "0x", "", -1), 16, 64) 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) { func (r *RPCClient) SendTransaction(from, to, gas, gasPrice, value string, autoGas bool) (string, error) {
params := map[string]string{ params := map[string]string{
"from": from, "from": from,
@ -214,7 +244,6 @@ func (r *RPCClient) SendTransaction(from, to, gas, gasPrice, value string, autoG
"value": value, "value": value,
} }
if !autoGas { if !autoGas {
// Sends as Legacy TX
params["gas"] = gas params["gas"] = gas
params["gasPrice"] = gasPrice params["gasPrice"] = gasPrice
} }

Loading…
Cancel
Save