OSDN Git Service

fix print json invalid type assertion
authorlbqds <lbqds@outlook.com>
Tue, 17 Apr 2018 02:44:35 +0000 (10:44 +0800)
committerlbqds <lbqds@outlook.com>
Tue, 17 Apr 2018 02:48:30 +0000 (10:48 +0800)
api/accounts.go
api/query.go
wallet/indexer.go

index cca6be5..67bcaa9 100644 (file)
@@ -103,7 +103,7 @@ func (a *API) listAddresses(ctx context.Context, ins struct {
                return NewErrorResponse(err)
        }
 
-       var addresses []*addressResp
+       addresses := []*addressResp{}
        for _, cp := range cps {
                if cp.Address == "" || (len(accountID) != 0 && strings.Compare(accountID, cp.AccountID) != 0) {
                        continue
index 3d2ded6..27379bb 100644 (file)
@@ -21,7 +21,7 @@ func (a *API) listAccounts(ctx context.Context, filter struct {
                return NewErrorResponse(err)
        }
 
-       var annotatedAccounts []query.AnnotatedAccount
+       annotatedAccounts := []query.AnnotatedAccount{}
        for _, acc := range accounts {
                annotatedAccounts = append(annotatedAccounts, *account.Annotated(acc))
        }
@@ -42,7 +42,7 @@ func (a *API) listAssets(ctx context.Context, filter struct {
        return NewSuccessResponse(assets)
 }
 
-// POST /listBalances
+// POST /list-balances
 func (a *API) listBalances(ctx context.Context) Response {
        return NewSuccessResponse(a.wallet.GetAccountBalances(""))
 }
@@ -66,7 +66,7 @@ func (a *API) listTransactions(ctx context.Context, filter struct {
        AccountID string `json:"account_id"`
        Detail    bool   `json:"detail"`
 }) Response {
-       var transactions []*query.AnnotatedTx
+       transactions := []*query.AnnotatedTx{}
        var err error
 
        if filter.AccountID != "" {
@@ -93,7 +93,7 @@ func (a *API) listUnspentOutputs(ctx context.Context, filter struct {
 }) Response {
        accountUTXOs := a.wallet.GetAccountUTXOs(filter.ID)
 
-       var UTXOs []query.AnnotatedUTXO
+       UTXOs := []query.AnnotatedUTXO{}
        for _, utxo := range accountUTXOs {
                UTXOs = append([]query.AnnotatedUTXO{{
                        AccountID:           utxo.AccountID,
index 4a55b13..2d5fd79 100644 (file)
@@ -425,7 +425,7 @@ func (w *Wallet) GetTransactionByTxID(txID string) (*query.AnnotatedTx, error) {
 
 // GetTransactionsByTxID get account txs by account tx ID
 func (w *Wallet) GetTransactionsByTxID(txID string) ([]*query.AnnotatedTx, error) {
-       var annotatedTxs []*query.AnnotatedTx
+       annotatedTxs := []*query.AnnotatedTx{}
        formatKey := ""
 
        if txID != "" {
@@ -503,7 +503,7 @@ func findTransactionsByAccount(annotatedTx *query.AnnotatedTx, accountID string)
 
 // GetTransactionsByAccountID get account txs by account ID
 func (w *Wallet) GetTransactionsByAccountID(accountID string) ([]*query.AnnotatedTx, error) {
-       var annotatedTxs []*query.AnnotatedTx
+       annotatedTxs := []*query.AnnotatedTx{}
 
        txIter := w.DB.IteratorPrefix([]byte(TxPrefix))
        defer txIter.Release()