Skip to content

Commit

Permalink
re-using rpcTransaction type (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
viveksb007 authored Feb 7, 2022
1 parent 35654c8 commit 2480052
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
32 changes: 7 additions & 25 deletions ethereum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (ec *Client) Transaction(
}

var raw json.RawMessage
err := ec.c.CallContext(ctx, &raw, "eth_getTransactionByHash", transactionIdentifier.Hash)
err := ec.c.CallContext(ctx, &raw, "eth_getTransactionByHash", transactionIdentifier.Hash)
if err != nil {
return nil, fmt.Errorf("%w: transaction fetch failed", err)
} else if len(raw) == 0 {
Expand Down Expand Up @@ -1558,38 +1558,20 @@ func (ec *Client) Call(
return nil, fmt.Errorf("%w: %s", ErrCallMethodInvalid, request.Method)
}

// TxPoolContentResponse represents the response for a call to
// txPoolContentResponse represents the response for a call to
// geth node on the "txpool_content" method.
type TxPoolContentResponse struct {
type txPoolContentResponse struct {
Pending txPool `json:"pending"`
Queued txPool `json:"queued"`
}

type txPool map[string]txPoolInner

type txPoolInner map[string]txPoolTxInfo

type txPoolTxInfo struct {
BlockHash *string `json:"blockHash"`
BlockNumber *string `json:"blockNumber"`
From string `json:"from"`
Gas string `json:"gas"`
GasPrice string `json:"gasPrice"`
Hash string `json:"hash"`
Input string `json:"input"`
Nonce string `json:"nonce"`
To string `json:"to"`
TransactionIndex int64 `json:"transactionIndex"`
Value string `json:"value"`
Type string `json:"type"`
V string `json:"v"`
R string `json:"r"`
S string `json:"s"`
}
type txPoolInner map[string]rpcTransaction

// GetMempool get and returns all the transactions on Ethereum TxPool (pending and queued).
func (ec *Client) GetMempool(ctx context.Context) (*RosettaTypes.MempoolResponse, error) {
var response TxPoolContentResponse
var response txPoolContentResponse
if err := ec.c.CallContext(ctx, &response, "txpool_content"); err != nil {
return nil, err
}
Expand All @@ -1599,15 +1581,15 @@ func (ec *Client) GetMempool(ctx context.Context) (*RosettaTypes.MempoolResponse
for _, inner := range response.Pending {
for _, info := range inner {
identifiers = append(identifiers, &RosettaTypes.TransactionIdentifier{
Hash: info.Hash,
Hash: info.tx.Hash().String(),
})
}
}

for _, inner := range response.Queued {
for _, info := range inner {
identifiers = append(identifiers, &RosettaTypes.TransactionIdentifier{
Hash: info.Hash,
Hash: info.tx.Hash().String(),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion ethereum/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2748,7 +2748,7 @@ func TestGetMempool(t *testing.T) {
nil,
).Run(
func(args mock.Arguments) {
r, ok := args.Get(1).(*TxPoolContentResponse)
r, ok := args.Get(1).(*txPoolContentResponse)
assert.True(t, ok)

file, err := ioutil.ReadFile("testdata/txpool_content.json")
Expand Down

0 comments on commit 2480052

Please sign in to comment.