Skip to content

Commit

Permalink
Allow f4 address to send to all address types if ID address exists on…
Browse files Browse the repository at this point in the history
… chain
  • Loading branch information
Geoff Stuart committed Feb 1, 2023
1 parent 27465e5 commit 9428979
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func EthAddressFromPubKey(pubk []byte) ([]byte, error) {
}

func EthAddressFromFilecoinAddress(addr address.Address) (EthAddress, error) {
fmt.Println(addr.String())
switch addr.Protocol() {
case address.ID:
id, err := address.IDFromAddress(addr)
Expand Down
17 changes: 16 additions & 1 deletion cli/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,23 @@ var sendCmd = &cli.Command{
}
defer srv.Close() //nolint:errcheck

api := srv.FullNodeAPI()

ctx := ReqContext(cctx)
var params SendParams

params.To, err = address.NewFromString(cctx.Args().Get(0))
toAddr, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return ShowHelp(cctx, fmt.Errorf("failed to parse target address: %w", err))
}

// Resolve id addr if possible.
idAddr, err := api.StateLookupID(ctx, toAddr, types.EmptyTSK)
if err == nil {
toAddr = idAddr
}
params.To = toAddr

val, err := types.ParseFIL(cctx.Args().Get(1))
if err != nil {
return ShowHelp(cctx, fmt.Errorf("failed to parse amount: %w", err))
Expand Down Expand Up @@ -117,6 +126,12 @@ var sendCmd = &cli.Command{
params.From = faddr
}

if params.From.Protocol() == address.Delegated {
if !(params.To.Protocol() == address.ID || params.To.Protocol() == address.Delegated) {
return xerrors.Errorf("can only send from f4 address to f0 or f4")
}
}

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

0 comments on commit 9428979

Please sign in to comment.