export class Amount { @inline constructor(public bytes: ByteArray) { if ((bytes.length != 8) && (bytes.length != 48)) rollback("", pack_error_code(bytes.length)); } @inline get length(): i32 { return this.bytes.length; } @inline isXrp(): bool { return this.length == 8; } @inline get drops(): i64 { if (!this.isXrp()) rollback("", pack_error_code(0)); if ((this.bytes[0]) >> 7) rollback("", pack_error_code(this.bytes[0])); return (((this.bytes[0]) & 0xb00111111) << 56) + ((this.bytes[1]) << 48) + ((this.bytes[2]) << 40) + ((this.bytes[3]) << 32) + ((this.bytes[4]) << 24) + ((this.bytes[5]) << 16) + ((this.bytes[6]) << 8) + (this.bytes[7]); } @inline get tokenAmount(): i64 { if (this.isXrp()) rollback("", pack_error_code(0)); let r = $float_sto_set(changetype(this.bytes), 8); if (r < 0) rollback("", pack_error_code(r)); return r; } @inline get currencyCode(): ByteView { if (this.isXrp()) rollback("", pack_error_code(0)); return new ByteView(this.bytes, 8, 20); } @inline static fromDrops(drops: u64): Amount { let buf = new ByteArray(8); buf[0] = ((drops >> 56) & 0x3F); buf[1] = ((drops >> 48) & 0xFF); buf[2] = ((drops >> 40) & 0xFF); buf[3] = ((drops >> 32) & 0xFF); buf[4] = ((drops >> 24) & 0xFF); buf[5] = ((drops >> 16) & 0xFF); buf[6] = ((drops >> 8) & 0xFF); buf[7] = (drops & 0xFF); return new Amount(buf); } };