Fixing the Simulated and Adding a new Fn TransactionByHashWithBlockNum

This commit is contained in:
Priyadarshan Vyas 2019-05-28 23:31:23 -04:00
parent 596b253e9c
commit 64da30ab06
3 changed files with 11 additions and 8 deletions

View file

@ -20,6 +20,8 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/paxosglobal/go-ethereum"
"github.com/paxosglobal/go-ethereum/common/hexutil"
"math/big" "math/big"
"sync" "sync"
"time" "time"
@ -186,9 +188,9 @@ func (b *SimulatedBackend) TransactionByHash(ctx context.Context, txHash common.
} }
// TransactionByHash returns the transaction with the given hash. // TransactionByHash returns the transaction with the given hash.
func (b *SimulatedBackend) TransactionByHashWithBlockNum(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending string, err error) { func (b *SimulatedBackend) TransactionByHashWithBlockNum(ctx context.Context, txHash common.Hash) (tx *types.Transaction, blockHexString string, err error) {
transaction, _, blockNumber, _ := rawdb.ReadTransaction(b.database, txHash) transaction, _, blockNumber, _ := rawdb.ReadTransaction(b.database, txHash)
return transaction, string(blockNumber), nil return transaction, hexutil.EncodeUint64(blockNumber), nil
} }
// BlockByNumber retrieves a block from the database by number, caching it // BlockByNumber retrieves a block from the database by number, caching it

View file

@ -22,6 +22,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/paxosglobal/go-ethereum"
"math/big" "math/big"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
@ -189,22 +190,22 @@ func (tx *rpcTransaction) UnmarshalJSON(msg []byte) error {
} }
// TransactionByHash returns the transaction with the given hash. // TransactionByHash returns the transaction with the given hash.
func (ec *Client) TransactionByHashWithBlockNum(ctx context.Context, hash common.Hash) (tx *types.Transaction, BlockNumber string, err error) { func (ec *Client) TransactionByHashWithBlockNum(ctx context.Context, hash common.Hash) (tx *types.Transaction, blockHexString string, err error) {
var json *rpcTransaction var json *rpcTransaction
err = ec.c.CallContext(ctx, &json, "eth_getTransactionByHash", hash) err = ec.c.CallContext(ctx, &json, "eth_getTransactionByHash", hash)
if err != nil { if err != nil {
return nil, "0", err return nil, "0x0", err
} else if json == nil { } else if json == nil {
return nil, "0", ethereum.NotFound return nil, "0x0", ethereum.NotFound
} else if _, r, _ := json.tx.RawSignatureValues(); r == nil { } else if _, r, _ := json.tx.RawSignatureValues(); r == nil {
return nil, "0", fmt.Errorf("server returned transaction without signature") return nil, "0x0", fmt.Errorf("server returned transaction without signature")
} }
if json.From != nil && json.BlockHash != nil { if json.From != nil && json.BlockHash != nil {
setSenderFromServer(json.tx, *json.From, *json.BlockHash) setSenderFromServer(json.tx, *json.From, *json.BlockHash)
} }
if json.BlockNumber == nil { if json.BlockNumber == nil {
return json.tx, "0", nil return json.tx, "0x0", nil
} }
return json.tx, *json.BlockNumber, nil return json.tx, *json.BlockNumber, nil

View file

@ -85,7 +85,7 @@ type TransactionReader interface {
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
// Same as TransactionByHash but returns the BlockNum // Same as TransactionByHash but returns the BlockNum
TransactionByHashWithBlockNum(ctx context.Context, hash common.Hash) (tx *types.Transaction, BlockNumber string, err error) TransactionByHashWithBlockNum(ctx context.Context, hash common.Hash) (tx *types.Transaction, blockHexString string, err error)
} }
// ChainStateReader wraps access to the state trie of the canonical blockchain. Note that // ChainStateReader wraps access to the state trie of the canonical blockchain. Note that