godprotocol
Version:
A distributed computing environment for Web 4.0 — integrating AI, decentralisation, and virtual computation.
83 lines (72 loc) • 2.11 kB
JavaScript
class Utils {
on = async (event_name, filter, handler) => {};
reload = async (payload) => {
let { address } = payload;
let res = await this.manager.oracle.read(`${address}/air`, {
address,
prefix: ".codes",
account: this.physical_address,
});
await this.load({
address: address.slice(this.physical_address.length + 1),
sequence: res,
compiler: true,
from_reload: true,
});
};
run_callback = async (res, { callback, socket }) => {
if (typeof callback === "string") {
if (callback === "store" && !Array.isArray(res)) {
let store_fn = await this.vm.callable("store");
await store_fn.callable(
{ object: await this.vm.cloth(res) },
{ vm: this.vm, chain: this.chain }
);
callback = res.value;
} else {
let net_fn = await this.vm.callable("net");
let url = await this.parse_net_url(callback);
if (url.path) return;
await net_fn.callable(
{
payload: {
header: { method: "POST" },
body: await this.vm.cloth(res),
},
account: url.account,
path: url.path,
server: url.server,
},
{ vm: this.vm, chain: this.chain, no_then: true }
);
}
} else if (typeof callback === "function") {
await callback(res);
}
if (socket) {
// handle socket
}
};
// acc+Arena://send_mail
parse_net_url = async (url) => {
url = url.split("://");
let protocol = url[0];
let payload = {};
if (protocol.startsWith("acc+")) {
payload.account = protocol.split("+")[1];
payload.path = url[1];
} else if (protocol.startsWith("http")) {
let addr = url[1].split("/");
addr[1] = addr.slice(1).join("/");
addr[0] = addr.split(":");
payload.server = {
hostname: addr[0][0],
port: Number(addr[0][1]) || null,
};
payload.path = addr[1];
}
return payload;
};
read = async (address, query) => {};
}
export default Utils;