-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathinfo.go
70 lines (59 loc) · 1.86 KB
/
info.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
package query
import (
"encoding/json"
"fmt"
"github.com/FourthState/plasma-mvp-sidechain/store"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"
"strings"
)
func init() {
queryCmd.AddCommand(infoCmd)
}
var infoCmd = &cobra.Command{
Use: "info <address>",
Args: cobra.ExactArgs(1),
Short: "Information on owned utxos valid and invalid",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.NewCLIContext()
addrStr := strings.TrimSpace(args[0])
if !common.IsHexAddress(addrStr) {
return fmt.Errorf("Invalid address provided. Please use hex format")
}
addr := common.HexToAddress(addrStr)
fmt.Printf("Querying information for 0x%x\n\n", addr)
utxos, err := Info(ctx, addr)
if err != nil {
return err
}
for i, utxo := range utxos {
fmt.Printf("UTXO %d\n", i)
fmt.Printf("Position: %s, Amount: %s, Spent: %t\nSpender Hash: %s\n", utxo.Tx.Position, utxo.Output.Output.Amount.String(), utxo.Output.Spent, utxo.Output.Spender)
fmt.Printf("Transaction Hash: 0x%x\nConfirmationHash: 0x%x\n", utxo.Tx.Transaction.TxHash(), utxo.Tx.ConfirmationHash)
// print inputs if applicable
positions := utxo.Tx.Transaction.InputPositions()
for i, p := range positions {
fmt.Printf("Input %d Position: %s\n", i, p)
}
fmt.Printf("End UTXO %d info\n\n", i)
}
if len(utxos) == 0 {
fmt.Println("no information available for this address")
}
return nil
},
}
func Info(ctx context.CLIContext, addr common.Address) ([]store.QueryOutput, error) {
// query for all utxos owned by this address
queryRoute := fmt.Sprintf("custom/utxo/info/%s", addr.Hex())
data, err := ctx.Query(queryRoute, nil)
if err != nil {
return nil, err
}
var utxos []store.QueryOutput
if err := json.Unmarshal(data, &utxos); err != nil {
return nil, err
}
return utxos, nil
}