forked from FactomProject/walletapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listj.go
78 lines (69 loc) · 2.04 KB
/
listj.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2015 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package main
import (
"encoding/hex"
"fmt"
"github.com/FactomProject/fctwallet/Wallet/Utility"
)
/************************************************************
* List
************************************************************/
type Listj struct {
}
var _ ICommand = (*List)(nil)
// List transactions <address list>
func (Listj) Execute(state IState, args []string) (err error) {
if len(args) <= 1 {
return fmt.Errorf("Nothing to list")
}
switch args[1] {
case "all":
fmt.Println("Listing all transactions: ")
var list []byte
if list, err = Utility.DumpTransactionsJSON(nil, 0, 0); err != nil {
return err
}
fmt.Print(string(list))
break
default:
var addresses [][]byte
var adr string
for i := 1; i < len(args); i++ {
adr, err = LookupAddress(state, "FA", args[i])
if err != nil {
adr, err = LookupAddress(state, "EC", args[i])
if err != nil {
return fmt.Errorf("Could not understand address %s", args[i])
}
}
badr, err := hex.DecodeString(adr)
if err != nil {
return fmt.Errorf("Could not understand address %s", args[i])
}
addresses = append(addresses, badr)
}
var list []byte
if list, err = Utility.DumpTransactionsJSON(addresses, 0, 0); err != nil {
return err
}
fmt.Print(string(list))
}
return nil
}
func (Listj) Name() string {
return "Listj"
}
func (Listj) ShortHelp() string {
return "Listj [all|address] -- [all] prints all transactions in JSON, while specifying\n" +
" limits transactions to those that involve the given\n" +
" address. All address types supported."
}
func (Listj) LongHelp() string {
return `
Listj [all | address] [all] prints all the factom transactions in JSON to date,
while address limits output to transactions that reference
the address. All address types are supported.
`
}