Merge pull request #2522 from filecoin-project/feat/paych-settle
Add CLI commands to settle & collect payment channels
This commit is contained in:
commit
7e760f956a
82
cli/paych.go
82
cli/paych.go
@ -21,6 +21,8 @@ var paychCmd = &cli.Command{
|
|||||||
paychGetCmd,
|
paychGetCmd,
|
||||||
paychListCmd,
|
paychListCmd,
|
||||||
paychVoucherCmd,
|
paychVoucherCmd,
|
||||||
|
paychSettleCmd,
|
||||||
|
paychCloseCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +92,86 @@ var paychListCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var paychSettleCmd = &cli.Command{
|
||||||
|
Name: "settle",
|
||||||
|
Usage: "Settle a payment channel",
|
||||||
|
ArgsUsage: "[channelAddress]",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
if cctx.Args().Len() != 1 {
|
||||||
|
return fmt.Errorf("must pass payment channel address")
|
||||||
|
}
|
||||||
|
|
||||||
|
ch, err := address.NewFromString(cctx.Args().Get(0))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse payment channel address: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
mcid, err := api.PaychSettle(ctx, ch)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mwait, err := api.StateWaitMsg(ctx, mcid, build.MessageConfidence)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if mwait.Receipt.ExitCode != 0 {
|
||||||
|
return fmt.Errorf("settle message execution failed (exit code %d)", mwait.Receipt.ExitCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Settled channel %s\n", ch)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var paychCloseCmd = &cli.Command{
|
||||||
|
Name: "collect",
|
||||||
|
Usage: "Collect funds for a payment channel",
|
||||||
|
ArgsUsage: "[channelAddress]",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
if cctx.Args().Len() != 1 {
|
||||||
|
return fmt.Errorf("must pass payment channel address")
|
||||||
|
}
|
||||||
|
|
||||||
|
ch, err := address.NewFromString(cctx.Args().Get(0))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse payment channel address: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
mcid, err := api.PaychCollect(ctx, ch)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mwait, err := api.StateWaitMsg(ctx, mcid, build.MessageConfidence)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if mwait.Receipt.ExitCode != 0 {
|
||||||
|
return fmt.Errorf("collect message execution failed (exit code %d)", mwait.Receipt.ExitCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Collected funds for channel %s\n", ch)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var paychVoucherCmd = &cli.Command{
|
var paychVoucherCmd = &cli.Command{
|
||||||
Name: "voucher",
|
Name: "voucher",
|
||||||
Usage: "Interact with payment channel vouchers",
|
Usage: "Interact with payment channel vouchers",
|
||||||
|
Loading…
Reference in New Issue
Block a user