Services
A service is a program running on a peer. Every service has an interface that consists of a list of functions. To call a service, the service must be identified: so, every service has an ID that must be resolved in the peer scope.
In the service definition, you enumerate all the functions, their names, argument, and return types, and optionally provide the default Service ID.
Services that are a part of the protocol, i.e. are available from the peer node, come along with IDs. Example of predefined service:
aqua
service Peer("peer"):foo() -- no arguments, no returnbar(i: bool) -> boolfunc usePeer() -> bool:Peer.foo() -- results in a call of service "peer", function "foo", on current peer IDz <- Peer.bar(true)<- z
aqua
service Peer("peer"):foo() -- no arguments, no returnbar(i: bool) -> boolfunc usePeer() -> bool:Peer.foo() -- results in a call of service "peer", function "foo", on current peer IDz <- Peer.bar(true)<- z
Example of a custom service:
aqua
service MyService:foo()bar(i: bool, z: i32) -> stringfunc useMyService(k: i32) -> string:-- Need to tell the compiler what does "my service" mean in this scopeMyService "my service id"MyService.foo()on "another peer id":-- Need to redefine MyService in scope of this peer as wellMyService "another service id"z <- MyService.bar(false, k)<- z
aqua
service MyService:foo()bar(i: bool, z: i32) -> stringfunc useMyService(k: i32) -> string:-- Need to tell the compiler what does "my service" mean in this scopeMyService "my service id"MyService.foo()on "another peer id":-- Need to redefine MyService in scope of this peer as wellMyService "another service id"z <- MyService.bar(false, k)<- z
Service definitions have types. Type of a service is a product type of arrows. See Types.