Skip to content

Commit

Permalink
[worker] fix sending trusted calls with author_submitExtrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb committed Apr 8, 2024
1 parent 823659d commit 46f550d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/worker-api/src/worker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down
16 changes: 10 additions & 6 deletions packages/worker-api/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -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<any> {
public async trustedBalanceTransfer(accountOrPubKey: KeyringPair | PubKeyPinPair, shard: ShardIdentifier, mrenclave: string, params: BalanceTransferArgs, options: CallOptions = {} as CallOptions): Promise<Hash> {
const nonce = await this.getNonce(accountOrPubKey, mrenclave, options);
const call = createTrustedCall(this, ['balance_transfer', 'BalanceTransferArgs'], accountOrPubKey, shard, mrenclave, nonce, params);
return this.sendTrustedCall<u32>(call, shard, 'u32', options);
return this.sendTrustedCall(call, shard, options);
}

async sendTrustedCall<T>(call: TrustedCallSigned, shard: ShardIdentifier, parser: string, options: CallOptions = {} as CallOptions): Promise<T> {
async sendTrustedCall(call: TrustedCallSigned, shard: ShardIdentifier, options: CallOptions = {} as CallOptions): Promise<Hash> {
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<Hash>(this, call, shard, true, 'TrustedOperationResult', options);
}
}

0 comments on commit 46f550d

Please sign in to comment.