From 59ba7b88ae4bb183201da9c23f9b57bbbf745689 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 1 Dec 2024 17:13:04 +0100 Subject: [PATCH] add trusted getter AccountInfoAndSessionProxies --- .../src/interfaces/integriteeWorker/definitions.ts | 6 +++++- .../types/src/interfaces/integriteeWorker/types.ts | 7 +++++++ packages/worker-api/src/integriteeWorker.spec.ts | 12 +++++++++++- packages/worker-api/src/integriteeWorker.ts | 11 +++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index 4a5855a..9b26718 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -59,7 +59,7 @@ export default { IntegriteeTrustedGetter: { _enum: { account_info: 'AccountId', - unused_index_1: null, + account_info_and_session_proxies: 'AccountId', unused_index_2: null, unused_index_3: null, unused_index_4: null, @@ -248,6 +248,10 @@ export default { seed: 'H256', }, AddSessionProxyArgs: '(AccountId, AccountId, SessionProxyCredentials)', + AccountInfoAndSessionProxies: { + account_info: 'AccountInfo', + session_proxies: 'Vec' + }, SendNoteArgs: '(AccountId, AccountId, String)', GuessTheNumberTrustedCall: { _enum: { diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index 9e878a0..90bd226 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -7,6 +7,7 @@ import type { Bytes, Enum, Option, Struct, Text, Vec, u16, u32, u64 } from '@pol import type { ITuple } from '@polkadot/types-codec/types'; import type { MultiSignature } from '@polkadot/types/interfaces/extrinsics'; import type {AccountId, Balance, H160, Moment} from '@polkadot/types/interfaces/runtime'; +import type {AccountInfo} from "@polkadot/types/interfaces/system"; /** @name AttemptsArg */ export interface AttemptsArg extends Struct { @@ -46,6 +47,12 @@ export interface SessionProxyCredentials extends Struct { readonly seed: Uint8Array; } +/** @name AccountInfoAndSessionProxies */ +export interface AccountInfoAndSessionProxies extends Struct { + readonly account_info: AccountInfo; + readonly session_proxies: Vec; +} + /** @name BalanceUnshieldArgs */ export interface BalanceUnshieldArgs extends ITuple<[AccountId, AccountId, BalanceType, ShardIdentifier]> {} diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index fb6657a..91c83be 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -211,7 +211,7 @@ describe('worker', () => { }); // race condition so skipped - describe.skip('session proxies (delegates) should work', () => { + describe.only('session proxies (delegates) should work', () => { it('add delegate should work', async () => { const shard = network.shard; const now = new Date(); @@ -232,6 +232,16 @@ describe('worker', () => { expect(result).toBeDefined(); }); + it('AccountInfoAndProxiesGetter should return new proxy', async () => { + const getter = await worker.accountInfoAndSessionProxiesGetter(alice, network.shard); + console.log(`accountInfoAndSessionProxies: ${JSON.stringify(getter)}`); + const result = await getter.send(); + console.log('accountInfoAndSessionProxies:', result.toHuman()); + const data = worker.createType('AccountInfoAndSessionProxies', result); + const expected_role = worker.createType('SessionProxyRole', 'Any'); + expect(data.session_proxies[0].role).toEqual(expected_role); + }); + it('call as delegate should work', async () => { const shard = network.shard; const localKeyring = new Keyring({ type: "sr25519", ss58Format: 42 }); diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index acd838b..a9ae0be 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -6,6 +6,7 @@ import type { GuessTheNumberTrustedCall, GuessTheNumberPublicGetter, GuessTheNumberTrustedGetter, + AccountInfoAndSessionProxies, AttemptsArg, ParentchainsInfo, NotesBucketInfo, TimestampedTrustedNote, SessionProxyRole, @@ -53,6 +54,16 @@ export class IntegriteeWorker extends Worker { return await submittableTrustedGetter(this, 'account_info', accountOrPubKey, trustedGetterArgs, asString(accountOrPubKey), 'AccountInfo'); } + public async accountInfoAndSessionProxiesGetter(accountOrPubKey: AddressOrPair, shard: string, signerOptions?: TrustedSignerOptions): Promise> { + const trustedGetterArgs = { + shard: shard, + account: accountOrPubKey, + delegate: signerOptions?.delegate, + signer: signerOptions?.signer, + } + return await submittableTrustedGetter(this, 'account_info_and_session_proxies', accountOrPubKey, trustedGetterArgs, asString(accountOrPubKey), 'AccountInfoAndSessionProxies'); + } + public parentchainsInfoGetter(shard: string): SubmittableGetter { const publicGetterArgs = { shard: shard,