Skip to content

Commit

Permalink
ethapi: adds txmeta fields to transaction rpc responses (#35)
Browse files Browse the repository at this point in the history
* core: transaction meta serialization

* test: txmeta queue origin set to 0

* ethapi: add queue origin to rpc txn

* api: debug

* api: add tx meta to rpc endpoints

* api: add type, l1messagesender to rpctx

* ethapi: render metadata
  • Loading branch information
tynes authored Sep 24, 2020
1 parent f47687c commit a842ccc
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,9 @@ type RPCTransaction struct {
V *hexutil.Big `json:"v"`
R *hexutil.Big `json:"r"`
S *hexutil.Big `json:"s"`
QueueOrigin string `json:"queueOrigin"`
Type string `json:"type"`
L1MessageSender *common.Address `json:"l1MessageSender"`
}

// newRPCTransaction returns a transaction that will serialize to the RPC
Expand Down Expand Up @@ -1090,6 +1093,23 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber))
result.TransactionIndex = (*hexutil.Uint64)(&index)
}

if meta := tx.GetMeta(); meta != nil {
result.L1MessageSender = meta.L1MessageSender
if meta.QueueOrigin != nil {
switch meta.QueueOrigin.Uint64() {
case uint64(2):
result.QueueOrigin = "sequencer"
}
}

switch meta.SignatureHashType {
case types.SighashEthSign:
result.Type = "EthSign"
case types.SighashEIP155:
result.Type = "EIP155"
}
}
return result
}

Expand Down Expand Up @@ -1508,6 +1528,8 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod
if err := rlp.DecodeBytes(encodedTx, tx); err != nil {
return common.Hash{}, err
}
meta := types.NewTransactionMeta(nil, nil, types.SighashEIP155)
tx.SetTransactionMeta(meta)
return SubmitTransaction(ctx, s.b, tx)
}

Expand All @@ -1520,8 +1542,8 @@ func (s *PublicTransactionPoolAPI) SendRawEthSignTransaction(ctx context.Context
if err := rlp.DecodeBytes(encodedTx, tx); err != nil {
return common.Hash{}, err
}

tx.SetSignatureHashType(types.SighashEthSign)
meta := types.NewTransactionMeta(nil, nil, types.SighashEthSign)
tx.SetTransactionMeta(meta)
return SubmitTransaction(ctx, s.b, tx)
}

Expand Down

0 comments on commit a842ccc

Please sign in to comment.