From d77e1fe26fd7ddb319d7bc0d1d463f3aef792323 Mon Sep 17 00:00:00 2001 From: Dallas Johnson Date: Mon, 7 Oct 2019 23:04:21 +0100 Subject: [PATCH] In order to specify permissions beyond `actor@active` more granular permissions options are needed which can be with this via the `auths` parameter. --- src/contracts/contract.ts | 21 +++++++++++++++------ src/contracts/typeGenerator.ts | 8 ++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/contracts/contract.ts b/src/contracts/contract.ts index 38b1b20..aea2c4d 100644 --- a/src/contracts/contract.ts +++ b/src/contracts/contract.ts @@ -36,6 +36,11 @@ export interface GetTableRowsOptions { showPayer?: boolean; } +export interface ActorPermission { + actor: string; + permission: string; +} + /** * Adds additional functionality to the EOSJS `Contract` class */ @@ -108,15 +113,19 @@ export class Contract implements EOSJSContract { // Who are we acting as? // We default to sending transactions from the contract account. - let authorization = account; + let authorization: Array = account.active; const options = arguments[action.fields.length]; - if (options && options.from && options.from instanceof Account) { - authorization = options.from; - } + if (options) { + if (options.from && options.from instanceof Account) { + authorization = options.from.active; // Ensure we have the key to sign with. - EOSManager.addSigningAccountIfMissing(authorization); + EOSManager.addSigningAccountIfMissing(options.from); + } else if (options.auths && options.auths instanceof Array) { + authorization = options.auths; + } + } return EOSManager.transact( { @@ -124,7 +133,7 @@ export class Contract implements EOSJSContract { { account: account.name, name: action.name, - authorization: authorization.active, + authorization: authorization, data, }, ], diff --git a/src/contracts/typeGenerator.ts b/src/contracts/typeGenerator.ts index 0bed1b7..c8c7fec 100644 --- a/src/contracts/typeGenerator.ts +++ b/src/contracts/typeGenerator.ts @@ -75,7 +75,11 @@ export const generateTypes = async (contractIdentifier: string) => { '', ]; // Define imports - const imports = ['Account', 'Contract', 'GetTableRowsOptions']; + const imports = [ + 'Account', + 'Contract', + 'GetTableRowsOptions', + ]; if (contractTables.length > 0) imports.push('TableRowsResult'); // Generate import definitions result.push(`import { ${imports.join(', ')} } from 'lamington';`); @@ -99,7 +103,7 @@ export const generateTypes = async (contractIdentifier: string) => { (parameter: any) => `${parameter.name}: ${mapParameterType(parameter.type)}` ); // Optional parameter at the end on every contract method. - parameters.push('options?: { from?: Account }'); + parameters.push('options?: { from?: Account, auths?: ActorPermission[] }'); return `${action.name}(${parameters.join(', ')}): Promise;`; });