From b91e9721f2f4a5d364f4d2fa116313ea0432bc87 Mon Sep 17 00:00:00 2001 From: clangenb <37865735+clangenb@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:30:40 +0200 Subject: [PATCH] Add `guessTheNumber` and `getParentchainsInfo` to the integritee worker (#113) * add guess the number game trusted call variants * add guess the number trusted call method * add guess the number public getter variant * implement guess the number public getters * successfully submit the guess the number trusted call. * define remaining trusted getters/calls * implement guess the number trusted/public getters * fix getAccountInfoGetter * fix guess the number definitions * fix getting guess attempts, get the number info getter fails to be constructed for some reason. * fix getting the info of the guess game * more consistent naming * add parentchainsInfo getter * rename GuessTheNumberArgs to guessArgs * add skip to worker test * v0.15.1-alpha.1 --- lerna.json | 2 +- packages/node-api/package.json | 4 +- packages/types/package.json | 2 +- .../types/src/interfaces/augment-types.ts | 14 +- .../integriteeWorker/definitions.ts | 195 ++++++++++++++- .../src/interfaces/integriteeWorker/types.ts | 229 ++++++++++++++++-- .../src/interfaces/worker/definitions.ts | 14 ++ packages/types/src/interfaces/worker/types.ts | 22 +- packages/util/package.json | 2 +- packages/worker-api/package.json | 8 +- .../worker-api/src/integriteeWorker.spec.ts | 52 +++- packages/worker-api/src/integriteeWorker.ts | 121 +++++++-- packages/worker-api/src/interface.ts | 13 +- packages/worker-api/src/requests.ts | 39 +-- packages/worker-api/src/sendRequest.ts | 23 +- packages/worker-api/src/testUtils/networks.ts | 4 +- yarn.lock | 14 +- 17 files changed, 633 insertions(+), 125 deletions(-) diff --git a/lerna.json b/lerna.json index 147c2e29..88b2a0c6 100644 --- a/lerna.json +++ b/lerna.json @@ -6,5 +6,5 @@ "publishConfig": { "directory": "build" }, - "version": "0.15.1-alpha.0" + "version": "0.15.1-alpha.1" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index cee880cf..37abb6e8 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -18,10 +18,10 @@ }, "sideEffects": false, "type": "module", - "version": "0.15.1-alpha.0", + "version": "0.15.1-alpha.1", "main": "index.js", "dependencies": { - "@encointer/types": "^0.15.1-alpha.0", + "@encointer/types": "^0.15.1-alpha.1", "@polkadot/api": "^11.2.1", "tslib": "^2.6.2" }, diff --git a/packages/types/package.json b/packages/types/package.json index 3a705ff8..7f8d011f 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -18,7 +18,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.15.1-alpha.0", + "version": "0.15.1-alpha.1", "main": "index.js", "scripts": { "generate:defs": "node --experimental-specifier-resolution=node --loader ts-node/esm ../../node_modules/.bin/polkadot-types-from-defs --package @encointer/types/interfaces --input ./src/interfaces", diff --git a/packages/types/src/interfaces/augment-types.ts b/packages/types/src/interfaces/augment-types.ts index 9fc866c2..9b915c0b 100644 --- a/packages/types/src/interfaces/augment-types.ts +++ b/packages/types/src/interfaces/augment-types.ts @@ -11,9 +11,9 @@ 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 { AttemptsArg, BalanceSetBalanceArgs, BalanceShieldArgs, BalanceTransferArgs, BalanceUnshieldArgs, GuessArgs, GuessTheNumberInfo, GuessTheNumberPublicGetter, GuessTheNumberSetWinningsArgs, GuessTheNumberTrustedCall, GuessTheNumberTrustedGetter, 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 { DirectRequestStatus, Enclave, EnclaveFingerprint, GetterArgs, ParentchainId, ParentchainInfo, ParentchainsInfo, 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'; @@ -139,6 +139,7 @@ declare module '@polkadot/types/types/registry' { AssignmentKind: AssignmentKind; AssignmentParams: AssignmentParams; AsyncBackingParams: AsyncBackingParams; + AttemptsArg: AttemptsArg; Attestation: Attestation; AttestationIndexType: AttestationIndexType; AttestedCandidate: AttestedCandidate; @@ -594,6 +595,13 @@ declare module '@polkadot/types/types/registry' { GrantReputationArgs: GrantReputationArgs; GroupIndex: GroupIndex; GroupRotationInfo: GroupRotationInfo; + GuessArgs: GuessArgs; + GuessTheNumberInfo: GuessTheNumberInfo; + GuessTheNumberPublicGetter: GuessTheNumberPublicGetter; + GuessTheNumberSetWinningsArgs: GuessTheNumberSetWinningsArgs; + GuessTheNumberTrustedCall: GuessTheNumberTrustedCall; + GuessTheNumberTrustedGetter: GuessTheNumberTrustedGetter; + GuessType: GuessType; H1024: H1024; H128: H128; H160: H160; @@ -880,6 +888,8 @@ declare module '@polkadot/types/types/registry' { ParathreadEntry: ParathreadEntry; ParaValidatorIndex: ParaValidatorIndex; ParentchainId: ParentchainId; + ParentchainInfo: ParentchainInfo; + ParentchainsInfo: ParentchainsInfo; ParticipantIndexType: ParticipantIndexType; ParticipantRegistration: ParticipantRegistration; Pays: Pays; diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index 6af7b5ac..575f5cb0 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -3,18 +3,112 @@ 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' + some_value: null, + total_issuance: null, + unused_index_2: null, + unused_index_3: null, + unused_index_4: null, + unused_index_5: null, + unused_index_6: null, + unused_index_7: null, + unused_index_8: null, + unused_index_9: null, + parentchains_info: null, + unused_index_11: null, + unused_index_12: null, + unused_index_13: null, + unused_index_14: null, + unused_index_15: null, + unused_index_16: null, + unused_index_17: null, + unused_index_18: null, + unused_index_19: null, + unused_index_20: null, + unused_index_21: null, + unused_index_22: null, + unused_index_23: null, + unused_index_24: null, + unused_index_25: null, + unused_index_26: null, + unused_index_27: null, + unused_index_28: null, + unused_index_29: null, + unused_index_30: null, + unused_index_31: null, + unused_index_32: null, + unused_index_33: null, + unused_index_34: null, + unused_index_35: null, + unused_index_36: null, + unused_index_37: null, + unused_index_38: null, + unused_index_39: null, + unused_index_40: null, + unused_index_41: null, + unused_index_42: null, + unused_index_43: null, + unused_index_44: null, + unused_index_45: null, + unused_index_46: null, + unused_index_47: null, + unused_index_48: null, + unused_index_49: null, + guess_the_number: 'GuessTheNumberPublicGetter', } }, IntegriteeTrustedGetter: { _enum: { account_info: 'AccountId', + unused_index_1: null, + unused_index_2: null, + unused_index_3: null, + unused_index_4: null, + unused_index_5: null, + unused_index_6: null, + unused_index_7: null, + unused_index_8: null, + unused_index_9: null, + unused_index_10: null, + unused_index_11: null, + unused_index_12: null, + unused_index_13: null, + unused_index_14: null, + unused_index_15: null, + unused_index_16: null, + unused_index_17: null, + unused_index_18: null, + unused_index_19: null, + unused_index_20: null, + unused_index_21: null, + unused_index_22: null, + unused_index_23: null, + unused_index_24: null, + unused_index_25: null, + unused_index_26: null, + unused_index_27: null, + unused_index_28: null, + unused_index_29: null, + unused_index_30: null, + unused_index_31: null, + unused_index_32: null, + unused_index_33: null, + unused_index_34: null, + unused_index_35: null, + unused_index_36: null, + unused_index_37: null, + unused_index_38: null, + unused_index_39: null, + unused_index_40: null, + unused_index_41: null, + unused_index_42: null, + unused_index_43: null, + unused_index_44: null, + unused_index_45: null, + unused_index_46: null, + unused_index_47: null, + unused_index_48: null, + unused_index_49: null, + guess_the_number: 'GuessTheNumberTrustedGetter', } }, IntegriteeTrustedGetterSigned: { @@ -42,17 +136,94 @@ 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', + balance_set_balance: 'BalanceSetBalanceArgs', + unused_index_6: null, + unused_index_7: null, + unused_index_8: null, + unused_index_9: null, + unused_index_10: null, + unused_index_11: null, + unused_index_12: null, + unused_index_13: null, + unused_index_14: null, + unused_index_15: null, + unused_index_16: null, + unused_index_17: null, + unused_index_18: null, + unused_index_19: null, + unused_index_20: null, + unused_index_21: null, + unused_index_22: null, + unused_index_23: null, + unused_index_24: null, + unused_index_25: null, + unused_index_26: null, + unused_index_27: null, + unused_index_28: null, + unused_index_29: null, + unused_index_30: null, + unused_index_31: null, + unused_index_32: null, + unused_index_33: null, + unused_index_34: null, + unused_index_35: null, + unused_index_36: null, + unused_index_37: null, + unused_index_38: null, + unused_index_39: null, + unused_index_40: null, + unused_index_41: null, + unused_index_42: null, + unused_index_43: null, + unused_index_44: null, + unused_index_45: null, + unused_index_46: null, + unused_index_47: null, + unused_index_48: null, + unused_index_49: null, + guess_the_number: 'GuessTheNumberTrustedCall' } }, - BalanceSetBalanceArgs: '(AccountId, AccountId, BalanceType, BalanceType)', + 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)', + GuessTheNumberPublicGetter: { + _enum: { + guess_the_number_info: null, + } + }, + GuessTheNumberTrustedGetter: { + _enum: { + attempts: 'AttemptsArg' + } + }, + AttemptsArg: { + origin: 'AccountId' + }, + GuessTheNumberTrustedCall: { + _enum: { + set_winnings: 'GuessTheNumberSetWinningsArgs', + push_by_one_day: 'AccountId', + guess: 'GuessArgs', + } + }, + 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)', + GuessArgs: '(AccountId, GuessType)', } } diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index 6f88c203..eb8e589f 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -2,12 +2,16 @@ /* 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 { 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, H160 } from '@polkadot/types/interfaces/runtime'; +import type { AccountId, Balance, H160, Moment } from '@polkadot/types/interfaces/runtime'; + +/** @name AttemptsArg */ +export interface AttemptsArg extends Struct { + readonly origin: AccountId; +} /** @name BalanceSetBalanceArgs */ export interface BalanceSetBalanceArgs extends ITuple<[AccountId, AccountId, BalanceType, BalanceType]> {} @@ -21,6 +25,50 @@ export interface BalanceTransferArgs extends ITuple<[AccountId, AccountId, Balan /** @name BalanceUnshieldArgs */ export interface BalanceUnshieldArgs extends ITuple<[AccountId, AccountId, BalanceType, ShardIdentifier]> {} +/** @name GuessArgs */ +export interface GuessArgs 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 GuessTheNumberPublicGetter */ +export interface GuessTheNumberPublicGetter extends Enum { + readonly isGuessTheNumberInfo: boolean; + readonly type: 'GuessTheNumberInfo'; +} + +/** @name GuessTheNumberSetWinningsArgs */ +export interface GuessTheNumberSetWinningsArgs extends ITuple<[AccountId, Balance]> {} + +/** @name GuessTheNumberTrustedCall */ +export interface GuessTheNumberTrustedCall extends Enum { + readonly isSetWinnings: boolean; + readonly asSetWinnings: GuessTheNumberSetWinningsArgs; + readonly isPushByOneDay: boolean; + readonly asPushByOneDay: AccountId; + readonly isGuess: boolean; + readonly asGuess: GuessArgs; + readonly type: 'SetWinnings' | 'PushByOneDay' | 'Guess'; +} + +/** @name GuessTheNumberTrustedGetter */ +export interface GuessTheNumberTrustedGetter extends Enum { + readonly isAttempts: boolean; + readonly asAttempts: AttemptsArg; + readonly type: 'Attempts'; +} + +/** @name GuessType */ +export interface GuessType extends u32 {} + /** @name IntegriteeGetter */ export interface IntegriteeGetter extends Enum { readonly isPublic: boolean; @@ -32,38 +80,122 @@ export interface IntegriteeGetter extends Enum { /** @name IntegriteePublicGetter */ export interface IntegriteePublicGetter extends Enum { + readonly isSomeValue: boolean; 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 isUnusedIndex2: boolean; + readonly isUnusedIndex3: boolean; + readonly isUnusedIndex4: boolean; + readonly isUnusedIndex5: boolean; + readonly isUnusedIndex6: boolean; + readonly isUnusedIndex7: boolean; + readonly isUnusedIndex8: boolean; + readonly isUnusedIndex9: boolean; + readonly isParentchainsInfo: boolean; + readonly isUnusedIndex11: boolean; + readonly isUnusedIndex12: boolean; + readonly isUnusedIndex13: boolean; + readonly isUnusedIndex14: boolean; + readonly isUnusedIndex15: boolean; + readonly isUnusedIndex16: boolean; + readonly isUnusedIndex17: boolean; + readonly isUnusedIndex18: boolean; + readonly isUnusedIndex19: boolean; + readonly isUnusedIndex20: boolean; + readonly isUnusedIndex21: boolean; + readonly isUnusedIndex22: boolean; + readonly isUnusedIndex23: boolean; + readonly isUnusedIndex24: boolean; + readonly isUnusedIndex25: boolean; + readonly isUnusedIndex26: boolean; + readonly isUnusedIndex27: boolean; + readonly isUnusedIndex28: boolean; + readonly isUnusedIndex29: boolean; + readonly isUnusedIndex30: boolean; + readonly isUnusedIndex31: boolean; + readonly isUnusedIndex32: boolean; + readonly isUnusedIndex33: boolean; + readonly isUnusedIndex34: boolean; + readonly isUnusedIndex35: boolean; + readonly isUnusedIndex36: boolean; + readonly isUnusedIndex37: boolean; + readonly isUnusedIndex38: boolean; + readonly isUnusedIndex39: boolean; + readonly isUnusedIndex40: boolean; + readonly isUnusedIndex41: boolean; + readonly isUnusedIndex42: boolean; + readonly isUnusedIndex43: boolean; + readonly isUnusedIndex44: boolean; + readonly isUnusedIndex45: boolean; + readonly isUnusedIndex46: boolean; + readonly isUnusedIndex47: boolean; + readonly isUnusedIndex48: boolean; + readonly isUnusedIndex49: boolean; + readonly isGuessTheNumber: boolean; + readonly asGuessTheNumber: GuessTheNumberPublicGetter; + readonly type: 'SomeValue' | 'TotalIssuance' | 'UnusedIndex2' | 'UnusedIndex3' | 'UnusedIndex4' | 'UnusedIndex5' | 'UnusedIndex6' | 'UnusedIndex7' | 'UnusedIndex8' | 'UnusedIndex9' | 'ParentchainsInfo' | 'UnusedIndex11' | 'UnusedIndex12' | 'UnusedIndex13' | 'UnusedIndex14' | 'UnusedIndex15' | 'UnusedIndex16' | 'UnusedIndex17' | 'UnusedIndex18' | 'UnusedIndex19' | 'UnusedIndex20' | 'UnusedIndex21' | 'UnusedIndex22' | 'UnusedIndex23' | 'UnusedIndex24' | 'UnusedIndex25' | 'UnusedIndex26' | 'UnusedIndex27' | 'UnusedIndex28' | 'UnusedIndex29' | 'UnusedIndex30' | 'UnusedIndex31' | 'UnusedIndex32' | 'UnusedIndex33' | 'UnusedIndex34' | 'UnusedIndex35' | 'UnusedIndex36' | 'UnusedIndex37' | 'UnusedIndex38' | 'UnusedIndex39' | 'UnusedIndex40' | 'UnusedIndex41' | 'UnusedIndex42' | 'UnusedIndex43' | 'UnusedIndex44' | 'UnusedIndex45' | 'UnusedIndex46' | 'UnusedIndex47' | 'UnusedIndex48' | 'UnusedIndex49' | 'GuessTheNumber'; } /** @name IntegriteeTrustedCall */ 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 isBalanceSetBalance: boolean; + readonly asBalanceSetBalance: BalanceSetBalanceArgs; + readonly isUnusedIndex6: boolean; + readonly isUnusedIndex7: boolean; + readonly isUnusedIndex8: boolean; + readonly isUnusedIndex9: boolean; + readonly isUnusedIndex10: boolean; + readonly isUnusedIndex11: boolean; + readonly isUnusedIndex12: boolean; + readonly isUnusedIndex13: boolean; + readonly isUnusedIndex14: boolean; + readonly isUnusedIndex15: boolean; + readonly isUnusedIndex16: boolean; + readonly isUnusedIndex17: boolean; + readonly isUnusedIndex18: boolean; + readonly isUnusedIndex19: boolean; + readonly isUnusedIndex20: boolean; + readonly isUnusedIndex21: boolean; + readonly isUnusedIndex22: boolean; + readonly isUnusedIndex23: boolean; + readonly isUnusedIndex24: boolean; + readonly isUnusedIndex25: boolean; + readonly isUnusedIndex26: boolean; + readonly isUnusedIndex27: boolean; + readonly isUnusedIndex28: boolean; + readonly isUnusedIndex29: boolean; + readonly isUnusedIndex30: boolean; + readonly isUnusedIndex31: boolean; + readonly isUnusedIndex32: boolean; + readonly isUnusedIndex33: boolean; + readonly isUnusedIndex34: boolean; + readonly isUnusedIndex35: boolean; + readonly isUnusedIndex36: boolean; + readonly isUnusedIndex37: boolean; + readonly isUnusedIndex38: boolean; + readonly isUnusedIndex39: boolean; + readonly isUnusedIndex40: boolean; + readonly isUnusedIndex41: boolean; + readonly isUnusedIndex42: boolean; + readonly isUnusedIndex43: boolean; + readonly isUnusedIndex44: boolean; + readonly isUnusedIndex45: boolean; + readonly isUnusedIndex46: boolean; + readonly isUnusedIndex47: boolean; + readonly isUnusedIndex48: boolean; + readonly isUnusedIndex49: boolean; + readonly isGuessTheNumber: boolean; + readonly asGuessTheNumber: GuessTheNumberTrustedCall; + readonly type: 'Noop' | 'TimestampSet' | 'BalanceTransfer' | 'BalanceUnshield' | 'BalanceShield' | 'BalanceSetBalance' | 'UnusedIndex6' | 'UnusedIndex7' | 'UnusedIndex8' | 'UnusedIndex9' | 'UnusedIndex10' | 'UnusedIndex11' | 'UnusedIndex12' | 'UnusedIndex13' | 'UnusedIndex14' | 'UnusedIndex15' | 'UnusedIndex16' | 'UnusedIndex17' | 'UnusedIndex18' | 'UnusedIndex19' | 'UnusedIndex20' | 'UnusedIndex21' | 'UnusedIndex22' | 'UnusedIndex23' | 'UnusedIndex24' | 'UnusedIndex25' | 'UnusedIndex26' | 'UnusedIndex27' | 'UnusedIndex28' | 'UnusedIndex29' | 'UnusedIndex30' | 'UnusedIndex31' | 'UnusedIndex32' | 'UnusedIndex33' | 'UnusedIndex34' | 'UnusedIndex35' | 'UnusedIndex36' | 'UnusedIndex37' | 'UnusedIndex38' | 'UnusedIndex39' | 'UnusedIndex40' | 'UnusedIndex41' | 'UnusedIndex42' | 'UnusedIndex43' | 'UnusedIndex44' | 'UnusedIndex45' | 'UnusedIndex46' | 'UnusedIndex47' | 'UnusedIndex48' | 'UnusedIndex49' | 'GuessTheNumber'; } /** @name IntegriteeTrustedCallSigned */ @@ -77,7 +209,58 @@ export interface IntegriteeTrustedCallSigned extends Struct { export interface IntegriteeTrustedGetter extends Enum { readonly isAccountInfo: boolean; readonly asAccountInfo: AccountId; - readonly type: 'AccountInfo'; + readonly isUnusedIndex1: boolean; + readonly isUnusedIndex2: boolean; + readonly isUnusedIndex3: boolean; + readonly isUnusedIndex4: boolean; + readonly isUnusedIndex5: boolean; + readonly isUnusedIndex6: boolean; + readonly isUnusedIndex7: boolean; + readonly isUnusedIndex8: boolean; + readonly isUnusedIndex9: boolean; + readonly isUnusedIndex10: boolean; + readonly isUnusedIndex11: boolean; + readonly isUnusedIndex12: boolean; + readonly isUnusedIndex13: boolean; + readonly isUnusedIndex14: boolean; + readonly isUnusedIndex15: boolean; + readonly isUnusedIndex16: boolean; + readonly isUnusedIndex17: boolean; + readonly isUnusedIndex18: boolean; + readonly isUnusedIndex19: boolean; + readonly isUnusedIndex20: boolean; + readonly isUnusedIndex21: boolean; + readonly isUnusedIndex22: boolean; + readonly isUnusedIndex23: boolean; + readonly isUnusedIndex24: boolean; + readonly isUnusedIndex25: boolean; + readonly isUnusedIndex26: boolean; + readonly isUnusedIndex27: boolean; + readonly isUnusedIndex28: boolean; + readonly isUnusedIndex29: boolean; + readonly isUnusedIndex30: boolean; + readonly isUnusedIndex31: boolean; + readonly isUnusedIndex32: boolean; + readonly isUnusedIndex33: boolean; + readonly isUnusedIndex34: boolean; + readonly isUnusedIndex35: boolean; + readonly isUnusedIndex36: boolean; + readonly isUnusedIndex37: boolean; + readonly isUnusedIndex38: boolean; + readonly isUnusedIndex39: boolean; + readonly isUnusedIndex40: boolean; + readonly isUnusedIndex41: boolean; + readonly isUnusedIndex42: boolean; + readonly isUnusedIndex43: boolean; + readonly isUnusedIndex44: boolean; + readonly isUnusedIndex45: boolean; + readonly isUnusedIndex46: boolean; + readonly isUnusedIndex47: boolean; + readonly isUnusedIndex48: boolean; + readonly isUnusedIndex49: boolean; + readonly isGuessTheNumber: boolean; + readonly asGuessTheNumber: GuessTheNumberTrustedGetter; + readonly type: 'AccountInfo' | 'UnusedIndex1' | 'UnusedIndex2' | 'UnusedIndex3' | 'UnusedIndex4' | 'UnusedIndex5' | 'UnusedIndex6' | 'UnusedIndex7' | 'UnusedIndex8' | 'UnusedIndex9' | 'UnusedIndex10' | 'UnusedIndex11' | 'UnusedIndex12' | 'UnusedIndex13' | 'UnusedIndex14' | 'UnusedIndex15' | 'UnusedIndex16' | 'UnusedIndex17' | 'UnusedIndex18' | 'UnusedIndex19' | 'UnusedIndex20' | 'UnusedIndex21' | 'UnusedIndex22' | 'UnusedIndex23' | 'UnusedIndex24' | 'UnusedIndex25' | 'UnusedIndex26' | 'UnusedIndex27' | 'UnusedIndex28' | 'UnusedIndex29' | 'UnusedIndex30' | 'UnusedIndex31' | 'UnusedIndex32' | 'UnusedIndex33' | 'UnusedIndex34' | 'UnusedIndex35' | 'UnusedIndex36' | 'UnusedIndex37' | 'UnusedIndex38' | 'UnusedIndex39' | 'UnusedIndex40' | 'UnusedIndex41' | 'UnusedIndex42' | 'UnusedIndex43' | 'UnusedIndex44' | 'UnusedIndex45' | 'UnusedIndex46' | 'UnusedIndex47' | 'UnusedIndex48' | 'UnusedIndex49' | 'GuessTheNumber'; } /** @name IntegriteeTrustedGetterSigned */ diff --git a/packages/types/src/interfaces/worker/definitions.ts b/packages/types/src/interfaces/worker/definitions.ts index 1e046534..adeea4ee 100644 --- a/packages/types/src/interfaces/worker/definitions.ts +++ b/packages/types/src/interfaces/worker/definitions.ts @@ -50,5 +50,19 @@ export default { TargetB: null, } }, + ParentchainsInfo: { + integritee: 'ParentchainInfo', + target_a: 'ParentchainInfo', + target_b: 'ParentchainInfo', + shielding_target: 'ParentchainId', + }, + ParentchainInfo: { + id: 'ParentchainId', + genesis_hash: 'Option', + block_number: 'Option', + now: 'Option', + creation_block_number: 'Option', + creation_timestamp: 'Option', + }, } } diff --git a/packages/types/src/interfaces/worker/types.ts b/packages/types/src/interfaces/worker/types.ts index ec7217a0..54cafebc 100644 --- a/packages/types/src/interfaces/worker/types.ts +++ b/packages/types/src/interfaces/worker/types.ts @@ -2,9 +2,9 @@ /* eslint-disable */ import type { CommunityIdentifier } from '@encointer/types/interfaces/community'; -import type { Bytes, Enum, Struct, Text, bool, u64 } from '@polkadot/types-codec'; +import type { Bytes, Enum, Option, Struct, Text, bool, u64 } from '@polkadot/types-codec'; import type { ITuple } from '@polkadot/types-codec/types'; -import type { AccountId, H256, Hash } from '@polkadot/types/interfaces/runtime'; +import type { AccountId, BlockNumber, H256, Hash, Moment } from '@polkadot/types/interfaces/runtime'; /** @name DirectRequestStatus */ export interface DirectRequestStatus extends Enum { @@ -37,6 +37,24 @@ export interface ParentchainId extends Enum { readonly type: 'Integritee' | 'TargetA' | 'TargetB'; } +/** @name ParentchainInfo */ +export interface ParentchainInfo extends Struct { + readonly id: ParentchainId; + readonly genesis_hash: Option; + readonly block_number: Option; + readonly now: Option; + readonly creation_block_number: Option; + readonly creation_timestamp: Option; +} + +/** @name ParentchainsInfo */ +export interface ParentchainsInfo extends Struct { + readonly integritee: ParentchainInfo; + readonly target_a: ParentchainInfo; + readonly target_b: ParentchainInfo; + readonly shielding_target: ParentchainId; +} + /** @name Request */ export interface Request extends Struct { readonly shard: ShardIdentifier; diff --git a/packages/util/package.json b/packages/util/package.json index 7907521d..b72acedb 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -20,7 +20,7 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.15.1-alpha.0", + "version": "0.15.1-alpha.1", "main": "index.js", "dependencies": { "@babel/runtime": "^7.18.9", diff --git a/packages/worker-api/package.json b/packages/worker-api/package.json index d119833f..99d16de4 100644 --- a/packages/worker-api/package.json +++ b/packages/worker-api/package.json @@ -19,12 +19,12 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.15.1-alpha.0", + "version": "0.15.1-alpha.1", "main": "index.js", "dependencies": { - "@encointer/node-api": "^0.15.1-alpha.0", - "@encointer/types": "^0.15.1-alpha.0", - "@encointer/util": "^0.15.1-alpha.0", + "@encointer/node-api": "^0.15.1-alpha.1", + "@encointer/types": "^0.15.1-alpha.1", + "@encointer/util": "^0.15.1-alpha.1", "@peculiar/webcrypto": "^1.4.6", "@polkadot/api": "^11.2.1", "@polkadot/keyring": "^12.6.2", diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index ff125132..0c3e3ff4 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -36,6 +36,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. @@ -73,12 +74,42 @@ describe('worker', () => { }); }); - describe('getAccountInfoGetter', () => { + describe('accountInfoGetter', () => { it('should return value', async () => { - const getter = await worker.getAccountInfoGetter(charlie, network.mrenclave); + const getter = await worker.accountInfoGetter(charlie, network.mrenclave); console.log(`AccountInfoGetter: ${JSON.stringify(getter)}`); const result = await getter.send(); - console.log('getAccountInfo', result); + console.log('getAccountInfo:', result); + expect(result).toBeDefined(); + }); + }); + + describe('parentchainsInfoGetter', () => { + it('should return value', async () => { + const getter = worker.parentchainsInfoGetter(network.mrenclave); + console.log(`parentchainsInfoGetter: ${JSON.stringify(getter)}`); + const result = await getter.send(); + console.log('parentchainsInfoGetter:', result); + expect(result).toBeDefined(); + }); + }); + + describe('guessTheNumberInfoGetter', () => { + it('should return value', async () => { + const getter = worker.guessTheNumberInfoGetter(network.mrenclave); + console.log(`GuessTheNumberInfo: ${JSON.stringify(getter)}`); + const result = await getter.send(); + console.log('GuessTheNumberInfo:', result); + expect(result).toBeDefined(); + }); + }); + + describe('guessTheNumberAttemptsGetter', () => { + it('should return value', async () => { + const getter = await worker.guessTheNumberAttemptsTrustedGetter(charlie, network.mrenclave); + console.log(`Attempts: ${JSON.stringify(getter)}`); + const result = await getter.send(); + console.log('Attempts:', result); expect(result).toBeDefined(); }); }); @@ -115,5 +146,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..58327834 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -1,25 +1,34 @@ import type {Hash} from '@polkadot/types/interfaces/runtime'; import type { - ShardIdentifier, IntegriteeTrustedCallSigned, IntegriteeGetter, + ShardIdentifier, + IntegriteeTrustedCallSigned, + IntegriteeGetter, + GuessTheNumberInfo, + GuessTheNumberTrustedCall, GuessTheNumberPublicGetter, GuessTheNumberTrustedGetter, AttemptsArg, } from '@encointer/types'; import { type RequestOptions, type ISubmittableGetter, - Request, - type JsonRpcRequest, type TrustedGetterArgs, type TrustedSignerOptions, + type JsonRpcRequest, + type TrustedGetterArgs, + type TrustedSignerOptions, + type PublicGetterArgs, + type IWorker, + type PublicGetterParams, type TrustedGetterParams, } from './interface.js'; import {Worker} from "./worker.js"; -import {callGetter, sendTrustedCall, sendWorkerRequest} from './sendRequest.js'; +import {sendTrustedCall, sendWorkerRequest} from './sendRequest.js'; import { - createGetterRpc, + createGetterRpc, createIntegriteeGetterPublic, createSignedGetter, createTrustedCall, - signTrustedCall, + signTrustedCall, type TrustedCallArgs, type TrustedCallVariant, } 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"; +import {asString} from "@encointer/util"; export class IntegriteeWorker extends Worker { @@ -29,20 +38,43 @@ export class IntegriteeWorker extends Worker { } public async getAccountInfo(accountOrPubKey: AddressOrPair, shard: string, singerOptions?: TrustedSignerOptions, requestOptions?: RequestOptions): Promise { - return await callGetter(this, [Request.TrustedGetter, 'account_info', 'AccountInfo'], { + const getter = await this.accountInfoGetter(accountOrPubKey, shard, singerOptions); + return getter.send(requestOptions); + } + + public async accountInfoGetter(accountOrPubKey: AddressOrPair, shard: string, signerOptions?: TrustedSignerOptions): Promise> { + const trustedGetterArgs = { shard: shard, account: accountOrPubKey, - signer: singerOptions?.signer - }, requestOptions) + signer: signerOptions?.signer, + } + return await submittableTrustedGetter(this, 'account_info', accountOrPubKey, trustedGetterArgs, asString(accountOrPubKey), 'AccountInfo'); + } + + public parentchainsInfoGetter(shard: string): SubmittableGetter { + const publicGetterArgs = { + shard: shard, + } + return submittablePublicGetter(this, 'parentchains_info', publicGetterArgs, null, 'ParentchainsInfo'); + } + + public guessTheNumberInfoGetter(shard: string): SubmittableGetter { + const publicGetterArgs = { + shard: shard, + } + const getterParams = guessTheNumberPublicGetter(this, 'guess_the_number_info'); + return submittablePublicGetter(this, 'guess_the_number', publicGetterArgs, getterParams, 'GuessTheNumberInfo'); } - public async getAccountInfoGetter(accountOrPubKey: AddressOrPair, shard: string, signerOptions?: TrustedSignerOptions): Promise> { + public async guessTheNumberAttemptsTrustedGetter(accountOrPubKey: AddressOrPair, shard: string, signerOptions?: TrustedSignerOptions): Promise> { const trustedGetterArgs = { shard: shard, account: accountOrPubKey, signer: signerOptions?.signer, } - return await submittableGetter(this, 'account_info', trustedGetterArgs,'AccountInfo'); + const args = this.createType('AttemptsArg', {origin: asString(accountOrPubKey)}); + const getterParams = guessTheNumberTrustedGetter(this, 'attempts', args); + return await submittableTrustedGetter(this, 'guess_the_number', accountOrPubKey, trustedGetterArgs, getterParams,'u8'); } public async trustedBalanceTransfer( @@ -82,6 +114,26 @@ 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('GuessArgs', [asString(account), guess]) + const guessThNumberCall = guessTheNumberCall(this, ['guess', 'GuessArgs'], params); + const call = createTrustedCall(this, ['guess_the_number', 'GuessTheNumberTrustedCall'], guessThNumberCall); + const signed = await signTrustedCall(this, call, account, shardT, mrenclave, nonce, signerOptions); + + console.log(`GuessTheNumber ${JSON.stringify(signed)}`); + 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.`) @@ -115,9 +167,50 @@ export class SubmittableGetter implements ISubmittableGe } } -export const submittableGetter = async (self: W, request: string, args: TrustedGetterArgs, returnType: string)=> { - const {shard, account} = args; +export const submittableTrustedGetter = async (self: W, request: string, account: AddressOrPair, args: TrustedGetterArgs, trustedGetterParams: TrustedGetterParams, returnType: string)=> { + const {shard} = args; + const shardT = self.createType('ShardIdentifier', bs58.decode(shard)); + const signedGetter = await createSignedGetter(self, request, account, trustedGetterParams, { signer: args?.signer }) + return new SubmittableGetter(self, shardT, signedGetter, returnType); +} + +export const submittablePublicGetter = (self: W, request: string, args: PublicGetterArgs, publicGetterParams: PublicGetterParams, returnType: string)=> { + const {shard} = args; const shardT = self.createType('ShardIdentifier', bs58.decode(shard)); - const signedGetter = await createSignedGetter(self, request, account, { signer: args?.signer }) + const signedGetter = createIntegriteeGetterPublic(self, request, publicGetterParams) return new SubmittableGetter(self, shardT, signedGetter, returnType); } + +export const guessTheNumberPublicGetter = ( + self: IWorker, + getterVariant: string, +): GuessTheNumberPublicGetter => { + return self.createType('GuessTheNumberPublicGetter', { + [getterVariant]: null + }); +} + +export const guessTheNumberTrustedGetter = ( + self: IWorker, + getterVariant: string, + params: GuessTheNumberTrustedGetterParams +): GuessTheNumberTrustedGetter => { + return self.createType('GuessTheNumberTrustedGetter', { + [getterVariant]: params + }); +} + +export type GuessTheNumberTrustedGetterParams = AttemptsArg | null; + + +export const guessTheNumberCall = ( + self: IWorker, + callVariant: TrustedCallVariant, + params: TrustedCallArgs +): GuessTheNumberTrustedCall => { + const [variant, argType] = callVariant; + + return self.createType('GuessTheNumberTrustedCall', { + [variant]: self.createType(argType, params) + }); +} diff --git a/packages/worker-api/src/interface.ts b/packages/worker-api/src/interface.ts index c6f9bc05..38edfbfa 100644 --- a/packages/worker-api/src/interface.ts +++ b/packages/worker-api/src/interface.ts @@ -5,7 +5,12 @@ import type {TypeRegistry, u32, Vec} from "@polkadot/types"; import type {RegistryTypes, Signer} from "@polkadot/types/types"; import type {AddressOrPair} from "@polkadot/api-base/types/submittable"; import {Worker} from "./worker.js"; -import type {IntegriteeGetter, ShardIdentifier} from "@encointer/types"; +import type { + GuessTheNumberPublicGetter, + GuessTheNumberTrustedGetter, + IntegriteeGetter, + ShardIdentifier +} from "@encointer/types"; export interface IWorker extends WebSocketAsPromised { rsCount: number; @@ -60,6 +65,8 @@ export interface TrustedGetterArgs { signer?: Signer } +export type TrustedGetterParams = string | GuessTheNumberTrustedGetter | null + /** * Signer options. * @@ -74,9 +81,11 @@ export interface TrustedSignerOptions { } export interface PublicGetterArgs { - cid: string; + shard: string; } +export type PublicGetterParams = GuessTheNumberPublicGetter | null + export type RequestArgs = PublicGetterArgs | TrustedGetterArgs | { } export interface RequestOptions { diff --git a/packages/worker-api/src/requests.ts b/packages/worker-api/src/requests.ts index 21969b3c..5dd22d2b 100644 --- a/packages/worker-api/src/requests.ts +++ b/packages/worker-api/src/requests.ts @@ -1,56 +1,39 @@ import { createJsonRpcRequest, - type IWorker, - type PublicGetterArgs, - type TrustedGetterArgs, + type IWorker, type PublicGetterParams, type TrustedGetterParams, type TrustedSignerOptions } from "./interface.js"; import type { BalanceTransferArgs, - BalanceUnshieldArgs, + BalanceUnshieldArgs, GuessTheNumberTrustedCall, IntegriteeGetter, IntegriteeTrustedCall, IntegriteeTrustedCallSigned, IntegriteeTrustedGetter, ShardIdentifier } from "@encointer/types"; -import {asString, signPayload} from "@encointer/util"; +import {signPayload} from "@encointer/util"; 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 getter = self.createType('IntegriteePublicGetter', { - [request]: cid - }); - +export const createIntegriteeGetterPublic = (self: IWorker, request: string, publicGetterParams: PublicGetterParams) => { const g = self.createType('IntegriteeGetter', { public: { - getter, + [request]: publicGetterParams , } }); - const shardT = self.createType('ShardIdentifier', bs58.decode(cid)); - - return createGetterRpc(self, g, shardT); -} - -export const clientRequestTrustedGetterRpc = async (self: IWorker, request: string, args: TrustedGetterArgs) => { - const {shard, account} = args; - const shardT = self.createType('ShardIdentifier', bs58.decode(shard)); - const signedGetter = await createSignedGetter(self, request, account, {signer: args?.signer}); - return createGetterRpc(self, signedGetter, shardT); + return g; } -export const createSignedGetter = async (self: IWorker, request: string, account: AddressOrPair, options: TrustedSignerOptions) => { - const trustedGetter = createTrustedGetter(self, request, asString(account)); +export const createSignedGetter = async (self: IWorker, request: string, account: AddressOrPair, trustedGetterParams: TrustedGetterParams, options: TrustedSignerOptions) => { + const trustedGetter = createTrustedGetter(self, request, trustedGetterParams); return await signTrustedGetter(self, account, trustedGetter, options); } -export const createTrustedGetter = (self: IWorker, request: string, address: string) => { +export const createTrustedGetter = (self: IWorker, request: string, params: TrustedGetterParams) => { return self.createType('IntegriteeTrustedGetter', { - [request]: address + [request]: params }); } @@ -80,7 +63,7 @@ export const createGetterRpc = (self: IWorker, getter: IntegriteeGetter, shard: } -export type TrustedCallArgs = (BalanceTransferArgs | BalanceUnshieldArgs); +export type TrustedCallArgs = (BalanceTransferArgs | BalanceUnshieldArgs | GuessTheNumberTrustedCall); export type TrustedCallVariant = [string, string] diff --git a/packages/worker-api/src/sendRequest.ts b/packages/worker-api/src/sendRequest.ts index 1b926d09..17f9145f 100644 --- a/packages/worker-api/src/sendRequest.ts +++ b/packages/worker-api/src/sendRequest.ts @@ -1,17 +1,11 @@ import { type IWorker, - type TrustedGetterArgs, - type PublicGetterArgs, type RequestArgs, type RequestOptions, type WorkerMethod, createJsonRpcRequest } from './interface.js'; import { Request } from './interface.js'; -import { - clientRequestGetterRpc, - clientRequestTrustedGetterRpc, -} from "./requests.js"; import type {ShardIdentifier, IntegriteeTrustedCallSigned} from "@encointer/types"; export const sendWorkerRequest = (self: IWorker, clientRequest: any, parserType: string, options?: RequestOptions): Promise =>{ @@ -25,13 +19,7 @@ export const sendWorkerRequest = (self: IWorker, clientRequest: any, parserType: ) } -const sendTrustedGetterRequest = async (self: IWorker, method: string, parser: string, args: TrustedGetterArgs, options?: RequestOptions) => - sendWorkerRequest(self, await clientRequestTrustedGetterRpc(self, method, args), parser, options) - -const sendPublicGetterRequest = (self: IWorker, method: string, parser: string, args: PublicGetterArgs, options?: RequestOptions) => - sendWorkerRequest(self, clientRequestGetterRpc(self, method, args), parser, options) - -export const callGetter = async (self: IWorker, workerMethod: WorkerMethod, args: RequestArgs, requestOptions?: RequestOptions): Promise => { +export const callGetter = async (self: IWorker, workerMethod: WorkerMethod, _args: RequestArgs, requestOptions?: RequestOptions): Promise => { if( !self.isOpened ) { await self.open(); } @@ -39,18 +27,11 @@ export const callGetter = async (self: IWorker, workerMethod: WorkerMethod, a let result: Promise; let parserType: string = requestOptions?.debug ? 'raw': parser; switch (getterType) { - case Request.TrustedGetter: - result = sendTrustedGetterRequest(self, method, parserType, args as TrustedGetterArgs, requestOptions) - break; - case Request.PublicGetter: - result = sendPublicGetterRequest(self, method, parserType, args as PublicGetterArgs, requestOptions) - break; case Request.Worker: result = sendWorkerRequest(self, createJsonRpcRequest(method, [], 1), parserType, requestOptions) break; default: - result = sendPublicGetterRequest(self, method, parserType, args as PublicGetterArgs, requestOptions) - break; + throw "Invalid request variant, public and trusted have been removed for the integritee worker" } return result as Promise } diff --git a/packages/worker-api/src/testUtils/networks.ts b/packages/worker-api/src/testUtils/networks.ts index 3d7b0767..42d4b43d 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: 'FtNhy2ZvHHDPZxHZY5atVav2VVkoipR3BE6zAbcveUcT', - chosenCid: 'FtNhy2ZvHHDPZxHZY5atVav2VVkoipR3BE6zAbcveUcT', + mrenclave: 'GopQCtWihHQ8Xw1sZP6DTWMDQuaijSBE2NM8GU2U4Erc', + chosenCid: 'GopQCtWihHQ8Xw1sZP6DTWMDQuaijSBE2NM8GU2U4Erc', customTypes: {}, palletOverrides: {} }; diff --git a/yarn.lock b/yarn.lock index 21e281d7..371be358 100644 --- a/yarn.lock +++ b/yarn.lock @@ -755,18 +755,18 @@ __metadata: languageName: node linkType: hard -"@encointer/node-api@npm:^0.15.1-alpha.0, @encointer/node-api@workspace:packages/node-api": +"@encointer/node-api@npm:^0.15.1-alpha.1, @encointer/node-api@workspace:packages/node-api": version: 0.0.0-use.local resolution: "@encointer/node-api@workspace:packages/node-api" dependencies: - "@encointer/types": "npm:^0.15.1-alpha.0" + "@encointer/types": "npm:^0.15.1-alpha.1" "@polkadot/api": "npm:^11.2.1" "@polkadot/util-crypto": "npm:^12.6.2" tslib: "npm:^2.6.2" languageName: unknown linkType: soft -"@encointer/types@npm:^0.15.1-alpha.0, @encointer/types@workspace:packages/types": +"@encointer/types@npm:^0.15.1-alpha.1, @encointer/types@workspace:packages/types": version: 0.0.0-use.local resolution: "@encointer/types@workspace:packages/types" dependencies: @@ -781,7 +781,7 @@ __metadata: languageName: unknown linkType: soft -"@encointer/util@npm:^0.15.1-alpha.0, @encointer/util@workspace:packages/util": +"@encointer/util@npm:^0.15.1-alpha.1, @encointer/util@workspace:packages/util": version: 0.0.0-use.local resolution: "@encointer/util@workspace:packages/util" dependencies: @@ -798,9 +798,9 @@ __metadata: version: 0.0.0-use.local resolution: "@encointer/worker-api@workspace:packages/worker-api" dependencies: - "@encointer/node-api": "npm:^0.15.1-alpha.0" - "@encointer/types": "npm:^0.15.1-alpha.0" - "@encointer/util": "npm:^0.15.1-alpha.0" + "@encointer/node-api": "npm:^0.15.1-alpha.1" + "@encointer/types": "npm:^0.15.1-alpha.1" + "@encointer/util": "npm:^0.15.1-alpha.1" "@peculiar/webcrypto": "npm:^1.4.6" "@polkadot/api": "npm:^11.2.1" "@polkadot/keyring": "npm:^12.6.2"