/
list_claims.go
50 lines (39 loc) · 1.1 KB
/
list_claims.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/singnet/snet-daemon/escrow"
)
// ListClaimsCmd shows list of channels from shared storage
var ListClaimsCmd = &cobra.Command{
Use: "claims",
Short: "List payments which are not written to blockchain yet",
Long: "List payments which are in progress state and not written" +
" to the blockchain.",
RunE: func(cmd *cobra.Command, args []string) error {
return RunAndCleanup(cmd, args, newListClaimsCommand)
},
}
type listClaimsCommand struct {
channelService escrow.PaymentChannelService
}
func newListClaimsCommand(cmd *cobra.Command, args []string, components *Components) (command Command, err error) {
command = &listClaimsCommand{
channelService: components.PaymentChannelService(),
}
return
}
func (command *listClaimsCommand) Run() (err error) {
claims, err := command.channelService.ListClaims()
if err != nil {
return
}
if len(claims) == 0 {
fmt.Println("no claims in shared storage")
}
for _, claim := range claims {
payment := claim.Payment()
fmt.Printf("%v: %v\n", payment.ID(), payment)
}
return nil
}