Skip to content

Commit

Permalink
refactor: remove indexerUrl (#3170)
Browse files Browse the repository at this point in the history
  • Loading branch information
twhy authored May 28, 2024
1 parent b44892a commit 810ff2f
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 33 deletions.
1 change: 0 additions & 1 deletion packages/neuron-wallet/src/block-sync-renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ export const createBlockSyncTask = async () => {
genesisHash: network.genesisHash,
url: network.remote,
addressMetas,
indexerUrl: network.remote,
nodeType: network.type,
}
const msg: Required<WorkerMessage<StartParams>> = { type: 'call', channel: 'start', id: requestId++, message }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import IndexerCacheService from './indexer-cache-service'
export default class FullSynchronizer extends Synchronizer {
private rpcService: RpcService

constructor(addresses: Address[], nodeUrl: string, indexerUrl: string, nodeType: NetworkType) {
super({ addresses, nodeUrl, indexerUrl })
constructor(addresses: Address[], nodeUrl: string, nodeType: NetworkType) {
super({ addresses, nodeUrl })
this.rpcService = new RpcService(nodeUrl, nodeType)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ export default class LightSynchronizer extends Synchronizer {
private addressMetas: AddressMeta[]

constructor(addresses: Address[], nodeUrl: string) {
super({
addresses,
nodeUrl,
indexerUrl: nodeUrl,
})
super({ addresses, nodeUrl })
this.lightRpc = new LightRPC(nodeUrl)
this.addressMetas = addresses.map(address => AddressMeta.fromObject(address))
// fetch some dep cell
Expand Down
6 changes: 2 additions & 4 deletions packages/neuron-wallet/src/block-sync-renderer/sync/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default class Queue {
#lockHashes: string[]
#url: string // ckb node
#nodeType: NetworkType
#indexerUrl: string
#addresses: AddressInterface[]
#rpcService: RpcService
#indexerConnector: Synchronizer | undefined
Expand All @@ -39,9 +38,8 @@ export default class Queue {
#anyoneCanPayLockHashes: string[]
#assetAccountInfo: AssetAccountInfo

constructor(url: string, addresses: AddressInterface[], indexerUrl: string, nodeType: NetworkType) {
constructor(url: string, addresses: AddressInterface[], nodeType: NetworkType) {
this.#url = url
this.#indexerUrl = indexerUrl
this.#addresses = addresses
this.#rpcService = new RpcService(url, nodeType)
this.#nodeType = nodeType
Expand Down Expand Up @@ -70,7 +68,7 @@ export default class Queue {
if (this.#url === BUNDLED_LIGHT_CKB_URL) {
this.#indexerConnector = new LightSynchronizer(this.#addresses, this.#url)
} else {
this.#indexerConnector = new FullSynchronizer(this.#addresses, this.#url, this.#indexerUrl, this.#nodeType)
this.#indexerConnector = new FullSynchronizer(this.#addresses, this.#url, this.#nodeType)
}
await this.#indexerConnector!.connect()
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export abstract class Synchronizer {
// do nothing
}

constructor({ addresses, nodeUrl, indexerUrl }: { addresses: Address[]; nodeUrl: string; indexerUrl: string }) {
this.indexer = new CkbIndexer(nodeUrl, indexerUrl)
constructor({ addresses, nodeUrl }: { addresses: Address[]; nodeUrl: string }) {
this.indexer = new CkbIndexer(nodeUrl)
this.addressesByWalletId = addresses
.map(address => AddressMeta.fromObject(address))
.reduce((addressesByWalletId, addressMeta) => {
Expand Down
5 changes: 2 additions & 3 deletions packages/neuron-wallet/src/block-sync-renderer/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export interface StartParams {
genesisHash: string
url: SyncQueueParams[0]
addressMetas: SyncQueueParams[1]
indexerUrl: SyncQueueParams[2]
nodeType: SyncQueueParams[3]
nodeType: SyncQueueParams[2]
}

export type QueryIndexerParams = QueryOptions
Expand Down Expand Up @@ -63,7 +62,7 @@ export const listener = async ({ type, id, channel, message }: WorkerMessage) =>
try {
await initConnection(message.genesisHash)

syncQueue = new SyncQueue(message.url, message.addressMetas, message.indexerUrl, message.nodeType)
syncQueue = new SyncQueue(message.url, message.addressMetas, message.nodeType)
syncQueue.start()
} catch (err) {
logger.error(`Block Sync Task:\t`, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,20 @@ describe('unit tests for IndexerConnector', () => {
})

describe('#constructor', () => {
const STUB_URI = 'stub_uri'

describe('when init with indexer folder path', () => {
beforeEach(() => {
new stubbedFullSynchronizer([], nodeUrl, STUB_URI)
new stubbedFullSynchronizer([], nodeUrl)
})
it('inits lumos indexer with a node url and indexer folder path', () => {
expect(stubbedIndexerConstructor).toHaveBeenCalledWith(nodeUrl, STUB_URI)
expect(stubbedIndexerConstructor).toHaveBeenCalledWith(nodeUrl)
})
})
describe('when init without indexer folder path', () => {
beforeEach(() => {
new stubbedFullSynchronizer([], nodeUrl)
})
it('inits mercury indexer with a node url and a default port', () => {
expect(stubbedIndexerConstructor).toHaveBeenCalledWith(nodeUrl, STUB_URI)
expect(stubbedIndexerConstructor).toHaveBeenCalledWith(nodeUrl)
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe(`Create block sync task`, () => {
message: {
addressMetas: STUB_ADDRESS_METAS,
genesisHash: STUB_NETWORK.genesisHash,
indexerUrl: STUB_NETWORK.remote,
nodeType: NetworkType.Normal,
url: STUB_NETWORK.remote,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,18 @@ describe('unit tests for IndexerConnector', () => {
})

describe('#constructor', () => {
const STUB_URI = 'stub_uri'

it('inits lumos indexer with a node url and indexer folder path', () => {
new TestSynchronizer({
addresses: [],
nodeUrl,
indexerUrl: STUB_URI,
})
expect(stubbedIndexerConstructor).toHaveBeenCalledWith(nodeUrl, STUB_URI)
expect(stubbedIndexerConstructor).toHaveBeenCalledWith(nodeUrl)
})

it('init with addresses', () => {
const synchronizer = new TestSynchronizer({
addresses: [addressObj1, addressObj2],
nodeUrl,
indexerUrl: STUB_URI,
})
expect(synchronizer.getAddressesByWalletId().get(walletId1)?.[0]).toStrictEqual(
AddressMeta.fromObject(addressObj1)
Expand All @@ -141,7 +137,6 @@ describe('unit tests for IndexerConnector', () => {
const synchronizer = new TestSynchronizer({
addresses: [addressObj1, addressObj2],
nodeUrl,
indexerUrl: '',
})
it('no cached tx', async () => {
stubbedNextUnprocessedTxsGroupedByBlockNumberFn.mockResolvedValue([])
Expand Down Expand Up @@ -179,7 +174,6 @@ describe('unit tests for IndexerConnector', () => {
const synchronizer = new TestSynchronizer({
addresses: [addressObj1, addressObj2],
nodeUrl,
indexerUrl: '',
})
synchronizer.blockTipsSubject.subscribe(stubbedBlockTipsSubscribe)

Expand Down Expand Up @@ -271,7 +265,6 @@ describe('unit tests for IndexerConnector', () => {
const synchronizer = new TestSynchronizer({
addresses: [addressObj1, addressObj2],
nodeUrl,
indexerUrl: '',
})

describe('when success', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/neuron-wallet/tests/block-sync-renderer/task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const STUB_START_MESSAGE = {
genesisHash: 'stub_genesis_hash',
url: 'stub_url',
addressMetas: 'stub_address_metas',
indexerUrl: 'stub_indexer_url',
nodeType: 2,
},
}
Expand Down Expand Up @@ -71,7 +70,6 @@ describe(`Block Sync Task`, () => {
expect(stubbedSyncQueue).toHaveBeenCalledWith(
STUB_START_MESSAGE.message.url,
STUB_START_MESSAGE.message.addressMetas,
STUB_START_MESSAGE.message.indexerUrl,
STUB_START_MESSAGE.message.nodeType
)
expect(stubbedSyncQueueStart).toHaveBeenCalled()
Expand Down

1 comment on commit 810ff2f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Packaging for test is done in 9262479869

Please sign in to comment.