8 "github.com/bytom/blockchain/query"
9 "github.com/bytom/blockchain/txfeed"
10 "github.com/bytom/errors"
11 "github.com/bytom/log"
12 "github.com/bytom/net/http/httpjson"
15 // POST /create-txfeed
16 func (a *BlockchainReactor) createTxFeed(ctx context.Context, in struct {
20 // ClientToken is the application's unique token for the txfeed. Every txfeed
21 // should have a unique client token. The client token is used to ensure
22 // idempotency of create txfeed requests. Duplicate create txfeed requests
23 // with the same client_token will only create one txfeed.
24 ClientToken string `json:"client_token"`
25 }) (*txfeed.TxFeed, error) {
26 log.Printf(ctx,"-------createTxFeed-------")
27 // after := fmt.Sprintf("%d:%d-%d", a.chain.Height(), math.MaxInt32, uint64(math.MaxInt64))
28 // return a.txFeeds.Create(ctx, in.Alias, in.Filter, after, in.ClientToken)
32 // POST /get-transaction-feed
33 func (a *BlockchainReactor) getTxFeed(ctx context.Context, in struct {
34 ID string `json:"id,omitempty"`
35 Alias string `json:"alias,omitempty"`
36 }) (*txfeed.TxFeed, error) {
37 log.Printf(ctx,"-------getTxFeed-------")
38 // return a.txFeeds.Find(ctx, in.ID, in.Alias)
42 // POST /delete-transaction-feed
43 func (a *BlockchainReactor) deleteTxFeed(ctx context.Context, in struct {
44 ID string `json:"id,omitempty"`
45 Alias string `json:"alias,omitempty"`
47 log.Printf(ctx,"-------deleteTxFeed-------")
48 // return a.txFeeds.Delete(ctx, in.ID, in.Alias)
52 // POST /update-transaction-feed
53 func (a *BlockchainReactor) updateTxFeed(ctx context.Context, in struct {
54 ID string `json:"id,omitempty"`
55 Alias string `json:"alias,omitempty"`
56 Prev string `json:"previous_after"`
57 After string `json:"after"`
58 }) (*txfeed.TxFeed, error) {
59 log.Printf(ctx,"-------updateTxFeed-------")
60 // TODO(tessr): Consider moving this function into the txfeed package.
61 // (It's currently outside the txfeed package to avoid a dependecy cycle
62 // between txfeed and query.)
63 bad, err := txAfterIsBefore(in.After, in.Prev)
69 return nil, errors.WithDetail(httpjson.ErrBadRequest, "new After cannot be before Prev")
71 // return a.txFeeds.Update(ctx, in.ID, in.Alias, in.After, in.Prev)
75 // txAfterIsBefore returns true if a is before b. It returns an error if either
76 // a or b are not valid query.TxAfters.
77 func txAfterIsBefore(a, b string) (bool, error) {
78 aAfter, err := query.DecodeTxAfter(a)
83 bAfter, err := query.DecodeTxAfter(b)
88 return aAfter.FromBlockHeight < bAfter.FromBlockHeight ||
89 (aAfter.FromBlockHeight == bAfter.FromBlockHeight &&
90 aAfter.FromPosition < bAfter.FromPosition), nil