/
list.go
79 lines (57 loc) · 1.97 KB
/
list.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
79
package cmd
import (
"errors"
AChain "github.com/ayachain/go-aya/chain"
ARsponse "github.com/ayachain/go-aya/response"
"github.com/ayachain/go-aya/vdb/transaction"
EComm "github.com/ethereum/go-ethereum/common"
cmds "github.com/ipfs/go-ipfs-cmds"
)
var listCMD = &cmds.Command{
Helptext:cmds.HelpText{
Tagline: "get transaction list or hash",
},
Arguments: []cmds.Argument {
cmds.StringArg("chainid", true, false, "aya chain id"),
cmds.StringArg("address", true, false, "owner address"),
},
Options: []cmds.Option{
cmds.BoolOption("detail", "d", "response tx content detail (default:false)"),
cmds.UintOption("offset", "o", "transaction offset (default:0)"),
cmds.UintOption("size", "s", "transaction size (default:20)"),
},
Run:func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
chain := AChain.GetChainByIdentifier(req.Arguments[0])
if chain == nil {
return ARsponse.EmitErrorResponse(re, errors.New("not exist chain connection") )
}
detail, _ := req.Options["detail"].(bool)
offset, _ := req.Options["offset"].(uint)
size, _ := req.Options["size"].(uint)
if size == 0 {
size = 20
}
if !detail {
txhashs := chain.CVFServices().Transactions().GetHistoryHash( EComm.HexToAddress(req.Arguments[1]), uint64(offset), uint64(size) )
return ARsponse.EmitSuccessResponse(re, txhashs)
} else {
txs, err := chain.CVFServices().Transactions().GetHistoryContent( EComm.HexToAddress(req.Arguments[1]), uint64(offset), uint64(size) )
if err != nil {
return ARsponse.EmitErrorResponse(re, errors.New("not exist transaction hash") )
} else {
var ctxs []*transaction.ConfirmTx
for _, tx := range txs {
txblock, err := chain.CVFServices().Blocks().GetBlocks(tx.BlockIndex)
if err != nil {
continue
}
ctxs = append(ctxs, &transaction.ConfirmTx{
Transaction:*tx,
Time:txblock[0].Timestamp,
})
}
return ARsponse.EmitSuccessResponse(re, txs)
}
}
},
}