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"
"errors"
"fmt"
"github.com/paxosglobal/go-ethereum"
"github.com/paxosglobal/go-ethereum/common/hexutil"
"math/big"
"sync"
"time"
@ -186,9 +188,9 @@ func (b *SimulatedBackend) TransactionByHash(ctx context.Context, txHash common.
}
// 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)
return transaction, string(blockNumber), nil
return transaction, hexutil.EncodeUint64(blockNumber), nil
}
// BlockByNumber retrieves a block from the database by number, caching it

View file

@ -22,6 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/paxosglobal/go-ethereum"
"math/big"
"github.com/ethereum/go-ethereum"
@ -189,22 +190,22 @@ func (tx *rpcTransaction) UnmarshalJSON(msg []byte) error {
}
// 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
err = ec.c.CallContext(ctx, &json, "eth_getTransactionByHash", hash)
if err != nil {
return nil, "0", err
return nil, "0x0", err
} else if json == nil {
return nil, "0", ethereum.NotFound
return nil, "0x0", ethereum.NotFound
} 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 {
setSenderFromServer(json.tx, *json.From, *json.BlockHash)
}
if json.BlockNumber == nil {
return json.tx, "0", nil
return json.tx, "0x0", 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)
// 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