fix: allow deploying from f1/f3 accounts (#9554)

Co-authored-by: Raúl Kripalani <raul@protocol.ai>
This commit is contained in:
Steven Allen 2022-10-26 13:53:23 +01:00 committed by vyzo
parent 6337d594fa
commit ea54499f24

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/base64" "encoding/base64"
"encoding/binary"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -17,6 +18,7 @@ import (
"time" "time"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/multiformats/go-varint"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -1618,6 +1620,12 @@ var ChainExecCmd = &cli.Command{
}, },
} }
// TODO: Find a home for this.
func isNativeEthereumAddress(addr address.Address) bool {
id, _, err := varint.FromUvarint(addr.Payload())
return err == nil && id == builtintypes.EthereumAddressManagerActorID
}
var ChainExecEVMCmd = &cli.Command{ var ChainExecEVMCmd = &cli.Command{
Name: "create-evm-actor", Name: "create-evm-actor",
Usage: "Create an new EVM actor via the init actor and return its address", Usage: "Create an new EVM actor via the init actor and return its address",
@ -1672,19 +1680,38 @@ var ChainExecEVMCmd = &cli.Command{
nonce = 0 // assume a zero nonce on error (e.g. sender doesn't exist). nonce = 0 // assume a zero nonce on error (e.g. sender doesn't exist).
} }
params, err := actors.SerializeParams(&eam.CreateParams{ var (
params []byte
method abi.MethodNum
)
if isNativeEthereumAddress(fromAddr) {
params, err = actors.SerializeParams(&eam.CreateParams{
Initcode: contract, Initcode: contract,
Nonce: nonce, Nonce: nonce,
}) })
if err != nil {
return fmt.Errorf("failed to serialize Create params: %w", err)
}
method = builtintypes.MethodsEAM.Create
} else {
var salt [32]byte
binary.BigEndian.PutUint64(salt[:], nonce)
params, err = actors.SerializeParams(&eam.Create2Params{
Initcode: contract,
Salt: salt,
})
if err != nil { if err != nil {
return fmt.Errorf("failed to serialize Create2 params: %w", err) return fmt.Errorf("failed to serialize Create2 params: %w", err)
} }
method = builtintypes.MethodsEAM.Create2
}
msg := &types.Message{ msg := &types.Message{
To: builtintypes.EthereumAddressManagerActorAddr, To: builtintypes.EthereumAddressManagerActorAddr,
From: fromAddr, From: fromAddr,
Value: big.Zero(), Value: big.Zero(),
Method: builtintypes.MethodsEAM.Create, Method: method,
Params: params, Params: params,
} }