Skip to content

Commit

Permalink
feat: add support for XLS-40d + add script to auto-generate models fr…
Browse files Browse the repository at this point in the history
…om rippled code (#2491)

Add support for XLS-40 and adds a script to automatically
generate transaction models from rippled source code.

### Context of Change

XRPLF/XRPL-Standards#136
XRPLF/rippled#4636
  • Loading branch information
mvadari authored Nov 15, 2023
1 parent 22dd17d commit c8f25a6
Show file tree
Hide file tree
Showing 17 changed files with 701 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .ci-config/rippled.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,6 @@ AMM
Clawback
fixReducedOffersV1
fixNFTokenRemint
# 2.0.0-b1 Amendments
# 2.0.0 Amendments
XChainBridge
DID
4 changes: 3 additions & 1 deletion packages/ripple-binary-codec/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# ripple-binary-codec Release History

## Unreleased
### Added
- Support for the DID amendment (XLS-40).

## 1.10.0 (2023-09-27)
### Added
- Support for the XChainBridge amendment.
- Support for the XChainBridge amendment (XLS-38).

## 1.9.0 (2023-08-24)

Expand Down
47 changes: 36 additions & 11 deletions packages/ripple-binary-codec/src/enums/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"NFTokenPage": 80,
"NFTokenOffer": 55,
"AMM": 121,
"DID": 73,
"Any": -3,
"Child": -2,
"Nickname": 110,
Expand Down Expand Up @@ -140,40 +141,40 @@
[
"LedgerEntry",
{
"nth": 1,
"nth": 257,
"isVLEncoded": false,
"isSerialized": false,
"isSigningField": true,
"isSigningField": false,
"type": "LedgerEntry"
}
],
[
"Transaction",
{
"nth": 1,
"nth": 257,
"isVLEncoded": false,
"isSerialized": false,
"isSigningField": true,
"isSigningField": false,
"type": "Transaction"
}
],
[
"Validation",
{
"nth": 1,
"nth": 257,
"isVLEncoded": false,
"isSerialized": false,
"isSigningField": true,
"isSigningField": false,
"type": "Validation"
}
],
[
"Metadata",
{
"nth": 1,
"nth": 257,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"isSerialized": false,
"isSigningField": false,
"type": "Metadata"
}
],
Expand Down Expand Up @@ -1897,6 +1898,26 @@
"type": "Blob"
}
],
[
"DIDDocument",
{
"nth": 26,
"isVLEncoded": true,
"isSerialized": true,
"isSigningField": true,
"type": "Blob"
}
],
[
"Data",
{
"nth": 27,
"isVLEncoded": true,
"isSerialized": true,
"isSigningField": true,
"type": "Blob"
}
],
[
"Account",
{
Expand Down Expand Up @@ -2681,6 +2702,7 @@
"temXCHAIN_BRIDGE_NONDOOR_OWNER": -257,
"temXCHAIN_BRIDGE_BAD_MIN_ACCOUNT_CREATE_AMOUNT": -256,
"temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT": -255,
"temEMPTY_DID": -254,

"tefFAILURE": -199,
"tefALREADY": -198,
Expand Down Expand Up @@ -2759,7 +2781,7 @@
"tecKILLED": 150,
"tecHAS_OBLIGATIONS": 151,
"tecTOO_SOON": 152,
"tecHOOK_ERROR": 153,
"tecHOOK_REJECTED": 153,
"tecMAX_SEQUENCE_REACHED": 154,
"tecNO_SUITABLE_NFTOKEN_PAGE": 155,
"tecNFTOKEN_BUY_SELL_MISMATCH": 156,
Expand Down Expand Up @@ -2792,7 +2814,8 @@
"tecXCHAIN_PAYMENT_FAILED": 183,
"tecXCHAIN_SELF_COMMIT": 184,
"tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR": 185,
"tecXCHAIN_CREATE_ACCOUNT_DISABLED": 186
"tecXCHAIN_CREATE_ACCOUNT_DISABLED": 186,
"tecEMPTY_DID": 187
},
"TRANSACTION_TYPES": {
"Invalid": -1,
Expand Down Expand Up @@ -2839,6 +2862,8 @@
"XChainAddAccountCreateAttestation": 46,
"XChainModifyBridge": 47,
"XChainCreateBridge": 48,
"DIDSet": 49,
"DIDDelete": 50,
"EnableAmendment": 100,
"SetFee": 101,
"UNLModify": 102
Expand Down
27 changes: 27 additions & 0 deletions packages/ripple-binary-codec/test/fixtures/codec-fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -4841,6 +4841,33 @@
"SigningPubKey": "ED7453D2572A2104E7B266A45888C53F503CEB1F11DC4BB3710EB2995238EC65B8",
"TxnSignature": "BC2F6E76969E3747E9BDE183C97573B086212F09D5387460E6EE2F32953E85EAEB9618FBBEF077276E30E59D619FCF7C7BDCDDDD9EB94D7CE1DD5CE9246B2107"
}
},
{
"binary": "1200322280000000240000000468400000000000000A7321ED9861C4CB029C0DA737B823D7D3459A70F227958D5C0C111CC7CF947FC5A93347744071E28B12465A1B47162C22E121DF61089DCD9AAF5773704B76179E771666886C8AAD5A33A87E34CC381A7D924E3FE3645F0BF98D565DE42C81E1A7A7E7981802811401476926B590BA3245F63C829116A0A3AF7F382D",
"json": {
"Account": "rfmDuhDyLGgx94qiwf3YF8BUV5j6KSvE8",
"Fee": "10",
"Flags": 2147483648,
"Sequence": 4,
"SigningPubKey": "ED9861C4CB029C0DA737B823D7D3459A70F227958D5C0C111CC7CF947FC5A93347",
"TransactionType": "DIDDelete",
"TxnSignature": "71E28B12465A1B47162C22E121DF61089DCD9AAF5773704B76179E771666886C8AAD5A33A87E34CC381A7D924E3FE3645F0BF98D565DE42C81E1A7A7E7981802"
}
},
{
"binary": "1200312280000000240000000368400000000000000A7321ED9861C4CB029C0DA737B823D7D3459A70F227958D5C0C111CC7CF947FC5A933477440AACD31A04CAE14670FC483A1382F393AA96B49C84479B58067F049FBD772999325667A6AA2520A63756EE84F3657298815019DD56A1AECE796B08535C4009C08750B6469645F6578616D706C65701A03646F63701B06617474657374811401476926B590BA3245F63C829116A0A3AF7F382D",
"json": {
"Account": "rfmDuhDyLGgx94qiwf3YF8BUV5j6KSvE8",
"Data": "617474657374",
"DIDDocument": "646F63",
"Fee": "10",
"Flags": 2147483648,
"Sequence": 3,
"SigningPubKey": "ED9861C4CB029C0DA737B823D7D3459A70F227958D5C0C111CC7CF947FC5A93347",
"TransactionType": "DIDSet",
"TxnSignature": "AACD31A04CAE14670FC483A1382F393AA96B49C84479B58067F049FBD772999325667A6AA2520A63756EE84F3657298815019DD56A1AECE796B08535C4009C08",
"URI": "6469645F6578616D706C65"
}
}
],
"ledgerData": [{
Expand Down
2 changes: 2 additions & 0 deletions packages/xrpl/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xrpl-announce) for release announcements. We recommend that xrpl.js (ripple-lib) users stay up-to-date with the latest stable release.

## Unreleased
### Added
- Support for the DID amendment (XLS-40).

### Added
* Support for `server_definitions` RPC
Expand Down
1 change: 1 addition & 0 deletions packages/xrpl/src/models/ledger/LedgerEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type LedgerEntryFilter =
| 'bridge'
| 'check'
| 'deposit_preauth'
| 'did'
| 'directory'
| 'escrow'
| 'fee'
Expand Down
20 changes: 20 additions & 0 deletions packages/xrpl/src/models/transactions/DIDDelete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { BaseTransaction, validateBaseTransaction } from './common'

// TODO: add docs

/**
* @category Transaction Models
*/
export interface DIDDelete extends BaseTransaction {
TransactionType: 'DIDDelete'
}

/**
* Verify the form and type of a DIDDelete at runtime.
*
* @param tx - A DIDDelete Transaction.
* @throws When the DIDDelete is malformed.
*/
export function validateDIDDelete(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
}
37 changes: 37 additions & 0 deletions packages/xrpl/src/models/transactions/DIDSet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
BaseTransaction,
isString,
validateBaseTransaction,
validateOptionalField,
} from './common'

// TODO: add docs

/**
* @category Transaction Models
*/
export interface DIDSet extends BaseTransaction {
TransactionType: 'DIDSet'

Data?: string

DIDDocument?: string

URI?: string
}

/**
* Verify the form and type of a DIDSet at runtime.
*
* @param tx - A DIDSet Transaction.
* @throws When the DIDSet is malformed.
*/
export function validateDIDSet(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)

validateOptionalField(tx, 'Data', isString)

validateOptionalField(tx, 'DIDDocument', isString)

validateOptionalField(tx, 'URI', isString)
}
2 changes: 2 additions & 0 deletions packages/xrpl/src/models/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export { CheckCancel } from './checkCancel'
export { CheckCash } from './checkCash'
export { CheckCreate } from './checkCreate'
export { Clawback } from './clawback'
export { DIDDelete } from './DIDDelete'
export { DIDSet } from './DIDSet'
export { DepositPreauth } from './depositPreauth'
export { EscrowCancel } from './escrowCancel'
export { EscrowCreate } from './escrowCreate'
Expand Down
52 changes: 32 additions & 20 deletions packages/xrpl/src/models/transactions/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { CheckCreate, validateCheckCreate } from './checkCreate'
import { Clawback, validateClawback } from './clawback'
import { isIssuedCurrency } from './common'
import { DepositPreauth, validateDepositPreauth } from './depositPreauth'
import { DIDDelete, validateDIDDelete } from './DIDDelete'
import { DIDSet, validateDIDSet } from './DIDSet'
import { EnableAmendment } from './enableAmendment'
import { EscrowCancel, validateEscrowCancel } from './escrowCancel'
import { EscrowCreate, validateEscrowCreate } from './escrowCreate'
Expand Down Expand Up @@ -91,18 +93,20 @@ import {
* @category Transaction Models
*/
export type Transaction =
| AccountDelete
| AccountSet
| AMMBid
| AMMCreate
| AMMDelete
| AMMDeposit
| AMMCreate
| AMMVote
| AMMWithdraw
| AccountDelete
| AccountSet
| CheckCancel
| CheckCash
| CheckCreate
| Clawback
| DIDDelete
| DIDSet
| DepositPreauth
| EscrowCancel
| EscrowCreate
Expand All @@ -122,13 +126,13 @@ export type Transaction =
| SignerListSet
| TicketCreate
| TrustSet
| XChainAccountCreateCommit
| XChainAddAccountCreateAttestation
| XChainAddClaimAttestation
| XChainClaim
| XChainCommit
| XChainCreateBridge
| XChainCreateClaimID
| XChainAccountCreateCommit
| XChainModifyBridge

export type PseudoTransaction = EnableAmendment | SetFee | UNLModify
Expand Down Expand Up @@ -210,18 +214,14 @@ export function validate(transaction: Record<string, unknown>): void {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- okay here
setTransactionFlagsToNumber(tx as unknown as Transaction)
switch (tx.TransactionType) {
case 'AccountDelete':
validateAccountDelete(tx)
break

case 'AccountSet':
validateAccountSet(tx)
break

case 'AMMBid':
validateAMMBid(tx)
break

case 'AMMCreate':
validateAMMCreate(tx)
break

case 'AMMDelete':
validateAMMDelete(tx)
break
Expand All @@ -230,10 +230,6 @@ export function validate(transaction: Record<string, unknown>): void {
validateAMMDeposit(tx)
break

case 'AMMCreate':
validateAMMCreate(tx)
break

case 'AMMVote':
validateAMMVote(tx)
break
Expand All @@ -242,6 +238,14 @@ export function validate(transaction: Record<string, unknown>): void {
validateAMMWithdraw(tx)
break

case 'AccountDelete':
validateAccountDelete(tx)
break

case 'AccountSet':
validateAccountSet(tx)
break

case 'CheckCancel':
validateCheckCancel(tx)
break
Expand All @@ -258,6 +262,14 @@ export function validate(transaction: Record<string, unknown>): void {
validateClawback(tx)
break

case 'DIDDelete':
validateDIDDelete(tx)
break

case 'DIDSet':
validateDIDSet(tx)
break

case 'DepositPreauth':
validateDepositPreauth(tx)
break
Expand Down Expand Up @@ -334,6 +346,10 @@ export function validate(transaction: Record<string, unknown>): void {
validateTrustSet(tx)
break

case 'XChainAccountCreateCommit':
validateXChainAccountCreateCommit(tx)
break

case 'XChainAddAccountCreateAttestation':
validateXChainAddAccountCreateAttestation(tx)
break
Expand All @@ -358,10 +374,6 @@ export function validate(transaction: Record<string, unknown>): void {
validateXChainCreateClaimID(tx)
break

case 'XChainAccountCreateCommit':
validateXChainAccountCreateCommit(tx)
break

case 'XChainModifyBridge':
validateXChainModifyBridge(tx)
break
Expand Down
Loading

0 comments on commit c8f25a6

Please sign in to comment.