Skip to content

Commit

Permalink
[worker] internally create strong types for trusted calls
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb committed Apr 11, 2024
1 parent 90b7b25 commit dbe3618
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
20 changes: 16 additions & 4 deletions packages/worker-api/src/integriteeWorker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ describe('worker', () => {
describe('balance transfer should work', () => {
it('should return value', async () => {
const shard = worker.createType('ShardIdentifier', bs58.decode(network.mrenclave));
const params = worker.createType('BalanceTransferArgs', [alice.address, charlie.address, 1100000000000])
const result = await worker.trustedBalanceTransfer(alice, shard, network.mrenclave, params);
const result = await worker.trustedBalanceTransfer(
alice,
shard,
network.mrenclave,
alice.address,
charlie.address,
1100000000000
);
console.log('balance transfer result', result.toHuman());
expect(result).toBeDefined();
});
Expand All @@ -86,8 +92,14 @@ 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, charlie.address, 1100000000000, shard])
const result = await worker.balanceUnshieldFunds(alice, shard, network.mrenclave, params);
const result = await worker.balanceUnshieldFunds(
alice,
shard,
network.mrenclave,
alice.address,
charlie.address,
1100000000000
);
console.log('balance unshield result', result.toHuman());
expect(result).toBeDefined();
});
Expand Down
23 changes: 20 additions & 3 deletions packages/worker-api/src/integriteeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import NodeRSA from 'node-rsa';
import type {KeyringPair} from '@polkadot/keyring/types';
import type {Balance, Hash} from '@polkadot/types/interfaces/runtime';
import type {
BalanceTransferArgs, BalanceUnshieldArgs,
ShardIdentifier, IntegriteeTrustedCallSigned,
} from '@encointer/types';

Expand All @@ -33,14 +32,32 @@ export class IntegriteeWorker extends Worker {
}, options)
}

public async trustedBalanceTransfer(accountOrPubKey: KeyringPair | PubKeyPinPair, shard: ShardIdentifier, mrenclave: string, params: BalanceTransferArgs, options: CallOptions = {} as CallOptions): Promise<Hash> {
public async trustedBalanceTransfer(
accountOrPubKey: KeyringPair | PubKeyPinPair,
shard: ShardIdentifier,
mrenclave: string,
from: String,
to: String,
amount: number,
options: CallOptions = {} as CallOptions
): Promise<Hash> {
const nonce = await this.getNonce(accountOrPubKey, mrenclave, options);
const params = this.createType('BalanceTransferArgs', [from, to, amount])
const call = createTrustedCall(this, ['balance_transfer', 'BalanceTransferArgs'], accountOrPubKey, shard, mrenclave, nonce, params);
return this.sendTrustedCall(call, shard, options);
}

public async balanceUnshieldFunds(accountOrPubKey: KeyringPair | PubKeyPinPair, shard: ShardIdentifier, mrenclave: string, params: BalanceUnshieldArgs, options: CallOptions = {} as CallOptions): Promise<Hash> {
public async balanceUnshieldFunds(
accountOrPubKey: KeyringPair | PubKeyPinPair,
shard: ShardIdentifier,
mrenclave: string,
fromIncognitoAddress: string,
toPublicAddress: string,
amount: number,
options: CallOptions = {} as CallOptions
): Promise<Hash> {
const nonce = await this.getNonce(accountOrPubKey, mrenclave, options);
const params = this.createType('BalanceUnshieldArgs', [fromIncognitoAddress, toPublicAddress, amount, shard])
const call = createTrustedCall(this, ['balance_unshield', 'BalanceUnshieldArgs'], accountOrPubKey, shard, mrenclave, nonce, params);
return this.sendTrustedCall(call, shard, options);
}
Expand Down

0 comments on commit dbe3618

Please sign in to comment.