BTP Message Center is a smart contract which builds BTP Message and sends it to BTP Message Relay and handles Relay Message from the other.
- Register BSHs for the services. BTP Token Service (BTS) is a BSH connected to BMC. (BSH should be deployed before the registration)
- Add links, BMCs of directly connected blockchains
- Add routes to other BMCs of in-directly connected blockchains
The BMC contract has to implement the following methods.
The BMC contract has to implement the following events.
-
- sendMessage
-
Name Type Description _to String Network Address of the destination blockchain _svc String Name of the service. _sn Integer Serial number of the message. _msg Bytes Service message to be delivered. -
A service handler sends a message through BMC.sendMessage. It accepts the requests from the registered BTP Service Handler(BSH). If service name of those requests is different from registration, then they will be rejected.
Then it builds a BTP Message from the request.
- Decide destination BMC from given Network Address
- Fill in other information from parameters.
- Serialize them for sending.
Then it tries to send the BTP Message.
- Decide next BMC from the destination referring routing information.
- Get sequence number corresponding to the next.
- Emit the event, Message including the information.
The event will be monitored by the Relay, it will build Relay Message for next BMC of destination chain.
-
- handleRelayMessage
-
Name Type Description _prev String BTP Address of the previous BMC _msg Bytes serialized Relay Message including BTP Messages -
This method receives the Relay Message from the relay, then it tries to decode it. It may contain multiple BTP Messages. It dispatches received BTP Messages one-by-one in the sequence.
If it is the destination, then it tries to find the BSH for the service, and then calls BSH.handleBTPMessage. It calls BSH.handleBTPError if it's an error.
If it's not the destination, then it tries to send the message to the next route.
If it fails, then it replies an error.
-
- Message
-
Name Type Description _next String BTP Address of the next BMC _seq Integer Sequence number of the msg to the next BMC _msg Bytes Serialized BTP Message -
The sendMessage method in BMC Contract generates a
Message
eventlog for the relay to pick up and perform transaction based on this event on the destination chain.