Skip to content

Commit

Permalink
Merge branch '2.0' into infallible-output-ignore-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Nov 21, 2023
2 parents 8b7c0ad + 3175a90 commit 2148972
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions bindings/nodejs/lib/types/block/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ enum AddressType {
Anchor = 24,
/** An implicit account creation address. */
ImplicitAccountCreation = 32,
/** A Multi address. */
Multi = 40,
/** An address with restricted capabilities. */
Restricted = 48,
}
Expand Down Expand Up @@ -78,6 +80,7 @@ abstract class Address {
throw new Error('Invalid JSON');
}
}

/**
* An Ed25519 Address.
*/
Expand Down Expand Up @@ -256,6 +259,70 @@ class RestrictedAddress extends Address {
}
}

/**
* A weighted address.
*/
class WeightedAddress {
/**
* The unlocked address.
*/
@Type(() => Address, {
discriminator: {
property: 'type',
subTypes: [
{ value: Ed25519Address, name: AddressType.Ed25519 as any },
{ value: AccountAddress, name: AddressType.Account as any },
{ value: NftAddress, name: AddressType.Nft as any },
{ value: AnchorAddress, name: AddressType.Anchor as any },
],
},
})
readonly address: Address;
/**
* The weight of the unlocked address.
*/
readonly weight: number;

/**
* @param address The unlocked address.
* @param weight The weight of the unlocked address.
*/
constructor(address: Address, weight: number) {
this.address = address;
this.weight = weight;
}
}

/**
* An address that consists of addresses with weights and a threshold value.
* The Multi Address can be unlocked if the cumulative weight of all unlocked addresses is equal to or exceeds the
* threshold.
*/
class MultiAddress extends Address {
/**
* The weighted unlocked addresses.
*/
readonly addresses: WeightedAddress[];
/**
* The threshold that needs to be reached by the unlocked addresses in order to unlock the multi address.
*/
readonly threshold: number;

/**
* @param addresses The weighted unlocked addresses.
* @param threshold The threshold that needs to be reached by the unlocked addresses in order to unlock the multi address.
*/
constructor(addresses: WeightedAddress[], threshold: number) {
super(AddressType.Multi);
this.addresses = addresses;
this.threshold = threshold;
}

toString(): string {
return JSON.stringify(this);
}
}

const AddressDiscriminator = {
property: 'type',
subTypes: [
Expand All @@ -267,6 +334,7 @@ const AddressDiscriminator = {
value: ImplicitAccountCreationAddress,
name: AddressType.ImplicitAccountCreation as any,
},
{ value: MultiAddress, name: AddressType.Multi as any },
{ value: RestrictedAddress, name: AddressType.Restricted as any },
],
};
Expand All @@ -281,5 +349,7 @@ export {
NftAddress,
AnchorAddress,
ImplicitAccountCreationAddress,
WeightedAddress,
MultiAddress,
RestrictedAddress,
};

0 comments on commit 2148972

Please sign in to comment.