Skip to content

Commit

Permalink
Shed: Allow send-csv to specify params and method
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Nov 25, 2021
1 parent e15bc39 commit 75b3cf6
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions cmd/lotus-shed/send-csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package main

import (
"encoding/csv"
"encoding/hex"
"fmt"
"os"
"strings"

"github.com/filecoin-project/lotus/chain/actors/builtin"

"github.com/ipfs/go-cid"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"
Expand All @@ -28,6 +31,19 @@ var sendCsvCmd = &cli.Command{
Usage: "specify the account to send funds from",
Required: true,
},
&cli.Uint64Flag{
Name: "method",
Usage: "specify method to invoke",
Value: uint64(builtin.MethodSend),
},
&cli.StringFlag{
Name: "params-json",
Usage: "specify invocation parameters in json",
},
&cli.StringFlag{
Name: "params-hex",
Usage: "specify invocation parameters in hex",
},
},
ArgsUsage: "[csvfile]",
Action: func(cctx *cli.Context) error {
Expand All @@ -43,6 +59,12 @@ var sendCsvCmd = &cli.Command{
defer closer()
ctx := lcli.ReqContext(cctx)

srv, err := lcli.GetFullNodeServices(cctx)
if err != nil {
return err
}
defer srv.Close() //nolint:errcheck

sender, err := address.NewFromString(cctx.String("from"))
if err != nil {
return err
Expand Down Expand Up @@ -77,14 +99,39 @@ var sendCsvCmd = &cli.Command{
}

msgs = append(msgs, &types.Message{
To: addr,
From: sender,
Value: abi.TokenAmount(value),
To: addr,
From: sender,
Value: abi.TokenAmount(value),
Method: abi.MethodNum(cctx.Uint64("method")),
})
}

if len(msgs) == 0 {
return nil
}

var params []byte
if cctx.IsSet("params-json") {
decparams, err := srv.DecodeTypedParamsFromJSON(ctx, msgs[0].To, msgs[0].Method, cctx.String("params-json"))
if err != nil {
return fmt.Errorf("failed to decode json params: %w", err)
}
params = decparams
}
if cctx.IsSet("params-hex") {
if params != nil {
return fmt.Errorf("can only specify one of 'params-json' and 'params-hex'")
}
decparams, err := hex.DecodeString(cctx.String("params-hex"))
if err != nil {
return fmt.Errorf("failed to decode hex params: %w", err)
}
params = decparams
}

var msgCids []cid.Cid
for i, msg := range msgs {
msg.Params = params
smsg, err := api.MpoolPushMessage(ctx, msg, nil)
if err != nil {
return err
Expand Down

0 comments on commit 75b3cf6

Please sign in to comment.