Modify tooling to support new WithdrawBalance return

This commit is contained in:
Aayush Rajasekaran
2021-09-29 13:01:04 -04:00
parent dc8de20b9a
commit 2bafdf7271
5 changed files with 499 additions and 32 deletions
+30
View File
@@ -2,6 +2,7 @@ package cli
import (
"bufio"
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
@@ -9,6 +10,8 @@ import (
"os"
"strings"
"github.com/filecoin-project/lotus/build"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"
@@ -528,6 +531,11 @@ var walletMarketWithdraw = &cli.Command{
Usage: "Market address to withdraw from (account or miner actor address, defaults to --wallet address)",
Aliases: []string{"a"},
},
&cli.IntFlag{
Name: "confidence",
Usage: "number of block confirmations to wait for",
Value: int(build.MessageConfidence),
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
@@ -614,6 +622,28 @@ var walletMarketWithdraw = &cli.Command{
fmt.Printf("WithdrawBalance message cid: %s\n", smsg)
// wait for it to get mined into a block
wait, err := api.StateWaitMsg(ctx, smsg, uint64(cctx.Int("confidence")))
if err != nil {
return err
}
// check it executed successfully
if wait.Receipt.ExitCode != 0 {
fmt.Println(cctx.App.Writer, "withdrawal failed!")
return err
}
var withdrawn abi.TokenAmount
if err := withdrawn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil {
return err
}
fmt.Printf("Successfully withdrew %s FIL\n", withdrawn)
if withdrawn != amt {
fmt.Printf("Note that this is less than the requested amount of %s FIL\n", amt)
}
return nil
},
}