Skip to content

Commit

Permalink
address review comments from @magik6k on #9617 (#9997)
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk authored Jan 12, 2023
1 parent 3ef3239 commit 014d954
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 329 deletions.
13 changes: 8 additions & 5 deletions api/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,13 @@ func init() {
})

ethint := ethtypes.EthUint64(5)

addExample(ethint)
addExample(&ethint)

ethaddr, _ := ethtypes.ParseEthAddress("0x5CbEeCF99d3fDB3f25E309Cc264f240bb0664031")
addExample(ethaddr)
addExample(&ethaddr)

ethhash, _ := ethtypes.EthHashFromCid(c)
addExample(ethhash)
addExample(&ethhash)
Expand All @@ -387,11 +388,13 @@ func init() {

addExample(&uuid.UUID{})

filterid, _ := ethtypes.ParseEthHash("0x5CbEeC012345673f25E309Cc264f240bb0664031")
addExample(ethtypes.EthFilterID(filterid))
filterid := ethtypes.EthFilterID(ethhash)
addExample(filterid)
addExample(&filterid)

subid, _ := ethtypes.ParseEthHash("0x5CbEeCF99d3fDB301234567c264f240bb0664031")
addExample(ethtypes.EthSubscriptionID(subid))
subid := ethtypes.EthSubscriptionID(ethhash)
addExample(subid)
addExample(&subid)

pstring := func(s string) *string { return &s }
addExample(&ethtypes.EthFilterSpec{
Expand Down
Binary file modified build/openrpc/full.json.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions chain/types/ethtypes/eth_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ func parseEip1559Tx(data []byte) (*EthTxArgs, error) {
return nil, fmt.Errorf("not an EIP-1559 transaction: decoded data is not a list")
}

if len(decoded) != 9 && len(decoded) != 12 {
return nil, fmt.Errorf("not an EIP-1559 transaction: should have 6 or 9 elements in the list")
if len(decoded) != 12 {
return nil, fmt.Errorf("not an EIP-1559 transaction: should have 12 elements in the rlp list")
}

chainId, err := parseInt(decoded[0])
Expand Down
4 changes: 2 additions & 2 deletions chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@ func decodeHexString(s string, expectedLen int) ([]byte, error) {
s = "0" + s
}
if len(s) != expectedLen*2 {
return []byte{}, xerrors.Errorf("expected length %d, got %d", expectedLen, len(s))
return nil, xerrors.Errorf("expected hex string length sans prefix %d, got %d", expectedLen*2, len(s))
}
b, err := hex.DecodeString(s)
if err != nil {
return []byte{}, xerrors.Errorf("cannot parse hex value: %w", err)
return nil, xerrors.Errorf("cannot parse hex value: %w", err)
}
return b, nil
}
Expand Down
10 changes: 6 additions & 4 deletions chain/types/ethtypes/rlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import (
"golang.org/x/xerrors"
)

// set a limit to make sure it doesn't loop infinitely
const maxListElements = 500
// maxListElements restricts the amount of RLP list elements we'll read.
// The ETH API only ever reads EIP-1559 transactions, which are bounded by
// 12 elements exactly, so we play it safe and set exactly that limit here.
const maxListElements = 12

func EncodeRLP(val interface{}) ([]byte, error) {
return encodeRLP(val)
}

func encodeRLPListItems(list []interface{}) (result []byte, err error) {
res := []byte{}
var res []byte
for _, elem := range list {
encoded, err := encodeRLP(elem)
if err != nil {
Expand Down Expand Up @@ -163,7 +165,7 @@ func decodeLength(data []byte, lenInBytes int) (length int, err error) {

func decodeListElems(data []byte, length int) (res []interface{}, err error) {
totalConsumed := 0
result := []interface{}{}
var result []interface{}

for i := 0; totalConsumed < length && i < maxListElements; i++ {
elem, consumed, err := decodeRLP(data[totalConsumed:])
Expand Down
2 changes: 1 addition & 1 deletion chain/wallet/key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewKey(keyinfo types.KeyInfo) (*Key, error) {
return nil, xerrors.Errorf("converting Secp256k1 to address: %w", err)
}
case types.KTDelegated:
// Assume eth for now
// Transitory Delegated signature verification as per FIP-0055
ethAddr, err := ethtypes.EthAddressFromPubKey(k.PublicKey)
if err != nil {
return nil, xerrors.Errorf("failed to calculate Eth address from public key: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var Commands = []*cli.Command{
WithCategory("developer", LogCmd),
WithCategory("developer", WaitApiCmd),
WithCategory("developer", FetchParamCmd),
WithCategory("developer", EthCmd),
WithCategory("developer", EvmCmd),
WithCategory("network", NetCmd),
WithCategory("network", SyncCmd),
WithCategory("status", StatusCmd),
Expand Down
26 changes: 13 additions & 13 deletions cli/eth.go → cli/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ import (
"github.com/filecoin-project/lotus/chain/types/ethtypes"
)

var EthCmd = &cli.Command{
Name: "eth",
Usage: "Ethereum operations",
var EvmCmd = &cli.Command{
Name: "evm",
Usage: "Commands related to the Filecoin EVM runtime",
Subcommands: []*cli.Command{
EthDeployCmd,
EthInvokeCmd,
EthGetInfoCmd,
EthCallSimulateCmd,
EthGetContractAddress,
EvmDeployCmd,
EvmInvokeCmd,
EvmGetInfoCmd,
EvmCallSimulateCmd,
EvmGetContractAddress,
},
}

var EthGetInfoCmd = &cli.Command{
var EvmGetInfoCmd = &cli.Command{
Name: "stat",
Usage: "Print eth/filecoin addrs and code cid",
Flags: []cli.Flag{
Expand Down Expand Up @@ -101,7 +101,7 @@ var EthGetInfoCmd = &cli.Command{
},
}

var EthCallSimulateCmd = &cli.Command{
var EvmCallSimulateCmd = &cli.Command{
Name: "call",
Usage: "Simulate an eth contract call",
ArgsUsage: "[from] [to] [params]",
Expand Down Expand Up @@ -150,7 +150,7 @@ var EthCallSimulateCmd = &cli.Command{
},
}

var EthGetContractAddress = &cli.Command{
var EvmGetContractAddress = &cli.Command{
Name: "contract-address",
Usage: "Generate contract address from smart contract code",
ArgsUsage: "[senderEthAddr] [salt] [contractHexPath]",
Expand Down Expand Up @@ -200,7 +200,7 @@ var EthGetContractAddress = &cli.Command{
},
}

var EthDeployCmd = &cli.Command{
var EvmDeployCmd = &cli.Command{
Name: "deploy",
Usage: "Deploy an EVM smart contract and return its address",
ArgsUsage: "contract",
Expand Down Expand Up @@ -329,7 +329,7 @@ var EthDeployCmd = &cli.Command{
},
}

var EthInvokeCmd = &cli.Command{
var EvmInvokeCmd = &cli.Command{
Name: "invoke",
Usage: "Invoke an EVM smart contract using the specified CALLDATA",
ArgsUsage: "address calldata",
Expand Down
Loading

0 comments on commit 014d954

Please sign in to comment.