Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pdp2121 committed Dec 12, 2024
1 parent 5b1db56 commit 3ea895c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 38 deletions.
5 changes: 3 additions & 2 deletions src/connection-manager/connections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable max-lines-per-function -- Disable for this file with complex websocket rules. */
import WebSocket from 'ws'
import { LedgerEntryResponse } from 'xrpl'
import { LedgerResponseExpanded } from 'xrpl/dist/npm/models/methods/ledger'

import {
query,
Expand All @@ -9,7 +10,7 @@ import {
getNetworks,
} from '../shared/database'
import { fetchAmendmentInfo } from '../shared/database/amendments'
import { FeeVote, LedgerResponseCorrected } from '../shared/types'
import { FeeVote } from '../shared/types'
import logger from '../shared/utils/logger'

import {
Expand Down Expand Up @@ -92,7 +93,7 @@ async function setHandlers(
)
} else if (data.result?.ledger && isInitialNode) {
void handleWsMessageLedgerEnableAmendments(
data as LedgerResponseCorrected,
data as LedgerResponseExpanded,
networks,
)
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/connection-manager/wsHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
rippleTimeToUnixTime,
} from 'xrpl'
import { AMENDMENTS_ID } from 'xrpl/dist/npm/models/ledger'
import { LedgerResponseExpanded } from 'xrpl/dist/npm/models/methods/ledger'

import {
query,
Expand All @@ -18,7 +19,6 @@ import {
AmendmentStatus,
DatabaseValidator,
FeeVote,
LedgerResponseCorrected,
StreamLedger,
StreamManifest,
ValidationRaw,
Expand Down Expand Up @@ -186,7 +186,7 @@ export async function handleWsMessageLedgerEntryAmendments(
* @param networks - The networks of the WebSocket node.
*/
export async function handleWsMessageLedgerEnableAmendments(
data: LedgerResponseCorrected,
data: LedgerResponseExpanded,
networks: string | undefined,
): Promise<void> {
if (!networks || !data.result.ledger.transactions) {
Expand Down Expand Up @@ -274,7 +274,7 @@ async function backtrackNetworkAmendmentStatus(
})

await handleWsMessageLedgerEnableAmendments(
ledger as LedgerResponseCorrected,
ledger as LedgerResponseExpanded,
network,
)
}
Expand Down
28 changes: 0 additions & 28 deletions src/shared/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import {
LedgerBinary,
LedgerResponse,
PseudoTransaction,
Transaction,
TransactionMetadata,
} from 'xrpl'
import { Ledger as LedgerXRPL } from 'xrpl/dist/npm/models/ledger'
import { Manifest, StreamManifest } from 'xrpl-validator-domains'

interface Chain {
Expand Down Expand Up @@ -37,25 +29,6 @@ interface StreamLedger {
type: string
}

// TODO: use xrpl LedgerResponse type once hash and date has been added to transactions in the response.
interface LedgerCorrected extends LedgerXRPL {
transactions: Array<
(Transaction | PseudoTransaction) & {
metaData?: TransactionMetadata
hash: string
}
>
}

interface LedgerResponseCorrected extends LedgerResponse {
result: {
ledger: LedgerCorrected | LedgerBinary
} & Pick<
LedgerResponse['result'],
Exclude<keyof LedgerResponse['result'], 'ledger'>
>
}

interface AmendmentEnabled {
amendment_id: string
networks: string
Expand Down Expand Up @@ -267,7 +240,6 @@ export {
StreamLedger,
Chain,
ValidatorKeys,
LedgerResponseCorrected,
AmendmentStatus,
AmendmentInfo,
}
7 changes: 4 additions & 3 deletions test/connections/amendment.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LedgerResponseExpanded } from 'xrpl/dist/npm/models/methods/ledger'

import { handleWsMessageLedgerEnableAmendments } from '../../src/connection-manager/wsHandling'
import { destroy, query, setupTables } from '../../src/shared/database'
import { LedgerResponseCorrected } from '../../src/shared/types'

import ledgerResponseNoFlag from './fixtures/ledgerWithNoFlag.json'
import ledgerResponseGotMajority from './fixtures/ledgerWithTfMajority.json'
Expand All @@ -26,7 +27,7 @@ describe('Amendments', () => {

test('Correctly finds EnableAmendment tx with tfGotMajority Flag (eta available) from ledger response', async () => {
await handleWsMessageLedgerEnableAmendments(
ledgerResponseGotMajority as LedgerResponseCorrected,
ledgerResponseGotMajority as LedgerResponseExpanded,
'main',
)

Expand All @@ -47,7 +48,7 @@ describe('Amendments', () => {

test('Correctly finds EnableAmendment tx with No Flag (amendment has been enabled) from ledger response', async () => {
await handleWsMessageLedgerEnableAmendments(
ledgerResponseNoFlag as LedgerResponseCorrected,
ledgerResponseNoFlag as LedgerResponseExpanded,
'main',
)

Expand Down
2 changes: 1 addition & 1 deletion test/connections/fixtures/ledgerWithNoFlag.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"close_time_resolution": 10,
"closed": true,
"ledger_hash": "FFAF101AF5FDAA24950BAFDD639947CB44C838E9F67FABE77E1A21EA4BD8C2B0",
"ledger_index": "84206081",
"ledger_index": 84206081,
"parent_close_time": 754411462,
"parent_hash": "55A44DCA100865307B6751D508E1766CB285F9559BADF9A261DF11CF9DA23126",
"total_coins": "99988187080224306",
Expand Down
2 changes: 1 addition & 1 deletion test/connections/fixtures/ledgerWithTfMajority.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"close_time_resolution": 10,
"closed": true,
"ledger_hash": "040103C742D29BE5DF25EFFB2B0BB4AC3F263D989D2F02FDF157A07E01650A9A",
"ledger_index": "85517825",
"ledger_index": 85517825,
"parent_close_time": 759508320,
"parent_hash": "32540158F82A25967041B14786357879CF43C982D34182464111108DA4DBD412",
"total_coins": "99987946023223668",
Expand Down

0 comments on commit 3ea895c

Please sign in to comment.