godprotocol
Version:
A distributed computing environment
60 lines (45 loc) • 1.54 kB
JavaScript
import create_server from "../utils/create_server";
import { post_request } from "../utils/services";
import Account from "./Account";
import Oracle from "./Oracle";
import Blockweb from "./Blockweb";
import Repository from "./Repository";
class Manager {
constructor(name, options) {
this.name = name;
this.options = options || {};
this.compiler = options.compiler;
this.trinity = options.trinity;
this.sync_server = options.sync_server;
if (this.sync_server && !this.sync_server.domain) {
this.sync_server.domain = `${this.sync_server.hostname}:${this.sync_server.port}`;
}
this.server = options.server;
this.accounts = new Object();
this.web = new Blockweb(this);
this.oracle = new Oracle(this);
this.repository = new Repository(this);
}
sync = async () => {
if (this.server && !this.server.domain) {
this.server.domain = `${this.server.hostname}:${this.server.port}`;
}
this.server_object =
this.server && (await create_server({ ...this.server, manager: this }));
this.post_request = post_request;
await this.oracle.sync();
await this.repository.sync(this.name);
};
add_account = async (name, options) => {
let account = this.accounts[name];
if (account) return account;
account = new Account(name, { ...options, manager: this });
await account.sync();
this.accounts[name] = account;
return account;
};
get_account = (name) => {
return this.accounts[name];
};
}
export default Manager;