-
Notifications
You must be signed in to change notification settings - Fork 514
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(xrpl): custom definitions support #2683
base: main
Are you sure you want to change the base?
Changes from 13 commits
23411ac
9249824
b529149
a618fb9
b283fc3
4689b02
59c2074
6089035
7021e63
02a8503
3153659
b047f04
eeb9f43
2900ab3
2c60a1e
071beb5
04446ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||||||||||||||||
|
||||||||||||||||||
/* eslint-disable max-lines -- Client is a large file w/ lots of imports/exports */ | ||||||||||||||||||
import { EventEmitter } from 'eventemitter3' | ||||||||||||||||||
import { XrplDefinitionsBase } from 'ripple-binary-codec' | ||||||||||||||||||
|
||||||||||||||||||
import { | ||||||||||||||||||
RippledError, | ||||||||||||||||||
|
@@ -219,6 +220,11 @@ class Client extends EventEmitter<EventTypes> { | |||||||||||||||||
public buildVersion: string | undefined | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* Custom rippled types to use instead of the default. Used for sidechains and amendments. | ||||||||||||||||||
* | ||||||||||||||||||
*/ | ||||||||||||||||||
public definitions: XrplDefinitionsBase | undefined | ||||||||||||||||||
|
||||||||||||||||||
* API Version used by the server this client is connected to | ||||||||||||||||||
mvadari marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
* | ||||||||||||||||||
*/ | ||||||||||||||||||
|
@@ -526,6 +532,33 @@ class Client extends EventEmitter<EventTypes> { | |||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* Get Definitions from server_definitions | ||||||||||||||||||
* | ||||||||||||||||||
* @returns void | ||||||||||||||||||
* @example | ||||||||||||||||||
* ```ts | ||||||||||||||||||
* const { Client } = require('xrpl') | ||||||||||||||||||
* const client = new Client('wss://s.altnet.rippletest.net:51233') | ||||||||||||||||||
* await client.getDefinitions() | ||||||||||||||||||
* console.log(client.definitions) | ||||||||||||||||||
* ``` | ||||||||||||||||||
*/ | ||||||||||||||||||
public async getDefinitions(): Promise<void> { | ||||||||||||||||||
try { | ||||||||||||||||||
const response = await this.request({ | ||||||||||||||||||
command: 'server_definitions', | ||||||||||||||||||
}) | ||||||||||||||||||
this.definitions = new XrplDefinitionsBase( | ||||||||||||||||||
JSON.parse(JSON.stringify(response.result)), | ||||||||||||||||||
{}, | ||||||||||||||||||
) | ||||||||||||||||||
} catch (error) { | ||||||||||||||||||
// eslint-disable-next-line no-console -- Print the error to console but allows client to be connected. | ||||||||||||||||||
console.error(error) | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+548
to
+561
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve error handling in Currently, errors in
|
||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* Tells the Client instance to connect to its rippled server. | ||||||||||||||||||
* | ||||||||||||||||||
|
@@ -760,7 +793,10 @@ class Client extends EventEmitter<EventTypes> { | |||||||||||||||||
wallet?: Wallet | ||||||||||||||||||
}, | ||||||||||||||||||
): Promise<SubmitResponse> { | ||||||||||||||||||
const signedTx = await getSignedTx(this, transaction, opts) | ||||||||||||||||||
const signedTx = await getSignedTx(this, transaction, { | ||||||||||||||||||
...opts, | ||||||||||||||||||
definitions: this.definitions, | ||||||||||||||||||
}) | ||||||||||||||||||
Comment on lines
+797
to
+800
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid overwriting user-provided definitions in By spreading const signedTx = await getSignedTx(this, transaction, {
...opts,
- definitions: this.definitions,
+ definitions: opts?.definitions ?? this.definitions,
}) This change ensures that if the user provides 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
return submitRequest(this, signedTx, opts?.failHard) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -834,7 +870,10 @@ class Client extends EventEmitter<EventTypes> { | |||||||||||||||||
wallet?: Wallet | ||||||||||||||||||
}, | ||||||||||||||||||
): Promise<TxResponse<T>> { | ||||||||||||||||||
const signedTx = await getSignedTx(this, transaction, opts) | ||||||||||||||||||
const signedTx = await getSignedTx(this, transaction, { | ||||||||||||||||||
...opts, | ||||||||||||||||||
definitions: this.definitions, | ||||||||||||||||||
}) | ||||||||||||||||||
Comment on lines
+874
to
+877
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consistent handling of definitions in Similar to the const signedTx = await getSignedTx(this, transaction, {
...opts,
- definitions: this.definitions,
+ definitions: opts?.definitions ?? this.definitions,
}) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
const lastLedger = getLastLedgerSequence(signedTx) | ||||||||||||||||||
if (lastLedger == null) { | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Documentation needed for the new
definitions
parameterThe new
definitions
parameter has been added to multiple methods, but there's no explanation of:XrplDefinitionsBase
objectConsider adding a new section that explains:
Also applies to: 29-29, 57-57, 65-65