import "@fluencelabs/aqua-lib/builtin.aqua"

const HELLO_WORLD_NODE_PEER_ID ?= "12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi"
const HELLO_WORLD_SERVICE_ID ?= "1e740ce4-81f6-4dd4-9bed-8d86e9c2fa50"

data HelloWorld:
  msg: string
  reply: string

-- The service runs on a Fluence node
service HelloWorld:
    hello(from: PeerId) -> HelloWorld

-- The service runs inside browser
service HelloPeer("HelloPeer"):
    hello(message: string) -> string

func sayHello(targetPeerId: PeerId, targetRelayPeerId: PeerId) -> string:
    -- execute computation on a Peer in the network
    on HELLO_WORLD_NODE_PEER_ID:
        HelloWorld HELLO_WORLD_SERVICE_ID
        comp <- HelloWorld.hello(%init_peer_id%)

    -- send the result to target browser in the background
    on targetPeerId via targetRelayPeerId:
        co HelloPeer.hello(%init_peer_id%)

    -- send the result to the initiator
    <- comp.reply