7 "github.com/bytom/blockchain/query"
8 "github.com/bytom/blockchain/query/filter"
9 "github.com/bytom/errors"
10 "github.com/bytom/net/http/httpjson"
11 //"github.com/bytom/log"
15 defGenericPageSize = 100
20 // POST /list-accounts
21 func (bcr *BlockchainReactor) listAccounts(ctx context.Context, in requestQuery) interface{} {
23 response,_ := bcr.accounts.QueryAll(ctx)
32 func (bcr *BlockchainReactor) listAssets(ctx context.Context, in requestQuery) interface{} {
34 response,_ := bcr.assets.QueryAll(ctx)
39 // POST /list-balances
40 func (bcr *BlockchainReactor) listBalances(ctx context.Context, in requestQuery) (result page, err error) {
41 var sumBy []filter.Field
43 // Since an empty SumBy yields a meaningless result, we'll provide a
44 // sensible default here.
45 if len(in.SumBy) == 0 {
46 in.SumBy = []string{"asset_alias", "asset_id"}
49 for _, field := range in.SumBy {
50 f, err := filter.ParseField(field)
54 sumBy = append(sumBy, f)
57 timestampMS := in.TimestampMS
59 timestampMS = math.MaxInt64
60 } else if timestampMS > math.MaxInt64 {
61 return result, errors.WithDetail(httpjson.ErrBadRequest, "timestamp is too large")
64 // TODO(jackson): paginate this endpoint.
65 /* balances, err := bcr.indexer.Balances(ctx, in.Filter, in.FilterParams, sumBy, timestampMS)
70 // result.Items = httpjson.Array(balances)
71 result.LastPage = true
76 // listTransactions is an http handler for listing transactions matching
77 // an index or an ad-hoc filter.
79 // POST /list-transactions
80 func (bcr *BlockchainReactor) listTransactions(ctx context.Context, in requestQuery) (result page, err error) {
81 var c context.CancelFunc
82 timeout := in.Timeout.Duration
84 ctx, c = context.WithTimeout(ctx, timeout)
90 limit = defGenericPageSize
93 endTimeMS := in.EndTimeMS
95 endTimeMS = math.MaxInt64
96 } else if endTimeMS > math.MaxInt64 {
97 return result, errors.WithDetail(httpjson.ErrBadRequest, "end timestamp is too large")
100 // Either parse the provided `after` or look one up for the time range.
101 // var after query.TxAfter
103 _, err = query.DecodeTxAfter(in.After)
105 return result, errors.Wrap(err, "decoding `after`")
108 /* after, err = bcr.indexer.LookupTxAfter(ctx, in.StartTimeMS, endTimeMS)
115 /* txns, nextAfter, err := bcr.indexer.Transactions(ctx, in.Filter, in.FilterParams, after, limit, in.AscLongPoll)
117 return result, errors.Wrap(err, "running tx query")
121 // out.After = nextAfter.String()
123 // Items: httpjson.Array(txns),
124 // LastPage: len(txns) < limit,
129 // listTxFeeds is an http handler for listing txfeeds. It does not take a filter.
131 // POST /list-transaction-feeds
132 func (bcr *BlockchainReactor) listTxFeeds(ctx context.Context, in requestQuery) (page, error) {
135 limit = defGenericPageSize
140 /* txfeeds, after, err := bcr.txFeeds.Query(ctx, after, limit)
142 return page{}, errors.Wrap(err, "running txfeed query")
148 // Items: httpjson.Array(txfeeds),
149 // LastPage: len(txfeeds) < limit,
154 // POST /list-unspent-outputs
155 func (bcr *BlockchainReactor) listUnspentOutputs(ctx context.Context, in requestQuery) (result page, err error) {
158 limit = defGenericPageSize
161 // var after *query.OutputsAfter
163 _, err = query.DecodeOutputsAfter(in.After)
165 return result, errors.Wrap(err, "decoding `after`")
169 timestampMS := in.TimestampMS
170 if timestampMS == 0 {
171 timestampMS = math.MaxInt64
172 } else if timestampMS > math.MaxInt64 {
173 return result, errors.WithDetail(httpjson.ErrBadRequest, "timestamp is too large")
175 /* outputs, nextAfter, err := bcr.indexer.Outputs(ctx, in.Filter, in.FilterParams, timestampMS, after, limit)
177 return result, errors.Wrap(err, "querying outputs")
181 // outQuery.After = nextAfter.String()
183 // Items: httpjson.Array(outputs),
184 // LastPage: len(outputs) < limit,