7 log "github.com/sirupsen/logrus"
9 "github.com/bytom/account"
10 "github.com/bytom/blockchain/query"
11 "github.com/bytom/consensus"
14 // POST /list-accounts
15 func (a *API) listAccounts(ctx context.Context, filter struct {
18 accounts, err := a.wallet.AccountMgr.ListAccounts(filter.ID)
20 log.Errorf("listAccounts: %v", err)
21 return NewErrorResponse(err)
24 annotatedAccounts := []query.AnnotatedAccount{}
25 for _, acc := range accounts {
26 annotatedAccounts = append(annotatedAccounts, *account.Annotated(acc))
29 return NewSuccessResponse(annotatedAccounts)
33 func (a *API) listAssets(ctx context.Context, filter struct {
36 assets, err := a.wallet.AssetReg.ListAssets(filter.ID)
38 log.Errorf("listAssets: %v", err)
39 return NewErrorResponse(err)
42 return NewSuccessResponse(assets)
45 // POST /list-balances
46 func (a *API) listBalances(ctx context.Context) Response {
47 return NewSuccessResponse(a.wallet.GetAccountBalances(""))
50 // POST /get-transaction
51 func (a *API) getTransaction(ctx context.Context, txInfo struct {
52 TxID string `json:"tx_id"`
54 transaction, err := a.wallet.GetTransactionByTxID(txInfo.TxID)
56 log.Errorf("getTransaction error: %v", err)
57 return NewErrorResponse(err)
60 return NewSuccessResponse(transaction)
63 // POST /list-transactions
64 func (a *API) listTransactions(ctx context.Context, filter struct {
66 AccountID string `json:"account_id"`
67 Detail bool `json:"detail"`
69 transactions := []*query.AnnotatedTx{}
72 if filter.AccountID != "" {
73 transactions, err = a.wallet.GetTransactionsByAccountID(filter.AccountID)
75 transactions, err = a.wallet.GetTransactionsByTxID(filter.ID)
79 log.Errorf("listTransactions: %v", err)
80 return NewErrorResponse(err)
83 if filter.Detail == false {
84 txSummary := a.wallet.GetTransactionsSummary(transactions)
85 return NewSuccessResponse(txSummary)
87 return NewSuccessResponse(transactions)
90 // POST /list-unspent-outputs
91 func (a *API) listUnspentOutputs(ctx context.Context, filter struct {
94 accountUTXOs := a.wallet.GetAccountUTXOs(filter.ID)
96 UTXOs := []query.AnnotatedUTXO{}
97 for _, utxo := range accountUTXOs {
98 UTXOs = append([]query.AnnotatedUTXO{{
99 AccountID: utxo.AccountID,
100 OutputID: utxo.OutputID.String(),
101 SourceID: utxo.SourceID.String(),
102 AssetID: utxo.AssetID.String(),
104 SourcePos: utxo.SourcePos,
105 Program: fmt.Sprintf("%x", utxo.ControlProgram),
106 ControlProgramIndex: utxo.ControlProgramIndex,
107 Address: utxo.Address,
108 ValidHeight: utxo.ValidHeight,
109 Alias: a.wallet.AccountMgr.GetAliasByID(utxo.AccountID),
110 AssetAlias: a.wallet.AssetReg.GetAliasByID(utxo.AssetID.String()),
115 return NewSuccessResponse(UTXOs)
119 func (a *API) gasRate() Response {
120 gasrate := map[string]int64{"gasRate": consensus.VMGasRate}
121 return NewSuccessResponse(gasrate)