From b7f218671cca4b0895c302acb154e877c02f3de6 Mon Sep 17 00:00:00 2001 From: Austin Roberts Date: Thu, 23 Apr 2020 09:48:40 -0500 Subject: [PATCH] eth/filters: Wrap Transaction with RPCTransaction Raw Transaction objects don't serialize the "from" field in JSON (because it's calculated from the signature). This wraps it in an RPCTransaction object, which makes sure the from field gets included. --- eth/filters/dropped_tx_subscription.go | 33 ++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/eth/filters/dropped_tx_subscription.go b/eth/filters/dropped_tx_subscription.go index 6116def83d..a53d7384e0 100644 --- a/eth/filters/dropped_tx_subscription.go +++ b/eth/filters/dropped_tx_subscription.go @@ -5,6 +5,8 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/rpc" ) @@ -15,10 +17,37 @@ type dropNotification struct { } type rejectNotification struct { - Tx *types.Transaction `json:"tx"` + Tx *ethapi.RPCTransaction `json:"tx"` Reason string `json:"reason"` } +// newRPCTransaction returns a transaction that will serialize to the RPC +// representation, with the given location metadata set (if available). +func newRPCPendingTransaction(tx *types.Transaction) *ethapi.RPCTransaction { + var signer types.Signer = types.FrontierSigner{} + if tx.Protected() { + signer = types.NewEIP155Signer(tx.ChainId()) + } + from, _ := types.Sender(signer, tx) + v, r, s := tx.RawSignatureValues() + + result := ðapi.RPCTransaction{ + From: from, + Gas: hexutil.Uint64(tx.Gas()), + GasPrice: (*hexutil.Big)(tx.GasPrice()), + Hash: tx.Hash(), + Input: hexutil.Bytes(tx.Data()), + Nonce: hexutil.Uint64(tx.Nonce()), + To: tx.To(), + Value: (*hexutil.Big)(tx.Value()), + V: (*hexutil.Big)(v), + R: (*hexutil.Big)(r), + S: (*hexutil.Big)(s), + } + return result +} + + // DroppedTransactions send a notification each time a transaction is dropped from the mempool func (api *PublicFilterAPI) DroppedTransactions(ctx context.Context) (*rpc.Subscription, error) { notifier, supported := rpc.NotifierFromContext(ctx) @@ -71,7 +100,7 @@ func (api *PublicFilterAPI) RejectedTransactions(ctx context.Context) (*rpc.Subs if d.Reason != nil { reason = d.Reason.Error() } - notifier.Notify(rpcSub.ID, &rejectNotification{Tx: d.Tx, Reason: reason}) + notifier.Notify(rpcSub.ID, &rejectNotification{Tx: newRPCPendingTransaction(d.Tx), Reason: reason}) case <-rpcSub.Err(): rejectedSub.Unsubscribe() return