Skip to content

Commit

Permalink
Added addCodePermission to contracts so it can be easily called fro…
Browse files Browse the repository at this point in the history
…m there.
  • Loading branch information
thekevinbrown committed May 20, 2019
1 parent 0f2fbd0 commit 8d68b10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/accounts/accountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,12 @@ export class AccountManager {

/**
* Grants `eosio.code` permission to the specified account's `active` key
* @note Should be moved to the `contracts/contract.ts` I think?
* @note Actually it is `account` based and not specific to contracts...
* @note Can also be called directly on a contract.
* @author Kevin Brown <github.com/thekevinbrown>
* @author Mitch Pierias <github.com/MitchPierias>
* @param account Account without `eosio.code` permissions
*/
static addCodePermission = async (account: Account) => {
public static addCodePermission = async (account: Account) => {
// We need to get their existing permissions, then add in a new eosio.code permission for this contract.
const { permissions } = await EOSManager.rpc.get_account(account.name);
const { required_auth } = permissions.find(
Expand Down
12 changes: 10 additions & 2 deletions src/contracts/contract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account } from '../accounts';
import { Account, AccountManager } from '../accounts';
import { nextBlock } from '../utils';
import { Api } from 'eosjs';
import { Contract as EOSJSContract, Type } from 'eosjs/dist/eosjs-serialize';
Expand Down Expand Up @@ -135,7 +135,7 @@ export class Contract implements EOSJSContract {
* @param table The table name
* @param scope Optional table scope, defaults to the table name
*/
getTableRows = async (table: string, scope?: string) => {
public getTableRows = async (table: string, scope?: string) => {
// Wait for the next block to appear before we query the values.
await nextBlock();

Expand Down Expand Up @@ -184,4 +184,12 @@ export class Contract implements EOSJSContract {

return result;
};

/**
* Grants `eosio.code` permission to the contract account's `active` key
* @note Can also be called from AccountManager, as the action is technically an account based action.
* @author Kevin Brown <github.com/thekevinbrown>
* @author Mitch Pierias <github.com/MitchPierias>
*/
public addCodePermission = () => AccountManager.addCodePermission(this._account);
}

0 comments on commit 8d68b10

Please sign in to comment.