@tokenz/tokens-smartcontract-sdk
Version:
Smart Contract SDK for Tokenz STO platform
134 lines (117 loc) • 4.97 kB
JavaScript
'use strict'
const coreLib = require('./Core');
class Governance{
constructor(){
this.macContract = new coreLib("macContract");
this.ruleEngine = new coreLib("ruleEngine");
this.fetchSubjectLabel = this.fetchSubjectLabel.bind(this);
this.fetchObjectLabel = this.fetchObjectLabel.bind(this);
this.setSubjectLabel = this.setSubjectLabel.bind(this);
this.setObjectLabel = this.setObjectLabel.bind(this);
this.checkPermission = this.checkPermission.bind(this);
this.setRule = this.setRule.bind(this);
this.fetchRule = this.fetchRule.bind(this);
this.enableRule = this.enableRule.bind(this);
this.disableRule = this.disableRule.bind(this);
}
async fetchSubjectLabel( address ){
return new Promise(async function( resolve , reject ) {
try{
let result = await this.macContract.callData("subject",[address]);
resolve( result );
}catch(err){
window.Sentry.captureException(err);
reject( 0 )
}
}.bind(this))
}
async fetchObjectLabel( address ){
return new Promise(async function( resolve , reject ) {
try{
let result = await this.macContract.callData("object",[address]);
resolve( result );
}catch(err){
window.Sentry.captureException(err);
reject( 0 )
}
}.bind(this))
}
async setSubjectLabel( address , label ){
return new Promise(async function( resolve , reject ) {
try{
let result = await this.macContract.sendTx("addPermissionSubject",[ address , label ]);
resolve( result );
}catch(err){
window.Sentry.captureException(err);
reject( 0 )
}
}.bind(this))
}
async setObjectLabel( hash , label ){
return new Promise(async function( resolve , reject ) {
try{
let result = await this.macContract.sendTx("addPermissionObject",[ hash , label ]);
resolve( result );
}catch(err){
window.Sentry.captureException(err);
reject( 0 )
}
}.bind(this))
}
async checkPermission( subjectLabel , objectLabel ){
return new Promise(async function( resolve , reject ) {
try{
let result = await this.macContract.callData("addPermissionObject",[ subjectLabel , objectLabel ]);
resolve( result );
}catch(err){
reject( 0 )
}
}.bind(this))
}
async setRule ( fromContractType , fromContractCategory , toContractType , toContractCategory ){
return new Promise(async function( resolve , reject ) {
try{
let result = await this.ruleEngine.sendTx("addRule" , [ fromContractType , fromContractCategory , toContractType , toContractCategory ]);
resolve( result );
}catch(err){
reject( 0 )
}
}.bind(this));
}
async fetchRule ( fromContractType , fromContractCategory , toContractType , toContractCategory ){
return new Promise(async function( resolve , reject ) {
try{
let result = await this.ruleEngine.callData("ruleCheck" , [ fromContractType , fromContractCategory , toContractType , toContractCategory ]);
resolve( result );
}catch(err){
window.Sentry.captureException(err);
reject( 0 )
}
}.bind(this));
}
async enableRule ( fromContractType , fromContractCategory , toContractType , toContractCategory ){
return new Promise(async function( resolve , reject ) {
try{
let hash = await this.ruleEngine.callData("fetchHash" , [ fromContractType , fromContractCategory , toContractType , toContractCategory ]);
let result = await this.ruleEngine.sendTx("enableRule" , [ hash ]);
resolve( result );
}catch(err){
window.Sentry.captureException(err);
reject( 0 )
}
}.bind(this));
}
async disableRule ( fromContractType , fromContractCategory , toContractType , toContractCategory ){
return new Promise(async function( resolve , reject ) {
try{
let hash = await this.ruleEngine.callData("fetchHash" , [ fromContractType , fromContractCategory , toContractType , toContractCategory ]);
let result = await this.ruleEngine.sendTx("disableRule" , [ hash ]);
resolve( result );
}catch(err){
window.Sentry.captureException(err);
reject( 0 )
}
}.bind(this));
}
}
module.exports = Governance;