From d84639d0daaeb285122e55362e8193f7b701bd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Thu, 16 Nov 2023 12:45:16 +0100 Subject: [PATCH 1/3] nodejs: add multi and empty unlock classes --- .../payload/signed_transaction/unlock.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts b/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts index de2107e7d2..6ae03e700f 100644 --- a/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts +++ b/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts @@ -28,6 +28,14 @@ enum UnlockType { * An NFT unlock. */ Nft = 4, + /** + * A multi unlock. + */ + Multi = 5, + /** + * An empty unlock. + */ + Empty = 6, } /** @@ -139,6 +147,33 @@ class NftUnlock extends Unlock { } } +/** + * Unlocks a MultiAddress with a list of other unlocks. + */ +class MultiUnlock extends Unlock { + /** + * The inner unlocks. + */ + readonly unlocks: Unlock[]; + + /** + * @param unlocks The inner unlocks. + */ + constructor(unlocks: Unlock[]) { + super(UnlockType.Multi); + this.unlocks = unlocks; + } +} + +/** + * Used to maintain correct index relationship between addresses and signatures when unlocking a MultiUnlock where not all addresses are unlocked. + */ +class EmptyUnlock extends Unlock { + constructor() { + super(UnlockType.Empty); + } +} + const UnlockDiscriminator = { property: 'type', subTypes: [ @@ -162,6 +197,14 @@ const UnlockDiscriminator = { value: NftUnlock, name: UnlockType.Nft as any, }, + { + value: MultiUnlock, + name: UnlockType.Multi as any, + }, + { + value: EmptyUnlock, + name: UnlockType.Empty as any, + }, ], }; @@ -173,5 +216,7 @@ export { AccountUnlock, AnchorUnlock, NftUnlock, + MultiUnlock, + EmptyUnlock, UnlockDiscriminator, }; From b0993e03cd1b0e43b72b33b3fed0a5f16f6fc3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Fri, 17 Nov 2023 09:21:53 +0100 Subject: [PATCH 2/3] Add @Type to unlocks --- .../lib/types/block/payload/signed_transaction/unlock.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts b/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts index 6ae03e700f..1d8551ad26 100644 --- a/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts +++ b/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts @@ -154,6 +154,10 @@ class MultiUnlock extends Unlock { /** * The inner unlocks. */ + @Type(() => Unlock, { + // @ts-ignore:next-line: no-use-before-declare + discriminator: UnlockDiscriminator, + }) readonly unlocks: Unlock[]; /** From 3d589f83bbb53381a2cd21346b06611bdcb55267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Fri, 17 Nov 2023 22:06:10 +0100 Subject: [PATCH 3/3] Fix Cannot access 'UnlockDiscriminator' before initialization --- .../payload/signed_transaction/unlock.ts | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts b/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts index 1d8551ad26..b9e73199db 100644 --- a/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts +++ b/bindings/nodejs/lib/types/block/payload/signed_transaction/unlock.ts @@ -147,6 +147,15 @@ class NftUnlock extends Unlock { } } +/** + * Used to maintain correct index relationship between addresses and signatures when unlocking a MultiUnlock where not all addresses are unlocked. + */ +class EmptyUnlock extends Unlock { + constructor() { + super(UnlockType.Empty); + } +} + /** * Unlocks a MultiAddress with a list of other unlocks. */ @@ -155,8 +164,35 @@ class MultiUnlock extends Unlock { * The inner unlocks. */ @Type(() => Unlock, { - // @ts-ignore:next-line: no-use-before-declare - discriminator: UnlockDiscriminator, + discriminator: { + property: 'type', + subTypes: [ + { + value: SignatureUnlock, + name: UnlockType.Signature as any, + }, + { + value: ReferenceUnlock, + name: UnlockType.Reference as any, + }, + { + value: AccountUnlock, + name: UnlockType.Account as any, + }, + { + value: AnchorUnlock, + name: UnlockType.Anchor as any, + }, + { + value: NftUnlock, + name: UnlockType.Nft as any, + }, + { + value: EmptyUnlock, + name: UnlockType.Empty as any, + }, + ], + }, }) readonly unlocks: Unlock[]; @@ -169,15 +205,6 @@ class MultiUnlock extends Unlock { } } -/** - * Used to maintain correct index relationship between addresses and signatures when unlocking a MultiUnlock where not all addresses are unlocked. - */ -class EmptyUnlock extends Unlock { - constructor() { - super(UnlockType.Empty); - } -} - const UnlockDiscriminator = { property: 'type', subTypes: [