Skip to content

Commit

Permalink
lotus send should accept ETH addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Jul 29, 2024
1 parent 792eecc commit 2edb655
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion cli/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,20 @@ var SendCmd = &cli.Command{

params.To, err = address.NewFromString(cctx.Args().Get(0))
if err != nil {
return ShowHelp(cctx, fmt.Errorf("failed to parse target address: %w", err))
// could be an ETH address
ea, err := ethtypes.ParseEthAddress(cctx.Args().Get(0))
if err != nil {
return ShowHelp(cctx, fmt.Errorf("failed to parse target address; address must be a valid FIL address or an ETH address: %w", err))
}
// this will be either "f410f..." or "f0..."
params.To, err = ea.ToFilecoinAddress()
if err != nil {
return ShowHelp(cctx, fmt.Errorf("failed to convert ETH address to FIL address: %w", err))
}
// ideally, this should never happen
if !(params.To.Protocol() == address.ID || params.To.Protocol() == address.Delegated) {
return ShowHelp(cctx, fmt.Errorf("ETH addresses can only map to a FIL addresses starting with f410f or f0"))
}
}

val, err := types.ParseFIL(cctx.Args().Get(1))
Expand Down Expand Up @@ -120,6 +133,17 @@ var SendCmd = &cli.Command{
params.From = faddr
}

if params.From == address.Undef {
defaddr, err := srv.FullNodeAPI().WalletDefaultAddress(ctx)
if err != nil {
return fmt.Errorf("failed to get default address: %w", err)
}
params.From = defaddr
}

_, _ = fmt.Fprintf(cctx.App.Writer, "Sending message from: %s\n", params.From.String())
_, _ = fmt.Fprintf(cctx.App.Writer, "Sending message to: %s\n", params.To.String())

if cctx.IsSet("params-hex") {
decparams, err := hex.DecodeString(cctx.String("params-hex"))
if err != nil {
Expand Down Expand Up @@ -166,6 +190,7 @@ var SendCmd = &cli.Command{
} else {
params.Method = abi.MethodNum(cctx.Uint64("method"))
}
_, _ = fmt.Fprintf(cctx.App.Writer, "Using Method: %d\n", params.Method)

if cctx.IsSet("gas-premium") {
gp, err := types.BigFromString(cctx.String("gas-premium"))
Expand Down

0 comments on commit 2edb655

Please sign in to comment.