7 log "github.com/sirupsen/logrus"
9 "github.com/bytom/account"
10 "github.com/bytom/blockchain/query"
13 // POST /list-accounts
14 func (a *API) listAccounts(ctx context.Context, filter struct {
17 accounts, err := a.wallet.AccountMgr.ListAccounts(filter.ID)
19 log.Errorf("listAccounts: %v", err)
20 return NewErrorResponse(err)
23 annotatedAccounts := make([]query.AnnotatedAccount, 0, len(accounts))
24 for _, acc := range accounts {
25 annotated, err := account.Annotated(acc)
27 return NewErrorResponse(err)
30 annotatedAccounts = append(annotatedAccounts, *annotated)
33 return NewSuccessResponse(annotatedAccounts)
37 func (a *API) listAssets(ctx context.Context, filter struct {
40 assets, err := a.wallet.AssetReg.ListAssets(filter.ID)
42 log.Errorf("listAssets: %v", err)
43 return NewErrorResponse(err)
46 return NewSuccessResponse(assets)
50 func (a *API) listBalances(ctx context.Context) Response {
51 if balances, err := a.wallet.GetAccountBalances(""); err != nil {
52 log.Errorf("GetAccountUTXOs: %v", err)
53 return NewErrorResponse(err)
55 return NewSuccessResponse(balances)
59 // POST /get-transaction
60 func (a *API) getTransaction(ctx context.Context, txInfo struct {
61 TxID string `json:"tx_id"`
63 transaction, err := a.wallet.GetTransactionByTxID(txInfo.TxID)
65 log.Errorf("getTransaction error: %v", err)
66 return NewErrorResponse(err)
69 return NewSuccessResponse(transaction)
72 // POST /list-transactions
73 func (a *API) listTransactions(ctx context.Context, filter struct {
75 AccountID string `json:"account_id"`
76 Detail bool `json:"detail"`
78 var transactions []*query.AnnotatedTx
81 if filter.AccountID != "" {
82 transactions, err = a.wallet.GetTransactionsByAccountID(filter.AccountID)
84 transactions, err = a.wallet.GetTransactionsByTxID(filter.ID)
88 log.Errorf("listTransactions: %v", err)
89 return NewErrorResponse(err)
92 if filter.Detail == false {
93 txSummary := a.wallet.GetTransactionsSummary(transactions)
94 return NewSuccessResponse(txSummary)
96 return NewSuccessResponse(transactions)
99 // POST /list-unspent-outputs
100 func (a *API) listUnspentOutputs(ctx context.Context, filter struct {
101 ID string `json:"id"`
103 accountUTXOs, err := a.wallet.GetAccountUTXOs(filter.ID)
105 log.Errorf("list Unspent Outputs: %v", err)
106 return NewErrorResponse(err)
109 var UTXOs []query.AnnotatedUTXO
110 for _, utxo := range accountUTXOs {
111 UTXOs = append(UTXOs, query.AnnotatedUTXO{
112 AccountID: utxo.AccountID,
113 OutputID: utxo.OutputID.String(),
114 SourceID: utxo.SourceID.String(),
115 AssetID: utxo.AssetID.String(),
117 SourcePos: utxo.SourcePos,
118 Program: fmt.Sprintf("%x", utxo.ControlProgram),
119 ControlProgramIndex: utxo.ControlProgramIndex,
120 Address: utxo.Address,
121 ValidHeight: utxo.ValidHeight,
122 Alias: a.wallet.AccountMgr.GetAliasByID(utxo.AccountID),
123 AssetAlias: a.wallet.AssetReg.GetAliasByID(utxo.AssetID.String()),
127 return NewSuccessResponse(UTXOs)