Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
2d192f51
Unverified
Commit
2d192f51
authored
Nov 22, 2021
by
Conner Fromknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: deserialize L2 TxMeta in ethclient
parent
996230de
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
1 deletion
+121
-1
transaction_meta.go
l2geth/core/types/transaction_meta.go
+14
-0
ethclient.go
l2geth/ethclient/ethclient.go
+32
-1
gen_rpc_tx_meta_json.go
l2geth/ethclient/gen_rpc_tx_meta_json.go
+75
-0
No files found.
l2geth/core/types/transaction_meta.go
View file @
2d192f51
...
@@ -7,6 +7,7 @@ package types
...
@@ -7,6 +7,7 @@ package types
import
(
import
(
"bytes"
"bytes"
"encoding/binary"
"encoding/binary"
"fmt"
"math/big"
"math/big"
"github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum-optimism/optimism/l2geth/common"
...
@@ -31,6 +32,19 @@ func (q QueueOrigin) String() string {
...
@@ -31,6 +32,19 @@ func (q QueueOrigin) String() string {
}
}
}
}
func
(
q
*
QueueOrigin
)
UnmarshalJSON
(
b
[]
byte
)
error
{
switch
string
(
b
)
{
case
"
\"
sequencer
\"
"
:
*
q
=
QueueOriginSequencer
return
nil
case
"
\"
l1
\"
"
:
*
q
=
QueueOriginL1ToL2
return
nil
default
:
return
fmt
.
Errorf
(
"Unknown QueueOrigin: %q"
,
b
)
}
}
//go:generate gencodec -type TransactionMeta -out gen_tx_meta_json.go
//go:generate gencodec -type TransactionMeta -out gen_tx_meta_json.go
type
TransactionMeta
struct
{
type
TransactionMeta
struct
{
...
...
l2geth/ethclient/ethclient.go
View file @
2d192f51
...
@@ -154,6 +154,13 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
...
@@ -154,6 +154,13 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
if
tx
.
From
!=
nil
{
if
tx
.
From
!=
nil
{
setSenderFromServer
(
tx
.
tx
,
*
tx
.
From
,
body
.
Hash
)
setSenderFromServer
(
tx
.
tx
,
*
tx
.
From
,
body
.
Hash
)
}
}
meta
:=
types
.
NewTransactionMeta
(
tx
.
meta
.
L1BlockNumber
,
tx
.
meta
.
L1Timestamp
,
tx
.
meta
.
L1MessageSender
,
tx
.
meta
.
QueueOrigin
,
tx
.
meta
.
Index
,
tx
.
meta
.
QueueIndex
,
tx
.
meta
.
RawTransaction
,
)
tx
.
tx
.
SetTransactionMeta
(
meta
)
txs
[
i
]
=
tx
.
tx
txs
[
i
]
=
tx
.
tx
}
}
return
types
.
NewBlockWithHeader
(
head
)
.
WithBody
(
txs
,
uncles
),
nil
return
types
.
NewBlockWithHeader
(
head
)
.
WithBody
(
txs
,
uncles
),
nil
...
@@ -181,10 +188,31 @@ func (ec *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.H
...
@@ -181,10 +188,31 @@ func (ec *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.H
}
}
type
rpcTransaction
struct
{
type
rpcTransaction
struct
{
tx
*
types
.
Transaction
tx
*
types
.
Transaction
meta
*
rpcTransactionMeta
txExtraInfo
txExtraInfo
}
}
//go:generate gencodec -type rpcTransactionMeta -field-override rpcTransactionMetaMarshaling -out gen_rpc_tx_meta_json.go
type
rpcTransactionMeta
struct
{
L1BlockNumber
*
big
.
Int
`json:"l1BlockNumber"`
L1Timestamp
uint64
`json:"l1Timestamp"`
L1MessageSender
*
common
.
Address
`json:"l1MessageSender"`
QueueOrigin
types
.
QueueOrigin
`json:"queueOrigin"`
Index
*
uint64
`json:"index"`
QueueIndex
*
uint64
`json:"queueIndex"`
RawTransaction
[]
byte
`json:"rawTransaction"`
}
type
rpcTransactionMetaMarshaling
struct
{
L1BlockNumber
*
hexutil
.
Big
L1Timestamp
hexutil
.
Uint64
Index
*
hexutil
.
Uint64
QueueIndex
*
hexutil
.
Uint64
RawTransaction
hexutil
.
Bytes
}
type
txExtraInfo
struct
{
type
txExtraInfo
struct
{
BlockNumber
*
string
`json:"blockNumber,omitempty"`
BlockNumber
*
string
`json:"blockNumber,omitempty"`
BlockHash
*
common
.
Hash
`json:"blockHash,omitempty"`
BlockHash
*
common
.
Hash
`json:"blockHash,omitempty"`
...
@@ -195,6 +223,9 @@ func (tx *rpcTransaction) UnmarshalJSON(msg []byte) error {
...
@@ -195,6 +223,9 @@ func (tx *rpcTransaction) UnmarshalJSON(msg []byte) error {
if
err
:=
json
.
Unmarshal
(
msg
,
&
tx
.
tx
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
msg
,
&
tx
.
tx
);
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
json
.
Unmarshal
(
msg
,
&
tx
.
meta
);
err
!=
nil
{
return
err
}
return
json
.
Unmarshal
(
msg
,
&
tx
.
txExtraInfo
)
return
json
.
Unmarshal
(
msg
,
&
tx
.
txExtraInfo
)
}
}
...
...
l2geth/ethclient/gen_rpc_tx_meta_json.go
0 → 100644
View file @
2d192f51
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package
ethclient
import
(
"encoding/json"
"math/big"
"github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum-optimism/optimism/l2geth/common/hexutil"
"github.com/ethereum-optimism/optimism/l2geth/core/types"
)
var
_
=
(
*
rpcTransactionMetaMarshaling
)(
nil
)
// MarshalJSON marshals as JSON.
func
(
r
rpcTransactionMeta
)
MarshalJSON
()
([]
byte
,
error
)
{
type
rpcTransactionMeta
struct
{
L1BlockNumber
*
hexutil
.
Big
`json:"l1BlockNumber"`
L1Timestamp
hexutil
.
Uint64
`json:"l1Timestamp"`
L1MessageSender
*
common
.
Address
`json:"l1MessageSender"`
QueueOrigin
types
.
QueueOrigin
`json:"queueOrigin"`
Index
*
hexutil
.
Uint64
`json:"index"`
QueueIndex
*
hexutil
.
Uint64
`json:"queueIndex"`
RawTransaction
hexutil
.
Bytes
`json:"rawTransaction"`
}
var
enc
rpcTransactionMeta
enc
.
L1BlockNumber
=
(
*
hexutil
.
Big
)(
r
.
L1BlockNumber
)
enc
.
L1Timestamp
=
hexutil
.
Uint64
(
r
.
L1Timestamp
)
enc
.
L1MessageSender
=
r
.
L1MessageSender
enc
.
QueueOrigin
=
r
.
QueueOrigin
enc
.
Index
=
(
*
hexutil
.
Uint64
)(
r
.
Index
)
enc
.
QueueIndex
=
(
*
hexutil
.
Uint64
)(
r
.
QueueIndex
)
enc
.
RawTransaction
=
r
.
RawTransaction
return
json
.
Marshal
(
&
enc
)
}
// UnmarshalJSON unmarshals from JSON.
func
(
r
*
rpcTransactionMeta
)
UnmarshalJSON
(
input
[]
byte
)
error
{
type
rpcTransactionMeta
struct
{
L1BlockNumber
*
hexutil
.
Big
`json:"l1BlockNumber"`
L1Timestamp
*
hexutil
.
Uint64
`json:"l1Timestamp"`
L1MessageSender
*
common
.
Address
`json:"l1MessageSender"`
QueueOrigin
*
types
.
QueueOrigin
`json:"queueOrigin"`
Index
*
hexutil
.
Uint64
`json:"index"`
QueueIndex
*
hexutil
.
Uint64
`json:"queueIndex"`
RawTransaction
*
hexutil
.
Bytes
`json:"rawTransaction"`
}
var
dec
rpcTransactionMeta
if
err
:=
json
.
Unmarshal
(
input
,
&
dec
);
err
!=
nil
{
return
err
}
if
dec
.
L1BlockNumber
!=
nil
{
r
.
L1BlockNumber
=
(
*
big
.
Int
)(
dec
.
L1BlockNumber
)
}
if
dec
.
L1Timestamp
!=
nil
{
r
.
L1Timestamp
=
uint64
(
*
dec
.
L1Timestamp
)
}
if
dec
.
L1MessageSender
!=
nil
{
r
.
L1MessageSender
=
dec
.
L1MessageSender
}
if
dec
.
QueueOrigin
!=
nil
{
r
.
QueueOrigin
=
*
dec
.
QueueOrigin
}
if
dec
.
Index
!=
nil
{
r
.
Index
=
(
*
uint64
)(
dec
.
Index
)
}
if
dec
.
QueueIndex
!=
nil
{
r
.
QueueIndex
=
(
*
uint64
)(
dec
.
QueueIndex
)
}
if
dec
.
RawTransaction
!=
nil
{
r
.
RawTransaction
=
*
dec
.
RawTransaction
}
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment