From 2f80f1f31bf8ce34c97df07e8f04096576962f5d Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Thu, 11 Apr 2024 15:26:01 +0800 Subject: [PATCH] [worker] consistent api, create shard identifier internally and take string as arg --- .../worker-api/src/integriteeWorker.spec.ts | 5 ++--- packages/worker-api/src/integriteeWorker.ts | 17 ++++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index e3bb7957..a8019fa9 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -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; @@ -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, @@ -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, diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index 7efb9781..ad90e89e 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -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 { @@ -34,7 +35,7 @@ export class IntegriteeWorker extends Worker { public async trustedBalanceTransfer( accountOrPubKey: KeyringPair | PubKeyPinPair, - shard: ShardIdentifier, + shard: string, mrenclave: string, from: String, to: String, @@ -42,14 +43,15 @@ export class IntegriteeWorker extends Worker { options: CallOptions = {} as CallOptions ): Promise { 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, @@ -57,9 +59,10 @@ export class IntegriteeWorker extends Worker { options: CallOptions = {} as CallOptions ): Promise { 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 {