All Products
Search
Document Center

Event Interface

Last Updated: May 24, 2019

listenAccount

You can call this operation to subscribe to an account.

  • Function
  1. public boolean listenAccount(Identity identity, EventHandler handler, EventModelType type)
  • Request parameters
Name Required Type Description
identity true Identity The business ID of the account.
handler true EventHandler A callback is called when a response is received or when a timeout or error occurs.
type true EventModelType The type of the event model. 1: PULL. 2: PUSH
  • Response parameters
Name Type Description
result bool The returned result. true: normal. false: error.
  • Examples
  1. // event handler
  2. EventHandler handler = new EventHandler() {
  3. @Override
  4. public void handle(Message message) {
  5. EventAccountMessage eventAccountMessage = (EventAccountMessage) message;
  6. //code
  7. }
  8. };
  9. // account: Tester001
  10. Identity identity = new Identity("c60a9d48105950a0cca07a4c6320b98c303ad42d694a634529e8e1a0a16fcdb5");
  11. // listen account
  12. boolean result = sdk.getEventService().listenAccount(identity, handler,EventModelType.PUSH)

listenContract

You can call this operation to subscribe to a contract.

  • Function
  1. public boolean listenContract(Identity identity, EventHandler handler, EventModelType type)
  • Request parameters
Name Required Type Description
identity true Identity The business ID of the account.
handler true EventHandler A callback is called when a response is received or when a timeout or error occurs.
type true EventModelType The type of the event model. 1: PULL. 2: PUSH
  • Response parameters
Name Type Description
result bool The returned result. true: normal. false: error.
  • Examples
  1. /event handler
  2. EventHandler handler = new EventHandler() {
  3. @Override
  4. public void handle(Message message) {
  5. EventContractMessage eventContractMessage = (EventContractMessage) message;
  6. // code
  7. }
  8. };
  9. Identity identity = new Identity("a7937b64b8caa58f03721bb6bacf5c78cb235febe0e70b1b84cd99541461a08e");
  10. //listen contract
  11. boolean result = sdk.getEventService().listenContract(identity, handler,EventModelType.PUSH)

listenTopics

You can call this operation to subscribe to topic events.

  • Function
  1. public boolean listenTopics(List<String> topics, EventHandler handler, EventModelType type)
  • Request parameters
Name Required Type Description
topics true List The topic list to be subscribed.
handler true EventHandler A callback is called when a response is received or when a timeout or error occurs.
type true EventModelType The type of the event model. 1: PULL. 2: PUSH
  • Response parameters
Name Type Description
result bool The returned result. true: normal. false: error.
  • Examples
  1. // evnet handler
  2. EventHandler handler = new EventHandler() {
  3. @Override
  4. public void handle(Message message) {
  5. EventTopicsMessage eventTopicsMessage = (EventTopicsMessage) message;
  6. //code
  7. }
  8. };
  9. // add contract
  10. List<String> topics = new ArrayList<>();
  11. topics.add("call_contract");
  12. // listen topics
  13. boolean result = sdk.getEventService().listenTopics(topics, handler, EventModelType.PUSH)

listenBlock

You can call this operation to subscribe to block events.

  • Function
  1. public boolean listenBlock(EventHandler handler, EventModelType type)
  • Request parameters
Name Required Type Description
topics true List The topic list to be subscribed to.
handler true EventHandler A callback is called when a response is received or when a timeout or error occurs.
type true EventModelType The type of the event model. 1: PULL. 2: PUSH
  • Response parameters
Name Type Description
result bool The returned result. true: normal. false: error.
  • Examples
  1. // event handler
  2. EventHandler handler = new EventHandler() {
  3. @Override
  4. public void handle(Message message) {
  5. // code
  6. }
  7. };
  8. // listen block
  9. boolean result = sdk.getEventService().listenBlock(handler, EventModelType.PUSH)

unListenAccount

You can call this operation to unsubscribe account events.

  • Function
  1. sdk.getEventService().unListenAccount(identity)
  • Request parameters
Name Required Type Description
identity true Identity The identity of the account to be unsubscribed.

unListenContract

You can call this operation to unsubscribe contract events.

  • Function
  1. public boolean unListenContract(Identity identity)
  • Request parameters
Name Required Type Description
identity true Identity The identifier of a canceled contract subscription.

unListenTopics

You can call this operation to unsubscribe topic events.

  • Function
  1. public boolean unListenTopics(List<String> topics)
  • Request parameters
Name Required Type Description
topics true List The topic list to be unsubscribed.

unListenBlock

You can call this operation to unsubscribe block events.

  • Function
  1. public boolean unListenBlock()