From d63a88c38c589312e00137d8fc1d468a45953ad9 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 13:36:03 +0200 Subject: [PATCH 01/11] update integritee trusted getter --- .../src/interfaces/integriteeWorker/definitions.ts | 4 +--- .../types/src/interfaces/integriteeWorker/types.ts | 10 +++------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index bd324299..6af7b5ac 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -14,9 +14,7 @@ export default { }, IntegriteeTrustedGetter: { _enum: { - free_balance: 'AccountId', - reserved_balance: 'AccountId', - nonce: 'AccountId', + account_info: 'AccountId', } }, IntegriteeTrustedGetterSigned: { diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index aa239de8..6f88c203 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -75,13 +75,9 @@ export interface IntegriteeTrustedCallSigned extends Struct { /** @name IntegriteeTrustedGetter */ export interface IntegriteeTrustedGetter extends Enum { - readonly isFreeBalance: boolean; - readonly asFreeBalance: AccountId; - readonly isReservedBalance: boolean; - readonly asReservedBalance: AccountId; - readonly isNonce: boolean; - readonly asNonce: AccountId; - readonly type: 'FreeBalance' | 'ReservedBalance' | 'Nonce'; + readonly isAccountInfo: boolean; + readonly asAccountInfo: AccountId; + readonly type: 'AccountInfo'; } /** @name IntegriteeTrustedGetterSigned */ From e3804add908f33473c5bdb81de0bf652a78360af Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 13:58:44 +0200 Subject: [PATCH 02/11] add `getAccountInfo` getter --- .../worker-api/src/integriteeWorker.spec.ts | 35 +++++++---------- packages/worker-api/src/integriteeWorker.ts | 39 +++++++------------ 2 files changed, 27 insertions(+), 47 deletions(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 2a62d8c7..50934875 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -1,6 +1,6 @@ import { Keyring } from '@polkadot/api'; import { cryptoWaitReady } from '@polkadot/util-crypto'; -import { paseoNetwork} from './testUtils/networks.js'; +import {localDockerNetwork} from './testUtils/networks.js'; import { IntegriteeWorker } from './integriteeWorker.js'; import WS from 'websocket'; import {type KeyringPair} from "@polkadot/keyring/types"; @@ -8,7 +8,7 @@ import {type KeyringPair} from "@polkadot/keyring/types"; const {w3cwebsocket: WebSocket} = WS; describe('worker', () => { - const network = paseoNetwork(); + const network = localDockerNetwork(); let keyring: Keyring; let worker: IntegriteeWorker; let alice: KeyringPair; @@ -39,7 +39,7 @@ describe('worker', () => { // skip it, as this requires a worker (and hence a node) to be running // To my knowledge jest does not have an option to run skipped tests specifically, does it? // Todo: add proper CI to test this too. - describe.skip('needs worker and node running', () => { + describe('needs worker and node running', () => { describe('getWorkerPubKey', () => { it('should return value', async () => { const result = await worker.getShieldingKey(); @@ -56,38 +56,29 @@ describe('worker', () => { }); }); - describe('getBalance', () => { + describe('getNonce', () => { it('should return value', async () => { - const result = await worker.getBalance(charlie, network.mrenclave); - console.log('getBalance toNumber:', result.toString(10)); + const result = await worker.getNonce(alice, network.mrenclave); + console.log('getAccountInfo', result); expect(result).toBeDefined(); }); }); - describe('getBalanceGetter', () => { - it('should return value', async () => { - const getter = await worker.getBalanceGetter(charlie, network.mrenclave); - console.log(`BalanceGetter: ${JSON.stringify(getter)}`); - const result = await getter.send(); - console.log('getBalance toNumber:', result.toString(10)); - expect(result).toBeDefined(); - }); - }); - describe('getNonce', () => { + describe('getAccountInfo', () => { it('should return value', async () => { - const result = await worker.getNonce(alice, network.mrenclave); - console.log('getNonce', result); + const result = await worker.getAccountInfo(alice, network.mrenclave); + console.log('getAccountInfo', result); expect(result).toBeDefined(); }); }); - describe('getNonceGetter', () => { + describe('getAccountInfoGetter', () => { it('should return value', async () => { - const getter = await worker.getNonceGetter(charlie, network.mrenclave); - console.log(`NonceGetter: ${JSON.stringify(getter)}`); + const getter = await worker.getAccountInfoGetter(charlie, network.mrenclave); + console.log(`AccountInfoGetter: ${JSON.stringify(getter)}`); const result = await getter.send(); - console.log('getNonce', result); + console.log('getAccountInfo', result); expect(result).toBeDefined(); }); }); diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index efb7e666..0d26fb44 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -1,6 +1,4 @@ -import type {u32} from '@polkadot/types'; - -import type {Balance, Hash} from '@polkadot/types/interfaces/runtime'; +import type {Hash} from '@polkadot/types/interfaces/runtime'; import type { ShardIdentifier, IntegriteeTrustedCallSigned, IntegriteeGetter, } from '@encointer/types'; @@ -20,41 +18,31 @@ import { } from "./requests.js"; import bs58 from "bs58"; import type {AddressOrPair} from "@polkadot/api-base/types/submittable"; +import type { AccountInfo } from "@polkadot/types/interfaces/system"; +import type {u32} from "@polkadot/types-codec"; export class IntegriteeWorker extends Worker { public async getNonce(accountOrPubKey: AddressOrPair, shard: string, singerOptions?: TrustedSignerOptions, requestOptions?: RequestOptions): Promise { - return await callGetter(this, [Request.TrustedGetter, 'nonce', 'u32'], { - shard: shard, - account: accountOrPubKey, - signer: singerOptions?.signer - }, requestOptions) + const info = await this.getAccountInfo(accountOrPubKey, shard, singerOptions, requestOptions); + return info.nonce; } - public async getNonceGetter(accountOrPubKey: AddressOrPair, shard: string, signerOptions?: TrustedSignerOptions): Promise> { - const trustedGetterArgs = { + public async getAccountInfo(accountOrPubKey: AddressOrPair, shard: string, singerOptions?: TrustedSignerOptions, requestOptions?: RequestOptions): Promise { + return await callGetter(this, [Request.TrustedGetter, 'account_info', 'AccountInfo'], { shard: shard, account: accountOrPubKey, - signer: signerOptions?.signer, - } - return await submittableGetter(this, 'nonce', trustedGetterArgs,'u32'); - } - - public async getBalance(accountOrPubKey: AddressOrPair, shard: string, signerOptions?: TrustedSignerOptions, requestOptions?: RequestOptions): Promise { - return await callGetter(this, [Request.TrustedGetter, 'free_balance', 'Balance'], { - shard: shard, - account: accountOrPubKey, - signer: signerOptions?.signer + signer: singerOptions?.signer }, requestOptions) } - public async getBalanceGetter(accountOrPubKey: AddressOrPair, shard: string, signerOptions?: TrustedSignerOptions): Promise> { + public async getAccountInfoGetter(accountOrPubKey: AddressOrPair, shard: string, signerOptions?: TrustedSignerOptions): Promise> { const trustedGetterArgs = { shard: shard, account: accountOrPubKey, - signer: signerOptions?.signer + signer: signerOptions?.signer, } - return await submittableGetter(this, 'free_balance', trustedGetterArgs,'Balance'); + return await submittableGetter(this, 'account_info', trustedGetterArgs,'AccountInfo'); } public async trustedBalanceTransfer( @@ -67,7 +55,7 @@ export class IntegriteeWorker extends Worker { signerOptions?: TrustedSignerOptions, requestOptions?: RequestOptions, ): Promise { - const nonce = signerOptions?.nonce ?? await this.getNonce(account, shard, signerOptions, requestOptions); + const nonce = signerOptions?.nonce ?? await this.getNonce(account, shard, signerOptions, requestOptions) const shardT = this.createType('ShardIdentifier', bs58.decode(shard)); const params = this.createType('BalanceTransferArgs', [from, to, amount]) const call = createTrustedCall(this, ['balance_transfer', 'BalanceTransferArgs'], params); @@ -85,7 +73,8 @@ export class IntegriteeWorker extends Worker { signerOptions?: TrustedSignerOptions, requestOptions?: RequestOptions, ): Promise { - const nonce = signerOptions?.nonce ?? await this.getNonce(account, shard, signerOptions, requestOptions); + const nonce = signerOptions?.nonce ?? await this.getNonce(account, shard, signerOptions, requestOptions) + const shardT = this.createType('ShardIdentifier', bs58.decode(shard)); const params = this.createType('BalanceUnshieldArgs', [fromIncognitoAddress, toPublicAddress, amount, shardT]) const call = createTrustedCall(this, ['balance_unshield', 'BalanceUnshieldArgs'], params); From 3bc67e7be571c37256b45bc110e798ecedb0854d Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 14:01:01 +0200 Subject: [PATCH 03/11] fix readme command --- packages/types/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/types/README.md b/packages/types/README.md index dbe257db..ec606644 100644 --- a/packages/types/README.md +++ b/packages/types/README.md @@ -31,8 +31,8 @@ export default { }; ``` -A subsequent `yarn generate:defs` updates the types. +A subsequent `yarn generate:types` updates the types. To update the polkadot types, upgrade the `@polkadot/types` package and generate the types again. -The type generation process is elaborated on in the polkadot.{js} [docs](https://polkadot.js.org/docs/api/examples/promise/typegen#types-setup). \ No newline at end of file +The type generation process is elaborated on in the polkadot.{js} [docs](https://polkadot.js.org/docs/api/examples/promise/typegen#types-setup). From 7b10058827cf7515785af38db3daa8d356b49b74 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 14:03:58 +0200 Subject: [PATCH 04/11] fix log in tests --- packages/worker-api/src/integriteeWorker.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 50934875..d8b64bba 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -59,7 +59,7 @@ describe('worker', () => { describe('getNonce', () => { it('should return value', async () => { const result = await worker.getNonce(alice, network.mrenclave); - console.log('getAccountInfo', result); + console.log('Nonce', result); expect(result).toBeDefined(); }); }); From 069329060b62782c1a32771397ff036eff325ee0 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 14:15:22 +0200 Subject: [PATCH 05/11] add `author_getFingerprint` --- packages/types/src/interfaces/augment-types.ts | 3 ++- packages/types/src/interfaces/worker/definitions.ts | 1 + packages/types/src/interfaces/worker/types.ts | 5 ++++- packages/worker-api/src/testUtils/networks.ts | 4 ++-- packages/worker-api/src/worker.spec.ts | 12 ++++++++++-- packages/worker-api/src/worker.ts | 6 +++++- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/packages/types/src/interfaces/augment-types.ts b/packages/types/src/interfaces/augment-types.ts index 864fed64..9fc866c2 100644 --- a/packages/types/src/interfaces/augment-types.ts +++ b/packages/types/src/interfaces/augment-types.ts @@ -13,7 +13,7 @@ import type { AnnouncementSigner, Bip340, CidDigest, CidName, CommunityCeremony, import type { EncointerBalanceTransferArgs, EncointerGetter, EncointerGetterArgs, EncointerPublicGetter, EncointerTrustedCall, EncointerTrustedCallSigned, EncointerTrustedGetter, EncointerTrustedGetterSigned, GrantReputationArgs, RegisterAttestationsArgs, RegisterParticipantArgs } from '@encointer/types/interfaces/encointerWorker'; import type { BalanceSetBalanceArgs, BalanceShieldArgs, BalanceTransferArgs, BalanceUnshieldArgs, IntegriteeGetter, IntegriteePublicGetter, IntegriteeTrustedCall, IntegriteeTrustedCallSigned, IntegriteeTrustedGetter, IntegriteeTrustedGetterSigned, IntegriteeTrustedOperation, TimestampSetArgs } from '@encointer/types/interfaces/integriteeWorker'; import type { SchedulerState, SystemNumber } from '@encointer/types/interfaces/scheduler'; -import type { DirectRequestStatus, Enclave, GetterArgs, ParentchainId, Request, RpcReturnValue, ShardIdentifier, TrustedOperationStatus, Vault, WorkerEncoded } from '@encointer/types/interfaces/worker'; +import type { DirectRequestStatus, Enclave, EnclaveFingerprint, GetterArgs, ParentchainId, Request, RpcReturnValue, ShardIdentifier, TrustedOperationStatus, Vault, WorkerEncoded } from '@encointer/types/interfaces/worker'; import type { Data, StorageKey } from '@polkadot/types'; import type { BitVec, Bool, Bytes, F32, F64, I128, I16, I256, I32, I64, I8, ISize, Json, Null, OptionBool, Raw, Text, Type, U128, U16, U256, U32, U64, U8, USize, bool, f32, f64, i128, i16, i256, i32, i64, i8, isize, u128, u16, u256, u32, u64, u8, usize } from '@polkadot/types-codec'; import type { TAssetConversion } from '@polkadot/types/interfaces/assetConversion'; @@ -426,6 +426,7 @@ declare module '@polkadot/types/types/registry' { ElectionSize: ElectionSize; ElectionStatus: ElectionStatus; Enclave: Enclave; + EnclaveFingerprint: EnclaveFingerprint; EncodedFinalityProofs: EncodedFinalityProofs; EncodedJustification: EncodedJustification; EncointerBalanceTransferArgs: EncointerBalanceTransferArgs; diff --git a/packages/types/src/interfaces/worker/definitions.ts b/packages/types/src/interfaces/worker/definitions.ts index 4be7303b..1e046534 100644 --- a/packages/types/src/interfaces/worker/definitions.ts +++ b/packages/types/src/interfaces/worker/definitions.ts @@ -2,6 +2,7 @@ export default { rpc: {}, types: { ShardIdentifier: 'Hash', + EnclaveFingerprint: 'H256', GetterArgs: '(AccountId, CommunityIdentifier)', Enclave: { pubkey: 'AccountId', diff --git a/packages/types/src/interfaces/worker/types.ts b/packages/types/src/interfaces/worker/types.ts index 194f3aca..ec7217a0 100644 --- a/packages/types/src/interfaces/worker/types.ts +++ b/packages/types/src/interfaces/worker/types.ts @@ -4,7 +4,7 @@ import type { CommunityIdentifier } from '@encointer/types/interfaces/community'; import type { Bytes, Enum, Struct, Text, bool, u64 } from '@polkadot/types-codec'; import type { ITuple } from '@polkadot/types-codec/types'; -import type { AccountId, Hash } from '@polkadot/types/interfaces/runtime'; +import type { AccountId, H256, Hash } from '@polkadot/types/interfaces/runtime'; /** @name DirectRequestStatus */ export interface DirectRequestStatus extends Enum { @@ -23,6 +23,9 @@ export interface Enclave extends Struct { readonly url: Text; } +/** @name EnclaveFingerprint */ +export interface EnclaveFingerprint extends H256 {} + /** @name GetterArgs */ export interface GetterArgs extends ITuple<[AccountId, CommunityIdentifier]> {} diff --git a/packages/worker-api/src/testUtils/networks.ts b/packages/worker-api/src/testUtils/networks.ts index a18308de..3d7b0767 100644 --- a/packages/worker-api/src/testUtils/networks.ts +++ b/packages/worker-api/src/testUtils/networks.ts @@ -39,8 +39,8 @@ export const localDockerNetwork = () => { chain: 'ws://127.0.0.1:9944', worker: 'wss://127.0.0.1:2000', genesisHash: '0x388c446a804e24e77ae89f5bb099edb60cacc2ac7c898ce175bdaa08629c1439', - mrenclave: '9jm9Wm4DwGxsUUPA1cvcWWxyTuynpJ2YeEcNGnm8nztk', - chosenCid: '9jm9Wm4DwGxsUUPA1cvcWWxyTuynpJ2YeEcNGnm8nztk', + mrenclave: 'FtNhy2ZvHHDPZxHZY5atVav2VVkoipR3BE6zAbcveUcT', + chosenCid: 'FtNhy2ZvHHDPZxHZY5atVav2VVkoipR3BE6zAbcveUcT', customTypes: {}, palletOverrides: {} }; diff --git a/packages/worker-api/src/worker.spec.ts b/packages/worker-api/src/worker.spec.ts index 4688e7c7..f2973023 100644 --- a/packages/worker-api/src/worker.spec.ts +++ b/packages/worker-api/src/worker.spec.ts @@ -1,13 +1,13 @@ import { Keyring } from '@polkadot/api'; import { cryptoWaitReady } from '@polkadot/util-crypto'; -import { paseoNetwork } from './testUtils/networks.js'; +import {localDockerNetwork} from './testUtils/networks.js'; import { Worker } from './worker.js'; import WS from 'websocket'; const {w3cwebsocket: WebSocket} = WS; describe('worker', () => { - const network = paseoNetwork(); + const network = localDockerNetwork(); let keyring: Keyring; let worker: Worker; beforeAll(async () => { @@ -51,5 +51,13 @@ describe('worker', () => { expect(result).toBeDefined(); }); }); + + describe('getFingerprint', () => { + it('should return value', async () => { + const result = await worker.getFingerprint(); + console.log('Fingerprint', result.toHuman()); + expect(result).toBeDefined(); + }); + }); }); }); diff --git a/packages/worker-api/src/worker.ts b/packages/worker-api/src/worker.ts index cdbfd70d..a954a57a 100644 --- a/packages/worker-api/src/worker.ts +++ b/packages/worker-api/src/worker.ts @@ -9,7 +9,7 @@ import WebSocketAsPromised from 'websocket-as-promised'; import {options as encointerOptions} from '@encointer/node-api'; import {parseI64F64} from '@encointer/util'; -import type {Vault} from '@encointer/types'; +import type {Vault, EnclaveFingerprint} from '@encointer/types'; import {type RequestOptions, type IWorker, Request, type WorkerOptions} from './interface.js'; import {parseBalance} from './parsers.js'; @@ -162,4 +162,8 @@ export class Worker extends WebSocketAsPromised implements IWorker { public async getShardVault(options: RequestOptions = {} as RequestOptions): Promise { return await callGetter(this, [Request.Worker, 'author_getShardVault', 'Vault'], {}, options) } + + public async getFingerprint(options: RequestOptions = {} as RequestOptions): Promise { + return await callGetter(this, [Request.Worker, 'author_getFingerprint', 'EnclaveFingerprint'], {}, options) + } } From 2385e1d2e6c70ee125072f274a9d966cca48e3df Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 14:37:35 +0200 Subject: [PATCH 06/11] add guess the number game trusted call variants --- .../types/src/interfaces/augment-types.ts | 5 +++- .../integriteeWorker/definitions.ts | 16 +++++++---- .../src/interfaces/integriteeWorker/types.ts | 27 ++++++++++++++----- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/packages/types/src/interfaces/augment-types.ts b/packages/types/src/interfaces/augment-types.ts index 9fc866c2..856cc05e 100644 --- a/packages/types/src/interfaces/augment-types.ts +++ b/packages/types/src/interfaces/augment-types.ts @@ -11,7 +11,7 @@ import type { Assignment, AssignmentCount, AssignmentParams, Attestation, Attest import type { FixedI64F64, IpfsCid, PalletString } from '@encointer/types/interfaces/common'; import type { AnnouncementSigner, Bip340, CidDigest, CidName, CommunityCeremony, CommunityIdentifier, CommunityMetadataType, CommunityRules, DegreeFixed, DegreeRpc, GeoHash, Location, LocationRpc, NominalIncomeType } from '@encointer/types/interfaces/community'; import type { EncointerBalanceTransferArgs, EncointerGetter, EncointerGetterArgs, EncointerPublicGetter, EncointerTrustedCall, EncointerTrustedCallSigned, EncointerTrustedGetter, EncointerTrustedGetterSigned, GrantReputationArgs, RegisterAttestationsArgs, RegisterParticipantArgs } from '@encointer/types/interfaces/encointerWorker'; -import type { BalanceSetBalanceArgs, BalanceShieldArgs, BalanceTransferArgs, BalanceUnshieldArgs, IntegriteeGetter, IntegriteePublicGetter, IntegriteeTrustedCall, IntegriteeTrustedCallSigned, IntegriteeTrustedGetter, IntegriteeTrustedGetterSigned, IntegriteeTrustedOperation, TimestampSetArgs } from '@encointer/types/interfaces/integriteeWorker'; +import type { BalanceSetBalanceArgs, BalanceShieldArgs, BalanceTransferArgs, BalanceUnshieldArgs, GuessTheNumberArgs, GuessTheNumberSetWinningsArgs, GuessType, IntegriteeGetter, IntegriteePublicGetter, IntegriteeTrustedCall, IntegriteeTrustedCallSigned, IntegriteeTrustedGetter, IntegriteeTrustedGetterSigned, IntegriteeTrustedOperation, TimestampSetArgs } from '@encointer/types/interfaces/integriteeWorker'; import type { SchedulerState, SystemNumber } from '@encointer/types/interfaces/scheduler'; import type { DirectRequestStatus, Enclave, EnclaveFingerprint, GetterArgs, ParentchainId, Request, RpcReturnValue, ShardIdentifier, TrustedOperationStatus, Vault, WorkerEncoded } from '@encointer/types/interfaces/worker'; import type { Data, StorageKey } from '@polkadot/types'; @@ -594,6 +594,9 @@ declare module '@polkadot/types/types/registry' { GrantReputationArgs: GrantReputationArgs; GroupIndex: GroupIndex; GroupRotationInfo: GroupRotationInfo; + GuessTheNumberArgs: GuessTheNumberArgs; + GuessTheNumberSetWinningsArgs: GuessTheNumberSetWinningsArgs; + GuessType: GuessType; H1024: H1024; H128: H128; H160: H160; diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index 6af7b5ac..3eee0b13 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -42,17 +42,23 @@ export default { IntegriteeTrustedCall: { _enum: { noop: 'AccountId', - balance_set_balance: 'BalanceSetBalanceArgs', + timestamp_set: 'TimestampSetArgs', balance_transfer: 'BalanceTransferArgs', balance_unshield: 'BalanceUnshieldArgs', balance_shield: 'BalanceShieldArgs', - timestamp_set: 'TimestampSetArgs', + guess_the_number_set_winnings: 'GuessTheNumberSetWinningsArgs', + guess_the_number_push_by_one_day: 'AccountId', + guess_the_number: 'GuessTheNumberArgs', + balance_set_balance: 'BalanceSetBalanceArgs', } }, - BalanceSetBalanceArgs: '(AccountId, AccountId, BalanceType, BalanceType)', + GuessType: 'u32', + GuessTheNumberSetWinningsArgs: '(AccountId, Balance)', + GuessTheNumberArgs: '(AccountId, GuessType)', + TimestampSetArgs: '(AccountId, H160, BalanceType)', BalanceTransferArgs: '(AccountId, AccountId, BalanceType)', - BalanceUnshieldArgs: '(AccountId, AccountId, BalanceType, ShardIdentifier)', BalanceShieldArgs: '(AccountId, AccountId, BalanceType, ParentchainId)', - TimestampSetArgs: '(AccountId, H160, BalanceType)', + BalanceUnshieldArgs: '(AccountId, AccountId, BalanceType, ShardIdentifier)', + BalanceSetBalanceArgs: '(AccountId, AccountId, BalanceType, BalanceType)', } } diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index 6f88c203..428de780 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -7,7 +7,7 @@ import type { ParentchainId, ShardIdentifier } from '@encointer/types/interfaces import type { Enum, Struct, u32 } from '@polkadot/types-codec'; import type { ITuple } from '@polkadot/types-codec/types'; import type { MultiSignature } from '@polkadot/types/interfaces/extrinsics'; -import type { AccountId, H160 } from '@polkadot/types/interfaces/runtime'; +import type { AccountId, Balance, H160 } from '@polkadot/types/interfaces/runtime'; /** @name BalanceSetBalanceArgs */ export interface BalanceSetBalanceArgs extends ITuple<[AccountId, AccountId, BalanceType, BalanceType]> {} @@ -21,6 +21,15 @@ export interface BalanceTransferArgs extends ITuple<[AccountId, AccountId, Balan /** @name BalanceUnshieldArgs */ export interface BalanceUnshieldArgs extends ITuple<[AccountId, AccountId, BalanceType, ShardIdentifier]> {} +/** @name GuessTheNumberArgs */ +export interface GuessTheNumberArgs extends ITuple<[AccountId, GuessType]> {} + +/** @name GuessTheNumberSetWinningsArgs */ +export interface GuessTheNumberSetWinningsArgs extends ITuple<[AccountId, Balance]> {} + +/** @name GuessType */ +export interface GuessType extends u32 {} + /** @name IntegriteeGetter */ export interface IntegriteeGetter extends Enum { readonly isPublic: boolean; @@ -53,17 +62,23 @@ export interface IntegriteePublicGetter extends Enum { export interface IntegriteeTrustedCall extends Enum { readonly isNoop: boolean; readonly asNoop: AccountId; - readonly isBalanceSetBalance: boolean; - readonly asBalanceSetBalance: BalanceSetBalanceArgs; + readonly isTimestampSet: boolean; + readonly asTimestampSet: TimestampSetArgs; readonly isBalanceTransfer: boolean; readonly asBalanceTransfer: BalanceTransferArgs; readonly isBalanceUnshield: boolean; readonly asBalanceUnshield: BalanceUnshieldArgs; readonly isBalanceShield: boolean; readonly asBalanceShield: BalanceShieldArgs; - readonly isTimestampSet: boolean; - readonly asTimestampSet: TimestampSetArgs; - readonly type: 'Noop' | 'BalanceSetBalance' | 'BalanceTransfer' | 'BalanceUnshield' | 'BalanceShield' | 'TimestampSet'; + readonly isGuessTheNumberSetWinnings: boolean; + readonly asGuessTheNumberSetWinnings: GuessTheNumberSetWinningsArgs; + readonly isGuessTheNumberPushByOneDay: boolean; + readonly asGuessTheNumberPushByOneDay: AccountId; + readonly isGuessTheNumber: boolean; + readonly asGuessTheNumber: GuessTheNumberArgs; + readonly isBalanceSetBalance: boolean; + readonly asBalanceSetBalance: BalanceSetBalanceArgs; + readonly type: 'Noop' | 'TimestampSet' | 'BalanceTransfer' | 'BalanceUnshield' | 'BalanceShield' | 'GuessTheNumberSetWinnings' | 'GuessTheNumberPushByOneDay' | 'GuessTheNumber' | 'BalanceSetBalance'; } /** @name IntegriteeTrustedCallSigned */ From 43813a00be3fd5f2d9455ccccf5be3aba12d6818 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 14:40:57 +0200 Subject: [PATCH 07/11] add guess the number trusted call method --- .../worker-api/src/integriteeWorker.spec.ts | 15 +++++++++++++++ packages/worker-api/src/integriteeWorker.ts | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index d8b64bba..fbe2288c 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -115,5 +115,20 @@ describe('worker', () => { expect(result).toBeDefined(); }); }); + + describe('guess the number should work', () => { + it('should return value', async () => { + const shard = network.chosenCid; + + const result = await worker.guessTheNumber( + alice, + shard, + network.mrenclave, + 1, + ); + console.log('guess the number result', result.toHuman()); + expect(result).toBeDefined(); + }); + }); }); }); diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index 0d26fb44..732f92cf 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -20,6 +20,7 @@ import bs58 from "bs58"; import type {AddressOrPair} from "@polkadot/api-base/types/submittable"; import type { AccountInfo } from "@polkadot/types/interfaces/system"; import type {u32} from "@polkadot/types-codec"; +import {asString} from "@encointer/util"; export class IntegriteeWorker extends Worker { @@ -82,6 +83,23 @@ export class IntegriteeWorker extends Worker { return this.sendTrustedCall(signed, shardT, requestOptions); } + public async guessTheNumber( + account: AddressOrPair, + shard: string, + mrenclave: string, + guess: number, + signerOptions?: TrustedSignerOptions, + requestOptions?: RequestOptions, + ): Promise { + const nonce = signerOptions?.nonce ?? await this.getNonce(account, shard, signerOptions, requestOptions) + + const shardT = this.createType('ShardIdentifier', bs58.decode(shard)); + const params = this.createType('GuessTheNumberArgs', [asString(account), guess]) + const call = createTrustedCall(this, ['guess_the_number', 'GuessTheNumberArgs'], params); + const signed = await signTrustedCall(this, call, account, shardT, mrenclave, nonce, signerOptions); + return this.sendTrustedCall(signed, shardT, requestOptions); + } + async sendTrustedCall(call: IntegriteeTrustedCallSigned, shard: ShardIdentifier, requestOptions?: RequestOptions): Promise { if (this.shieldingKey() == undefined) { console.log(`[sentTrustedCall] Setting the shielding pubKey of the worker.`) From f199c113407f4dbdfbb593caf50322d88f00d097 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 14:44:50 +0200 Subject: [PATCH 08/11] add guess the number public getter variant --- .../integriteeWorker/definitions.ts | 10 +++------- .../src/interfaces/integriteeWorker/types.ts | 20 ++++--------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index 3eee0b13..a09c2dc5 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -3,13 +3,9 @@ export default { types: { IntegriteePublicGetter: { _enum: { - total_issuance: 'CommunityIdentifier', - participant_count: 'CommunityIdentifier', - meetup_count: 'CommunityIdentifier', - ceremony_reward: 'CommunityIdentifier', - location_tolerance: 'CommunityIdentifier', - time_tolerance: 'CommunityIdentifier', - scheduler_state: 'CommunityIdentifier' + guess_the_number_last_lucky_number: null, + guess_the_number_last_winning_distance: null, + guess_the_number_info: null, } }, IntegriteeTrustedGetter: { diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index 428de780..64922afd 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -2,7 +2,6 @@ /* eslint-disable */ import type { BalanceType } from '@encointer/types/interfaces/balances'; -import type { CommunityIdentifier } from '@encointer/types/interfaces/community'; import type { ParentchainId, ShardIdentifier } from '@encointer/types/interfaces/worker'; import type { Enum, Struct, u32 } from '@polkadot/types-codec'; import type { ITuple } from '@polkadot/types-codec/types'; @@ -41,21 +40,10 @@ export interface IntegriteeGetter extends Enum { /** @name IntegriteePublicGetter */ export interface IntegriteePublicGetter extends Enum { - readonly isTotalIssuance: boolean; - readonly asTotalIssuance: CommunityIdentifier; - readonly isParticipantCount: boolean; - readonly asParticipantCount: CommunityIdentifier; - readonly isMeetupCount: boolean; - readonly asMeetupCount: CommunityIdentifier; - readonly isCeremonyReward: boolean; - readonly asCeremonyReward: CommunityIdentifier; - readonly isLocationTolerance: boolean; - readonly asLocationTolerance: CommunityIdentifier; - readonly isTimeTolerance: boolean; - readonly asTimeTolerance: CommunityIdentifier; - readonly isSchedulerState: boolean; - readonly asSchedulerState: CommunityIdentifier; - readonly type: 'TotalIssuance' | 'ParticipantCount' | 'MeetupCount' | 'CeremonyReward' | 'LocationTolerance' | 'TimeTolerance' | 'SchedulerState'; + readonly isGuessTheNumberLastLuckyNumber: boolean; + readonly isGuessTheNumberLastWinningDistance: boolean; + readonly isGuessTheNumberInfo: boolean; + readonly type: 'GuessTheNumberLastLuckyNumber' | 'GuessTheNumberLastWinningDistance' | 'GuessTheNumberInfo'; } /** @name IntegriteeTrustedCall */ From 6ef39c28c063ab575dbc01cd67979c5de1d0c27f Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 15:21:47 +0200 Subject: [PATCH 09/11] implement guess the number public getters --- .../types/src/interfaces/augment-types.ts | 3 +- .../integriteeWorker/definitions.ts | 9 +++++ .../src/interfaces/integriteeWorker/types.ts | 15 ++++++-- packages/worker-api/src/integriteeWorker.ts | 35 +++++++++++++++++-- packages/worker-api/src/interface.ts | 2 +- packages/worker-api/src/requests.ts | 14 +++++--- packages/worker-api/src/worker.spec.ts | 2 +- 7 files changed, 67 insertions(+), 13 deletions(-) diff --git a/packages/types/src/interfaces/augment-types.ts b/packages/types/src/interfaces/augment-types.ts index 856cc05e..04f2af88 100644 --- a/packages/types/src/interfaces/augment-types.ts +++ b/packages/types/src/interfaces/augment-types.ts @@ -11,7 +11,7 @@ import type { Assignment, AssignmentCount, AssignmentParams, Attestation, Attest import type { FixedI64F64, IpfsCid, PalletString } from '@encointer/types/interfaces/common'; import type { AnnouncementSigner, Bip340, CidDigest, CidName, CommunityCeremony, CommunityIdentifier, CommunityMetadataType, CommunityRules, DegreeFixed, DegreeRpc, GeoHash, Location, LocationRpc, NominalIncomeType } from '@encointer/types/interfaces/community'; import type { EncointerBalanceTransferArgs, EncointerGetter, EncointerGetterArgs, EncointerPublicGetter, EncointerTrustedCall, EncointerTrustedCallSigned, EncointerTrustedGetter, EncointerTrustedGetterSigned, GrantReputationArgs, RegisterAttestationsArgs, RegisterParticipantArgs } from '@encointer/types/interfaces/encointerWorker'; -import type { BalanceSetBalanceArgs, BalanceShieldArgs, BalanceTransferArgs, BalanceUnshieldArgs, GuessTheNumberArgs, GuessTheNumberSetWinningsArgs, GuessType, IntegriteeGetter, IntegriteePublicGetter, IntegriteeTrustedCall, IntegriteeTrustedCallSigned, IntegriteeTrustedGetter, IntegriteeTrustedGetterSigned, IntegriteeTrustedOperation, TimestampSetArgs } from '@encointer/types/interfaces/integriteeWorker'; +import type { BalanceSetBalanceArgs, BalanceShieldArgs, BalanceTransferArgs, BalanceUnshieldArgs, GuessTheNumberArgs, GuessTheNumberInfo, GuessTheNumberSetWinningsArgs, GuessType, IntegriteeGetter, IntegriteePublicGetter, IntegriteeTrustedCall, IntegriteeTrustedCallSigned, IntegriteeTrustedGetter, IntegriteeTrustedGetterSigned, IntegriteeTrustedOperation, TimestampSetArgs } from '@encointer/types/interfaces/integriteeWorker'; import type { SchedulerState, SystemNumber } from '@encointer/types/interfaces/scheduler'; import type { DirectRequestStatus, Enclave, EnclaveFingerprint, GetterArgs, ParentchainId, Request, RpcReturnValue, ShardIdentifier, TrustedOperationStatus, Vault, WorkerEncoded } from '@encointer/types/interfaces/worker'; import type { Data, StorageKey } from '@polkadot/types'; @@ -595,6 +595,7 @@ declare module '@polkadot/types/types/registry' { GroupIndex: GroupIndex; GroupRotationInfo: GroupRotationInfo; GuessTheNumberArgs: GuessTheNumberArgs; + GuessTheNumberInfo: GuessTheNumberInfo; GuessTheNumberSetWinningsArgs: GuessTheNumberSetWinningsArgs; GuessType: GuessType; H1024: H1024; diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index a09c2dc5..d8e75f79 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -49,6 +49,15 @@ export default { } }, GuessType: 'u32', + GuessTheNumberInfo: { + account: 'AccountId', + balance: 'Balance', + winnings: 'Balance', + next_round_timestamp: 'Moment', + last_winners: 'Vec', + maybe_last_lucky_number: 'Option', + maybe_last_winning_distance: 'Option', + }, GuessTheNumberSetWinningsArgs: '(AccountId, Balance)', GuessTheNumberArgs: '(AccountId, GuessType)', TimestampSetArgs: '(AccountId, H160, BalanceType)', diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index 64922afd..3cfa1a62 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -3,10 +3,10 @@ import type { BalanceType } from '@encointer/types/interfaces/balances'; import type { ParentchainId, ShardIdentifier } from '@encointer/types/interfaces/worker'; -import type { Enum, Struct, u32 } from '@polkadot/types-codec'; +import type { Enum, Option, Struct, Vec, u32 } from '@polkadot/types-codec'; import type { ITuple } from '@polkadot/types-codec/types'; import type { MultiSignature } from '@polkadot/types/interfaces/extrinsics'; -import type { AccountId, Balance, H160 } from '@polkadot/types/interfaces/runtime'; +import type { AccountId, Balance, H160, Moment } from '@polkadot/types/interfaces/runtime'; /** @name BalanceSetBalanceArgs */ export interface BalanceSetBalanceArgs extends ITuple<[AccountId, AccountId, BalanceType, BalanceType]> {} @@ -23,6 +23,17 @@ export interface BalanceUnshieldArgs extends ITuple<[AccountId, AccountId, Balan /** @name GuessTheNumberArgs */ export interface GuessTheNumberArgs extends ITuple<[AccountId, GuessType]> {} +/** @name GuessTheNumberInfo */ +export interface GuessTheNumberInfo extends Struct { + readonly account: AccountId; + readonly balance: Balance; + readonly winnings: Balance; + readonly next_round_timestamp: Moment; + readonly last_winners: Vec; + readonly maybe_last_lucky_number: Option; + readonly maybe_last_winning_distance: Option; +} + /** @name GuessTheNumberSetWinningsArgs */ export interface GuessTheNumberSetWinningsArgs extends ITuple<[AccountId, Balance]> {} diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index 732f92cf..af09ce95 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -1,17 +1,17 @@ import type {Hash} from '@polkadot/types/interfaces/runtime'; import type { - ShardIdentifier, IntegriteeTrustedCallSigned, IntegriteeGetter, + ShardIdentifier, IntegriteeTrustedCallSigned, IntegriteeGetter, GuessType, GuessTheNumberArgs, GuessTheNumberInfo, } from '@encointer/types'; import { type RequestOptions, type ISubmittableGetter, Request, - type JsonRpcRequest, type TrustedGetterArgs, type TrustedSignerOptions, + type JsonRpcRequest, type TrustedGetterArgs, type TrustedSignerOptions, type PublicGetterArgs, } from './interface.js'; import {Worker} from "./worker.js"; import {callGetter, sendTrustedCall, sendWorkerRequest} from './sendRequest.js'; import { - createGetterRpc, + createGetterRpc, createIntegriteeGetterPublic, createSignedGetter, createTrustedCall, signTrustedCall, @@ -46,6 +46,28 @@ export class IntegriteeWorker extends Worker { return await submittableGetter(this, 'account_info', trustedGetterArgs,'AccountInfo'); } + public getGuessTheNumberLastLuckyNumberGetter(shard: string): SubmittableGetter { + const publicGetterArgs = { + shard: shard, + } + return submittablePublicGetter(this, 'guess_the_number_last_lucky_number', publicGetterArgs,'GuessType'); + } + + public getGuessTheNumberWinningDistanceGetter(shard: string): SubmittableGetter { + const publicGetterArgs = { + shard: shard, + } + return submittablePublicGetter(this, 'guess_the_number_last_winning_distance', publicGetterArgs,'GuessType'); + } + + + public getGuessTheNumberInfoGetter(shard: string): SubmittableGetter { + const publicGetterArgs = { + shard: shard, + } + return submittablePublicGetter(this, 'guess_the_number_info', publicGetterArgs,'GuessTheNumberInfo'); + } + public async trustedBalanceTransfer( account: AddressOrPair, shard: string, @@ -139,3 +161,10 @@ export const submittableGetter = async (self: W, request: s const signedGetter = await createSignedGetter(self, request, account, { signer: args?.signer }) return new SubmittableGetter(self, shardT, signedGetter, returnType); } + +export const submittablePublicGetter = (self: W, request: string, args: PublicGetterArgs, returnType: string)=> { + const {shard} = args; + const shardT = self.createType('ShardIdentifier', bs58.decode(shard)); + const signedGetter = createIntegriteeGetterPublic(self, request) + return new SubmittableGetter(self, shardT, signedGetter, returnType); +} diff --git a/packages/worker-api/src/interface.ts b/packages/worker-api/src/interface.ts index c6f9bc05..f42f111a 100644 --- a/packages/worker-api/src/interface.ts +++ b/packages/worker-api/src/interface.ts @@ -74,7 +74,7 @@ export interface TrustedSignerOptions { } export interface PublicGetterArgs { - cid: string; + shard: string; } export type RequestArgs = PublicGetterArgs | TrustedGetterArgs | { } diff --git a/packages/worker-api/src/requests.ts b/packages/worker-api/src/requests.ts index 21969b3c..fc87ce4a 100644 --- a/packages/worker-api/src/requests.ts +++ b/packages/worker-api/src/requests.ts @@ -19,11 +19,16 @@ import type {u32} from "@polkadot/types"; import bs58 from "bs58"; import type {AddressOrPair} from "@polkadot/api-base/types/submittable"; -// Todo: Properly resolve cid vs shard export const clientRequestGetterRpc = (self: IWorker, request: string, args: PublicGetterArgs) => { - const {cid} = args; + const {shard} = args; + const getter = createIntegriteeGetterPublic(self, request); + const shardT = self.createType('ShardIdentifier', bs58.decode(shard)); + return createGetterRpc(self, getter, shardT); +} + +export const createIntegriteeGetterPublic = (self: IWorker, request: string) => { const getter = self.createType('IntegriteePublicGetter', { - [request]: cid + [request]: null }); const g = self.createType('IntegriteeGetter', { @@ -31,9 +36,8 @@ export const clientRequestGetterRpc = (self: IWorker, request: string, args: Pub getter, } }); - const shardT = self.createType('ShardIdentifier', bs58.decode(cid)); - return createGetterRpc(self, g, shardT); + return g; } export const clientRequestTrustedGetterRpc = async (self: IWorker, request: string, args: TrustedGetterArgs) => { diff --git a/packages/worker-api/src/worker.spec.ts b/packages/worker-api/src/worker.spec.ts index f2973023..73c5d7d7 100644 --- a/packages/worker-api/src/worker.spec.ts +++ b/packages/worker-api/src/worker.spec.ts @@ -26,7 +26,7 @@ describe('worker', () => { undefined, // Allow the worker's self-signed certificate, needed in non-reverse proxy setups // where we talk to the worker directly. - // { rejectUnauthorized: false } + { rejectUnauthorized: false } ), api: null, }); From d07c0d2e11ef503f3ebf94d581e357bf1f0331a0 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 15:47:01 +0200 Subject: [PATCH 10/11] debug author_getFingerprint --- .../worker-api/src/integriteeWorker.spec.ts | 94 +++++++++---------- packages/worker-api/src/integriteeWorker.ts | 2 +- packages/worker-api/src/worker.spec.ts | 6 +- packages/worker-api/src/worker.ts | 2 +- 4 files changed, 54 insertions(+), 50 deletions(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index fbe2288c..980ddbcf 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -83,52 +83,52 @@ describe('worker', () => { }); }); - describe('balance transfer should work', () => { - it('should return value', async () => { - const shard = network.chosenCid; - const result = await worker.trustedBalanceTransfer( - alice, - shard, - network.mrenclave, - alice.address, - charlie.address, - 1100000000000 - ); - console.log('balance transfer result', result.toHuman()); - expect(result).toBeDefined(); - }); - }); - - describe('balance unshield should work', () => { - it('should return value', async () => { - const shard = network.chosenCid; - - const result = await worker.balanceUnshieldFunds( - alice, - shard, - network.mrenclave, - alice.address, - charlie.address, - 1100000000000, - ); - console.log('balance unshield result', result.toHuman()); - expect(result).toBeDefined(); - }); - }); - - describe('guess the number should work', () => { - it('should return value', async () => { - const shard = network.chosenCid; - - const result = await worker.guessTheNumber( - alice, - shard, - network.mrenclave, - 1, - ); - console.log('guess the number result', result.toHuman()); - expect(result).toBeDefined(); - }); - }); + // describe('balance transfer should work', () => { + // it('should return value', async () => { + // const shard = network.chosenCid; + // const result = await worker.trustedBalanceTransfer( + // alice, + // shard, + // network.mrenclave, + // alice.address, + // charlie.address, + // 1100000000000 + // ); + // console.log('balance transfer result', result.toHuman()); + // expect(result).toBeDefined(); + // }); + // }); + // + // describe('balance unshield should work', () => { + // it('should return value', async () => { + // const shard = network.chosenCid; + // + // const result = await worker.balanceUnshieldFunds( + // alice, + // shard, + // network.mrenclave, + // alice.address, + // charlie.address, + // 1100000000000, + // ); + // console.log('balance unshield result', result.toHuman()); + // expect(result).toBeDefined(); + // }); + // }); + // + // describe('guess the number should work', () => { + // it('should return value', async () => { + // const shard = network.chosenCid; + // + // const result = await worker.guessTheNumber( + // alice, + // shard, + // network.mrenclave, + // 1, + // ); + // console.log('guess the number result', result.toHuman()); + // expect(result).toBeDefined(); + // }); + // }); }); }); diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index af09ce95..ab4d32bd 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -1,6 +1,6 @@ import type {Hash} from '@polkadot/types/interfaces/runtime'; import type { - ShardIdentifier, IntegriteeTrustedCallSigned, IntegriteeGetter, GuessType, GuessTheNumberArgs, GuessTheNumberInfo, + ShardIdentifier, IntegriteeTrustedCallSigned, IntegriteeGetter, GuessType, GuessTheNumberInfo, } from '@encointer/types'; import { type RequestOptions, diff --git a/packages/worker-api/src/worker.spec.ts b/packages/worker-api/src/worker.spec.ts index 73c5d7d7..bc201dbe 100644 --- a/packages/worker-api/src/worker.spec.ts +++ b/packages/worker-api/src/worker.spec.ts @@ -3,6 +3,7 @@ import { cryptoWaitReady } from '@polkadot/util-crypto'; import {localDockerNetwork} from './testUtils/networks.js'; import { Worker } from './worker.js'; import WS from 'websocket'; +import bs58 from "bs58"; const {w3cwebsocket: WebSocket} = WS; @@ -55,7 +56,10 @@ describe('worker', () => { describe('getFingerprint', () => { it('should return value', async () => { const result = await worker.getFingerprint(); - console.log('Fingerprint', result.toHuman()); + // console.log('Fingerprint', result); + + const f = worker.createType('EnclaveFingerPrint', bs58.decode(result.toString())) + console.log('Fingerprint1', f); expect(result).toBeDefined(); }); }); diff --git a/packages/worker-api/src/worker.ts b/packages/worker-api/src/worker.ts index a954a57a..81729ecc 100644 --- a/packages/worker-api/src/worker.ts +++ b/packages/worker-api/src/worker.ts @@ -9,7 +9,7 @@ import WebSocketAsPromised from 'websocket-as-promised'; import {options as encointerOptions} from '@encointer/node-api'; import {parseI64F64} from '@encointer/util'; -import type {Vault, EnclaveFingerprint} from '@encointer/types'; +import type {EnclaveFingerprint, Vault} from '@encointer/types'; import {type RequestOptions, type IWorker, Request, type WorkerOptions} from './interface.js'; import {parseBalance} from './parsers.js'; From 24ba8aca7732e09f6272f314e6427cd37f07c48f Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 15:51:55 +0200 Subject: [PATCH 11/11] fix author_getFingerprint --- packages/worker-api/src/worker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/worker-api/src/worker.ts b/packages/worker-api/src/worker.ts index 81729ecc..b94ea87e 100644 --- a/packages/worker-api/src/worker.ts +++ b/packages/worker-api/src/worker.ts @@ -63,7 +63,7 @@ const parseGetterResponse = (self: IWorker, responseType: string, data: string) console.log(`Got shielding key: ${jsonStr.toJSON().substring(2)}`); parsedData = parseWebCryptoRSA(jsonStr.toJSON().substring(2)); break - case 'Vault': + case 'Vault' || 'EnclaveFingerprint': parsedData = self.createType(responseType, returnValue.value); break case 'TrustedOperationResult':