|
| 1 | +import { BaseCoin, BaseUnit, CoinFeature, CoinKind, KeyCurve, UnderlyingAsset } from './base'; |
| 2 | +import { CantonNetwork } from './networks'; |
| 3 | + |
| 4 | +export interface CantonConstructorOptions { |
| 5 | + id: string; |
| 6 | + fullName: string; |
| 7 | + name: string; |
| 8 | + network: CantonNetwork; |
| 9 | + features: CoinFeature[]; |
| 10 | + asset: UnderlyingAsset; |
| 11 | + prefix?: string; |
| 12 | + suffix?: string; |
| 13 | + primaryKeyCurve: KeyCurve; |
| 14 | +} |
| 15 | + |
| 16 | +export class Canton extends BaseCoin { |
| 17 | + public readonly network: CantonNetwork; |
| 18 | + |
| 19 | + constructor(options: CantonConstructorOptions) { |
| 20 | + super({ |
| 21 | + ...options, |
| 22 | + kind: CoinKind.CRYPTO, |
| 23 | + isToken: false, |
| 24 | + decimalPlaces: 10, |
| 25 | + baseUnit: BaseUnit.CANTON, |
| 26 | + }); |
| 27 | + this.network = options.network; |
| 28 | + } |
| 29 | + |
| 30 | + protected disallowedFeatures(): Set<CoinFeature> { |
| 31 | + return new Set([CoinFeature.ACCOUNT_MODEL]); |
| 32 | + } |
| 33 | + |
| 34 | + protected requiredFeatures(): Set<CoinFeature> { |
| 35 | + return new Set([CoinFeature.UNSPENT_MODEL]); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * Factory function for canton coin instances |
| 41 | + * |
| 42 | + * @param {String} id unique identifier (uuid v4) |
| 43 | + * @param {String} name unique identifier of the coin |
| 44 | + * @param {String} fullName complete human-readable name of the coin |
| 45 | + * @param {CantonNetwork} network network object for this coin |
| 46 | + * @param {UnderlyingAsset} asset asset which this coin represents. This is the same for both mainNet and testNet variants of a coin. |
| 47 | + * @param {CoinFeature[]} features features of this coin. Defaults to the CANTON_DEFAULT_FEATURES defined in `account` |
| 48 | + * @param {String} prefix optional coin prefix. Defaults to empty string |
| 49 | + * @param {String} suffix optional coin suffix. Defaults to coin name. |
| 50 | + * @param {KeyCurve} primaryKeyCurve the elliptic curve for this chain/token |
| 51 | + */ |
| 52 | +export function canton( |
| 53 | + id: string, |
| 54 | + name: string, |
| 55 | + fullName: string, |
| 56 | + network: CantonNetwork, |
| 57 | + asset: UnderlyingAsset, |
| 58 | + features: CoinFeature[], |
| 59 | + prefix = '', |
| 60 | + suffix: string = name.toUpperCase(), |
| 61 | + primaryKeyCurve: KeyCurve = KeyCurve.Ed25519 |
| 62 | +): Readonly<Canton> { |
| 63 | + return Object.freeze( |
| 64 | + new Canton({ |
| 65 | + id, |
| 66 | + name, |
| 67 | + fullName, |
| 68 | + network, |
| 69 | + prefix, |
| 70 | + suffix, |
| 71 | + features, |
| 72 | + asset, |
| 73 | + primaryKeyCurve, |
| 74 | + }) |
| 75 | + ); |
| 76 | +} |
0 commit comments