From 26702988a0810de9a33921b7fcdd608ed10aba63 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 8 Nov 2022 22:17:57 -0500 Subject: [PATCH] rename IssuedCurrency -> Issue to match rippled --- .../ripple-binary-codec/src/types/index.ts | 4 +-- .../types/{issued-currency.ts => issue.ts} | 36 +++++++++---------- .../src/types/xchain-bridge.ts | 10 +++--- 3 files changed, 23 insertions(+), 27 deletions(-) rename packages/ripple-binary-codec/src/types/{issued-currency.ts => issue.ts} (69%) diff --git a/packages/ripple-binary-codec/src/types/index.ts b/packages/ripple-binary-codec/src/types/index.ts index c4096d5d5e..5204947a69 100644 --- a/packages/ripple-binary-codec/src/types/index.ts +++ b/packages/ripple-binary-codec/src/types/index.ts @@ -11,7 +11,7 @@ import { Currency } from './currency' import { Hash128 } from './hash-128' import { Hash160 } from './hash-160' import { Hash256 } from './hash-256' -import { IssuedCurrency } from './issued-currency' +import { Issue } from './issue' import { PathSet } from './path-set' import { STArray } from './st-array' import { STObject } from './st-object' @@ -31,7 +31,7 @@ const coreTypes = { Hash128, Hash160, Hash256, - IssuedCurrency, + Issue, PathSet, STArray, STObject, diff --git a/packages/ripple-binary-codec/src/types/issued-currency.ts b/packages/ripple-binary-codec/src/types/issue.ts similarity index 69% rename from packages/ripple-binary-codec/src/types/issued-currency.ts rename to packages/ripple-binary-codec/src/types/issue.ts index b4419224c0..1537aa8c00 100644 --- a/packages/ripple-binary-codec/src/types/issued-currency.ts +++ b/packages/ripple-binary-codec/src/types/issue.ts @@ -8,7 +8,7 @@ import { Buffer } from 'buffer/' /** * Interface for JSON objects that represent amounts */ -interface IssuedCurrencyObject extends JsonObject { +interface IssueObject extends JsonObject { currency: string issuer: string } @@ -16,7 +16,7 @@ interface IssuedCurrencyObject extends JsonObject { /** * Type guard for AmountObject */ -function isIssuedCurrencyObject(arg): arg is IssuedCurrencyObject { +function isIssueObject(arg): arg is IssueObject { const keys = Object.keys(arg).sort() return keys.length === 2 && keys[0] === 'currency' && keys[1] === 'issuer' } @@ -24,13 +24,11 @@ function isIssuedCurrencyObject(arg): arg is IssuedCurrencyObject { /** * Class for serializing/Deserializing Amounts */ -class IssuedCurrency extends SerializedType { - static readonly ZERO_ISSUED_CURRENCY: IssuedCurrency = new IssuedCurrency( - Buffer.alloc(20), - ) +class Issue extends SerializedType { + static readonly ZERO_ISSUED_CURRENCY: Issue = new Issue(Buffer.alloc(20)) constructor(bytes: Buffer) { - super(bytes ?? IssuedCurrency.ZERO_ISSUED_CURRENCY.bytes) + super(bytes ?? Issue.ZERO_ISSUED_CURRENCY.bytes) } /** @@ -40,25 +38,23 @@ class IssuedCurrency extends SerializedType { * representing an integer amount * @returns An Amount object */ - static from( - value: T, - ): IssuedCurrency { - if (value instanceof IssuedCurrency) { + static from(value: T): Issue { + if (value instanceof Issue) { return value } if (typeof value === 'string') { - IssuedCurrency.assertXrpIsValid(value) + Issue.assertXrpIsValid(value) const currency = Currency.from(value).toBytes() - return new IssuedCurrency(currency) + return new Issue(currency) } - if (isIssuedCurrencyObject(value)) { + if (isIssueObject(value)) { const currency = Currency.from(value.currency).toBytes() const issuer = AccountID.from(value.issuer).toBytes() - return new IssuedCurrency(Buffer.concat([currency, issuer])) + return new Issue(Buffer.concat([currency, issuer])) } throw new Error('Invalid type to construct an Amount') @@ -70,13 +66,13 @@ class IssuedCurrency extends SerializedType { * @param parser BinaryParser to read the Amount from * @returns An Amount object */ - static fromParser(parser: BinaryParser): IssuedCurrency { + static fromParser(parser: BinaryParser): Issue { const currency = parser.read(20) if (new Currency(currency).toJSON() === 'XRP') { - return new IssuedCurrency(currency) + return new Issue(currency) } const currencyAndIssuer = [currency, parser.read(20)] - return new IssuedCurrency(Buffer.concat(currencyAndIssuer)) + return new Issue(Buffer.concat(currencyAndIssuer)) } /** @@ -84,7 +80,7 @@ class IssuedCurrency extends SerializedType { * * @returns the JSON interpretation of this.bytes */ - toJSON(): IssuedCurrencyObject | string { + toJSON(): IssueObject | string { const parser = new BinaryParser(this.toString()) const currency = Currency.fromParser(parser) as Currency if (currency.toJSON() === 'XRP') { @@ -111,4 +107,4 @@ class IssuedCurrency extends SerializedType { } } -export { IssuedCurrency, IssuedCurrencyObject } +export { Issue, IssueObject } diff --git a/packages/ripple-binary-codec/src/types/xchain-bridge.ts b/packages/ripple-binary-codec/src/types/xchain-bridge.ts index 4870129ac3..82fd512568 100644 --- a/packages/ripple-binary-codec/src/types/xchain-bridge.ts +++ b/packages/ripple-binary-codec/src/types/xchain-bridge.ts @@ -3,16 +3,16 @@ import { BinaryParser } from '../serdes/binary-parser' import { AccountID } from './account-id' import { JsonObject, SerializedType } from './serialized-type' import { Buffer } from 'buffer/' -import { IssuedCurrency, IssuedCurrencyObject } from './issued-currency' +import { Issue, IssueObject } from './issue' /** * Interface for JSON objects that represent cross-chain bridges */ interface XChainBridgeObject extends JsonObject { LockingChainDoor: string - LockingChainIssue: IssuedCurrencyObject | string + LockingChainIssue: IssueObject | string IssuingChainDoor: string - IssuingChainIssue: IssuedCurrencyObject | string + IssuingChainIssue: IssueObject | string } /** @@ -45,9 +45,9 @@ class XChainBridge extends SerializedType { static readonly TYPE_ORDER: { name: string; type: typeof SerializedType }[] = [ { name: 'LockingChainDoor', type: AccountID }, - { name: 'LockingChainIssue', type: IssuedCurrency }, + { name: 'LockingChainIssue', type: Issue }, { name: 'IssuingChainDoor', type: AccountID }, - { name: 'IssuingChainIssue', type: IssuedCurrency }, + { name: 'IssuingChainIssue', type: Issue }, ] constructor(bytes: Buffer) {