clean up code

This commit is contained in:
Mayukha Vadari
2021-06-24 17:36:19 -04:00
parent f25aecd853
commit 32dcd3070a

View File

@@ -27,7 +27,9 @@ function isoCodeFromHex(code: Buffer): string | undefined {
const iso = code.toString(); const iso = code.toString();
console.log(iso); console.log(iso);
if (iso === "XRP") { if (iso === "XRP") {
throw new Error("Disallowed currency code: to indicate the currency XRP you must use 20 bytes of 0s"); throw new Error(
"Disallowed currency code: to indicate the currency XRP you must use 20 bytes of 0s"
);
} }
if (isIsoCode(iso)) { if (isIsoCode(iso)) {
return iso; return iso;
@@ -81,24 +83,10 @@ function bytesFromRepresentation(input: string): Buffer {
class Currency extends Hash160 { class Currency extends Hash160 {
static readonly XRP = new Currency(Buffer.alloc(20)); static readonly XRP = new Currency(Buffer.alloc(20));
private readonly _iso?: string; private readonly _iso?: string;
// private readonly _isNative: boolean;
constructor(byteBuf: Buffer) { constructor(byteBuf: Buffer) {
super(byteBuf ?? Currency.XRP.bytes); super(byteBuf ?? Currency.XRP.bytes);
// let onlyISO = true;
// const bytes = this.bytes;
const code = this.bytes.slice(12, 15); const code = this.bytes.slice(12, 15);
// const iso = code.toString();
// for (let i = bytes.length - 1; i >= 0; i--) {
// if (bytes[i] !== 0 && !(i === 12 || i === 13 || i === 14)) {
// onlyISO = false;
// break;
// }
// }
if (this.bytes[0] !== 0 && this.bytes[0] !== 0) { if (this.bytes[0] !== 0 && this.bytes[0] !== 0) {
this._iso = undefined; this._iso = undefined;
@@ -107,21 +95,8 @@ class Currency extends Hash160 {
} else { } else {
this._iso = isoCodeFromHex(code); this._iso = isoCodeFromHex(code);
} }
// const lossLessISO = onlyISO && iso !== "XRP" && ISO_REGEX.test(iso);
// this._isNative = onlyISO && code.toString("hex") === "000000";
// this._iso = this._isNative ? "XRP" : lossLessISO ? iso : undefined;
} }
// /**
// * Tells if this currency is native
// *
// * @returns true if native, false if not
// */
// isNative(): boolean {
// return this._isNative;
// }
/** /**
* Return the ISO code of this currency * Return the ISO code of this currency
* *