Skip to content

feat: add support for Batch amendment #2801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 109 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
4803cdc
improve scripts
mvadari May 3, 2024
84c8900
Update settings.json
mvadari May 7, 2024
6ca94b7
Merge branch 'main' into better-scripts
mvadari May 8, 2024
810bc42
Merge branch 'main' into better-scripts
mvadari May 8, 2024
dce0947
Merge branch 'main' into better-scripts
mvadari May 8, 2024
bac69ca
Merge branch 'main' into better-scripts
mvadari May 23, 2024
7866790
Merge branch 'main' into better-scripts
mvadari Jul 1, 2024
768eb08
Merge branch 'main' into better-scripts
mvadari Jul 3, 2024
8df48e2
Merge branch 'main' into better-scripts
mvadari Jul 8, 2024
e1747a9
Merge branch 'main' into better-scripts
mvadari Jul 9, 2024
9d69271
Merge branch 'main' into better-scripts
mvadari Jul 11, 2024
78e3d05
Merge branch 'main' into better-scripts
mvadari Jul 16, 2024
dc98b1b
Merge branch 'main' into better-scripts
mvadari Jul 22, 2024
fe08836
Merge branch 'main' into better-scripts
mvadari Aug 27, 2024
4fe1986
Merge branch 'main' into better-scripts
mvadari Sep 19, 2024
e696113
Merge branch 'main' into better-scripts
mvadari Sep 24, 2024
ab8d1b1
Merge branch 'main' into better-scripts
mvadari Sep 26, 2024
66dc844
Merge branch 'better-scripts' of https://github.com/XRPLF/xrpl.js int…
mvadari Oct 1, 2024
25ccc09
update file locations after refactor
mvadari Oct 1, 2024
7597807
add LedgerStateFix
mvadari Oct 1, 2024
ef4ab32
add Batch
mvadari Oct 1, 2024
762e57e
add BatchTxn autofill
mvadari Oct 1, 2024
28bce04
add multi-account signing
mvadari Oct 1, 2024
f671532
add combine function
mvadari Oct 1, 2024
9643508
add Batch support to hashing txs
mvadari Oct 1, 2024
e743ddc
add autofill TxID support
mvadari Oct 1, 2024
826fff8
better validation
mvadari Oct 1, 2024
ab09e38
add metadata
mvadari Oct 1, 2024
a4b55e2
update definitions.json
mvadari Oct 1, 2024
7d7acae
clean up
mvadari Oct 1, 2024
8fc2600
update binary codec for signing
mvadari Oct 1, 2024
0d86085
add Batchnet faucet
mvadari Oct 1, 2024
438a9d2
get basic tests working
mvadari Oct 2, 2024
591af47
add rbc tests
mvadari Oct 2, 2024
9b8c819
add autofill tests
mvadari Oct 2, 2024
78e3ad9
add signMultiBatch tests
mvadari Oct 2, 2024
4e3a5fb
refactor
mvadari Oct 2, 2024
7fb9927
add basic tests for combineBatchSigners
mvadari Oct 2, 2024
447c747
handle more edge cases
mvadari Oct 2, 2024
4d84930
better error validation
mvadari Oct 3, 2024
f120ea6
rename
mvadari Oct 3, 2024
1772b45
Merge branch 'main' into batch
mvadari Oct 7, 2024
009e98f
update history
mvadari Oct 7, 2024
211d46a
fix import
mvadari Oct 9, 2024
ff9929c
add more validation
mvadari Oct 10, 2024
29991c2
Merge branch 'main' into batch
mvadari Oct 11, 2024
fcd579a
Merge branch 'main' into batch
mvadari Oct 22, 2024
3818b29
Merge branch 'main' into batch
mvadari Nov 4, 2024
7212c5e
remove BatchTxn, fix autofill
mvadari Nov 7, 2024
39c7ef5
replace BatchTxn in some more places, fix tests
mvadari Nov 7, 2024
3903599
fix linter issues
mvadari Nov 7, 2024
e5f5d3c
Merge branch 'main' into batch
mvadari Nov 7, 2024
ec24418
update definitions
mvadari Nov 7, 2024
f8376eb
Batch integration test
mvadari Nov 7, 2024
260bc32
remove debug statement
mvadari Nov 7, 2024
bf19d12
fix TxnSignature
mvadari Nov 8, 2024
6b03f91
fix BatchMetadata
mvadari Nov 8, 2024
6d63995
Merge branch 'main' into batch
mvadari Dec 13, 2024
4a22d5b
Merge branch 'main' into batch
mvadari Jan 8, 2025
e084f43
fix tests
mvadari Jan 8, 2025
0d08deb
more updates
mvadari Jan 10, 2025
f427bc4
remove TransactionIDs
mvadari Jan 11, 2025
2280b95
add more tests
mvadari Jan 11, 2025
a5d72f9
remove LedgerStateFix
mvadari Jan 12, 2025
08543fc
fix build issues
mvadari Jan 12, 2025
d243ecc
uncomment now-passing test
mvadari Jan 12, 2025
503cf6c
fix linter
mvadari Jan 12, 2025
b3b2c4c
drive-by multisign fix
mvadari Jan 12, 2025
b092a94
add more tests
mvadari Jan 12, 2025
c48957d
better docstrings
mvadari Jan 13, 2025
b519151
Merge branch 'main' into batch
mvadari Feb 6, 2025
793d42f
redo definitions.json
mvadari Feb 6, 2025
f06e83c
fix error
mvadari Feb 6, 2025
dd36b47
minor cleanup
mvadari Feb 7, 2025
60940fa
Merge branch 'main' into batch
mvadari Feb 7, 2025
021999e
Merge branch 'main' into batch
mvadari Feb 10, 2025
1f7c48c
update vscode settings
mvadari Feb 10, 2025
1773246
fix linter
mvadari Feb 10, 2025
27a39bf
fix history
mvadari Feb 10, 2025
4c36d4d
Merge branch 'main' into batch
mvadari Feb 11, 2025
357b5b0
fix tests
mvadari Feb 12, 2025
5d4efda
Merge branch 'main' into batch
mvadari Feb 13, 2025
23e3e07
fix build issue
mvadari Feb 13, 2025
ae20b6b
bump versions for beta
mvadari Feb 13, 2025
3c56343
update packagelock
mvadari Feb 13, 2025
3b899a7
Merge branch 'main' into batch
mvadari Feb 18, 2025
82de5ac
Merge branch 'main' into batch
mvadari Mar 18, 2025
c4a1b21
update package-lock
mvadari Mar 26, 2025
646f71e
Merge branch 'main' into batch
mvadari Mar 26, 2025
916b4a6
Merge branch 'main' into batch
mvadari Apr 1, 2025
0e49ebf
back out unrelated changes
mvadari Apr 1, 2025
f9afbfd
more backing out
mvadari Apr 1, 2025
0b8ecf8
Merge branch 'main' into batch
mvadari Apr 9, 2025
027861e
rename test file
mvadari Apr 10, 2025
3021822
update tfInnerBatchTxn handling
mvadari Apr 10, 2025
335eafe
Merge branch 'main' into batch
mvadari Apr 16, 2025
9a54bec
respond to comments
mvadari Apr 16, 2025
b8db856
fix coderabbit issues
mvadari Apr 16, 2025
27efb57
improve type-checking
mvadari Apr 16, 2025
cffc141
fix errors
mvadari Apr 16, 2025
b612edc
fix errors
mvadari Apr 16, 2025
c3405e0
fix autofill
mvadari Apr 16, 2025
f20f16c
fix ts issues
mvadari Apr 16, 2025
808748d
more fixes
mvadari Apr 16, 2025
d1a4a41
more fixes
mvadari Apr 16, 2025
b2e1122
respond to comments
mvadari Apr 17, 2025
a707718
Merge branch 'main' into batch
mvadari Apr 17, 2025
e19cc51
disable
mvadari Apr 17, 2025
ee1a7ed
Merge branch 'main' into batch
mvadari Apr 23, 2025
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
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"cSpell.words": [
"altnet",
"Autofills",
"Batchnet",
"bignumber",
"Clawback",
"hostid",
"keypair",
Expand All @@ -16,7 +18,8 @@
"secp256k1",
"Setf",
"Sidechains",
"xchain"
"xchain",
"xrplf"
],
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/ripple-binary-codec/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Added
* Support for the `Batch` amendment (XLS-56).

### Fixed
* add `MPTCurrency` support in `Issue` (rippled internal type)
* Throw an error during serialization if a field is unknown, rather than silently throwing it away.
Expand All @@ -15,7 +18,7 @@
## 2.2.0 (2024-12-23)

### Added
* Support for the Multi-Purpose Token amendment (XLS-33)
* Support for the Multi-Purpose Token amendment (XLS-33).

## 2.1.0 (2024-06-03)

Expand Down
2 changes: 1 addition & 1 deletion packages/ripple-binary-codec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ripple-binary-codec",
"version": "2.3.0",
"version": "2.3.0-batch.0",
"description": "XRP Ledger binary codec",
"files": [
"dist/*",
Expand Down
41 changes: 41 additions & 0 deletions packages/ripple-binary-codec/src/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,51 @@ function multiSigningData(
})
}

/**
* Interface describing fields required for a Batch signer
* @property flags - Flags indicating Batch transaction properties
* @property txIDs - Array of transaction IDs included in the Batch
*/
interface BatchObject extends JsonObject {
flags: number
txIDs: string[]
}

/**
* Serialize a signingClaim
*
* @param batch A Batch object to serialize.
* @returns the serialized object with appropriate prefix
*/
function signingBatchData(batch: BatchObject): Uint8Array {
if (batch.flags == null) {
throw Error("No field `flags'")
}
if (batch.txIDs == null) {
throw Error('No field `txIDs`')
}
const prefix = HashPrefix.batch
const flags = coreTypes.UInt32.from(batch.flags).toBytes()
const txIDsLength = coreTypes.UInt32.from(batch.txIDs.length).toBytes()

const bytesList = new BytesList()

bytesList.put(prefix)
bytesList.put(flags)
bytesList.put(txIDsLength)
batch.txIDs.forEach((txID: string) => {
bytesList.put(coreTypes.Hash256.from(txID).toBytes())
})

return bytesList.toBytes()
}

export {
BinaryParser,
BinarySerializer,
BytesList,
ClaimObject,
BatchObject,
makeParser,
serializeObject,
readJSON,
Expand All @@ -191,4 +231,5 @@ export {
binaryToJSON,
sha512Half,
transactionID,
signingBatchData,
}
52 changes: 52 additions & 0 deletions packages/ripple-binary-codec/src/enums/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,16 @@
"type": "Hash256"
}
],
[
"ParentBatchID",
{
"isSerialized": true,
"isSigningField": true,
"isVLEncoded": false,
"nth": 35,
"type": "Hash256"
}
],
[
"hash",
{
Expand Down Expand Up @@ -2340,6 +2350,26 @@
"type": "STObject"
}
],
[
"RawTransaction",
{
"isSerialized": true,
"isSigningField": true,
"isVLEncoded": false,
"nth": 34,
"type": "STObject"
}
],
[
"BatchSigner",
{
"isSerialized": true,
"isSigningField": true,
"isVLEncoded": false,
"nth": 35,
"type": "STObject"
}
],
[
"Signers",
{
Expand Down Expand Up @@ -2560,6 +2590,26 @@
"type": "STArray"
}
],
[
"RawTransactions",
{
"isSerialized": true,
"isSigningField": true,
"isVLEncoded": false,
"nth": 29,
"type": "STArray"
}
],
[
"BatchSigners",
{
"isSerialized": true,
"isSigningField": false,
"isVLEncoded": false,
"nth": 30,
"type": "STArray"
}
],
[
"CloseResolution",
{
Expand Down Expand Up @@ -3059,6 +3109,7 @@
"temINVALID_ACCOUNT_ID": -268,
"temINVALID_COUNT": -266,
"temINVALID_FLAG": -276,
"temINVALID_INNER_BATCH": -250,
"temMALFORMED": -299,
"temREDUNDANT": -275,
"temRIPPLE_EMPTY": -274,
Expand Down Expand Up @@ -3098,6 +3149,7 @@
"AMMWithdraw": 37,
"AccountDelete": 21,
"AccountSet": 3,
"Batch": 64,
"CheckCancel": 18,
"CheckCash": 17,
"CheckCreate": 16,
Expand Down
2 changes: 2 additions & 0 deletions packages/ripple-binary-codec/src/hash-prefixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const HashPrefix: Record<string, Uint8Array> = {
proposal: bytes(0x50525000),
// payment channel claim
paymentChannelClaim: bytes(0x434c4d00),
// batch
batch: bytes(0x42434800),
}

export { HashPrefix }
33 changes: 23 additions & 10 deletions packages/ripple-binary-codec/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { quality, binary, HashPrefix } from './coretypes'
import { decodeLedgerData } from './ledger-hashes'
import { ClaimObject } from './binary'
import { ClaimObject, BatchObject } from './binary'
import { JsonObject } from './types/serialized-type'
import {
XrplDefinitionsBase,
Expand All @@ -15,6 +15,7 @@ const {
signingData,
signingClaimData,
multiSigningData,
signingBatchData,
binaryToJSON,
serializeObject,
} = binary
Expand Down Expand Up @@ -71,12 +72,10 @@ function encodeForSigning(
}

/**
* Encode a transaction and prepare for signing with a claim
* Encode a payment channel claim for signing.
*
* @param json JSON object representing the transaction
* @param signer string representing the account to sign the transaction with
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns a hex string of the encoded transaction
* @param json JSON object representing the claim.
* @returns a hex string of the encoded claim.
*/
function encodeForSigningClaim(json: object): string {
if (typeof json !== 'object') {
Expand All @@ -86,12 +85,12 @@ function encodeForSigningClaim(json: object): string {
}

/**
* Encode a transaction and prepare for multi-signing
* Encode a transaction and prepare for multi-signing.
*
* @param json JSON object representing the transaction
* @param signer string representing the account to sign the transaction with
* @param json JSON object representing the transaction.
* @param signer string representing the account to sign the transaction with.
* @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns a hex string of the encoded transaction
* @returns a hex string of the encoded transaction.
*/
function encodeForMultisigning(
json: object,
Expand All @@ -110,6 +109,19 @@ function encodeForMultisigning(
)
}

/**
* Encode a Batch transaction for signing.
*
* @param json JSON object representing the transaction.
* @returns a hex string of the encoded transaction.
*/
function encodeForSigningBatch(json: object): string {
if (typeof json !== 'object') {
throw new Error('Need an object to encode a Batch transaction')
}
return bytesToHex(signingBatchData(json as BatchObject))
}

/**
* Encode a quality value
*
Expand Down Expand Up @@ -142,6 +154,7 @@ export {
encodeForSigning,
encodeForSigningClaim,
encodeForMultisigning,
encodeForSigningBatch,
encodeQuality,
decodeQuality,
decodeLedgerData,
Expand Down
3 changes: 3 additions & 0 deletions packages/ripple-binary-codec/src/types/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Hash extends Comparable<Hash | string> {
}

if (typeof value === 'string') {
if (!/^[A-F0-9]*$/i.test(value)) {
throw new Error(`Invalid hash string ${value}`)
}
return new this(hexToBytes(value))
}

Expand Down
24 changes: 24 additions & 0 deletions packages/ripple-binary-codec/test/signing-data-encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
encodeForSigning,
encodeForSigningClaim,
encodeForMultisigning,
encodeForSigningBatch,
} = require('../src')

const normalDefinitions = require('../src/enums/definitions.json')
Expand Down Expand Up @@ -244,4 +245,27 @@ describe('Signing data', function () {
].join(''),
)
})

it('can create batch blob', function () {
const flags = 1
const txIDs = [
'ABE4871E9083DF66727045D49DEEDD3A6F166EB7F8D1E92FE868F02E76B2C5CA',
'795AAC88B59E95C3497609749127E69F12958BC016C600C770AEEB1474C840B4',
]
const json = { flags, txIDs }
const actual = encodeForSigningBatch(json)
expect(actual).toBe(
[
// hash prefix
'42434800',
// flags
'00000001',
// txIds length
'00000002',
// txIds
'ABE4871E9083DF66727045D49DEEDD3A6F166EB7F8D1E92FE868F02E76B2C5CA',
'795AAC88B59E95C3497609749127E69F12958BC016C600C770AEEB1474C840B4',
].join(''),
)
})
})
2 changes: 1 addition & 1 deletion packages/xrpl/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports = {
'tsdoc/syntax': 'off',
'jsdoc/require-description-complete-sentence': 'off',
'import/prefer-default-export': 'off',
'max-depth': ['warn', 3],
},
overrides: [
{
Expand Down Expand Up @@ -155,7 +156,6 @@ module.exports = {
'max-lines-per-function': ['off'],
'max-statements': ['off'],
complexity: ['off'],
'max-depth': ['warn', 3],
},
},
],
Expand Down
1 change: 1 addition & 0 deletions packages/xrpl/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr

### Added
* Support for `NFTokenMintOffer` (XLS-52)
* Add support for `Batch` amendment (XLS-56)

### Fixed
* `OracleSet` transaction accepts hexadecimal string values for `AssetPrice` field
Expand Down
6 changes: 3 additions & 3 deletions packages/xrpl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xrpl",
"version": "4.2.5",
"version": "4.2.0-batch.0",
"license": "ISC",
"description": "A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser",
"files": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"bignumber.js": "^9.0.0",
"eventemitter3": "^5.0.1",
"ripple-address-codec": "^5.0.0",
"ripple-binary-codec": "^2.3.0",
"ripple-binary-codec": "^2.3.0-batch.0",
"ripple-keypairs": "^2.0.0"
},
"devDependencies": {
Expand Down Expand Up @@ -61,7 +61,7 @@
"test": "jest --config=jest.config.unit.js --verbose false --silent=false",
"test:integration": "TS_NODE_PROJECT=tsconfig.build.json jest --config=jest.config.integration.js --verbose false --silent=false --runInBand",
"test:browser": "npm run build && npm run build:browserTests && karma start ./karma.config.js",
"test:watch": "jest --watch --verbose false --silent=false --runInBand ./test/**/*.test.ts --testPathIgnorePatterns=./test/integration --testPathIgnorePatterns=./test/fixtures",
"test:watch": "jest --watch --config=jest.config.unit.js --verbose false --silent=false",
"format": "prettier --write '{src,test}/**/*.ts'",
"lint": "eslint . --ext .ts --max-warnings 0",
"perf": "./scripts/perf_test.sh",
Expand Down
Loading
Loading