All Products
Search
Document Center

Blockchain as a Service:Event Interface

Last Updated:Jul 31, 2024

listenAccount

You can call this operation to subscribe to an account.

  • Function
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
// event handler 
EventHandler handler = new EventHandler() {
        @Override
        public void handle(Message message) {
            EventAccountMessage eventAccountMessage = (EventAccountMessage) message;
            //code
        }
    };

// account: Tester001
Identity identity = new Identity("c60a9d48105950a0cca07a4c6320b98c303ad42d694a634529e8e1a0a16fcdb5");

// listen account
boolean result = sdk.getEventService().listenAccount(identity, handler,EventModelType.PUSH)

listenContract

You can call this operation to subscribe to a contract.

  • Function
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
/event handler
EventHandler handler = new EventHandler() {
    @Override
    public void handle(Message message) {
        EventContractMessage eventContractMessage = (EventContractMessage) message;
        // code
    }
};

Identity identity = new Identity("a7937b64b8caa58f03721bb6bacf5c78cb235febe0e70b1b84cd99541461a08e");

//listen contract
boolean result = sdk.getEventService().listenContract(identity, handler,EventModelType.PUSH)

listenTopics

You can call this operation to subscribe to topic events.

  • Function
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
// evnet handler
EventHandler handler = new EventHandler() {
    @Override
    public void handle(Message message) {
        EventTopicsMessage eventTopicsMessage = (EventTopicsMessage) message;
        //code
    }
};

// add contract
List<String> topics = new ArrayList<>(); 
topics.add("call_contract");

// listen topics
boolean result = sdk.getEventService().listenTopics(topics, handler, EventModelType.PUSH)

listenBlock

You can call this operation to subscribe to block events.

  • Function
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
// event handler
EventHandler handler = new EventHandler() {
    @Override
    public void handle(Message message) {
        // code
    }
};
// listen block
boolean result = sdk.getEventService().listenBlock(handler, EventModelType.PUSH)

unListenAccount

You can call this operation to unsubscribe account events.

  • Function
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
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
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
public boolean unListenBlock()