From ff8b95df934264f9c85bb0ecb82bb7cf7b277176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 4 Jan 2022 23:31:22 +0100 Subject: [PATCH] paych: Reserve flag for add-funds cli --- cli/paych.go | 9 ++++++--- paychmgr/store.go | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cli/paych.go b/cli/paych.go index eef262272..171ab38ab 100644 --- a/cli/paych.go +++ b/cli/paych.go @@ -39,12 +39,15 @@ var paychAddFundsCmd = &cli.Command{ Usage: "Add funds to the payment channel between fromAddress and toAddress. Creates the payment channel if it doesn't already exist.", ArgsUsage: "[fromAddress toAddress amount]", Flags: []cli.Flag{ - &cli.BoolFlag{ Name: "restart-retrievals", Usage: "restart stalled retrieval deals on this payment channel", Value: true, }, + &cli.BoolFlag{ + Name: "reserve", + Usage: "mark funds as reserved", + }, }, Action: func(cctx *cli.Context) error { if cctx.Args().Len() != 3 { @@ -66,7 +69,7 @@ var paychAddFundsCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("parsing amount failed: %s", err)) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := GetFullNodeAPIV1(cctx) if err != nil { return err } @@ -76,7 +79,7 @@ var paychAddFundsCmd = &cli.Command{ // Send a message to chain to create channel / add funds to existing // channel - info, err := api.PaychGet(ctx, from, to, types.BigInt(amt)) + info, err := api.PaychGet(ctx, from, to, types.BigInt(amt), cctx.Bool("reserve")) if err != nil { return err } diff --git a/paychmgr/store.go b/paychmgr/store.go index bbc549b86..d5c8e1980 100644 --- a/paychmgr/store.go +++ b/paychmgr/store.go @@ -502,5 +502,11 @@ func unmarshallChannelInfo(stored *ChannelInfo, value []byte) (*ChannelInfo, err stored.Channel = nil } + // backwards compat + if stored.AvailableAmount.Int == nil { + stored.AvailableAmount = types.NewInt(0) + stored.PendingAvailableAmount = types.NewInt(0) + } + return stored, nil }