OSDN Git Service

merge with dev
[bytom/bytom.git] / api / query.go
index 5d3e9ee..4a4737e 100644 (file)
@@ -14,10 +14,8 @@ import (
 )
 
 // POST /list-accounts
-func (a *API) listAccounts(ctx context.Context, filter struct {
-       ID string `json:"id"`
-}) Response {
-       accounts, err := a.wallet.AccountMgr.ListAccounts(filter.ID)
+func (a *API) listAccounts(ctx context.Context) Response {
+       accounts, err := a.wallet.AccountMgr.ListAccounts()
        if err != nil {
                log.Errorf("listAccounts: %v", err)
                return NewErrorResponse(err)
@@ -31,11 +29,22 @@ func (a *API) listAccounts(ctx context.Context, filter struct {
        return NewSuccessResponse(annotatedAccounts)
 }
 
-// POST /list-assets
-func (a *API) listAssets(ctx context.Context, filter struct {
+// POST /get-asset
+func (a *API) getAsset(ctx context.Context, filter struct {
        ID string `json:"id"`
 }) Response {
-       assets, err := a.wallet.AssetReg.ListAssets(filter.ID)
+       asset, err := a.wallet.AssetReg.GetAsset(filter.ID)
+       if err != nil {
+               log.Errorf("getAsset: %v", err)
+               return NewErrorResponse(err)
+       }
+
+       return NewSuccessResponse(asset)
+}
+
+// POST /list-assets
+func (a *API) listAssets(ctx context.Context) Response {
+       assets, err := a.wallet.AssetReg.ListAssets()
        if err != nil {
                log.Errorf("listAssets: %v", err)
                return NewErrorResponse(err)
@@ -123,6 +132,11 @@ func (a *API) getUnconfirmedTx(ctx context.Context, filter struct {
        return NewSuccessResponse(tx)
 }
 
+type unconfirmedTxsResp struct {
+       Total uint64    `json:"total"`
+       TxIDs []bc.Hash `json:"tx_ids"`
+}
+
 // POST /list-unconfirmed-transactions
 func (a *API) listUnconfirmedTxs(ctx context.Context) Response {
        txIDs := []bc.Hash{}
@@ -133,7 +147,10 @@ func (a *API) listUnconfirmedTxs(ctx context.Context) Response {
                txIDs = append(txIDs, bc.Hash(txDesc.Tx.ID))
        }
 
-       return NewSuccessResponse(txIDs)
+       return NewSuccessResponse(&unconfirmedTxsResp{
+               Total: uint64(len(txIDs)),
+               TxIDs: txIDs,
+       })
 }
 
 // POST /list-unspent-outputs
@@ -166,6 +183,6 @@ func (a *API) listUnspentOutputs(ctx context.Context, filter struct {
 
 // return gasRate
 func (a *API) gasRate() Response {
-       gasrate := map[string]int64{"gasRate": consensus.VMGasRate}
+       gasrate := map[string]int64{"gas_rate": consensus.VMGasRate}
        return NewSuccessResponse(gasrate)
 }