Skip to content

Commit 912ed57

Browse files
authored
feat: nownodes utxo migration (#1267)
1 parent 93f5c9b commit 912ed57

18 files changed

Lines changed: 47 additions & 91 deletions

File tree

node/coinstacks/bitcoin/api/src/app.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const INDEXER_WS_URL = process.env.INDEXER_WS_URL
1515
const INDEXER_API_KEY = process.env.INDEXER_API_KEY
1616

1717
if (!INDEXER_WS_URL) throw new Error('INDEXER_WS_URL env var not set')
18-
19-
const IS_LIQUIFY = INDEXER_WS_URL.toLowerCase().includes('liquify')
20-
const IS_NOWNODES = INDEXER_WS_URL.toLowerCase().includes('nownodes')
18+
if (!INDEXER_API_KEY) throw new Error('INDEXER_API_KEY env var not set')
2119

2220
const logger = new Logger({
2321
namespace: ['unchained', 'coinstacks', 'bitcoin', 'api'],
@@ -70,15 +68,12 @@ const transactionHandler: TransactionHandler<BlockbookTx, utxo.Tx> = async (bloc
7068

7169
const registry = new Registry({ addressFormatter: formatAddress, blockHandler, transactionHandler })
7270

73-
const wsUrl = INDEXER_API_KEY && IS_LIQUIFY ? `${INDEXER_WS_URL}/api=${INDEXER_API_KEY}` : INDEXER_WS_URL
74-
const apiKey = INDEXER_API_KEY && IS_NOWNODES ? INDEXER_API_KEY : undefined
75-
7671
const blockbook = new WebsocketClient(
77-
wsUrl,
72+
INDEXER_WS_URL,
7873
{
74+
apiKey: INDEXER_API_KEY,
7975
blockHandler: registry.onBlock.bind(registry),
8076
transactionHandler: registry.onTransaction.bind(registry),
81-
apiKey,
8277
},
8378
{ resetInterval: 15 * 60 * 1000 } // 15 minutes
8479
)

node/coinstacks/bitcoin/api/src/controller.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ export const logger = new Logger({
2323
level: process.env.LOG_LEVEL,
2424
})
2525

26-
const httpURL = `${INDEXER_URL}/api=${INDEXER_API_KEY}`
27-
const wsURL = `${INDEXER_WS_URL}/api=${INDEXER_API_KEY}`
28-
const rpcUrl = `${RPC_URL}/api=${RPC_API_KEY}`
29-
30-
const blockbook = new Blockbook({ httpURL, wsURL, logger })
26+
const blockbook = new Blockbook({ httpURL: INDEXER_URL, wsURL: INDEXER_WS_URL, apiKey: INDEXER_API_KEY, logger })
3127

3228
const isXpub = (pubkey: string): boolean => {
3329
return pubkey.startsWith('xpub') || pubkey.startsWith('ypub') || pubkey.startsWith('zpub')
@@ -41,7 +37,8 @@ export const formatAddress = (address: string): string => {
4137

4238
export const service = new Service({
4339
blockbook,
44-
rpcUrl,
40+
rpcUrl: RPC_URL,
41+
rpcApiKey: RPC_API_KEY,
4542
isXpub,
4643
addressFormatter: formatAddress,
4744
})

node/coinstacks/bitcoin/sample.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ INDEXER_API_KEY=
33
RPC_API_KEY=
44

55
# ENVIRONMENT VARIABLES
6-
INDEXER_URL=https://gateway.liquify.com
7-
INDEXER_WS_URL=wss://gateway.liquify.com
6+
INDEXER_URL=https://btcbook.nownodes.io
7+
INDEXER_WS_URL=wss://btcbook.nownodes.io/wss
88
LOG_LEVEL=debug
99
NETWORK=mainnet
10-
RPC_URL=https://gateway.liquify.com
10+
RPC_URL=https://btc.nownodes.io

node/coinstacks/bitcoincash/api/src/app.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const INDEXER_WS_URL = process.env.INDEXER_WS_URL
1515
const INDEXER_API_KEY = process.env.INDEXER_API_KEY
1616

1717
if (!INDEXER_WS_URL) throw new Error('INDEXER_WS_URL env var not set')
18-
19-
const IS_LIQUIFY = INDEXER_WS_URL.toLowerCase().includes('liquify')
20-
const IS_NOWNODES = INDEXER_WS_URL.toLowerCase().includes('nownodes')
18+
if (!INDEXER_API_KEY) throw new Error('INDEXER_API_KEY env var not set')
2119

2220
const logger = new Logger({
2321
namespace: ['unchained', 'coinstacks', 'bitcoincash', 'api'],
@@ -72,13 +70,10 @@ const transactionHandler: TransactionHandler<BlockbookTx, utxo.Tx> = async (bloc
7270

7371
const registry = new Registry({ addressFormatter: formatAddress, blockHandler, transactionHandler })
7472

75-
const wsUrl = INDEXER_API_KEY && IS_LIQUIFY ? `${INDEXER_WS_URL}/api=${INDEXER_API_KEY}` : INDEXER_WS_URL
76-
const apiKey = INDEXER_API_KEY && IS_NOWNODES ? INDEXER_API_KEY : undefined
77-
7873
const blockbook = new WebsocketClient(
79-
wsUrl,
74+
INDEXER_WS_URL,
8075
{
81-
apiKey,
76+
apiKey: INDEXER_API_KEY,
8277
blockHandler: registry.onBlock.bind(registry),
8378
transactionHandler: registry.onTransaction.bind(registry),
8479
},

node/coinstacks/bitcoincash/api/src/controller.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ export const logger = new Logger({
2323
level: process.env.LOG_LEVEL,
2424
})
2525

26-
const httpURL = `${INDEXER_URL}/api=${INDEXER_API_KEY}`
27-
const wsURL = `${INDEXER_WS_URL}/api=${INDEXER_API_KEY}`
28-
const rpcUrl = `${RPC_URL}/api=${RPC_API_KEY}`
29-
30-
const blockbook = new Blockbook({ httpURL, wsURL, logger })
26+
const blockbook = new Blockbook({ httpURL: INDEXER_URL, wsURL: INDEXER_WS_URL, apiKey: INDEXER_API_KEY, logger })
3127

3228
const isXpub = (pubkey: string): boolean => {
3329
return pubkey.startsWith('xpub') || pubkey.startsWith('ypub') || pubkey.startsWith('zpub')
@@ -51,7 +47,8 @@ export const formatAddress = (address: string): string => {
5147

5248
export const service = new Service({
5349
blockbook,
54-
rpcUrl,
50+
rpcUrl: RPC_URL,
51+
rpcApiKey: RPC_API_KEY,
5552
isXpub,
5653
addressFormatter: formatAddress,
5754
})

node/coinstacks/bitcoincash/sample.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ INDEXER_API_KEY=
33
RPC_API_KEY=
44

55
# ENVIRONMENT VARIABLES
6-
INDEXER_URL=https://gateway.liquify.com
7-
INDEXER_WS_URL=wss://gateway.liquify.com
6+
INDEXER_URL=https://bchbook.nownodes.io
7+
INDEXER_WS_URL=wss://bchbook.nownodes.io/wss
88
LOG_LEVEL=debug
99
NETWORK=mainnet
10-
RPC_URL=https://gateway.liquify.com
10+
RPC_URL=https://bch.nownodes.io

node/coinstacks/common/api/src/middleware.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import cors from 'cors'
66
import { ValidateError } from 'tsoa'
77
import { ApiError, NotFoundError } from '.'
88

9-
export function errorHandler(err: Error, req: Request, res: Response, next: NextFunction): Response | void {
9+
export function errorHandler(err: Error, _: Request, res: Response, next: NextFunction): Response | void {
1010
if (err instanceof ValidateError) {
1111
const e = err as ValidateError
1212

13-
console.warn(`Caught Validation Error for ${req.path}:`, e.fields)
14-
1513
return res.status(422).json({
1614
message: 'Validation Failed',
1715
details: e.fields,

node/coinstacks/dogecoin/api/src/app.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const INDEXER_WS_URL = process.env.INDEXER_WS_URL
1515
const INDEXER_API_KEY = process.env.INDEXER_API_KEY
1616

1717
if (!INDEXER_WS_URL) throw new Error('INDEXER_WS_URL env var not set')
18-
19-
const IS_LIQUIFY = INDEXER_WS_URL.toLowerCase().includes('liquify')
20-
const IS_NOWNODES = INDEXER_WS_URL.toLowerCase().includes('nownodes')
18+
if (!INDEXER_API_KEY) throw new Error('INDEXER_API_KEY env var not set')
2119

2220
const logger = new Logger({
2321
namespace: ['unchained', 'coinstacks', 'dogecoin', 'api'],
@@ -72,13 +70,10 @@ const transactionHandler: TransactionHandler<BlockbookTx, utxo.Tx> = async (bloc
7270

7371
const registry = new Registry({ addressFormatter: formatAddress, blockHandler, transactionHandler })
7472

75-
const wsUrl = INDEXER_API_KEY && IS_LIQUIFY ? `${INDEXER_WS_URL}/api=${INDEXER_API_KEY}` : INDEXER_WS_URL
76-
const apiKey = INDEXER_API_KEY && IS_NOWNODES ? INDEXER_API_KEY : undefined
77-
7873
const blockbook = new WebsocketClient(
79-
wsUrl,
74+
INDEXER_WS_URL,
8075
{
81-
apiKey,
76+
apiKey: INDEXER_API_KEY,
8277
blockHandler: registry.onBlock.bind(registry),
8378
transactionHandler: registry.onTransaction.bind(registry),
8479
},

node/coinstacks/dogecoin/api/src/controller.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ export const logger = new Logger({
2222
level: process.env.LOG_LEVEL,
2323
})
2424

25-
const httpURL = `${INDEXER_URL}/api=${INDEXER_API_KEY}`
26-
const wsURL = `${INDEXER_WS_URL}/api=${INDEXER_API_KEY}`
27-
const rpcUrl = `${RPC_URL}/api=${RPC_API_KEY}`
28-
29-
const blockbook = new Blockbook({ httpURL, wsURL, logger })
25+
const blockbook = new Blockbook({ httpURL: INDEXER_URL, wsURL: INDEXER_WS_URL, apiKey: INDEXER_API_KEY, logger })
3026

3127
const isXpub = (pubkey: string): boolean => {
3228
return pubkey.startsWith('dgub')
@@ -36,7 +32,8 @@ export const formatAddress = (address: string): string => address
3632

3733
export const service = new Service({
3834
blockbook,
39-
rpcUrl,
35+
rpcUrl: RPC_URL,
36+
rpcApiKey: RPC_API_KEY,
4037
isXpub,
4138
addressFormatter: formatAddress,
4239
})

node/coinstacks/dogecoin/sample.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ INDEXER_API_KEY=
33
RPC_API_KEY=
44

55
# ENVIRONMENT VARIABLES
6-
INDEXER_URL=https://gateway.liquify.com
7-
INDEXER_WS_URL=wss://gateway.liquify.com
6+
INDEXER_URL=https://dogebook.nownodes.io
7+
INDEXER_WS_URL=wss://dogebook.nownodes.io/wss
88
LOG_LEVEL=debug
99
NETWORK=mainnet
10-
RPC_URL=https://gateway.liquify.com
10+
RPC_URL=https://doge.nownodes.io

0 commit comments

Comments
 (0)