Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making get_accounts_by_authorizers match API pattern #75

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/api/v1/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Name,
NameType,
PackedTransaction,
PublicKeyType,
SignedTransaction,
SignedTransactionType,
UInt128,
Expand All @@ -24,6 +23,7 @@ import {
AccountObject,
AccountsByAuthorizers,
GetAbiResponse,
GetAccountsByAuthorizersParams,
GetBlockHeaderStateResponse,
GetBlockResponse,
GetInfoResponse,
Expand Down Expand Up @@ -75,10 +75,10 @@ export class ChainAPI {
})
}

async get_accounts_by_authorizers(keys: PublicKeyType[]) {
async get_accounts_by_authorizers(params: GetAccountsByAuthorizersParams) {
return this.client.call({
path: '/v1/chain/get_accounts_by_authorizers',
params: {keys: keys},
params,
responseType: AccountsByAuthorizers,
})
}
Expand Down
10 changes: 9 additions & 1 deletion src/api/v1/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {
KeyWeight,
Name,
NameType,
PermissionLevel,
PublicKey,
PublicKeyType,
Signature,
Struct,
TimePoint,
Expand Down Expand Up @@ -173,7 +175,8 @@ export class AccountObject extends Struct {
export class AccountByAuthorizersRow extends Struct {
@Struct.field(Name) declare account_name: Name
@Struct.field(Name) declare permission_name: Name
@Struct.field(PublicKey) declare authorizing_key: PublicKey
@Struct.field(PublicKey, {optional: true}) declare authorizing_key: PublicKey
@Struct.field(PermissionLevel, {optional: true}) declare authorizing_account: PermissionLevel
@Struct.field(Weight) declare weight: Weight
@Struct.field(UInt32) declare threshold: UInt32
}
Expand Down Expand Up @@ -690,3 +693,8 @@ export interface GetProtocolFeaturesParams {
/** Whether to iterate records in reverse order. */
reverse?: boolean
}

export interface GetAccountsByAuthorizersParams {
accounts?: NameType[]
keys?: PublicKeyType[]
}
21 changes: 17 additions & 4 deletions test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ suite('api v1', function () {
assert.isTrue(permission.linked_actions[0].action.equals('transfer'))
})

test('chain get_accounts_by_authorizers', async function () {
const response = await jungle4.v1.chain.get_accounts_by_authorizers([
'PUB_K1_6RWZ1CmDL4B6LdixuertnzxcRuUDac3NQspJEvMnebGcXY4zZj',
])
test('chain get_accounts_by_authorizers (keys)', async function () {
const response = await jungle4.v1.chain.get_accounts_by_authorizers({
keys: ['PUB_K1_6RWZ1CmDL4B6LdixuertnzxcRuUDac3NQspJEvMnebGcXY4zZj'],
})
assert.lengthOf(response.accounts, 5)
assert.isTrue(response.accounts[0].account_name.equals('testtestasdf'))
assert.isTrue(response.accounts[0].permission_name.equals('owner'))
Expand All @@ -186,6 +186,19 @@ suite('api v1', function () {
assert.isTrue(response.accounts[0].threshold.equals(1))
})

test('chain get_accounts_by_authorizers (accounts)', async function () {
const response = await jungle4.v1.chain.get_accounts_by_authorizers({
accounts: ['eosio.prods'],
})
assert.lengthOf(response.accounts, 1)
assert.isTrue(response.accounts[0].account_name.equals('eosio'))
assert.isTrue(response.accounts[0].permission_name.equals('active'))
assert.isTrue(response.accounts[0].authorizing_account.actor.equals('eosio.prods'))
assert.isTrue(response.accounts[0].authorizing_account.permission.equals('active'))
assert.isTrue(response.accounts[0].weight.equals(1))
assert.isTrue(response.accounts[0].threshold.equals(1))
})

test('chain get_activated_protocol_features', async function () {
const response = await jungle4.v1.chain.get_activated_protocol_features()
assert.lengthOf(response.activated_protocol_features, 10)
Expand Down
28 changes: 28 additions & 0 deletions test/data/4406a3af18dbfafd488dffdd79db994d8cc09706.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"headers": {
"access-control-allow-headers": "Origin, X-Requested-With, Content-Type, Accept",
"access-control-allow-methods": "GET, POST, HEAD, OPTIONS",
"access-control-allow-origin": "*",
"connection": "close",
"content-length": "159",
"content-type": "application/json",
"date": "Mon, 14 Aug 2023 01:17:06 GMT",
"server": "nginx/1.24.0"
},
"status": 200,
"json": {
"accounts": [
{
"account_name": "eosio",
"permission_name": "active",
"authorizing_account": {
"actor": "eosio.prods",
"permission": "active"
},
"weight": 1,
"threshold": 1
}
]
},
"text": "{\"accounts\":[{\"account_name\":\"eosio\",\"permission_name\":\"active\",\"authorizing_account\":{\"actor\":\"eosio.prods\",\"permission\":\"active\"},\"weight\":1,\"threshold\":1}]}"
}