Skip to content

Commit

Permalink
respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Sep 15, 2023
1 parent 519e8f0 commit c2a10fc
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 164 deletions.
10 changes: 5 additions & 5 deletions packages/ripple-binary-codec/src/types/xchain-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class XChainBridge extends SerializedType {
/**
* Construct a cross-chain bridge from a JSON
*
* @param value XChainBridge or JSON to parse into a XChainBridge
* @returns A XChainBridge object
* @param value XChainBridge or JSON to parse into an XChainBridge
* @returns An XChainBridge object
*/
static from<T extends XChainBridge | XChainBridgeObject>(
value: T,
Expand All @@ -80,14 +80,14 @@ class XChainBridge extends SerializedType {
return new XChainBridge(Buffer.concat(bytes))
}

throw new Error('Invalid type to construct a XChainBridge')
throw new Error('Invalid type to construct an XChainBridge')
}

/**
* Read a XChainBridge from a BinaryParser
* Read an XChainBridge from a BinaryParser
*
* @param parser BinaryParser to read the XChainBridge from
* @returns A XChainBridge object
* @returns An XChainBridge object
*/
static fromParser(parser: BinaryParser): XChainBridge {
const bytes: Array<Buffer> = []
Expand Down
12 changes: 12 additions & 0 deletions packages/xrpl/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,17 @@ module.exports = {
'import/no-unused-modules': 'off',
},
},
{
files: ['tools/*.ts', 'tools/*.js'],
rules: {
'no-console': ['off'],
'node/no-process-exit': ['off'],
'@typescript-eslint/no-magic-numbers': ['off'],
'max-lines-per-function': ['off'],
'max-statements': ['off'],
complexity: ['off'],
'max-depth': ['warn', 3],
},
},
],
}
19 changes: 13 additions & 6 deletions packages/xrpl/snippets/src/bridgeTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ async function bridgeTransfer(): Promise<void> {
const bridge: XChainBridge = bridgeData.XChainBridge
console.log(bridge)

console.log('Creating wallet on the locking chain via the faucet...')
const { wallet: wallet1 } = await lockingClient.fundWallet()
console.log(wallet1)
const wallet2 = Wallet.generate()

console.log(
Expand All @@ -68,7 +70,9 @@ async function bridgeTransfer(): Promise<void> {
})
console.log(fundResponse)

// wait for the attestation to go through
console.log(
'Waiting for the attestation to go through... (usually 8-12 seconds)',
)
let ledgersWaited = 0
let initialBalance = '0'
while (ledgersWaited < MAX_LEDGERS_WAITED) {
Expand All @@ -83,6 +87,7 @@ async function bridgeTransfer(): Promise<void> {
ledgersWaited += 1
// eslint-disable-next-line max-depth -- needed here
if (ledgersWaited === MAX_LEDGERS_WAITED) {
// This error should never be hit if the bridge is running
throw Error('Destination account creation via the bridge failed.')
}
}
Expand All @@ -106,7 +111,7 @@ async function bridgeTransfer(): Promise<void> {
wallet: wallet2,
})

// extract new claim ID from metadata
// Extract new claim ID from metadata
const nodes = (claimIdResult.result.meta as TransactionMetadata).AffectedNodes
const createdNodes = nodes.filter((node) =>
Object.keys(node).includes('CreatedNode'),
Expand All @@ -123,9 +128,9 @@ async function bridgeTransfer(): Promise<void> {

console.log(`Claim ID for the transfer: ${xchainClaimId}`)

// XChainCommit
console.log('Step 2: Locking the funds on the locking chain...')

console.log(
'Step 2: Locking the funds on the locking chain with an XChainCommit transaction...',
)
const commitTx: XChainCommit = {
TransactionType: 'XChainCommit',
Account: wallet1.classicAddress,
Expand All @@ -139,7 +144,9 @@ async function bridgeTransfer(): Promise<void> {
})
console.log(commitResult)

// wait for the attestations to go through
console.log(
'Waiting for the attestation to go through... (usually 8-12 seconds)',
)
ledgersWaited = 0
while (ledgersWaited < MAX_LEDGERS_WAITED) {
await sleep(LEDGER_CLOSE_TIME)
Expand Down
20 changes: 18 additions & 2 deletions packages/xrpl/src/models/ledger/XChainOwnedClaimID.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Amount } from 'ripple-binary-codec/dist/types'

import { XChainBridge } from '../common'

import BaseLedgerEntry from './BaseLedgerEntry'
Expand Down Expand Up @@ -35,14 +37,28 @@ export default interface XChainOwnedClaimID extends BaseLedgerEntry {
*/
OtherChainSource: string

// TODO: type this better
/**
* Attestations collected from the witness servers. This includes the parameters
* needed to recreate the message that was signed, including the amount, which
* chain (locking or issuing), optional destination, and reward account for that
* signature.
*/
XChainClaimAttestations: object[]
XChainClaimAttestations: Array<{
// TODO: add docs
XChainClaimProofSig: {
Amount: Amount

AttestationRewardAccount: string

AttestationSignerAccount: string

Destination?: string

PublicKey: string

WasLockingChainSend: 0 | 1
}
}>

/**
* The total amount to pay the witness servers for their signatures. It must be at
Expand Down
18 changes: 16 additions & 2 deletions packages/xrpl/src/models/ledger/XChainOwnedCreateAccountClaimID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,29 @@ export default interface XChainOwnedCreateAccountClaimID
*/
XChainAccountCreateCount: number

// TODO: type this better
/**
* Attestations collected from the witness servers. This includes the parameters
* needed to recreate the message that was signed, including the amount, destination,
* signature reward amount, and reward account for that signature. With the
* exception of the reward account, all signatures must sign the message created with
* common parameters.
*/
XChainCreateAccountAttestations: object[]
XChainCreateAccountAttestations: Array<{
// TODO: add docs
XChainCreateAccountProofSig: {
Amount: string

AttestationRewardAccount: string

AttestationSignerAccount: string

Destination: string

PublicKey: string

WasLockingChainSend: 0 | 1
}
}>

/**
* A bit-map of boolean flags. No flags are defined for,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export interface XChainAccountCreateCommit extends BaseTransaction {
}

/**
* Verify the form and type of a XChainAccountCreateCommit at runtime.
* Verify the form and type of an XChainAccountCreateCommit at runtime.
*
* @param tx - A XChainAccountCreateCommit Transaction.
* @param tx - An XChainAccountCreateCommit Transaction.
* @throws When the XChainAccountCreateCommit is malformed.
*/
// eslint-disable-next-line max-lines-per-function -- okay for this function, there's a lot of things to check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export interface XChainAddAccountCreateAttestation extends BaseTransaction {
}

/**
* Verify the form and type of a XChainAddAccountCreateAttestation at runtime.
* Verify the form and type of an XChainAddAccountCreateAttestation at runtime.
*
* @param tx - A XChainAddAccountCreateAttestation Transaction.
* @param tx - An XChainAddAccountCreateAttestation Transaction.
* @throws When the XChainAddAccountCreateAttestation is malformed.
*/
// eslint-disable-next-line max-lines-per-function, max-statements -- okay for this function, lots of things to check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export interface XChainAddClaimAttestation extends BaseTransaction {
}

/**
* Verify the form and type of a XChainAddClaimAttestation at runtime.
* Verify the form and type of an XChainAddClaimAttestation at runtime.
*
* @param tx - A XChainAddClaimAttestation Transaction.
* @param tx - An XChainAddClaimAttestation Transaction.
* @throws When the XChainAddClaimAttestation is malformed.
*/
// eslint-disable-next-line max-lines-per-function, max-statements -- okay for this function, lots of things to check
Expand Down
4 changes: 2 additions & 2 deletions packages/xrpl/src/models/transactions/XChainClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export interface XChainClaim extends BaseTransaction {
}

/**
* Verify the form and type of a XChainClaim at runtime.
* Verify the form and type of an XChainClaim at runtime.
*
* @param tx - A XChainClaim Transaction.
* @param tx - An XChainClaim Transaction.
* @throws When the XChainClaim is malformed.
*/
export function validateXChainClaim(tx: Record<string, unknown>): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/xrpl/src/models/transactions/XChainCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export interface XChainCommit extends BaseTransaction {
}

/**
* Verify the form and type of a XChainCommit at runtime.
* Verify the form and type of an XChainCommit at runtime.
*
* @param tx - A XChainCommit Transaction.
* @param tx - An XChainCommit Transaction.
* @throws When the XChainCommit is malformed.
*/
export function validateXChainCommit(tx: Record<string, unknown>): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/xrpl/src/models/transactions/XChainCreateBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export interface XChainCreateBridge extends BaseTransaction {
}

/**
* Verify the form and type of a XChainCreateBridge at runtime.
* Verify the form and type of an XChainCreateBridge at runtime.
*
* @param tx - A XChainCreateBridge Transaction.
* @param tx - An XChainCreateBridge Transaction.
* @throws When the XChainCreateBridge is malformed.
*/
export function validateXChainCreateBridge(tx: Record<string, unknown>): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/xrpl/src/models/transactions/XChainCreateClaimID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export interface XChainCreateClaimID extends BaseTransaction {
}

/**
* Verify the form and type of a XChainCreateClaimID at runtime.
* Verify the form and type of an XChainCreateClaimID at runtime.
*
* @param tx - A XChainCreateClaimID Transaction.
* @param tx - An XChainCreateClaimID Transaction.
* @throws When the XChainCreateClaimID is malformed.
*/
export function validateXChainCreateClaimID(tx: Record<string, unknown>): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/xrpl/src/models/transactions/XChainModifyBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export interface XChainModifyBridge extends BaseTransaction {
}

/**
* Verify the form and type of a XChainModifyBridge at runtime.
* Verify the form and type of an XChainModifyBridge at runtime.
*
* @param tx - A XChainModifyBridge Transaction.
* @param tx - An XChainModifyBridge Transaction.
* @throws When the XChainModifyBridge is malformed.
*/
export function validateXChainModifyBridge(tx: Record<string, unknown>): void {
Expand Down
Loading

0 comments on commit c2a10fc

Please sign in to comment.