Skip to content

Commit

Permalink
[worker] consistent api, create shard identifier internally and take …
Browse files Browse the repository at this point in the history
…string as arg
  • Loading branch information
clangenb committed Apr 11, 2024
1 parent 84fd409 commit 2f80f1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions packages/worker-api/src/integriteeWorker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { localDockerNetwork } from './testUtils/networks.js';
import { IntegriteeWorker } from './integriteeWorker.js';
import WS from 'websocket';
import {type KeyringPair} from "@polkadot/keyring/types";
import bs58 from "bs58";

const {w3cwebsocket: WebSocket} = WS;

Expand Down Expand Up @@ -75,7 +74,7 @@ describe('worker', () => {

describe('balance transfer should work', () => {
it('should return value', async () => {
const shard = worker.createType('ShardIdentifier', bs58.decode(network.mrenclave));
const shard = network.mrenclave;
const result = await worker.trustedBalanceTransfer(
alice,
shard,
Expand All @@ -91,7 +90,7 @@ describe('worker', () => {

describe('balance unshield should work', () => {
it('should return value', async () => {
const shard = worker.createType('ShardIdentifier', bs58.decode(network.mrenclave));
const shard = network.mrenclave;
const result = await worker.balanceUnshieldFunds(
alice,
shard,
Expand Down
17 changes: 10 additions & 7 deletions packages/worker-api/src/integriteeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {callGetter, sendTrustedCall} from './sendRequest.js';
import {createTrustedCall} from "./requests.js";
import {PubKeyPinPair, toAccount} from "@encointer/util/common";
import {Worker} from "./worker.js";
import bs58 from "bs58";

export class IntegriteeWorker extends Worker {

Expand All @@ -34,32 +35,34 @@ export class IntegriteeWorker extends Worker {

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

public async balanceUnshieldFunds(
accountOrPubKey: KeyringPair | PubKeyPinPair,
shard: ShardIdentifier,
shard: string,
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);
const shardT = this.createType('ShardIdentifier', bs58.decode(shard));
const params = this.createType('BalanceUnshieldArgs', [fromIncognitoAddress, toPublicAddress, amount, shardT])
const call = createTrustedCall(this, ['balance_unshield', 'BalanceUnshieldArgs'], accountOrPubKey, shardT, mrenclave, nonce, params);
return this.sendTrustedCall(call, shardT, options);
}

async sendTrustedCall(call: IntegriteeTrustedCallSigned, shard: ShardIdentifier, options: CallOptions = {} as CallOptions): Promise<Hash> {
Expand Down

0 comments on commit 2f80f1f

Please sign in to comment.