From 29473cc25ac5a62a29d805494f6b077e7106c552 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Mon, 8 Apr 2024 15:08:48 +0800 Subject: [PATCH] [worker] implement balance_unshield trusted call --- packages/worker-api/src/worker.spec.ts | 10 ++++++++++ packages/worker-api/src/worker.ts | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/worker-api/src/worker.spec.ts b/packages/worker-api/src/worker.spec.ts index 8799a21e..3f833c75 100644 --- a/packages/worker-api/src/worker.spec.ts +++ b/packages/worker-api/src/worker.spec.ts @@ -83,6 +83,16 @@ describe('worker', () => { }); }); + describe('balance unshield should work', () => { + it('should return value', async () => { + const shard = worker.createType('ShardIdentifier', bs58.decode(network.mrenclave)); + const params = worker.createType('BalanceUnshieldArgs', [alice.address, bob.address, 1100000000000, shard]) + const result = await worker.balanceUnshieldFunds(alice, shard, network.mrenclave, params); + console.log('balance unshield result', result.toHuman()); + expect(result).toBeDefined(); + }); + }); + // Tests specific for the encointer protocol describe('encointer-worker', () => { describe('getTotalIssuance', () => { diff --git a/packages/worker-api/src/worker.ts b/packages/worker-api/src/worker.ts index 9af9d0b2..77ce1437 100644 --- a/packages/worker-api/src/worker.ts +++ b/packages/worker-api/src/worker.ts @@ -17,7 +17,7 @@ import type {KeyringPair} from '@polkadot/keyring/types'; import type {AccountId, Balance, Hash, Moment} from '@polkadot/types/interfaces/runtime'; import type { Attestation, - BalanceTransferArgs, + BalanceTransferArgs, BalanceUnshieldArgs, CommunityIdentifier, MeetupIndexType, ParticipantIndexType, @@ -244,6 +244,12 @@ export class EncointerWorker extends WebSocketAsPromised implements IEncointerWo return this.sendTrustedCall(call, shard, options); } + public async balanceUnshieldFunds(accountOrPubKey: KeyringPair | PubKeyPinPair, shard: ShardIdentifier, mrenclave: string, params: BalanceUnshieldArgs, options: CallOptions = {} as CallOptions): Promise { + const nonce = await this.getNonce(accountOrPubKey, mrenclave, options); + const call = createTrustedCall(this, ['balance_unshield', 'BalanceUnshieldArgs'], accountOrPubKey, shard, mrenclave, nonce, params); + return this.sendTrustedCall(call, shard, options); + } + async sendTrustedCall(call: TrustedCallSigned, shard: ShardIdentifier, options: CallOptions = {} as CallOptions): Promise { if (this.shieldingKey() == undefined) { const key = await this.getShieldingKey(options);