-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
paych: get available funds by address or by from/to #3547
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import ( | |
"sort" | ||
"strings" | ||
|
||
"github.com/filecoin-project/lotus/api" | ||
|
||
"github.com/filecoin-project/lotus/paychmgr" | ||
|
||
"github.com/filecoin-project/go-address" | ||
|
@@ -80,13 +82,13 @@ var paychAddFundsCmd = &cli.Command{ | |
}, | ||
} | ||
|
||
var paychStatusCmd = &cli.Command{ | ||
Name: "status", | ||
Usage: "Show the status of an outbound payment channel between fromAddress and toAddress", | ||
var paychStatusByFromToCmd = &cli.Command{ | ||
Name: "status-by-from-to", | ||
Usage: "Show the status of an active outbound payment channel by from/to addresses", | ||
ArgsUsage: "[fromAddress toAddress]", | ||
Action: func(cctx *cli.Context) error { | ||
if cctx.Args().Len() != 2 { | ||
return ShowHelp(cctx, fmt.Errorf("must pass two arguments: <from> <to>")) | ||
return ShowHelp(cctx, fmt.Errorf("must pass two arguments: <from address> <to address>")) | ||
} | ||
|
||
from, err := address.NewFromString(cctx.Args().Get(0)) | ||
|
@@ -105,52 +107,86 @@ var paychStatusCmd = &cli.Command{ | |
} | ||
defer closer() | ||
|
||
avail, err := api.PaychAvailableFunds(from, to) | ||
avail, err := api.PaychAvailableFundsByFromTo(from, to) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if avail.Channel == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic of formatting the channel status output is the same, it's just been extracted into a method that's called by both |
||
if avail.PendingWaitSentinel != nil { | ||
fmt.Fprint(cctx.App.Writer, "Creating channel\n") | ||
fmt.Fprintf(cctx.App.Writer, " From: %s\n", from) | ||
fmt.Fprintf(cctx.App.Writer, " To: %s\n", to) | ||
fmt.Fprintf(cctx.App.Writer, " Pending Amt: %d\n", avail.PendingAmt) | ||
fmt.Fprintf(cctx.App.Writer, " Wait Sentinel: %s\n", avail.PendingWaitSentinel) | ||
return nil | ||
} | ||
fmt.Fprint(cctx.App.Writer, "Channel does not exist\n") | ||
fmt.Fprintf(cctx.App.Writer, " From: %s\n", from) | ||
fmt.Fprintf(cctx.App.Writer, " To: %s\n", to) | ||
return nil | ||
paychStatus(cctx.App.Writer, avail) | ||
return nil | ||
}, | ||
} | ||
|
||
var paychStatusCmd = &cli.Command{ | ||
Name: "status", | ||
Usage: "Show the status of an outbound payment channel", | ||
ArgsUsage: "[channelAddress]", | ||
Action: func(cctx *cli.Context) error { | ||
if cctx.Args().Len() != 1 { | ||
return ShowHelp(cctx, fmt.Errorf("must pass an argument: <channel address>")) | ||
} | ||
|
||
if avail.PendingWaitSentinel != nil { | ||
fmt.Fprint(cctx.App.Writer, "Adding Funds to channel\n") | ||
} else { | ||
fmt.Fprint(cctx.App.Writer, "Channel exists\n") | ||
ch, err := address.NewFromString(cctx.Args().Get(0)) | ||
if err != nil { | ||
return ShowHelp(cctx, fmt.Errorf("failed to parse channel address: %s", err)) | ||
} | ||
|
||
nameValues := [][]string{ | ||
{"Channel", avail.Channel.String()}, | ||
{"From", from.String()}, | ||
{"To", to.String()}, | ||
{"Confirmed Amt", fmt.Sprintf("%d", avail.ConfirmedAmt)}, | ||
{"Pending Amt", fmt.Sprintf("%d", avail.PendingAmt)}, | ||
{"Queued Amt", fmt.Sprintf("%d", avail.QueuedAmt)}, | ||
{"Voucher Redeemed Amt", fmt.Sprintf("%d", avail.VoucherReedeemedAmt)}, | ||
api, closer, err := GetFullNodeAPI(cctx) | ||
if err != nil { | ||
return err | ||
} | ||
if avail.PendingWaitSentinel != nil { | ||
nameValues = append(nameValues, []string{ | ||
"Add Funds Wait Sentinel", | ||
avail.PendingWaitSentinel.String(), | ||
}) | ||
defer closer() | ||
|
||
avail, err := api.PaychAvailableFunds(ch) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Fprint(cctx.App.Writer, formatNameValues(nameValues)) | ||
|
||
paychStatus(cctx.App.Writer, avail) | ||
return nil | ||
}, | ||
} | ||
|
||
func paychStatus(writer io.Writer, avail *api.ChannelAvailableFunds) { | ||
if avail.Channel == nil { | ||
if avail.PendingWaitSentinel != nil { | ||
fmt.Fprint(writer, "Creating channel\n") | ||
fmt.Fprintf(writer, " From: %s\n", avail.From) | ||
fmt.Fprintf(writer, " To: %s\n", avail.To) | ||
fmt.Fprintf(writer, " Pending Amt: %d\n", avail.PendingAmt) | ||
fmt.Fprintf(writer, " Wait Sentinel: %s\n", avail.PendingWaitSentinel) | ||
return | ||
} | ||
fmt.Fprint(writer, "Channel does not exist\n") | ||
fmt.Fprintf(writer, " From: %s\n", avail.From) | ||
fmt.Fprintf(writer, " To: %s\n", avail.To) | ||
return | ||
} | ||
|
||
if avail.PendingWaitSentinel != nil { | ||
fmt.Fprint(writer, "Adding Funds to channel\n") | ||
} else { | ||
fmt.Fprint(writer, "Channel exists\n") | ||
} | ||
|
||
nameValues := [][]string{ | ||
{"Channel", avail.Channel.String()}, | ||
{"From", avail.From.String()}, | ||
{"To", avail.To.String()}, | ||
{"Confirmed Amt", fmt.Sprintf("%d", avail.ConfirmedAmt)}, | ||
{"Pending Amt", fmt.Sprintf("%d", avail.PendingAmt)}, | ||
{"Queued Amt", fmt.Sprintf("%d", avail.QueuedAmt)}, | ||
{"Voucher Redeemed Amt", fmt.Sprintf("%d", avail.VoucherReedeemedAmt)}, | ||
} | ||
if avail.PendingWaitSentinel != nil { | ||
nameValues = append(nameValues, []string{ | ||
"Add Funds Wait Sentinel", | ||
avail.PendingWaitSentinel.String(), | ||
}) | ||
} | ||
fmt.Fprint(writer, formatNameValues(nameValues)) | ||
} | ||
|
||
func formatNameValues(nameValues [][]string) string { | ||
maxLen := 0 | ||
for _, nv := range nameValues { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an indentation change