From 069329060b62782c1a32771397ff036eff325ee0 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 9 Oct 2024 14:15:22 +0200 Subject: [PATCH] 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) + } }