Skip to content

Commit

Permalink
Merge pull request #191 from hashcloak/add-more-query
Browse files Browse the repository at this point in the history
plugin: add more query
  • Loading branch information
sc0Vu authored Jun 12, 2023
2 parents 326d49a + 8704ae3 commit b9a37ee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
36 changes: 35 additions & 1 deletion plugin/pkg/chain/ethereum_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ func (ec *ETHChain) WrapRequest(rpcURL string, cmd uint8, payload []byte) (*Http
return nil, err
}

case command.EthQueryTransaction:
var req command.EthQueryTransactionRequest
dec := codec.NewDecoderBytes(payload, &jsonHandle)
err := dec.Decode(&req)
if err != nil {
return nil, err
}
blockNumberRequest := ethRequest{
ID: 2,
JSONRPC: "2.0",
METHOD: "eth_blockNumber",
}
receiptRequest := ethRequest{
ID: 1,
JSONRPC: "2.0",
METHOD: "eth_getTransactionReceipt",
Params: []string{req.TxHash},
}
marshalledRequest, err = json.Marshal([]ethRequest{
blockNumberRequest,
receiptRequest,
})
if err != nil {
return nil, err
}

case command.EthQuery:
var req command.EthQueryRequest
dec := codec.NewDecoderBytes(payload, &jsonHandle)
Expand Down Expand Up @@ -89,7 +115,7 @@ func (ec *ETHChain) WrapRequest(rpcURL string, cmd uint8, payload []byte) (*Http
ID: 3,
JSONRPC: "2.0",
METHOD: "eth_call",
Params: []interface{}{param},
Params: []interface{}{param, "latest"},
}
marshalledRequest, err = json.Marshal([]ethRequest{
nonceRequest,
Expand Down Expand Up @@ -128,6 +154,14 @@ func (ec *ETHChain) UnwrapResponse(cmd uint8, payload []RPCResponse) ([]byte, er
return json.Marshal(command.PostTransactionResponse{
TxHash: payload[0].Result,
})
case command.EthQueryTransaction:
if len(payload) != 2 {
return nil, errNumResponse(2, len(payload))
}
return json.Marshal(command.EthQueryTransactionResponse{
BlockNumber: payload[0].Result,
Tx: payload[1].Result,
})
case command.EthQuery:
if len(payload) != 4 {
return nil, errNumResponse(4, len(payload))
Expand Down
12 changes: 11 additions & 1 deletion plugin/pkg/command/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package command
import "math/big"

const (
EthQuery uint8 = 0x10
EthQuery uint8 = 0x10
EthQueryTransaction uint8 = 0x11
)

// Request Types
Expand All @@ -14,10 +15,19 @@ type EthQueryRequest struct {
Data string
}

type EthQueryTransactionRequest struct {
TxHash string
}

// Response Types
type EthQueryResponse struct {
Nonce string
GasPrice string
GasLimit string
CallResult string
}

type EthQueryTransactionResponse struct {
BlockNumber string
Tx string
}

0 comments on commit b9a37ee

Please sign in to comment.