Skip to content

Commit

Permalink
nodejs: add multi and empty unlock classes (#1627)
Browse files Browse the repository at this point in the history
* nodejs: add multi and empty unlock classes

* Add @type to unlocks

* Fix Cannot access 'UnlockDiscriminator' before initialization

---------

Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
Thoralf-M and thibault-martinez authored Nov 20, 2023
1 parent e2703a1 commit 7a1310f
Showing 1 changed file with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ enum UnlockType {
* An NFT unlock.
*/
Nft = 4,
/**
* A multi unlock.
*/
Multi = 5,
/**
* An empty unlock.
*/
Empty = 6,
}

/**
Expand Down Expand Up @@ -139,6 +147,64 @@ 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.
*/
class MultiUnlock extends Unlock {
/**
* The inner unlocks.
*/
@Type(() => Unlock, {
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[];

/**
* @param unlocks The inner unlocks.
*/
constructor(unlocks: Unlock[]) {
super(UnlockType.Multi);
this.unlocks = unlocks;
}
}

const UnlockDiscriminator = {
property: 'type',
subTypes: [
Expand All @@ -162,6 +228,14 @@ const UnlockDiscriminator = {
value: NftUnlock,
name: UnlockType.Nft as any,
},
{
value: MultiUnlock,
name: UnlockType.Multi as any,
},
{
value: EmptyUnlock,
name: UnlockType.Empty as any,
},
],
};

Expand All @@ -173,5 +247,7 @@ export {
AccountUnlock,
AnchorUnlock,
NftUnlock,
MultiUnlock,
EmptyUnlock,
UnlockDiscriminator,
};

0 comments on commit 7a1310f

Please sign in to comment.