-
Notifications
You must be signed in to change notification settings - Fork 518
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 current sidechain design #2039
Conversation
packages/xrpl/src/models/transactions/sidechainXChainAccountCreate.ts
Outdated
Show resolved
Hide resolved
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.
Approving since it's fine to omit docstrings for a beta release.
a59fafb
to
ee927a1
Compare
00fcf0d
to
92b1751
Compare
92b1751
to
169edfd
Compare
9b09094
to
2670298
Compare
aa4a306
to
8cb1ad2
Compare
010abe8
to
c2a10fc
Compare
export function validateXChainModifyBridge(tx: Record<string, unknown>): void { | ||
validateBaseTransaction(tx) | ||
|
||
if (tx.XChainBridge == 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.
A lot of this logic is shared between multiple transaction types. Maybe have a base xchain validation function.
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.
This is already done with isXChainBridge
. I don't think it matters that much for the two if
statements that are replicated between all the transactions. I'm can change this if you object though.
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.
Fixed in 6594c19 - the helper functions aren't going to be used in existing models in this PR because that would be a lot of work (and make this PR even more gargantuan), but the script should work for those as well.
@@ -152,6 +153,30 @@ export interface LedgerEntryRequest extends BaseRequest, LookupByLedgerRequest { | |||
* Must be the object ID of the NFToken page, as hexadecimal | |||
*/ | |||
nft_page?: string | |||
|
|||
bridge_account?: string |
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.
nit: document these new fields.
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.
cc @oeggert
* common parameters. | ||
*/ | ||
XChainCreateAccountAttestations: Array<{ | ||
// TODO: add docs |
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.
nit: forgotten TODO.
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.
cc @oeggert
ledgersWaited = 0 | ||
while (ledgersWaited < MAX_LEDGERS_WAITED) { | ||
await sleep(LEDGER_CLOSE_TIME) | ||
const currentBalance = await issuingClient.getXrpBalance( |
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.
That error might be helpful regardless of it if is sidechain or not.
import { | ||
XChainModifyBridge, | ||
validateXChainModifyBridge, | ||
} from './XChainModifyBridge' | ||
|
||
/** |
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.
Rolling out a tx system like the explorer could clean this up a bit. Maybe something for 4.0
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.
Approving ahead of the documentation additions.
* signature. | ||
*/ | ||
XChainClaimAttestations: Array<{ | ||
// TODO: add docs |
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.
Is this TODO being tracked somewhere?
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.
Yes - @oeggert has it in his backlog
@@ -78,7 +78,7 @@ describe('BaseTransaction', function () { | |||
assert.throws( | |||
() => validateBaseTransaction(invalidFee), | |||
ValidationError, | |||
'BaseTransaction: invalid Fee', | |||
'Payment: invalid field Fee', |
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.
Why was this changed from BaseTransaction
to Payment
?
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.
The error was changed when I refactored the validateBaseTransaction
method to use the new helper functions.
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.
LGTM - documentation changes can be added in a separate PR
* add XChainAddAttestation tests, fix model * add XChainClaim model tests * add XChainCommit model tests, fix typo * add XChainCreateBridge model tests * add XChainCreateClaimID model tests * fix tests * add XChainModifyBridge tests * fix tests * fix more tests * fix linting errors * update to most recent version of code * remove XChainAddAttestationBatch tests * fix rebase issues * fix linter issues * add more validation tests * fix linter errors * fix tests * switch createValidateTests to JS
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.
LGTM, just nit comments
if (value instanceof XChainBridge) { | ||
return value | ||
} | ||
|
||
if (isXChainBridgeObject(value)) { | ||
const bytes: Array<Buffer> = [] | ||
this.TYPE_ORDER.forEach((item) => { | ||
const { name, type } = item | ||
if (type === AccountID) { | ||
bytes.push(Buffer.from([0x14])) | ||
} | ||
const object = type.from(value[name]) | ||
bytes.push(object.toBytes()) | ||
}) | ||
return new XChainBridge(Buffer.concat(bytes)) | ||
} | ||
|
||
throw new Error('Invalid type to construct an XChainBridge') |
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.
nit: I prefer throwing validation errors near the top of a function.
if (value instanceof XChainBridge) { | |
return value | |
} | |
if (isXChainBridgeObject(value)) { | |
const bytes: Array<Buffer> = [] | |
this.TYPE_ORDER.forEach((item) => { | |
const { name, type } = item | |
if (type === AccountID) { | |
bytes.push(Buffer.from([0x14])) | |
} | |
const object = type.from(value[name]) | |
bytes.push(object.toBytes()) | |
}) | |
return new XChainBridge(Buffer.concat(bytes)) | |
} | |
throw new Error('Invalid type to construct an XChainBridge') | |
if (value instanceof XChainBridge) { | |
return value | |
} | |
if (!isXChainBridgeObject(value)) { | |
throw new Error('Invalid type to construct an XChainBridge') | |
} | |
const bytes: Array<Buffer> = [] | |
this.TYPE_ORDER.forEach((item) => { | |
const { name, type } = item | |
if (type === AccountID) { | |
bytes.push(Buffer.from([0x14])) | |
} | |
const object = type.from(value[name]) | |
bytes.push(object.toBytes()) | |
}) | |
return new XChainBridge(Buffer.concat(bytes)) |
* transaction. If this isn't present, the {@link XChainAccountCreateCommit} | ||
* transaction will fail. This field can only be present on XRP-XRP bridges. | ||
*/ | ||
MinAccountCreateAmount?: string |
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.
I also prefer optional fields being after required ones. Personally, it's easier to read. :)
High Level Overview of Change
This PR adds support for the latest version of the sidechain design.
There are 8 new transaction types:
XChainCreateBridge
(creates a new cross-chain bridge)XChainModifyBridge
(modifies the properties of a cross-chain bridge)XChainCreateClaimID
(creates a new cross-chain claim ID)XChainCommit
(locks/burns the funds on the source chain)XChainAccountCreateCommit
(creates an account on the destination chain)XChainClaim
(claims the transfer funds on the destination chain)XChainAddClaimAttestation
(submits a claim attestation from a witness server)XChainAddAccountCreateAttestation
(submits an account creation attestation from a witness server)#2059 and #2301 should be merged into this PR before this PR is merged.
Context of Change
sidechain prod release
Type of Change
Before / After
Test Plan
Tests were added for all the new features. CI passes.