-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
ethclient: move TransactionOpts to avoid import internal package; #2736
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package types | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
) | ||
|
||
type AccountStorage struct { | ||
StorageRoot *common.Hash | ||
StorageSlots map[common.Hash]common.Hash | ||
} | ||
|
||
func (a *AccountStorage) UnmarshalJSON(data []byte) error { | ||
var hash common.Hash | ||
if err := json.Unmarshal(data, &hash); err == nil { | ||
a.StorageRoot = &hash | ||
return nil | ||
} | ||
return json.Unmarshal(data, &a.StorageSlots) | ||
} | ||
|
||
func (a AccountStorage) MarshalJSON() ([]byte, error) { | ||
if a.StorageRoot != nil { | ||
return json.Marshal(*a.StorageRoot) | ||
} | ||
return json.Marshal(a.StorageSlots) | ||
} | ||
|
||
type KnownAccounts map[common.Address]AccountStorage | ||
|
||
// It is known that marshaling is broken | ||
// https://github.com/golang/go/issues/55890 | ||
|
||
//go:generate go run github.com/fjl/gencodec -type TransactionOpts -out gen_tx_opts_json.go | ||
type TransactionOpts struct { | ||
KnownAccounts KnownAccounts `json:"knownAccounts"` | ||
BlockNumberMin *hexutil.Uint64 `json:"blockNumberMin,omitempty"` | ||
BlockNumberMax *hexutil.Uint64 `json:"blockNumberMax,omitempty"` | ||
TimestampMin *hexutil.Uint64 `json:"timestampMin,omitempty"` | ||
TimestampMax *hexutil.Uint64 `json:"timestampMax,omitempty"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,52 +2,15 @@ package ethapi | |
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core/state" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
type AccountStorage struct { | ||
StorageRoot *common.Hash | ||
StorageSlots map[common.Hash]common.Hash | ||
} | ||
|
||
func (a *AccountStorage) UnmarshalJSON(data []byte) error { | ||
var hash common.Hash | ||
if err := json.Unmarshal(data, &hash); err == nil { | ||
a.StorageRoot = &hash | ||
return nil | ||
} | ||
return json.Unmarshal(data, &a.StorageSlots) | ||
} | ||
|
||
func (a AccountStorage) MarshalJSON() ([]byte, error) { | ||
if a.StorageRoot != nil { | ||
return json.Marshal(*a.StorageRoot) | ||
} | ||
return json.Marshal(a.StorageSlots) | ||
} | ||
|
||
type KnownAccounts map[common.Address]AccountStorage | ||
|
||
// It is known that marshaling is broken | ||
// https://github.com/golang/go/issues/55890 | ||
|
||
//go:generate go run github.com/fjl/gencodec -type TransactionOpts -out gen_tx_opts_json.go | ||
type TransactionOpts struct { | ||
KnownAccounts KnownAccounts `json:"knownAccounts"` | ||
BlockNumberMin *hexutil.Uint64 `json:"blockNumberMin,omitempty"` | ||
BlockNumberMax *hexutil.Uint64 `json:"blockNumberMax,omitempty"` | ||
TimestampMin *hexutil.Uint64 `json:"timestampMin,omitempty"` | ||
TimestampMax *hexutil.Uint64 `json:"timestampMax,omitempty"` | ||
} | ||
|
||
const MaxNumberOfEntries = 1000 | ||
|
||
func (o *TransactionOpts) Check(blockNumber uint64, timeStamp uint64, statedb *state.StateDB) error { | ||
func TxOptsCheck(o types.TransactionOpts, blockNumber uint64, timeStamp uint64, statedb *state.StateDB) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why these Check functions also not transferred to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, |
||
if o.BlockNumberMin != nil && blockNumber < uint64(*o.BlockNumberMin) { | ||
return errors.New("BlockNumberMin condition not met") | ||
} | ||
|
@@ -71,10 +34,10 @@ func (o *TransactionOpts) Check(blockNumber uint64, timeStamp uint64, statedb *s | |
if counter > MaxNumberOfEntries { | ||
return errors.New("knownAccounts too large") | ||
} | ||
return o.CheckStorage(statedb) | ||
return TxOptsCheckStorage(o, statedb) | ||
} | ||
|
||
func (o *TransactionOpts) CheckStorage(statedb *state.StateDB) error { | ||
func TxOptsCheckStorage(o types.TransactionOpts, statedb *state.StateDB) error { | ||
for address, accountStorage := range o.KnownAccounts { | ||
if accountStorage.StorageRoot != nil { | ||
rootHash := statedb.GetRoot(address) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just a pointer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean I know that code was just moved but maybe we could improve it