Skip to content

Commit

Permalink
Handle alternative self destruct state diff format.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed May 11, 2022
1 parent c208cd4 commit 79cb6a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
16 changes: 10 additions & 6 deletions api/transactionstatechange.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ func (t *TransactionStateChange) unpack(data *transactionStateChangeJSON) error
}

if data.Alteration != nil {
t.From, err = util.StrToBigInt("from", data.Alteration.From)
if err != nil {
return err
if data.Alteration.From != "" {
t.From, err = util.StrToBigInt("from", data.Alteration.From)
if err != nil {
return err
}
}

t.To, err = util.StrToBigInt("to", data.Alteration.To)
if err != nil {
return err
if data.Alteration.To != "" {
t.To, err = util.StrToBigInt("to", data.Alteration.To)
if err != nil {
return err
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions api/transactionstatediff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ func TestTransactionStateDiff(t *testing.T) {
input: []byte(`{"balance":{"*":{"from":"0x1d53ae02be969d05","to":"0x1d0ddce00eb7500a"}},"code":"=","nonce":{"*":{"from":"0x397","to":"0x398"}},"storage":{}}`),
expected: []byte(`{"balance":{"*":{"from":"0x1d53ae02be969d05","to":"0x1d0ddce00eb7500a"}},"nonce":{"*":{"from":"0x397","to":"0x398"}}}`),
},
{
name: "GoodNewBalance",
input: []byte(`{"balance":{"+":"0x1d53ae02be969d05"},"code":"=","nonce":{"+":"0x0"}}`),
expected: []byte(`{"balance":{"+":"0x1d53ae02be969d05"},"nonce":{"+":"0x0"}}`),
},
{
name: "GoodNoChanges",
input: []byte(`{"balance":"=","code":"=","nonce":"="}`),
expected: []byte(`{}`),
},
{
name: "GoodSelfDestruct",
input: []byte(`{"balance":{"*":{"from":"0x1","to":null}},"code":{"*":{"from":"0x608060405260","to":null}},"nonce":{"*":{"from":"0x1","to":null}}}`),
expected: []byte(`{"balance":{"-":"0x1"},"nonce":{"-":"0x1"}}`),
},
{
name: "GoodSelfDestructCanonical",
input: []byte(`{"balance":{"-":"0x1"},"code":{"-":"0x608060405260"},"nonce":{"-":"0x1"}}`),
expected: []byte(`{"balance":{"-":"0x1"},"nonce":{"-":"0x1"}}`),
},
}

for _, test := range tests {
Expand Down

0 comments on commit 79cb6a7

Please sign in to comment.