feat: add support for XLS-40d + add script to auto-generate models from rippled code (#2491)

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

### Context of Change

https://github.com/XRPLF/XRPL-Standards/pull/136
https://github.com/XRPLF/rippled/pull/4636
This commit is contained in:
Mayukha Vadari
2023-11-15 17:19:50 -05:00
committed by GitHub
parent 22dd17d6b7
commit c8f25a6347
17 changed files with 701 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
const fs = require('fs')
const fixtures = require('ripple-binary-codec/test/fixtures/codec-fixtures.json')
const path = require('path')
const fixtures = require('../../ripple-binary-codec/test/fixtures/codec-fixtures.json')
const NORMAL_TYPES = ['number', 'string']
const NUMBERS = ['0', '1']
@@ -9,15 +10,20 @@ function getTx(txName) {
const validTxs = fixtures.transactions
.filter((tx) => tx.json.TransactionType === txName)
.map((tx) => tx.json)
if (validTxs.length == 0) {
throw new Error(`Must have ripple-binary-codec fixture for ${txName}`)
}
const validTx = validTxs[0]
delete validTx.TxnSignature
delete validTx.SigningPubKey
return JSON.stringify(validTx, null, 2)
}
function main() {
const modelName = process.argv[2]
const filename = `./packages/xrpl/src/models/transactions/${modelName}.ts`
function main(modelName) {
const filename = path.join(
path.dirname(__filename),
`../src/models/transactions/${modelName}.ts`,
)
const [model, txName] = getModel(filename)
return processModel(model, txName)
}
@@ -61,6 +67,8 @@ function getInvalidValue(paramTypes) {
return 123
} else if (paramType == 'IssuedCurrency') {
return JSON.stringify({ test: 'test' })
} else if (paramType == 'Currency') {
return JSON.stringify({ test: 'test' })
} else if (paramType == 'Amount') {
return JSON.stringify({ currency: 'ETH' })
} else if (paramType == 'XChainBridge') {
@@ -184,4 +192,12 @@ describe('${txName}', function () {
return output
}
console.log(main())
if (require.main === module) {
if (process.argv.length < 3) {
console.log(`Usage: ${process.argv[0]} ${process.argv[1]} TxName`)
process.exit(1)
}
console.log(main(process.argv[2]))
}
module.exports = main