module Main

export account_state, send_money, NearSignerApi, account_state_view, transfer_money, JsService

data Services:
    peerId: string
    relayPeerId: string

service JsService("JsService"):
    get: -> Services

data AccountState:
    amount: string
    block_hash: string
    block_height: u64
    code_hash: string
    locked: string
    storage_paid_at: u64
    storage_usage: u64

service NearSignerApi("near"):
    account_state(network_id: string, account_id: string, password: string) -> string
    send_money(network_id: string, account_id: string, receiver_id:string, amount:string, password: string) -> string
    get_balance(network_id: string, account_id: string, password: string) -> string

func account_state_view(network_id:string, account_id:string, password: string) -> string:
    services <- JsService.get()
    on services.peerId via services.relayPeerId:
        res <- NearSignerApi.account_state(network_id, account_id, password)
    <- res

func account_state(network_id:string, account_id:string, password: string, node:string, relay:string) -> string:
    on node via relay:
        res <- NearSignerApi.account_state(network_id, account_id, password)
    <- res

func transfer_money(network_id:string, account_id:string, receiver_id:string, amount:string, password: string) -> string:
    services <- JsService.get()
    on services.peerId via services.relayPeerId:
        res <- NearSignerApi.send_money(network_id, account_id, receiver_id, amount, password)
    <- res

func send_money(network_id:string, account_id:string, receiver_id:string, amount:string, password: string,  node:string, relay:string) -> string:
    on node via relay:
        res <- NearSignerApi.send_money(network_id, account_id, receiver_id, amount, password)
    <- res

func get_balance(network_id: string, account_id: string, password: string, node:string, relay:string) -> string:
    on node via relay:
        res <- NearSignerApi.get_balance(network_id, account_id, password)
    <- res