Skip to content

Commit

Permalink
Support getSubscribers & getsubscription for nknc pubsub
Browse files Browse the repository at this point in the history
Signed-off-by: gdmmx <[email protected]>
  • Loading branch information
gdmmx authored and yilunzhang committed Dec 16, 2019
1 parent 7171b0f commit c4cee36
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cli/pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ func subscribeAction(c *cli.Context) error {
txn, _ := MakeUnsubscribeTransaction(myWallet, id, topic, nonce, txnFee)
buff, _ := txn.Marshal()
resp, err = client.Call(Address(), "sendrawtransaction", 0, map[string]interface{}{"tx": hex.EncodeToString(buff)})
case c.Bool("get"):
topic := c.String("topic")
if topic == "" {
fmt.Println("topic is required with [--topic]")
return nil
}

params := map[string]interface{}{"topic": topic}
subscriber := c.String("subscriber")
if subscriber == "" { // get list of topic
params["offset"] = c.Uint64("offset")
params["limit"] = c.Uint64("limit")
resp, err = client.Call(Address(), "getsubscribers", 0, params)
} else { // get details of specified subscriber
params["subscriber"] = subscriber
resp, err = client.Call(Address(), "getsubscription", 0, params)
}
default:
cli.ShowSubcommandHelp(c)
return nil
Expand Down Expand Up @@ -109,6 +126,10 @@ func NewCommand() *cli.Command {
Name: "unsub, u",
Usage: "unsubscribe from topic",
},
cli.BoolFlag{
Name: "get, g",
Usage: "get subscribes list of specified topic or get details info of a specified subscriber",
},
cli.StringFlag{
Name: "identifier, id",
Usage: "identifier",
Expand All @@ -121,6 +142,18 @@ func NewCommand() *cli.Command {
Name: "duration",
Usage: "duration",
},
cli.Uint64Flag{
Name: "offset",
Usage: "get subscribes skip previous offset items",
},
cli.Uint64Flag{
Name: "limit",
Usage: "limit subscribes amount which start from offset",
},
cli.StringFlag{
Name: "subscriber",
Usage: "specified subscriber which you want details",
},
cli.StringFlag{
Name: "meta",
Usage: "meta",
Expand Down

0 comments on commit c4cee36

Please sign in to comment.