Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth.Transaction: support new yParity field #91

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions eth/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Transaction struct {
V Quantity `json:"v"`
R Quantity `json:"r"`
S Quantity `json:"s"`
YParity *Quantity `json:"yParity,omitempty"`

// Gas Price (optional since not included in EIP-1559)
GasPrice *Quantity `json:"gasPrice,omitempty"`
Expand Down Expand Up @@ -161,6 +162,12 @@ func (t *Transaction) RawRepresentation() (*Data, error) {
if err != nil {
return nil, err
}
var yParity Quantity
if t.YParity != nil {
yParity = *t.YParity
} else {
yParity = t.V
}
payload := rlp.Value{List: []rlp.Value{
t.ChainId.RLP(),
t.Nonce.RLP(),
Expand All @@ -170,7 +177,7 @@ func (t *Transaction) RawRepresentation() (*Data, error) {
t.Value.RLP(),
{String: t.Input.String()},
t.AccessList.RLP(),
t.V.RLP(),
yParity.RLP(),
t.R.RLP(),
t.S.RLP(),
}}
Expand All @@ -185,6 +192,12 @@ func (t *Transaction) RawRepresentation() (*Data, error) {
if err != nil {
return nil, err
}
var yParity Quantity
if t.YParity != nil {
yParity = *t.YParity
} else {
yParity = t.V
}
payload := rlp.Value{List: []rlp.Value{
t.ChainId.RLP(),
t.Nonce.RLP(),
Expand All @@ -195,7 +208,7 @@ func (t *Transaction) RawRepresentation() (*Data, error) {
t.Value.RLP(),
{String: t.Input.String()},
t.AccessList.RLP(),
t.V.RLP(),
yParity.RLP(),
t.R.RLP(),
t.S.RLP(),
}}
Expand Down
3 changes: 3 additions & 0 deletions eth/transaction_from_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (t *Transaction) FromRaw(input string) error {
t.Input = data
t.AccessList = &accessList
t.V = v
t.YParity = &v
t.R = r
t.S = s
t.ChainId = &chainId
Expand Down Expand Up @@ -121,6 +122,7 @@ func (t *Transaction) FromRaw(input string) error {
t.Input = data
t.AccessList = &accessList
t.V = v
t.YParity = &v
t.R = r
t.S = s
t.ChainId = &chainId
Expand Down Expand Up @@ -168,6 +170,7 @@ func (t *Transaction) FromRaw(input string) error {
t.Value = value
t.Input = data
t.V = v
t.YParity = nil
t.R = r
t.S = s

Expand Down
2 changes: 2 additions & 0 deletions eth/transaction_from_raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ func TestTransaction_FromRawEIP2930(t *testing.T) {
require.Equal(t, "0x1684eb52101a049f7bda9b0239dbd56db6735f8eed4207cdabd682dde3ed06bf", tx.R.String())
require.Equal(t, "0x71d5cf480a272dc907ff4a4efb2a4a96e2132409592268747acfa5d03f50deb7", tx.S.String())
require.Equal(t, "0x0", tx.V.String())
require.NotNil(t, tx.YParity)
require.Equal(t, "0x0", tx.YParity.String())
require.Equal(t, "0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192", tx.To.String())
require.Equal(t, "0x1", tx.Type.String())
require.Equal(t, int64(0), tx.Value.Int64())
Expand Down
3 changes: 3 additions & 0 deletions eth/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func TestTransactionTypeDynamicFee(t *testing.T) {
"transactionIndex": "0x41",
"value": "0x0",
"v": "0x1",
"yParity": "0x1",
"r": "0x396864e5f9132327defdb1449504252e1fa6bce73feb8cd6f348a342b198af34",
"s": "0x44dbba72e6d3304104848277143252ee43627c82f02d1ef8e404e1bf97c70158",
"gasPrice": "0x4a817c800",
Expand All @@ -206,6 +207,8 @@ func TestTransactionTypeDynamicFee(t *testing.T) {
require.NotNil(t, tx.Type)
require.Equal(t, eth.TransactionTypeDynamicFee, tx.Type.Int64())
require.Equal(t, eth.TransactionTypeDynamicFee, tx.TransactionType())
require.NotNil(t, tx.YParity)
require.Equal(t, tx.V, *tx.YParity)

j, err := json.Marshal(&tx)
require.NoError(t, err)
Expand Down
4 changes: 4 additions & 0 deletions eth/zz_deepcopy_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.