| 30 | * The DARC class is used to interact with the DARC contract. |
| 31 | */ |
| 32 | export class DARC { |
| 33 | private darcContract: Contract; |
| 34 | private darcAddress: string; |
| 35 | private darcVersion: darcBinary.DARC_VERSION; |
| 36 | private wallet: ethers.Wallet | undefined; |
| 37 | private provider: ethers.providers.Provider | undefined; |
| 38 | |
| 39 | /** |
| 40 | * The constructor of the DARC class. |
| 41 | * @param param: the init param including the address, version, wallet and/or provider. |
| 42 | */ |
| 43 | constructor(param: InitParam) { |
| 44 | const { address, version, wallet, provider } = param; |
| 45 | this.darcAddress = address; |
| 46 | this.darcVersion = version; |
| 47 | this.wallet = wallet; |
| 48 | this.provider = provider; |
| 49 | if (wallet !== undefined) { |
| 50 | this.darcContract = new ethers.Contract(address, darcBinary.darcBinary(version).abi, wallet); |
| 51 | } else if (provider !== undefined) { |
| 52 | this.darcContract = new ethers.Contract(address, darcBinary.darcBinary(version).abi, provider); |
| 53 | } else { |
| 54 | throw new Error("Either wallet or provider should be provided."); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Run the program on the DARC contract. |
| 60 | * @param program: the program to be run. |
| 61 | */ |
| 62 | async entrance(program:any){ |
| 63 | if (this.wallet === undefined){ |
| 64 | throw new Error("Wallet is not provided for this DARC instance."); |
| 65 | } |
| 66 | await this.darcContract.entrance(program); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Below are all DARC's dashboard functions, read parameters from the DARC contract. |
| 71 | */ |
| 72 | async getTokenOwners(tokenClass: BigInt): Promise<string[]> { |
| 73 | return await this.darcContract.getTokenOwners(tokenClass); |
| 74 | } |
| 75 | |
| 76 | async getTokenInfo(tokenClass: BigInt): Promise<TokenInfo> { |
| 77 | const result = await this.darcContract.getTokenInfo(tokenClass); |
| 78 | //console.log("result: " + JSON.stringify(result)); |
| 79 | const {0: returnVotingWeight, 1: returnDividendWeight, 2: returnTokenInfo, 3: returnTotalSupply} = result; |
| 80 | |
| 81 | let returnStruct: TokenInfo = { |
| 82 | votingWeight: returnVotingWeight, |
| 83 | dividendWeight: returnDividendWeight, |
| 84 | tokenInfo: returnTokenInfo, |
| 85 | totalSupply: returnTotalSupply, |
| 86 | }; |
| 87 | |
| 88 | return returnStruct; |
| 89 | } |
nothing calls this directly
no outgoing calls
no test coverage detected