Programming Hotmoka
A tutorial on Hotmoka and smart contracts in Takamaka
8.6 Remote nodes
A service can be published and its methods can be called through JSON queries. This is relatively easy for methods such as getManifest() and getConfig() of the interface Node. However, it becomes harder if we want to call methods of Node that need parameters, such as getState() or the many add/post/run methods for scheduling transactions on the node. Parameters should be passed as JSON payload of the websockets connection, in a format that is hard to remember, easy to get wrong and possibly changing in the future. Moreover, the JSON responses must be parsed back. In principle, this can be done by hand or through software that builds the requests for the server and interprets its responses. Nevertheless, it is not the suggested way to proceed.
A typical solution to this problem is to provide a software SDK, that is, a library that takes care of serializing the requests into JSON and deserializing the responses from JSON. Roughly speaking, this is the approach taken in Hotmoka. More precisely, we can forget about the details of the JSON serialization and deserialization of requests and responses and only program against the Node interface, by using an adaptor of a published Hotmoka service into a Node. This adaptor is called a remote Hotmoka node.
We have used remote nodes from the very beginning of this tutorial. Namely, if you go back to Sec. 3.2, you will see that we have built a Hotmoka node from a remote service:
try (var node = RemoteNodes.of(new URI(args[0]), 150000)) {
...
}
The RemoteNodes.of(...) method adapts a remote service into a Hotmoka node, so that we can call all its methods (Fig. 8.1). The 150000 parameter is the timeout, in milliseconds, for connecting to the service and for the methods called on the remote node.
