-
Notifications
You must be signed in to change notification settings - Fork 0
/
txs.go
52 lines (48 loc) · 1.26 KB
/
txs.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
51
52
package cli
import (
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spf13/cobra"
"github.com/sudachen/smwlt/fu/errstr"
"github.com/sudachen/smwlt/fu/stdio"
"github.com/sudachen/smwlt/wallet"
"strconv"
"strings"
)
var cmdTxs = &cobra.Command{
Use: "txs <account> [startLayer]",
Short: "List transactions (outgoing and incoming) for the account",
Args: cobra.RangeArgs(1, 2),
Run: func(cmd *cobra.Command, args []string) {
w := loadWallet()
acc := wallet.LuckyLookup(args[0], w...)
c := newClient()
layer := uint64(0)
if len(args) > 1 {
x, err := strconv.Atoi(args[1])
if err != nil {
panic(errstr.Format(0, "bad layer '%v'", args[1]))
}
layer = uint64(x)
}
mark := func(address types.Address) string {
if address == acc.Address {
return "*"
}
return ""
}
txs := c.LuckyTxList(acc.Address, layer)
stdio.Println("TX list for " + acc.Address.Hex() + ":")
for i, x := range txs {
tx := c.LuckyTransactionInfo(x)
stdio.Printf("%3d:"+strings.Repeat("\t"+keyValueFormat, 7),
i,
"Id:", tx.Id.String(),
"From"+mark(tx.From)+":", tx.From.String(),
"To"+mark(tx.To)+":", tx.To.String(),
"Amount:", tx.Amount,
"Fee:", tx.Fee,
"Layer:", tx.LayerId,
"Status:", tx.Status)
}
},
}