diff --git a/packages/worker-api/src/worker.spec.ts b/packages/worker-api/src/worker.spec.ts index 1d363ab4..4195b9ef 100644 --- a/packages/worker-api/src/worker.spec.ts +++ b/packages/worker-api/src/worker.spec.ts @@ -77,7 +77,7 @@ describe('worker', () => { const shard = worker.createType('ShardIdentifier', bs58.decode(network.mrenclave)); const params = worker.createType('BalanceTransferArgs', [alice.address, bob.address, 1100000000000]) const result = await worker.trustedBalanceTransfer(alice, shard, network.mrenclave, params); - console.log('balance transfer result', result); + console.log('balance transfer result', result.toHuman()); expect(result).toBeDefined(); }); }); diff --git a/packages/worker-api/src/worker.ts b/packages/worker-api/src/worker.ts index 23f479f0..9af9d0b2 100644 --- a/packages/worker-api/src/worker.ts +++ b/packages/worker-api/src/worker.ts @@ -14,7 +14,7 @@ import NodeRSA from 'node-rsa'; import type {KeyringPair} from '@polkadot/keyring/types'; -import type {AccountId, Balance, Moment} from '@polkadot/types/interfaces/runtime'; +import type {AccountId, Balance, Hash, Moment} from '@polkadot/types/interfaces/runtime'; import type { Attestation, BalanceTransferArgs, @@ -74,12 +74,15 @@ const parseGetterResponse = (self: IEncointerWorker, responseType: string, data: const jsonStr = self.createType('String', returnValue.value); // Todo: For some reason there are 2 non-utf characters, where I don't know where // they come from currently. - // console.log(`jsonStr.sub(2): ${jsonStr.toJSON().substring(2)}`); + console.log(`Got shielding key: ${jsonStr.toJSON().substring(2)}`); parsedData = parseNodeRSA(jsonStr.toJSON().substring(2)); break case 'Vault': parsedData = self.createType(responseType, returnValue.value); break + case 'TrustedOperationResult': + parsedData = self.createType('Hash', returnValue.value); + break default: parsedData = unwrapWorkerResponse(self, returnValue.value); console.log(`unwrapped data ${parsedData}`); @@ -235,18 +238,19 @@ export class EncointerWorker extends WebSocketAsPromised implements IEncointerWo }, options) } - public async trustedBalanceTransfer(accountOrPubKey: KeyringPair | PubKeyPinPair, shard: ShardIdentifier, mrenclave: string, params: BalanceTransferArgs, options: CallOptions = {} as CallOptions): Promise { + public async trustedBalanceTransfer(accountOrPubKey: KeyringPair | PubKeyPinPair, shard: ShardIdentifier, mrenclave: string, params: BalanceTransferArgs, options: CallOptions = {} as CallOptions): Promise { const nonce = await this.getNonce(accountOrPubKey, mrenclave, options); const call = createTrustedCall(this, ['balance_transfer', 'BalanceTransferArgs'], accountOrPubKey, shard, mrenclave, nonce, params); - return this.sendTrustedCall(call, shard, 'u32', options); + return this.sendTrustedCall(call, shard, options); } - async sendTrustedCall(call: TrustedCallSigned, shard: ShardIdentifier, parser: string, options: CallOptions = {} as CallOptions): Promise { + async sendTrustedCall(call: TrustedCallSigned, shard: ShardIdentifier, options: CallOptions = {} as CallOptions): Promise { if (this.shieldingKey() == undefined) { const key = await this.getShieldingKey(options); + console.log(`Setting the shielding pubKey of the worker.`) this.setShieldingKey(key); } - return sendTrustedCall(this, call, shard, true, parser, options); + return sendTrustedCall(this, call, shard, true, 'TrustedOperationResult', options); } }