Services

service

Service definition.
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:
1
service Peer("peer"):
2
foo() -- no arguments, no return
3
bar(i: bool) -> bool
4
​
5
func usePeer() -> bool:
6
Peer.foo() -- results in a call of service "peer", function "foo", on current peer ID
7
z <- Peer.bar(true)
8
<- z
Copied!
Example of a custom service:
1
service MyService:
2
foo()
3
bar(i: bool, z: i32) -> string
4
​
5
func useMyService(k: i32) -> string:
6
-- Need to tell the compiler what does "my service" mean in this scope
7
MyService "my service id"
8
MyService.foo()
9
on "another peer id":
10
-- Need to redefine MyService in scope of this peer as well
11
MyService "another service id"
12
z <- MyService.bar(false, k)
13
<- z
Copied!
Service definitions have types. Type of a service is a product type of arrows. See Types.
Copy link