Skip to content

Commit

Permalink
add trusted getter AccountInfoAndSessionProxies
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Dec 1, 2024
1 parent b580214 commit 59ba7b8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -248,6 +248,10 @@ export default {
seed: 'H256',
},
AddSessionProxyArgs: '(AccountId, AccountId, SessionProxyCredentials)',
AccountInfoAndSessionProxies: {
account_info: 'AccountInfo',
session_proxies: 'Vec<SessionProxyCredentials>'
},
SendNoteArgs: '(AccountId, AccountId, String)',
GuessTheNumberTrustedCall: {
_enum: {
Expand Down
7 changes: 7 additions & 0 deletions packages/types/src/interfaces/integriteeWorker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<SessionProxyCredentials>;
}

/** @name BalanceUnshieldArgs */
export interface BalanceUnshieldArgs extends ITuple<[AccountId, AccountId, BalanceType, ShardIdentifier]> {}

Expand Down
12 changes: 11 additions & 1 deletion packages/worker-api/src/integriteeWorker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 });
Expand Down
11 changes: 11 additions & 0 deletions packages/worker-api/src/integriteeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
GuessTheNumberTrustedCall,
GuessTheNumberPublicGetter,
GuessTheNumberTrustedGetter,
AccountInfoAndSessionProxies,
AttemptsArg,
ParentchainsInfo,
NotesBucketInfo, TimestampedTrustedNote, SessionProxyRole,
Expand Down Expand Up @@ -53,6 +54,16 @@ export class IntegriteeWorker extends Worker {
return await submittableTrustedGetter<IntegriteeWorker, AccountInfo>(this, 'account_info', accountOrPubKey, trustedGetterArgs, asString(accountOrPubKey), 'AccountInfo');
}

public async accountInfoAndSessionProxiesGetter(accountOrPubKey: AddressOrPair, shard: string, signerOptions?: TrustedSignerOptions): Promise<SubmittableGetter<IntegriteeWorker, AccountInfoAndSessionProxies>> {
const trustedGetterArgs = {
shard: shard,
account: accountOrPubKey,
delegate: signerOptions?.delegate,
signer: signerOptions?.signer,
}
return await submittableTrustedGetter<IntegriteeWorker, AccountInfoAndSessionProxies>(this, 'account_info_and_session_proxies', accountOrPubKey, trustedGetterArgs, asString(accountOrPubKey), 'AccountInfoAndSessionProxies');
}

public parentchainsInfoGetter(shard: string): SubmittableGetter<IntegriteeWorker, ParentchainsInfo> {
const publicGetterArgs = {
shard: shard,
Expand Down

0 comments on commit 59ba7b8

Please sign in to comment.