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 Dec 7, 2021
1 parent c9a557e commit b0a9a27
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions cmd/lotus-shed/send-csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

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

"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -43,6 +45,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 All @@ -60,8 +68,11 @@ var sendCsvCmd = &cli.Command{
return xerrors.Errorf("read csv: %w", err)
}

if strings.TrimSpace(records[0][0]) != "Recipient" || strings.TrimSpace(records[0][1]) != "FIL" {
return xerrors.Errorf("expected header row to be \"Recipient, FIL\"")
if strings.TrimSpace(records[0][0]) != "Recipient" ||
strings.TrimSpace(records[0][1]) != "FIL" ||
strings.TrimSpace(records[0][2]) != "Method" ||
strings.TrimSpace(records[0][3]) != "Params" {
return xerrors.Errorf("expected header row to be \"Recipient, FIL, Method, Params\"")
}

var msgs []*types.Message
Expand All @@ -76,21 +87,41 @@ var sendCsvCmd = &cli.Command{
return xerrors.Errorf("failed to parse value balance: %w", err)
}

method, err := strconv.Atoi(strings.TrimSpace(e[2]))
if err != nil {
return xerrors.Errorf("failed to parse method number: %w", err)
}

var params []byte
if strings.TrimSpace(e[3]) != "nil" {
params, err = hex.DecodeString(strings.TrimSpace(e[3]))
if err != nil {
return xerrors.Errorf("failed to parse hexparams: %w", err)
}
}

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

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

var msgCids []cid.Cid
for i, msg := range msgs {
smsg, err := api.MpoolPushMessage(ctx, msg, nil)
if err != nil {
return err
fmt.Printf("%d, ERROR %s\n", i, err)
continue
}

fmt.Printf("sending %s to %s in msg %s\n", msg.Value.String(), msg.To, smsg.Cid())
fmt.Printf("%d, %s\n", i, smsg.Cid())

if i > 0 && i%100 == 0 {
fmt.Printf("catching up until latest message lands")
Expand All @@ -103,7 +134,7 @@ var sendCsvCmd = &cli.Command{
msgCids = append(msgCids, smsg.Cid())
}

fmt.Println("waiting on messages")
fmt.Println("waiting on messages...")

for _, msgCid := range msgCids {
ml, err := api.StateWaitMsg(ctx, msgCid, 5, lapi.LookbackNoLimit, true)
Expand All @@ -115,6 +146,7 @@ var sendCsvCmd = &cli.Command{
}
}

fmt.Println("all sent messages succeeded")
return nil
},
}

0 comments on commit b0a9a27

Please sign in to comment.