import { BitcoinError , BitcoinErrorCode , LockTime } from "." ; import { ICloneable } from "./ICloneable" ; /**
 * Represents bitcoin value that can be converted to or from multiple
 * formats.
 */ export class Value implements ICloneable < Value > { param num public static fromBitcoin ( num ) { return Value . fromSats ( Math . trunc ( num * 1e8 ) ) ; } param num public static fromSats ( num ) { return new Value ( BigInt ( num ) * BigInt ( 1e12 ) ) ; } param num public static fromMilliSats ( num ) { return new Value ( BigInt ( num ) * BigInt ( 1e9 ) ) ; } param num public static fromMicroSats ( num ) { return new Value ( BigInt ( num ) * BigInt ( 1e6 ) ) ; } param num public static fromPicoSats ( num ) { return new Value ( BigInt ( num ) ) ; } /**
     * Generates a value instance of zero
     */ public static zero ( ) { return new Value ( BigInt ( 0 ) ) ; } private _picoSats : bigint ; /**
     * Gets the value in picosatoshis (1/1e12 satoshis)
     */ public get psats ( ) : bigint { return this . _picoSats ; } /**
     * Gets the value in millionth of satoshis (1/1e6 satoshis)
     */ public get microsats ( ) : bigint { return this . _picoSats / BigInt ( 1e6 ) ; } /**
     * Gets the value in millisatoshis (1/1000 satoshis)
     */ public get msats ( ) : bigint { return this . _picoSats / BigInt ( 1e9 ) ; } /**
     * Gets the value in satoshis (1/1e8 bitcoin)
     */ public get sats ( ) : bigint { return this . _picoSats / BigInt ( 1e12 ) ; } /**
     * Gets the value in bitcoin
     */ public get bitcoin ( ) : number { return Math . max ( 0 , Number ( this . sats ) / 1e8 ) ; } private constructor ( picoSats ) { this . _picoSats = picoSats ; } /**
     * Clone via deep copy
     */ public clone ( ) { return new Value ( this . _picoSats ) ; } param other returns public eq ( other ) { return other . _picoSats === this . _picoSats ; } param other returns public neq ( other ) { return other . _picoSats !== this . _picoSats ; } param other returns public gt ( other ) { return this . _picoSats > other . _picoSats ; } param other returns public gte ( other ) { return this . _picoSats >= other . _picoSats ; } param other public lt ( other ) { return this . _picoSats < other . _picoSats ; } param other returns public lte ( other ) { return this . _picoSats <= other . _picoSats ; } param other public add ( other ) { this . _picoSats += other . _picoSats ; } param other public sub ( other ) { if ( this . _picoSats - other . _picoSats < 0 ) { throw new BitcoinError ( BitcoinErrorCode . ValueUnderflow ) ; } this . _picoSats -= other . _picoSats ; } }