From 0f966b53f7f2d410853496150d9c49352e235708 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Fri, 8 Nov 2024 17:18:51 +0100 Subject: [PATCH 1/6] generate types for notes getters --- .../types/src/interfaces/augment-types.ts | 10 +++- .../integriteeWorker/definitions.ts | 25 +++++++-- .../src/interfaces/integriteeWorker/types.ts | 53 +++++++++++++++---- 3 files changed, 71 insertions(+), 17 deletions(-) diff --git a/packages/types/src/interfaces/augment-types.ts b/packages/types/src/interfaces/augment-types.ts index 9b915c0b..2ec8efac 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 { 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 { AttemptsArg, BalanceShieldArgs, BalanceTransferArgs, BalanceTransferWithNoteArgs, BalanceUnshieldArgs, BucketIndex, BucketInfo, GuessArgs, GuessTheNumberInfo, GuessTheNumberPublicGetter, GuessTheNumberSetWinningsArgs, GuessTheNumberTrustedCall, GuessTheNumberTrustedGetter, GuessType, IntegriteeGetter, IntegriteePublicGetter, IntegriteeTrustedCall, IntegriteeTrustedCallSigned, IntegriteeTrustedGetter, IntegriteeTrustedGetterSigned, IntegriteeTrustedOperation, NoteIndex, NotesBucketInfo, NotesForArgs, TimestampSetArgs, TrustedNote } from '@encointer/types/interfaces/integriteeWorker'; import type { SchedulerState, SystemNumber } from '@encointer/types/interfaces/scheduler'; 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'; @@ -168,9 +168,9 @@ declare module '@polkadot/types/types/registry' { Balance: Balance; BalanceEntry: BalanceEntry; BalanceOf: BalanceOf; - BalanceSetBalanceArgs: BalanceSetBalanceArgs; BalanceShieldArgs: BalanceShieldArgs; BalanceTransferArgs: BalanceTransferArgs; + BalanceTransferWithNoteArgs: BalanceTransferWithNoteArgs; BalanceType: BalanceType; BalanceUnshieldArgs: BalanceUnshieldArgs; BeefyAuthoritySet: BeefyAuthoritySet; @@ -226,6 +226,8 @@ declare module '@polkadot/types/types/registry' { BridgedBlockNumber: BridgedBlockNumber; BridgedHeader: BridgedHeader; BridgeMessageId: BridgeMessageId; + BucketIndex: BucketIndex; + BucketInfo: BucketInfo; BufferedSessionChange: BufferedSessionChange; BusinessData: BusinessData; BusinessIdentifier: BusinessIdentifier; @@ -813,6 +815,9 @@ declare module '@polkadot/types/types/registry' { NominatorIndex: NominatorIndex; NominatorIndexCompact: NominatorIndexCompact; NotConnectedPeer: NotConnectedPeer; + NoteIndex: NoteIndex; + NotesBucketInfo: NotesBucketInfo; + NotesForArgs: NotesForArgs; NpApiError: NpApiError; NpPoolId: NpPoolId; Null: Null; @@ -1221,6 +1226,7 @@ declare module '@polkadot/types/types/registry' { TreasuryProposal: TreasuryProposal; TrieId: TrieId; TrieIndex: TrieIndex; + TrustedNote: TrustedNote; TrustedOperationStatus: TrustedOperationStatus; Type: Type; u128: u128; diff --git a/packages/types/src/interfaces/integriteeWorker/definitions.ts b/packages/types/src/interfaces/integriteeWorker/definitions.ts index 575f5cb0..8aae2610 100644 --- a/packages/types/src/interfaces/integriteeWorker/definitions.ts +++ b/packages/types/src/interfaces/integriteeWorker/definitions.ts @@ -14,7 +14,7 @@ export default { unused_index_8: null, unused_index_9: null, parentchains_info: null, - unused_index_11: null, + note_buckets_info: null, unused_index_12: null, unused_index_13: null, unused_index_14: null, @@ -68,7 +68,7 @@ export default { unused_index_7: null, unused_index_8: null, unused_index_9: null, - unused_index_10: null, + notes_for: 'NotesForArgs', unused_index_11: null, unused_index_12: null, unused_index_13: null, @@ -140,7 +140,7 @@ export default { balance_transfer: 'BalanceTransferArgs', balance_unshield: 'BalanceUnshieldArgs', balance_shield: 'BalanceShieldArgs', - balance_set_balance: 'BalanceSetBalanceArgs', + balance_transfer_with_note: 'BalanceTransferWithNoteArgs', unused_index_6: null, unused_index_7: null, unused_index_8: null, @@ -190,9 +190,26 @@ export default { }, TimestampSetArgs: '(AccountId, H160, BalanceType)', BalanceTransferArgs: '(AccountId, AccountId, BalanceType)', + BalanceTransferWithNoteArgs: '(AccountId, AccountId, BalanceType, String)', BalanceShieldArgs: '(AccountId, AccountId, BalanceType, ParentchainId)', BalanceUnshieldArgs: '(AccountId, AccountId, BalanceType, ShardIdentifier)', - BalanceSetBalanceArgs: '(AccountId, AccountId, BalanceType, BalanceType)', + NotesForArgs: '(AccountId, BucketIndex)', + BucketIndex: 'u32', + NoteIndex: 'u64', + TrustedNote: { + _enum: { + TrustedCall: 'Vec', + SgxRuntimeEvent: 'Vec' + } + }, + BucketInfo: { + index: 'BucketIndex', + bytes: 'u32', + }, + NotesBucketInfo: { + first: 'BucketInfo', + last: 'BucketInfo', + }, GuessTheNumberPublicGetter: { _enum: { guess_the_number_info: null, diff --git a/packages/types/src/interfaces/integriteeWorker/types.ts b/packages/types/src/interfaces/integriteeWorker/types.ts index eb8e589f..40ac12a0 100644 --- a/packages/types/src/interfaces/integriteeWorker/types.ts +++ b/packages/types/src/interfaces/integriteeWorker/types.ts @@ -3,7 +3,7 @@ import type { BalanceType } from '@encointer/types/interfaces/balances'; import type { ParentchainId, ShardIdentifier } from '@encointer/types/interfaces/worker'; -import type { Enum, Option, Struct, Vec, u32 } from '@polkadot/types-codec'; +import type { Bytes, Enum, Option, Struct, Text, Vec, u32, u64 } 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, Moment } from '@polkadot/types/interfaces/runtime'; @@ -13,18 +13,27 @@ export interface AttemptsArg extends Struct { readonly origin: AccountId; } -/** @name BalanceSetBalanceArgs */ -export interface BalanceSetBalanceArgs extends ITuple<[AccountId, AccountId, BalanceType, BalanceType]> {} - /** @name BalanceShieldArgs */ export interface BalanceShieldArgs extends ITuple<[AccountId, AccountId, BalanceType, ParentchainId]> {} /** @name BalanceTransferArgs */ export interface BalanceTransferArgs extends ITuple<[AccountId, AccountId, BalanceType]> {} +/** @name BalanceTransferWithNoteArgs */ +export interface BalanceTransferWithNoteArgs extends ITuple<[AccountId, AccountId, BalanceType, Text]> {} + /** @name BalanceUnshieldArgs */ export interface BalanceUnshieldArgs extends ITuple<[AccountId, AccountId, BalanceType, ShardIdentifier]> {} +/** @name BucketIndex */ +export interface BucketIndex extends u32 {} + +/** @name BucketInfo */ +export interface BucketInfo extends Struct { + readonly index: BucketIndex; + readonly bytes: u32; +} + /** @name GuessArgs */ export interface GuessArgs extends ITuple<[AccountId, GuessType]> {} @@ -91,7 +100,7 @@ export interface IntegriteePublicGetter extends Enum { readonly isUnusedIndex8: boolean; readonly isUnusedIndex9: boolean; readonly isParentchainsInfo: boolean; - readonly isUnusedIndex11: boolean; + readonly isNoteBucketsInfo: boolean; readonly isUnusedIndex12: boolean; readonly isUnusedIndex13: boolean; readonly isUnusedIndex14: boolean; @@ -132,7 +141,7 @@ export interface IntegriteePublicGetter extends Enum { 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'; + readonly type: 'SomeValue' | 'TotalIssuance' | 'UnusedIndex2' | 'UnusedIndex3' | 'UnusedIndex4' | 'UnusedIndex5' | 'UnusedIndex6' | 'UnusedIndex7' | 'UnusedIndex8' | 'UnusedIndex9' | 'ParentchainsInfo' | 'NoteBucketsInfo' | '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 */ @@ -147,8 +156,8 @@ export interface IntegriteeTrustedCall extends Enum { readonly asBalanceUnshield: BalanceUnshieldArgs; readonly isBalanceShield: boolean; readonly asBalanceShield: BalanceShieldArgs; - readonly isBalanceSetBalance: boolean; - readonly asBalanceSetBalance: BalanceSetBalanceArgs; + readonly isBalanceTransferWithNote: boolean; + readonly asBalanceTransferWithNote: BalanceTransferWithNoteArgs; readonly isUnusedIndex6: boolean; readonly isUnusedIndex7: boolean; readonly isUnusedIndex8: boolean; @@ -195,7 +204,7 @@ export interface IntegriteeTrustedCall extends Enum { 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'; + readonly type: 'Noop' | 'TimestampSet' | 'BalanceTransfer' | 'BalanceUnshield' | 'BalanceShield' | 'BalanceTransferWithNote' | '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 */ @@ -218,7 +227,8 @@ export interface IntegriteeTrustedGetter extends Enum { readonly isUnusedIndex7: boolean; readonly isUnusedIndex8: boolean; readonly isUnusedIndex9: boolean; - readonly isUnusedIndex10: boolean; + readonly isNotesFor: boolean; + readonly asNotesFor: NotesForArgs; readonly isUnusedIndex11: boolean; readonly isUnusedIndex12: boolean; readonly isUnusedIndex13: boolean; @@ -260,7 +270,7 @@ export interface IntegriteeTrustedGetter extends Enum { 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'; + readonly type: 'AccountInfo' | 'UnusedIndex1' | 'UnusedIndex2' | 'UnusedIndex3' | 'UnusedIndex4' | 'UnusedIndex5' | 'UnusedIndex6' | 'UnusedIndex7' | 'UnusedIndex8' | 'UnusedIndex9' | 'NotesFor' | '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 */ @@ -280,7 +290,28 @@ export interface IntegriteeTrustedOperation extends Enum { readonly type: 'IndirectCall' | 'DirectCall' | 'Get'; } +/** @name NoteIndex */ +export interface NoteIndex extends u64 {} + +/** @name NotesBucketInfo */ +export interface NotesBucketInfo extends Struct { + readonly first: BucketInfo; + readonly last: BucketInfo; +} + +/** @name NotesForArgs */ +export interface NotesForArgs extends ITuple<[AccountId, BucketIndex]> {} + /** @name TimestampSetArgs */ export interface TimestampSetArgs extends ITuple<[AccountId, H160, BalanceType]> {} +/** @name TrustedNote */ +export interface TrustedNote extends Enum { + readonly isTrustedCall: boolean; + readonly asTrustedCall: Bytes; + readonly isSgxRuntimeEvent: boolean; + readonly asSgxRuntimeEvent: Bytes; + readonly type: 'TrustedCall' | 'SgxRuntimeEvent'; +} + export type PHANTOM_INTEGRITEEWORKER = 'integriteeWorker'; From b60a380c6317343d671cb9b18aa345791479c2f9 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Sat, 9 Nov 2024 11:28:54 +0100 Subject: [PATCH 2/6] support getting notes, and sending transfer with notes. --- .../worker-api/src/integriteeWorker.spec.ts | 15 +++++++ packages/worker-api/src/integriteeWorker.ts | 39 +++++++++++++++++-- packages/worker-api/src/worker.ts | 15 +++++-- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 1cdfd156..0d2a4a3b 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -130,6 +130,21 @@ describe('worker', () => { console.log('balance transfer result', JSON.stringify(result)); expect(result).toBeDefined(); }); + + it('should return value with note', async () => { + const shard = network.shard; + const result = await worker.trustedBalanceTransfer( + alice, + shard, + network.mrenclave, + alice.address, + charlie.address, + 1100000000000, + "My test note" + ); + console.log('balance transfer result', JSON.stringify(result)); + expect(result).toBeDefined(); + }); }); // race condition so skipped diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index d4ddeeef..6232ac4c 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -3,7 +3,12 @@ import type { IntegriteeTrustedCallSigned, IntegriteeGetter, GuessTheNumberInfo, - GuessTheNumberTrustedCall, GuessTheNumberPublicGetter, GuessTheNumberTrustedGetter, AttemptsArg, ParentchainsInfo, + GuessTheNumberTrustedCall, + GuessTheNumberPublicGetter, + GuessTheNumberTrustedGetter, + AttemptsArg, + ParentchainsInfo, + TrustedNote, NotesBucketInfo, } from '@encointer/types'; import { type ISubmittableGetter, @@ -24,6 +29,7 @@ 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"; +import {Vec} from "@polkadot/types"; export class IntegriteeWorker extends Worker { @@ -53,6 +59,24 @@ export class IntegriteeWorker extends Worker { return submittablePublicGetter(this, 'parentchains_info', publicGetterArgs, null, 'ParentchainsInfo'); } + public noteBucketsInfoGetter(shard: string): SubmittableGetter { + const publicGetterArgs = { + shard: shard, + } + return submittablePublicGetter(this, 'note_buckets_info', publicGetterArgs, null, 'ParentchainsInfo'); + } + + + public async notesForTrustedGetter(accountOrPubKey: AddressOrPair, bucketIndex: number, shard: string, signerOptions?: TrustedSignerOptions): Promise>> { + const trustedGetterArgs = { + shard: shard, + account: accountOrPubKey, + signer: signerOptions?.signer, + } + const notesForArgs = this.createType('NotesForArgs', (asString(accountOrPubKey), bucketIndex)); + return await submittableTrustedGetter>(this, 'notes_for', accountOrPubKey, trustedGetterArgs, notesForArgs,'u8'); + } + public guessTheNumberInfoGetter(shard: string): SubmittableGetter { const publicGetterArgs = { shard: shard, @@ -79,12 +103,21 @@ export class IntegriteeWorker extends Worker { from: String, to: String, amount: number, + note?: string, signerOptions?: TrustedSignerOptions, ): Promise { const nonce = signerOptions?.nonce ?? await this.getNonce(account, shard, signerOptions) const shardT = this.createType('ShardIdentifier', bs58.decode(shard)); - const params = this.createType('BalanceTransferArgs', [from, to, amount]) - const call = createTrustedCall(this, ['balance_transfer', 'BalanceTransferArgs'], params); + + let call; + if (note == null) { + const params = this.createType('BalanceTransferArgs', [from, to, amount]) + call = createTrustedCall(this, ['balance_transfer', 'BalanceTransferArgs'], params); + } else { + const params = this.createType('BalanceTransferWithNoteArgs', [from, to, amount, note]) + call = createTrustedCall(this, ['balance_transfer_with_note', 'BalanceTransferWithNoteArgs'], params); + } + const signed = await signTrustedCall(this, call, account, shardT, mrenclave, nonce, signerOptions); return this.sendTrustedCall(signed, shardT); } diff --git a/packages/worker-api/src/worker.ts b/packages/worker-api/src/worker.ts index 6ef29700..1e11aafc 100644 --- a/packages/worker-api/src/worker.ts +++ b/packages/worker-api/src/worker.ts @@ -1,7 +1,7 @@ import type {Vec} from '@polkadot/types'; import {TypeRegistry} from '@polkadot/types'; import type {RegistryTypes} from '@polkadot/types/types'; -import {compactAddLength, hexToU8a} from '@polkadot/util'; +import {compactAddLength, hexToString, hexToU8a} from '@polkadot/util'; import {options as encointerOptions} from '@encointer/node-api'; @@ -215,8 +215,17 @@ export class Worker implements IWorkerBase { const res = await this.#ws.subscribe('author_submitAndWatchExtrinsic', 'author_submitAndWatchExtrinsic', [request.toHex()], onStatusChange ); - topHash = this.createType('Hash', res); - console.debug(`topHash: ${topHash}`); + + console.debug(`return value: ${res}`); + + try { + topHash = this.createType('Hash', res); + console.debug(`topHash: ${topHash}`); + } catch (e) { + console.warn(`Could not return trusted call return value. It is probably an error`); + // Fixe: if the worker fully implements JSON_RPC2.0, the error should have a dedicated field. + reject(hexToString(res as string)); + } } catch (err) { console.error(err); reject(err); From d90bd57546ce9265266153503616ccedab6434ca Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Sat, 9 Nov 2024 11:43:12 +0100 Subject: [PATCH 3/6] fix getting notes and add integration tests for it --- .../worker-api/src/integriteeWorker.spec.ts | 46 ++++++++++++++++++- packages/worker-api/src/integriteeWorker.ts | 6 +-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 0d2a4a3b..78e12f0f 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -96,6 +96,26 @@ describe('worker', () => { }); }); + describe('noteBucketsInfoGetter', () => { + it('should return value', async () => { + const getter = worker.noteBucketsInfoGetter(network.shard); + console.log(`noteBucketsInfoGetter: ${JSON.stringify(getter)}`); + const result = await getter.send(); + console.log('noteBucketsInfoGetter:', result.toHuman()); + expect(result).toBeDefined(); + }); + }); + + describe('notesForTrustedGetter', () => { + it('should return value', async () => { + const getter = await worker.notesForTrustedGetter(alice, 0, network.shard); + console.log(`notesForTrustedGetter: ${JSON.stringify(getter)}`); + const result = await getter.send(); + console.log('notesForTrustedGetter:', result.toHuman()); + expect(result).toBeDefined(); + }); + }); + describe('guessTheNumberInfoGetter', () => { it('should return value', async () => { const getter = worker.guessTheNumberInfoGetter(network.shard); @@ -116,7 +136,31 @@ describe('worker', () => { }); }); - describe('balance transfer should work', () => { + describe('should return note of the executed trusted call', () => { + it('should return balance transfer with note as note', async () => { + const shard = network.shard; + const result = await worker.trustedBalanceTransfer( + charlie, + shard, + network.mrenclave, + charlie.address, + alice.address, + 1100000000000, + "My test note" + ); + console.log('balance transfer result', JSON.stringify(result)); + expect(result).toBeDefined(); + + const getter = await worker.notesForTrustedGetter(alice, 0, network.shard); + console.log(`notesForTrustedGetter: ${JSON.stringify(getter)}`); + const notes = await getter.send(); + console.log('notesForTrustedGetter:', notes.toHuman()); + expect(notes.length).toBeGreaterThanOrEqual(1); + }); + }); + + // race condition so skipped + describe.skip('balance transfer should work', () => { it('should return value', async () => { const shard = network.shard; const result = await worker.trustedBalanceTransfer( diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index 6232ac4c..2f8f1c85 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -63,7 +63,7 @@ export class IntegriteeWorker extends Worker { const publicGetterArgs = { shard: shard, } - return submittablePublicGetter(this, 'note_buckets_info', publicGetterArgs, null, 'ParentchainsInfo'); + return submittablePublicGetter(this, 'note_buckets_info', publicGetterArgs, null, 'NotesBucketInfo'); } @@ -73,8 +73,8 @@ export class IntegriteeWorker extends Worker { account: accountOrPubKey, signer: signerOptions?.signer, } - const notesForArgs = this.createType('NotesForArgs', (asString(accountOrPubKey), bucketIndex)); - return await submittableTrustedGetter>(this, 'notes_for', accountOrPubKey, trustedGetterArgs, notesForArgs,'u8'); + const notesForArgs = this.createType('NotesForArgs', [asString(accountOrPubKey), bucketIndex]); + return await submittableTrustedGetter>(this, 'notes_for', accountOrPubKey, trustedGetterArgs, notesForArgs,'Vec'); } public guessTheNumberInfoGetter(shard: string): SubmittableGetter { From 77dc6a54560d9fb0d911089055a4f0bd996ea0b3 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Sat, 9 Nov 2024 11:43:25 +0100 Subject: [PATCH 4/6] [test-utils] update mrenclave --- packages/worker-api/src/testUtils/networks.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/worker-api/src/testUtils/networks.ts b/packages/worker-api/src/testUtils/networks.ts index 786e3269..b5814adf 100644 --- a/packages/worker-api/src/testUtils/networks.ts +++ b/packages/worker-api/src/testUtils/networks.ts @@ -39,9 +39,9 @@ export const localDockerNetwork = () => { chain: 'ws://127.0.0.1:9944', worker: 'wss://127.0.0.1:2000', genesisHash: '0x388c446a804e24e77ae89f5bb099edb60cacc2ac7c898ce175bdaa08629c1439', - mrenclave: 'BrFk2gARyQxD56NLpDKVbZinDmD1Twt1GwMsEyQuWshx', - shard: 'BrFk2gARyQxD56NLpDKVbZinDmD1Twt1GwMsEyQuWshx', - chosenCid: 'BrFk2gARyQxD56NLpDKVbZinDmD1Twt1GwMsEyQuWshx', + mrenclave: 'ExUoZaWmrqx2P3g77ERLzkkaaewdJP2atieSMbQHHGmq', + shard: 'ExUoZaWmrqx2P3g77ERLzkkaaewdJP2atieSMbQHHGmq', + chosenCid: 'ExUoZaWmrqx2P3g77ERLzkkaaewdJP2atieSMbQHHGmq', customTypes: {}, palletOverrides: {} }; From b21c411635f07ff4bdddc9570458071ae932c5a3 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Sat, 9 Nov 2024 11:45:17 +0100 Subject: [PATCH 5/6] v0.16.1-alpha.0 --- lerna.json | 2 +- packages/node-api/package.json | 4 ++-- packages/types/package.json | 2 +- packages/util/package.json | 2 +- packages/worker-api/package.json | 8 ++++---- yarn.lock | 14 +++++++------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lerna.json b/lerna.json index 9886c7bc..8b124a36 100644 --- a/lerna.json +++ b/lerna.json @@ -6,5 +6,5 @@ "publishConfig": { "directory": "build" }, - "version": "0.16.0-alpha.1" + "version": "0.16.1-alpha.0" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index 140c5f1b..c104dff2 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -18,10 +18,10 @@ }, "sideEffects": false, "type": "module", - "version": "0.16.0-alpha.1", + "version": "0.16.1-alpha.0", "main": "index.js", "dependencies": { - "@encointer/types": "^0.16.0-alpha.1", + "@encointer/types": "^0.16.1-alpha.0", "@polkadot/api": "^11.2.1", "tslib": "^2.6.2" }, diff --git a/packages/types/package.json b/packages/types/package.json index b16de67f..31aeb211 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -18,7 +18,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.16.0-alpha.1", + "version": "0.16.1-alpha.0", "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/util/package.json b/packages/util/package.json index 5e082db3..2133f85b 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.16.0-alpha.1", + "version": "0.16.1-alpha.0", "main": "index.js", "dependencies": { "@babel/runtime": "^7.18.9", diff --git a/packages/worker-api/package.json b/packages/worker-api/package.json index cd34e9b5..eb7a420d 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.16.0-alpha.1", + "version": "0.16.1-alpha.0", "main": "index.js", "dependencies": { - "@encointer/node-api": "^0.16.0-alpha.1", - "@encointer/types": "^0.16.0-alpha.1", - "@encointer/util": "^0.16.0-alpha.1", + "@encointer/node-api": "^0.16.1-alpha.0", + "@encointer/types": "^0.16.1-alpha.0", + "@encointer/util": "^0.16.1-alpha.0", "@peculiar/webcrypto": "^1.4.6", "@polkadot/api": "^11.2.1", "@polkadot/keyring": "^12.6.2", diff --git a/yarn.lock b/yarn.lock index b92f5a39..403a89b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -755,18 +755,18 @@ __metadata: languageName: node linkType: hard -"@encointer/node-api@npm:^0.16.0-alpha.1, @encointer/node-api@workspace:packages/node-api": +"@encointer/node-api@npm:^0.16.1-alpha.0, @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.16.0-alpha.1" + "@encointer/types": "npm:^0.16.1-alpha.0" "@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.16.0-alpha.1, @encointer/types@workspace:packages/types": +"@encointer/types@npm:^0.16.1-alpha.0, @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.16.0-alpha.1, @encointer/util@workspace:packages/util": +"@encointer/util@npm:^0.16.1-alpha.0, @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.16.0-alpha.1" - "@encointer/types": "npm:^0.16.0-alpha.1" - "@encointer/util": "npm:^0.16.0-alpha.1" + "@encointer/node-api": "npm:^0.16.1-alpha.0" + "@encointer/types": "npm:^0.16.1-alpha.0" + "@encointer/util": "npm:^0.16.1-alpha.0" "@peculiar/webcrypto": "npm:^1.4.6" "@polkadot/api": "npm:^11.2.1" "@polkadot/keyring": "npm:^12.6.2" From 62075c23161fa3170aa920633bf7763b4994e5b3 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Sat, 9 Nov 2024 11:45:36 +0100 Subject: [PATCH 6/6] v0.17.0-alpha.0 --- lerna.json | 2 +- packages/node-api/package.json | 4 ++-- packages/types/package.json | 2 +- packages/util/package.json | 2 +- packages/worker-api/package.json | 8 ++++---- yarn.lock | 14 +++++++------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lerna.json b/lerna.json index 8b124a36..a05472ed 100644 --- a/lerna.json +++ b/lerna.json @@ -6,5 +6,5 @@ "publishConfig": { "directory": "build" }, - "version": "0.16.1-alpha.0" + "version": "0.17.0-alpha.0" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index c104dff2..8f917dfb 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -18,10 +18,10 @@ }, "sideEffects": false, "type": "module", - "version": "0.16.1-alpha.0", + "version": "0.17.0-alpha.0", "main": "index.js", "dependencies": { - "@encointer/types": "^0.16.1-alpha.0", + "@encointer/types": "^0.17.0-alpha.0", "@polkadot/api": "^11.2.1", "tslib": "^2.6.2" }, diff --git a/packages/types/package.json b/packages/types/package.json index 31aeb211..823a133b 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -18,7 +18,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.16.1-alpha.0", + "version": "0.17.0-alpha.0", "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/util/package.json b/packages/util/package.json index 2133f85b..16ec101e 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.16.1-alpha.0", + "version": "0.17.0-alpha.0", "main": "index.js", "dependencies": { "@babel/runtime": "^7.18.9", diff --git a/packages/worker-api/package.json b/packages/worker-api/package.json index eb7a420d..595e8512 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.16.1-alpha.0", + "version": "0.17.0-alpha.0", "main": "index.js", "dependencies": { - "@encointer/node-api": "^0.16.1-alpha.0", - "@encointer/types": "^0.16.1-alpha.0", - "@encointer/util": "^0.16.1-alpha.0", + "@encointer/node-api": "^0.17.0-alpha.0", + "@encointer/types": "^0.17.0-alpha.0", + "@encointer/util": "^0.17.0-alpha.0", "@peculiar/webcrypto": "^1.4.6", "@polkadot/api": "^11.2.1", "@polkadot/keyring": "^12.6.2", diff --git a/yarn.lock b/yarn.lock index 403a89b3..0572f8bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -755,18 +755,18 @@ __metadata: languageName: node linkType: hard -"@encointer/node-api@npm:^0.16.1-alpha.0, @encointer/node-api@workspace:packages/node-api": +"@encointer/node-api@npm:^0.17.0-alpha.0, @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.16.1-alpha.0" + "@encointer/types": "npm:^0.17.0-alpha.0" "@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.16.1-alpha.0, @encointer/types@workspace:packages/types": +"@encointer/types@npm:^0.17.0-alpha.0, @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.16.1-alpha.0, @encointer/util@workspace:packages/util": +"@encointer/util@npm:^0.17.0-alpha.0, @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.16.1-alpha.0" - "@encointer/types": "npm:^0.16.1-alpha.0" - "@encointer/util": "npm:^0.16.1-alpha.0" + "@encointer/node-api": "npm:^0.17.0-alpha.0" + "@encointer/types": "npm:^0.17.0-alpha.0" + "@encointer/util": "npm:^0.17.0-alpha.0" "@peculiar/webcrypto": "npm:^1.4.6" "@polkadot/api": "npm:^11.2.1" "@polkadot/keyring": "npm:^12.6.2"