From c3df219a7be302d43be14c6b410e8dcd9cf705e3 Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Fri, 10 May 2024 12:15:37 -0400 Subject: [PATCH] Make newRPCTransaction public (#26) --- lib/ethapi/api.go | 10 +++++----- lib/ethapi/api_test.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ethapi/api.go b/lib/ethapi/api.go index 7fdd7c2070..251dfd00da 100644 --- a/lib/ethapi/api.go +++ b/lib/ethapi/api.go @@ -1349,9 +1349,9 @@ type RPCTransaction struct { YParity *hexutil.Uint64 `json:"yParity,omitempty"` } -// newRPCTransaction returns a transaction that will serialize to the RPC +// NewRPCTransaction returns a transaction that will serialize to the RPC // representation, with the given location metadata set (if available). -func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, blockTime uint64, index uint64, baseFee *big.Int, config *params.ChainConfig) *RPCTransaction { +func NewRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, blockTime uint64, index uint64, baseFee *big.Int, config *params.ChainConfig) *RPCTransaction { signer := types.MakeSigner(config, new(big.Int).SetUint64(blockNumber), blockTime) from, _ := types.Sender(signer, tx) v, r, s := tx.RawSignatureValues() @@ -1449,7 +1449,7 @@ func NewRPCPendingTransaction(tx *types.Transaction, current *types.Header, conf blockNumber = current.Number.Uint64() blockTime = current.Time } - return newRPCTransaction(tx, common.Hash{}, blockNumber, blockTime, 0, baseFee, config) + return NewRPCTransaction(tx, common.Hash{}, blockNumber, blockTime, 0, baseFee, config) } // newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation. @@ -1458,7 +1458,7 @@ func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *param if index >= uint64(len(txs)) { return nil } - return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), b.Time(), index, b.BaseFee(), config) + return NewRPCTransaction(txs[index], b.Hash(), b.NumberU64(), b.Time(), index, b.BaseFee(), config) } // newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index. @@ -1657,7 +1657,7 @@ func (s *TransactionAPI) GetTransactionByHash(ctx context.Context, hash common.H if err != nil { return nil, err } - return newRPCTransaction(tx, blockHash, blockNumber, header.Time, index, header.BaseFee, s.b.ChainConfig()), nil + return NewRPCTransaction(tx, blockHash, blockNumber, header.Time, index, header.BaseFee, s.b.ChainConfig()), nil } // No finalized transaction, try to retrieve it from the pool if tx := s.b.GetPoolTransaction(hash); tx != nil { diff --git a/lib/ethapi/api_test.go b/lib/ethapi/api_test.go index 870438e41d..1d8807e29f 100644 --- a/lib/ethapi/api_test.go +++ b/lib/ethapi/api_test.go @@ -75,7 +75,7 @@ func testTransactionMarshal(t *testing.T, tests []txData, config *params.ChainCo } // rpcTransaction - rpcTx := newRPCTransaction(tx, common.Hash{}, 0, 0, 0, nil, config) + rpcTx := NewRPCTransaction(tx, common.Hash{}, 0, 0, 0, nil, config) if data, err := json.Marshal(rpcTx); err != nil { t.Fatalf("test %d: marshalling failed; %v", i, err) } else if err = tx2.UnmarshalJSON(data); err != nil {