Skip to content

Commit

Permalink
Updated EOSIO contract and added linkauth and unlinkauth methods (#13)
Browse files Browse the repository at this point in the history
* chore: updated eosio contract

* chore: added linkauth and unlinkauth Account methods

closes issue #12

* Regenerated System Contract

---------

Co-authored-by: Aaron Cox <[email protected]>
  • Loading branch information
dafuga and aaroncox authored Sep 9, 2023
1 parent 6df4e7a commit ca4d9d8
Show file tree
Hide file tree
Showing 4 changed files with 1,561 additions and 1,522 deletions.
23 changes: 17 additions & 6 deletions src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {Contract} from '@wharfkit/contract'
import {Resources} from '@wharfkit/resources'

import {Permission} from './permission'
import {SystemContract} from './contracts/eosio'
import * as SystemContract from './contracts/eosio'
import {Resource, ResourceType} from './resource'

export interface AccountArgs {
Expand Down Expand Up @@ -42,7 +42,7 @@ export interface UndelegateOptions {

export class Account {
readonly data: API.v1.AccountObject
readonly systemContract: Contract
readonly systemContract: SystemContract.Contract
readonly client: APIClient

constructor(args: AccountArgs) {
Expand Down Expand Up @@ -141,12 +141,23 @@ export class Account {
})
}

linkauth() {
// TODO: Implement `linkauth` action calls
linkauth(contract: NameType, action: NameType, requiredPermission: NameType): Action {
return this.systemContract.action('linkauth', {
account: this.accountName,
code: contract,
type: action,
requirement: requiredPermission,
authorized_by: '',
})
}

unlinkauth() {
// TODO: Implement `unlinkauth` action calls
unlinkauth(contract: NameType, action: NameType): Action {
return this.systemContract.action('unlinkauth', {
account: this.accountName,
code: contract,
type: action,
authorized_by: '',
})
}

buyRam(amount: AssetType, options?: BuyramOptions): Action {
Expand Down
3,030 changes: 1,515 additions & 1,515 deletions src/contracts/eosio.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './account'
export * from './permission'
export * from './kit'
export * from './contracts/eosio'
export * as SystemContract from './contracts/eosio'
28 changes: 28 additions & 0 deletions test/tests/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,34 @@ suite('Account', function () {
})
})

test('linkauth', () => {
const action = testAccount.linkauth('eosio.token', 'transfer', 'active')
assert.isTrue(action.account.equals('eosio'))
assert.isTrue(action.name.equals('linkauth'))
assert.isTrue(action.authorization[0].equals(PlaceholderAuth))

const decoded = Serializer.decode({data: action.data, type: SystemContract.Types.Linkauth})
assert.isTrue(decoded.account.equals('wharfkit1133'))
assert.isTrue(decoded.code.equals('eosio.token'))
assert.isTrue(decoded.type.equals('transfer'))
assert.isTrue(decoded.requirement.equals('active'))
})

test('unlinkauth', () => {
const action = testAccount.unlinkauth('eosio.token', 'transfer')
assert.isTrue(action.account.equals('eosio'))
assert.isTrue(action.name.equals('unlinkauth'))
assert.isTrue(action.authorization[0].equals(PlaceholderAuth))

const decoded = Serializer.decode({
data: action.data,
type: SystemContract.Types.Unlinkauth,
})
assert.isTrue(decoded.account.equals('wharfkit1133'))
assert.isTrue(decoded.code.equals('eosio.token'))
assert.isTrue(decoded.type.equals('transfer'))
})

suite('buyRam', () => {
test('only amount', () => {
const action = testAccount.buyRam('1.0000 EOS')
Expand Down

0 comments on commit ca4d9d8

Please sign in to comment.