mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
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.
This commit is contained in:
parent
24eb6797e2
commit
b7f218671c
1 changed files with 31 additions and 2 deletions
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"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"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
@ -15,10 +17,37 @@ type dropNotification struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type rejectNotification struct {
|
type rejectNotification struct {
|
||||||
Tx *types.Transaction `json:"tx"`
|
Tx *ethapi.RPCTransaction `json:"tx"`
|
||||||
Reason string `json:"reason"`
|
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
|
// DroppedTransactions send a notification each time a transaction is dropped from the mempool
|
||||||
func (api *PublicFilterAPI) DroppedTransactions(ctx context.Context) (*rpc.Subscription, error) {
|
func (api *PublicFilterAPI) DroppedTransactions(ctx context.Context) (*rpc.Subscription, error) {
|
||||||
notifier, supported := rpc.NotifierFromContext(ctx)
|
notifier, supported := rpc.NotifierFromContext(ctx)
|
||||||
|
|
@ -71,7 +100,7 @@ func (api *PublicFilterAPI) RejectedTransactions(ctx context.Context) (*rpc.Subs
|
||||||
if d.Reason != nil {
|
if d.Reason != nil {
|
||||||
reason = d.Reason.Error()
|
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():
|
case <-rpcSub.Err():
|
||||||
rejectedSub.Unsubscribe()
|
rejectedSub.Unsubscribe()
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue