Skip to content

Commit

Permalink
Merge pull request #38 from nasdf/main
Browse files Browse the repository at this point in the history
update to latest go-ethereum version
  • Loading branch information
i-norden authored Oct 18, 2021
2 parents 7a6d75a + 46eead3 commit ba8a840
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 58 deletions.
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ module github.com/vulcanize/go-codec-dageth
go 1.15

require (
github.com/ethereum/go-ethereum v1.10.4
github.com/fxamacker/cbor/v2 v2.3.0
github.com/ethereum/go-ethereum v1.10.10
github.com/ipfs/go-cid v0.0.7
github.com/ipld/go-ipld-prime v0.10.0
github.com/multiformats/go-multihash v0.0.15
golang.org/x/tools v0.1.5 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)

replace github.com/ethereum/go-ethereum v1.10.4 => github.com/vulcanize/go-ethereum v1.10.4-ir-0.0.1
104 changes: 70 additions & 34 deletions go.sum

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions state_account/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ipld/go-ipld-prime"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
Expand Down Expand Up @@ -36,7 +36,7 @@ func Encode(node ipld.Node, w io.Writer) error {
// This means less copying of bytes, and if the destination has enough capacity,
// fewer allocations.
func AppendEncode(enc []byte, inNode ipld.Node) ([]byte, error) {
account := new(state.Account)
account := new(types.StateAccount)
if err := EncodeAccount(account, inNode); err != nil {
return enc, err
}
Expand All @@ -48,7 +48,7 @@ func AppendEncode(enc []byte, inNode ipld.Node) ([]byte, error) {
}

// EncodeAccount packs the node into the provided go-ethereum Account
func EncodeAccount(header *state.Account, inNode ipld.Node) error {
func EncodeAccount(header *types.StateAccount, inNode ipld.Node) error {
// Wrap in a typed node for some basic schema form checking
builder := dageth.Type.Account.NewBuilder()
if err := builder.AssignNode(inNode); err != nil {
Expand All @@ -63,14 +63,14 @@ func EncodeAccount(header *state.Account, inNode ipld.Node) error {
return nil
}

var requiredPackFuncs = []func(*state.Account, ipld.Node) error{
var requiredPackFuncs = []func(*types.StateAccount, ipld.Node) error{
packNonce,
packBalance,
packStorageRootCID,
packCodeCID,
}

func packNonce(account *state.Account, node ipld.Node) error {
func packNonce(account *types.StateAccount, node ipld.Node) error {
n, err := node.LookupByString("Nonce")
if err != nil {
return err
Expand All @@ -83,7 +83,7 @@ func packNonce(account *state.Account, node ipld.Node) error {
return nil
}

func packBalance(account *state.Account, node ipld.Node) error {
func packBalance(account *types.StateAccount, node ipld.Node) error {
b, err := node.LookupByString("Balance")
if err != nil {
return err
Expand All @@ -96,7 +96,7 @@ func packBalance(account *state.Account, node ipld.Node) error {
return nil
}

func packStorageRootCID(account *state.Account, node ipld.Node) error {
func packStorageRootCID(account *types.StateAccount, node ipld.Node) error {
srCID, err := node.LookupByString("StorageRootCID")
if err != nil {
return err
Expand All @@ -118,7 +118,7 @@ func packStorageRootCID(account *state.Account, node ipld.Node) error {
return nil
}

func packCodeCID(account *state.Account, node ipld.Node) error {
func packCodeCID(account *types.StateAccount, node ipld.Node) error {
cCID, err := node.LookupByString("CodeCID")
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions state_account/state_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ipld/go-ipld-prime"
Expand All @@ -21,7 +21,7 @@ var (
emptyStateRootNodeRLP, _ = rlp.EncodeToBytes([]byte{})
mockStateRoot = crypto.Keccak256Hash(emptyStateRootNodeRLP)
emptyCodeHash = crypto.Keccak256Hash([]byte{}).Bytes()
mockAccount = &state.Account{
mockAccount = &types.StateAccount{
Root: mockStateRoot,
Balance: big.NewInt(1000000000),
CodeHash: emptyCodeHash,
Expand Down
16 changes: 8 additions & 8 deletions state_account/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
"io/ioutil"

"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime"
Expand Down Expand Up @@ -35,15 +35,15 @@ func Decode(na ipld.NodeAssembler, in io.Reader) error {
// Decode will grab or read all the bytes from an io.Reader anyway, so this can
// save having to copy the bytes or create a bytes.Buffer.
func DecodeBytes(na ipld.NodeAssembler, src []byte) error {
var account state.Account
var account types.StateAccount
if err := rlp.DecodeBytes(src, &account); err != nil {
return err
}
return DecodeAccount(na, account)
}

// DecodeAccount unpacks a go-ethereum Account into a NodeAssembler
func DecodeAccount(na ipld.NodeAssembler, header state.Account) error {
func DecodeAccount(na ipld.NodeAssembler, header types.StateAccount) error {
ma, err := na.BeginMap(15)
if err != nil {
return err
Expand All @@ -56,14 +56,14 @@ func DecodeAccount(na ipld.NodeAssembler, header state.Account) error {
return ma.Finish()
}

var requiredUnpackFuncs = []func(ipld.MapAssembler, state.Account) error{
var requiredUnpackFuncs = []func(ipld.MapAssembler, types.StateAccount) error{
unpackNonce,
unpackBalance,
unpackStorageRootCID,
unpackCodeCID,
}

func unpackNonce(ma ipld.MapAssembler, account state.Account) error {
func unpackNonce(ma ipld.MapAssembler, account types.StateAccount) error {
if err := ma.AssembleKey().AssignString("Nonce"); err != nil {
return err
}
Expand All @@ -75,7 +75,7 @@ func unpackNonce(ma ipld.MapAssembler, account state.Account) error {
return nil
}

func unpackBalance(ma ipld.MapAssembler, account state.Account) error {
func unpackBalance(ma ipld.MapAssembler, account types.StateAccount) error {
if account.Balance == nil {
return fmt.Errorf("account balance cannot be null")
}
Expand All @@ -88,7 +88,7 @@ func unpackBalance(ma ipld.MapAssembler, account state.Account) error {
return nil
}

func unpackStorageRootCID(ma ipld.MapAssembler, account state.Account) error {
func unpackStorageRootCID(ma ipld.MapAssembler, account types.StateAccount) error {
srMh, err := multihash.Encode(account.Root.Bytes(), MultiHashType)
if err != nil {
return err
Expand All @@ -101,7 +101,7 @@ func unpackStorageRootCID(ma ipld.MapAssembler, account state.Account) error {
return ma.AssembleValue().AssignLink(srLinkCID)
}

func unpackCodeCID(ma ipld.MapAssembler, account state.Account) error {
func unpackCodeCID(ma ipld.MapAssembler, account types.StateAccount) error {
cMh, err := multihash.Encode(account.CodeHash, MultiHashType)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions state_trie/state_trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ipld/go-ipld-prime"
Expand All @@ -24,7 +24,7 @@ import (
)

var (
mockAccount = state.Account{
mockAccount = types.StateAccount{
Nonce: 2,
Balance: big.NewInt(1337),
CodeHash: crypto.Keccak256([]byte{}),
Expand Down

0 comments on commit ba8a840

Please sign in to comment.