Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
112 lines (95 sloc) 1.99 KB
/**
*
*/
export class Client {
public provider;
public modules;
/**
*
*/
public constructor(options: {
provider: any;
modules: any;
}) {
this.provider = options.provider;
this.modules = options.modules || [];
}
/**
*
*/
public async deployAssetLedger(config: any) {
const module = this.getModule('AssetLedger');
if (!module) {
throw this.getMissingModuleError('AssetLedger');
} else {
return module.object.deploy(this.provider, config);
}
}
/**
*
*/
public async deployValueLedger(config: any) {
const module = this.getModule('ValueLedger');
if (!module) {
throw this.getMissingModuleError('ValueLedger');
} else {
return module.object.deploy(this.provider, config);
}
}
/**
*
*/
public getAssetLedger(id: string) {
const module = this.getModule('AssetLedger');
if (!module) {
throw this.getMissingModuleError('AssetLedger');
} else {
return new module.object(this.provider, id);
}
}
/**
*
*/
public getOrderGateway(id?: string) {
const module = this.getModule('OrderGateway');
if (!module) {
throw this.getMissingModuleError('OrderGateway');
} else {
return new module.object(this.provider, id);
}
}
/**
*
*/
public getValueLedger(id: string) {
const module = this.getModule('ValueLedger');
if (!module) {
throw this.getMissingModuleError('ValueLedger');
} else {
return new module.object(this.provider, id);
}
}
/**
*
*/
public createCert(schema: any) {
const module = this.getModule('Cert');
if (!module) {
throw this.getMissingModuleError('Cert');
} else {
return new module.object(schema);
}
}
/**
*
*/
public getModule(name: string) {
return this.modules.find((m) => m.name === name);
}
/**
*
*/
protected getMissingModuleError(name: string) {
throw new Error(`The ${name} module is not available.`);
}
}
You can’t perform that action at this time.