Skip to content
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

feat: add support for Batch amendment #2801

Draft
wants to merge 70 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 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
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 @@ -15,7 +17,8 @@
"secp256k1",
"Setf",
"Sidechains",
"xchain"
"xchain",
"xrplf"
],
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
Expand Down
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,10 +2,13 @@

## Unreleased

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

## 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
40 changes: 40 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,50 @@ function multiSigningData(
})
}

/**
* Interface describing fields required for a Batch signer
*/
interface BatchObject extends JsonObject {
flags: number
txIDs: string[]
}

/**
* Serialize a signingClaim
*
* @param batch A Batch object to serialize
* @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
* @returns the serialized object with appropriate prefix
*/
Comment on lines +188 to +194
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add return type annotation and opts parameter.

The function signature should follow the pattern of other signing functions in this file.

Update the signature:

-function signingBatchData(batch: BatchObject): Uint8Array {
+function signingBatchData(
+  batch: BatchObject,
+  opts: { definitions?: XrplDefinitionsBase } = {},
+): Uint8Array {

Committable suggestion was skipped due to low confidence.

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())
})
Comment on lines +211 to +213
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add validation for txIDs format.

The function should validate the format of each txID before serialization.

Add validation:

   batch.txIDs.forEach((txID: string) => {
+    if (!/^[A-F0-9]{64}$/i.test(txID)) {
+      throw new Error(`Invalid transaction ID format: ${txID}`)
+    }
     bytesList.put(coreTypes.Hash256.from(txID).toBytes())
   })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
batch.txIDs.forEach((txID: string) => {
bytesList.put(coreTypes.Hash256.from(txID).toBytes())
})
batch.txIDs.forEach((txID: string) => {
if (!/^[A-F0-9]{64}$/i.test(txID)) {
throw new Error(`Invalid transaction ID format: ${txID}`)
}
bytesList.put(coreTypes.Hash256.from(txID).toBytes())
})


return bytesList.toBytes()
}

export {
BinaryParser,
BinarySerializer,
BytesList,
ClaimObject,
BatchObject,
makeParser,
serializeObject,
readJSON,
Expand All @@ -191,4 +230,5 @@ export {
binaryToJSON,
sha512Half,
transactionID,
signingBatchData,
}
Loading
Loading