OSDN Git Service

support list-accounts and list-assets
authoricodezjb <icodezjb@163.com>
Tue, 26 Sep 2017 08:28:20 +0000 (16:28 +0800)
committericodezjb <icodezjb@163.com>
Tue, 26 Sep 2017 08:28:20 +0000 (16:28 +0800)
blockchain/account/accounts.go
blockchain/asset/asset.go
blockchain/query.go
cmd/bytomcli/main.go

index 9da7ddd..cec6f3c 100644 (file)
@@ -326,16 +326,19 @@ func (m *Manager) nextIndex(ctx context.Context) (uint64, error) {
        return n, nil
 }
 
-/*
-func tagsToNullString(tags map[string]interface{}) (*stdsql.NullString, error) {
-       var tagsJSON []byte
-       if len(tags) != 0 {
-               var err error
-               tagsJSON, err = json.Marshal(tags)
-               if err != nil {
-                       return nil, errors.Wrap(err)
+
+func (m *Manager) QueryAll(ctx context.Context) (interface{}, error){
+       ret := make([]interface{},0)
+
+       iter := m.db.Iterator()
+       for iter.Next() {
+               value := string(iter.Value())
+               if value[:3] == "acc"{
+                       continue
                }
+               ret = append(ret,value)
+               //log.Printf(ctx,"%s\t", value)
        }
-       return &stdsql.NullString{String: string(tagsJSON), Valid: len(tagsJSON) > 0}, nil
-}
-*/
+
+       return ret,nil
+}
\ No newline at end of file
index 64912ab..d9c4fa4 100644 (file)
@@ -18,6 +18,7 @@ import (
        "github.com/bytom/protocol"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/vm/vmutil"
+       //"github.com/bytom/log"
 )
 
 const maxAssetCache = 1000
@@ -271,6 +272,19 @@ func (reg *Registry) FindByAlias(ctx context.Context, alias string) (*Asset, err
 
 }
 
+func (reg *Registry) QueryAll(ctx context.Context) (interface{}, error){
+       ret := make([]interface{},0)
+
+       iter := reg.db.Iterator()
+       for iter.Next() {
+               value := string(iter.Value())
+               ret = append(ret,value)
+               //log.Printf(ctx,"%s\t", value)
+       }
+
+       return ret,nil
+}
+
 // insertAsset adds the asset to the database. If the asset has a client token,
 // and there already exists an asset with that client token, insertAsset will
 // lookup and return the existing asset instead.
index 39060c3..623d893 100644 (file)
@@ -8,63 +8,32 @@ import (
        "github.com/bytom/blockchain/query/filter"
        "github.com/bytom/errors"
        "github.com/bytom/net/http/httpjson"
+       //"github.com/bytom/log"
 )
 
 const (
        defGenericPageSize = 100
 )
 
-// listAccounts is an http handler for listing accounts matching
-// an index or an ad-hoc filter.
+
 //
 // POST /list-accounts
-func (bcr *BlockchainReactor) listAccounts(ctx context.Context, in requestQuery) (page, error) {
-       limit := in.PageSize
-       if limit == 0 {
-               limit = defGenericPageSize
-       }
-       after := in.After
-/*
-       // Use the filter engine for querying account tags.
-       accounts, after, err := bcr.indexer.Accounts(ctx, in.Filter, in.FilterParams, after, limit)
-       if err != nil {
-               return page{}, errors.Wrap(err, "running acc query")
-       }
-*/
-       // Pull in the accounts by the IDs
-       out := in
-       out.After = after
-       return page{
-//             Items:    httpjson.Array(accounts),
-//             LastPage: len(accounts) < limit,
-               Next:     out,
-       }, nil
+func (bcr *BlockchainReactor) listAccounts(ctx context.Context, in requestQuery) interface{} {
+
+       response,_ := bcr.accounts.QueryAll(ctx)
+
+       return response
+
 }
 
-// listAssets is an http handler for listing assets matching
-// an index or an ad-hoc filter.
+
 //
 // POST /list-assets
-func (bcr *BlockchainReactor) listAssets(ctx context.Context, in requestQuery) (page, error) {
-       limit := in.PageSize
-       if limit == 0 {
-               limit = defGenericPageSize
-       }
-       after := in.After
+func (bcr *BlockchainReactor) listAssets(ctx context.Context, in requestQuery) interface{} {
 
-/*     // Use the query engine for querying asset tags.
-       assets, after, err := bcr.indexer.Assets(ctx, in.Filter, in.FilterParams, after, limit)
-       if err != nil {
-               return page{}, errors.Wrap(err, "running asset query")
-       }
-*/
-       out := in
-       out.After = after
-       return page{
-//             Items:    httpjson.Array(assets),
-//             LastPage: len(assets) < limit,
-               Next:     out,
-       }, nil
+       response,_ := bcr.assets.QueryAll(ctx)
+
+       return response
 }
 
 // POST /list-balances
index 30f3b48..f945780 100644 (file)
@@ -543,10 +543,14 @@ func listAccounts(client *rpc.Client, args []string) {
                Aliases      []string      `json:"aliases,omitempty"`
        }
        var in requestQuery
-       after := in.After
-       out := in
-       out.After = after
-       client.Call(context.Background(), "/list-accounts", &[]requestQuery{in}, nil)
+
+
+       responses := make([]interface{}, 1)
+
+       client.Call(context.Background(), "/list-accounts", in, &responses)
+       for i,item := range responses{
+               fmt.Println(i,"-----",item)
+       }
 }
 
 func listAssets(client *rpc.Client, args []string) {
@@ -568,10 +572,13 @@ func listAssets(client *rpc.Client, args []string) {
                Aliases      []string      `json:"aliases,omitempty"`
        }
        var in requestQuery
-       after := in.After
-       out := in
-       out.After = after
-       client.Call(context.Background(), "/list-assets", &[]requestQuery{in}, nil)
+       responses := make([]interface{}, 1)
+
+       client.Call(context.Background(), "/list-assets", in, &responses)
+       for i,item := range responses{
+               fmt.Println(i,"-----",item)
+       }
+
 }
 
 func listTxFeeds(client *rpc.Client, args []string) {