package balius:app@0.1.0;
interface kv {
type payload = list<u8>;
variant kv-error {
upstream(string),
internal(string),
not-found(string)
}
get-value: func(key: string) -> result<payload, kv-error>;
set-value: func(key: string, value: payload) -> result<_, kv-error>;
list-values: func(prefix: string) -> result<list<string>, kv-error>;
}
interface ledger {
type cbor = list<u8>;
type json = list<u8>;
variant ledger-error {
upstream(string),
internal(string),
not-found(txo-ref)
}
record txo-ref {
tx-hash: list<u8>,
tx-index: u32,
}
record utxo {
body: cbor,
ref: txo-ref,
}
record address-pattern {
exact-address: list<u8>,
}
record asset-pattern {
policy: list<u8>,
name: option<list<u8>>,
}
record utxo-pattern {
address: option<address-pattern>,
asset: option<asset-pattern>,
}
record utxo-page {
utxos: list<utxo>,
next-token: option<string>,
}
read-utxos: func(refs: list<txo-ref>) -> result<list<utxo>, ledger-error>;
search-utxos: func(pattern: utxo-pattern, start: option<string>, max-items: u32) -> result<utxo-page, ledger-error>;
read-params: func() -> result<json, ledger-error>;
}
interface submit {
type cbor = list<u8>;
type submit-error = u32;
submit-tx: func(tx: cbor) -> result<_, submit-error>;
}
interface broadcast {
type msg = list<u8>;
type broadcast-error = u32;
publish-msg: func(topic: string, payload: msg) -> result<_, broadcast-error>;
}
interface driver {
type handle-error = u32;
type cbor = list<u8>;
type json = list<u8>;
type timestamp = u64;
type params = json;
record txo-ref {
tx-hash: list<u8>,
txo-index: u32,
}
record block-ref {
block-hash: list<u8>,
block-height: u64,
}
record utxo {
body: cbor,
ref: txo-ref,
block: block-ref,
}
variant event {
utxo(utxo),
utxo-undo(utxo),
timer(timestamp),
request(params),
message(json),
}
type address = list<u8>;
record token-pattern {
policy: list<u8>,
name: option<list<u8>>,
}
record utxo-pattern {
address: option<address>,
token: option<token-pattern>,
}
type timer-interval = string;
type method = string;
type topic = string;
variant event-pattern {
utxo(utxo-pattern),
utxo-undo(utxo-pattern),
timer(timer-interval),
request(method),
message(topic),
}
variant response {
acknowledge,
json(json),
cbor(cbor),
partial-tx(cbor)
}
register-channel: func(id: u32, pattern: event-pattern);
}
world worker {
import kv;
import broadcast;
import submit;
import ledger;
use driver.{event, response};
type config = list<u8>;
export init: func(config: config);
record handle-error {
message: string,
code: u32,
}
export handle: func(channel: u32, evt: event) -> result<response, handle-error>;
}