Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci-config/rippled.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ TokenEscrow
SingleAssetVault
LendingProtocol
PermissionDelegationV1_1
MPTokensV2

# This section can be used to simulate various FeeSettings scenarios for rippled node in standalone mode
[voting]
Expand Down
2 changes: 2 additions & 0 deletions packages/ripple-binary-codec/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Added
* Add `Int32` serialized type.
* Introduce unit tests for the `PathSet` rippled type
* Update the serialization of `PathSet` rippled type to accommodate `mpt_issuance_id` PathElement. This update is a part of the XLS-82d MPT-DEX amendment.

### Fixed
* Fix STNumber serialization logic to work with large mantissa scale [10^18, 10^19-1].
Expand Down
20 changes: 20 additions & 0 deletions packages/ripple-binary-codec/src/enums/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,26 @@
"type": "Hash192"
}
],
[
"TakerPaysMPT",
{
"isSerialized": true,
"isSigningField": true,
"isVLEncoded": false,
"nth": 3,
"type": "Hash192"
}
],
[
"TakerGetsMPT",
{
"isSerialized": true,
"isSigningField": true,
"isVLEncoded": false,
"nth": 4,
"type": "Hash192"
}
],
[
"LockingChainIssue",
{
Expand Down
3 changes: 2 additions & 1 deletion packages/ripple-binary-codec/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Hash256 } from './hash-256'
import { Int32 } from './int-32'
import { Issue } from './issue'
import { STNumber } from './st-number'
import { PathSet } from './path-set'
import { PathSet, HopObject } from './path-set'
import { STArray } from './st-array'
import { STObject } from './st-object'
import { UInt16 } from './uint-16'
Expand Down Expand Up @@ -68,4 +68,5 @@ export {
UInt32,
UInt64,
Vector256,
HopObject,
}
2 changes: 1 addition & 1 deletion packages/ripple-binary-codec/src/types/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function isIssueObject(arg): arg is IssueObject {
return isXRP || isIOU || isMPT
}

const MPT_WIDTH = 44
export const MPT_WIDTH = 44
const NO_ACCOUNT = AccountID.from('0000000000000000000000000000000000000001')

/**
Expand Down
38 changes: 34 additions & 4 deletions packages/ripple-binary-codec/src/types/path-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Currency } from './currency'
import { BinaryParser } from '../serdes/binary-parser'
import { SerializedType, JsonObject } from './serialized-type'
import { bytesToHex, concat } from '@xrplf/isomorphic/utils'
import { Hash192 } from './hash-192'

/**
* Constants for separating Paths in a PathSet
Expand All @@ -16,14 +17,17 @@ const PATH_SEPARATOR_BYTE = 0xff
const TYPE_ACCOUNT = 0x01
const TYPE_CURRENCY = 0x10
const TYPE_ISSUER = 0x20
const TYPE_MPT = 0x40

/**
* The object representation of a Hop, an issuer AccountID, an account AccountID, and a Currency
* The object representation of a Hop, an issuer AccountID, an account AccountID, and a Currency.
* Alternatively, this could also contain an MPTIssuanceID
*/
interface HopObject extends JsonObject {
issuer?: string
account?: string
currency?: string
mpt_issuance_id?: string
}

/**
Expand All @@ -33,7 +37,8 @@ function isHopObject(arg): arg is HopObject {
return (
arg.issuer !== undefined ||
arg.account !== undefined ||
arg.currency !== undefined
arg.currency !== undefined ||
arg.mpt_issuance_id !== undefined
)
}

Expand Down Expand Up @@ -70,9 +75,18 @@ class Hop extends SerializedType {
bytes[0][0] |= TYPE_ACCOUNT
}

if (value.currency && value.mpt_issuance_id) {
throw new Error(
'Currency and mpt_issuance_id are mutually exclusive in a path hop',
)
}

if (value.currency) {
bytes.push(Currency.from(value.currency).toBytes())
bytes[0][0] |= TYPE_CURRENCY
} else if (value.mpt_issuance_id) {
bytes.push(Hash192.from(value.mpt_issuance_id).toBytes())
bytes[0][0] |= TYPE_MPT
}

if (value.issuer) {
Expand All @@ -93,12 +107,20 @@ class Hop extends SerializedType {
const type = parser.readUInt8()
const bytes: Array<Uint8Array> = [Uint8Array.from([type])]

if (type & TYPE_CURRENCY && type & TYPE_MPT) {
throw new Error(
'Invalid binary input: Currency and mpt_issuance_id are mutually exclusive in a path hop',
)
}

if (type & TYPE_ACCOUNT) {
bytes.push(parser.read(AccountID.width))
}

if (type & TYPE_CURRENCY) {
bytes.push(parser.read(Currency.width))
} else if (type & TYPE_MPT) {
bytes.push(parser.read(Hash192.width))
}

if (type & TYPE_ISSUER) {
Expand All @@ -117,7 +139,7 @@ class Hop extends SerializedType {
const hopParser = new BinaryParser(bytesToHex(this.bytes))
const type = hopParser.readUInt8()

let account, currency, issuer
let account, currency, issuer, mpt_issuance_id
if (type & TYPE_ACCOUNT) {
account = (AccountID.fromParser(hopParser) as AccountID).toJSON()
}
Expand All @@ -126,6 +148,10 @@ class Hop extends SerializedType {
currency = (Currency.fromParser(hopParser) as Currency).toJSON()
}

if (type & TYPE_MPT) {
mpt_issuance_id = (Hash192.fromParser(hopParser) as Hash192).toHex()
}

if (type & TYPE_ISSUER) {
issuer = (AccountID.fromParser(hopParser) as AccountID).toJSON()
}
Expand All @@ -143,6 +169,10 @@ class Hop extends SerializedType {
result.currency = currency
}

if (mpt_issuance_id) {
result.mpt_issuance_id = mpt_issuance_id
}

return result
}

Expand Down Expand Up @@ -287,4 +317,4 @@ class PathSet extends SerializedType {
}
}

export { PathSet }
export { PathSet, HopObject }
Loading
Loading