diff --git a/CHANGELOG.md b/CHANGELOG.md index c74c9d3c..302e6428 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- added: New fallback server engine info, starting with NOWNodes blockbook servers + ## 2.5.4 (2024-01-26) - fixed: Check for NaN target totals in `subtractFee` style transactions diff --git a/src/bch.ts b/src/bch.ts index b2f8b694..8755948e 100644 --- a/src/bch.ts +++ b/src/bch.ts @@ -1,6 +1,6 @@ import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types' -import { makeCurrencyPlugin } from './common/plugin/makeCurrencyPlugin' +import { makeCurrencyPlugin } from './common/plugin/CurrencyPlugin' import { info } from './common/utxobased/info/bitcoincash' const plugin = (options: EdgeCorePluginOptions): EdgeCurrencyPlugin => diff --git a/src/bsv.ts b/src/bsv.ts index f51cb9ab..8059f176 100644 --- a/src/bsv.ts +++ b/src/bsv.ts @@ -1,6 +1,6 @@ import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types' -import { makeCurrencyPlugin } from './common/plugin/makeCurrencyPlugin' +import { makeCurrencyPlugin } from './common/plugin/CurrencyPlugin' import { info } from './common/utxobased/info/bitcoinsv' const plugin = (options: EdgeCorePluginOptions): EdgeCurrencyPlugin => diff --git a/src/btc.ts b/src/btc.ts index b9fb7b2a..2f457c1c 100644 --- a/src/btc.ts +++ b/src/btc.ts @@ -1,6 +1,6 @@ import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types' -import { makeCurrencyPlugin } from './common/plugin/makeCurrencyPlugin' +import { makeCurrencyPlugin } from './common/plugin/CurrencyPlugin' import { info } from './common/utxobased/info/bitcoin' const plugin = (options: EdgeCorePluginOptions): EdgeCurrencyPlugin => diff --git a/src/common/plugin/makeCurrencyPlugin.ts b/src/common/plugin/CurrencyPlugin.ts similarity index 77% rename from src/common/plugin/makeCurrencyPlugin.ts rename to src/common/plugin/CurrencyPlugin.ts index 565b8701..6c483339 100644 --- a/src/common/plugin/makeCurrencyPlugin.ts +++ b/src/common/plugin/CurrencyPlugin.ts @@ -7,11 +7,14 @@ import { EdgeWalletInfo } from 'edge-core-js/types' -import { makeUtxoEngine } from '../utxobased/engine/makeUtxoEngine' -import { asUtxoUserSettings } from '../utxobased/engine/types' -import { makeCurrencyTools } from './makeCurrencyTools' -import { makeEngineEmitter } from './makeEngineEmitter' -import { makePluginState } from './pluginState' +import { + asUtxoInitOptions, + asUtxoUserSettings +} from '../utxobased/engine/types' +import { makeUtxoEngine } from '../utxobased/engine/UtxoEngine' +import { makeCurrencyTools } from './CurrencyTools' +import { makeEngineEmitter } from './EngineEmitter' +import { makePluginState } from './PluginState' import { EngineConfig, PluginInfo } from './types' export function makeCurrencyPlugin( @@ -19,7 +22,7 @@ export function makeCurrencyPlugin( pluginInfo: PluginInfo ): EdgeCurrencyPlugin { const { currencyInfo } = pluginInfo - const { io, log, pluginDisklet } = pluginOptions + const { io, log, pluginDisklet, initOptions } = pluginOptions const currencyTools = makeCurrencyTools(io, pluginInfo) const { defaultSettings, pluginId, currencyCode } = currencyInfo const pluginState = makePluginState({ @@ -43,6 +46,7 @@ export function makeCurrencyPlugin( pluginInfo, pluginDisklet, currencyTools, + initOptions: asUtxoInitOptions(initOptions), io, options: { ...pluginOptions, diff --git a/src/common/plugin/makeCurrencyTools.ts b/src/common/plugin/CurrencyTools.ts similarity index 100% rename from src/common/plugin/makeCurrencyTools.ts rename to src/common/plugin/CurrencyTools.ts diff --git a/src/common/plugin/makeEngineEmitter.ts b/src/common/plugin/EngineEmitter.ts similarity index 97% rename from src/common/plugin/makeEngineEmitter.ts rename to src/common/plugin/EngineEmitter.ts index 2542f8e6..f8b463c0 100644 --- a/src/common/plugin/makeEngineEmitter.ts +++ b/src/common/plugin/EngineEmitter.ts @@ -5,7 +5,7 @@ import { } from 'edge-core-js/types' import { EventEmitter } from 'events' -import { SubscribeAddressResponse } from '../utxobased/network/BlockBookAPI' +import { SubscribeAddressResponse } from '../utxobased/network/blockbookApi' export declare interface EngineEmitter { emit: (( diff --git a/src/common/plugin/makeMetadata.ts b/src/common/plugin/Metadata.ts similarity index 97% rename from src/common/plugin/makeMetadata.ts rename to src/common/plugin/Metadata.ts index 8361fecb..bec6d8cf 100644 --- a/src/common/plugin/makeMetadata.ts +++ b/src/common/plugin/Metadata.ts @@ -4,7 +4,7 @@ import { EdgeLog } from 'edge-core-js/types' import { makeMemlet } from 'memlet' import AwaitLock from '../utxobased/engine/await-lock' -import { EngineEmitter, EngineEvent } from './makeEngineEmitter' +import { EngineEmitter, EngineEvent } from './EngineEmitter' import { asLocalWalletMetadata, LocalWalletMetadata } from './types' import { removeItem } from './utils' diff --git a/src/common/plugin/pluginState.ts b/src/common/plugin/PluginState.ts similarity index 94% rename from src/common/plugin/pluginState.ts rename to src/common/plugin/PluginState.ts index 780ec3f2..6daeecdf 100644 --- a/src/common/plugin/pluginState.ts +++ b/src/common/plugin/PluginState.ts @@ -5,19 +5,19 @@ import { Disklet } from 'disklet' import { EdgeIo, EdgeLog } from 'edge-core-js/types' import { makeMemlet } from 'memlet' -import { UtxoEngineState } from '../utxobased/engine/makeUtxoEngineState' import { UtxoUserSettings } from '../utxobased/engine/types' +import { UtxoEngineState } from '../utxobased/engine/UtxoEngineState' import { asServerCache, ServerCache, ServerList, ServerScores -} from './serverScores' +} from './ServerScores' // Info server endpoint to getting ServerListInfo data -const serverListInfoUrl = 'https://info1.edge.app/v1/blockBook/' -// The filename for ServerInfoCache data (see serverScores.ts) -// Perhaps this should be in serverScores.ts file, but that'll take some refactoring +const serverListInfoUrl = 'https://info1.edge.app/v1/blockbook/' +// The filename for ServerInfoCache data (see ServerScores.ts) +// Perhaps this should be in ServerScores.ts file, but that'll take some refactoring const SERVER_CACHE_FILE = 'serverCache.json' // ServerListInfo data structure from info server and saved to disk @@ -51,7 +51,7 @@ export interface PluginState { clearCache: () => Promise getLocalServers: ( numServersWanted: number, - includePatterns: string[] + includePatterns?: Array ) => string[] refreshServers: () => Promise updateServers: (settings: UtxoUserSettings) => Promise @@ -209,7 +209,7 @@ export function makePluginState(settings: PluginStateSettings): PluginState { getLocalServers( numServersWanted: number, - includePatterns: string[] = [] + includePatterns: Array = [] ): string[] { return serverScores.getServers( knownServers, diff --git a/src/common/plugin/serverScores.ts b/src/common/plugin/ServerScores.ts similarity index 96% rename from src/common/plugin/serverScores.ts rename to src/common/plugin/ServerScores.ts index 5990ad14..9a64a22a 100644 --- a/src/common/plugin/serverScores.ts +++ b/src/common/plugin/ServerScores.ts @@ -208,7 +208,7 @@ export class ServerScores { getServers( servers: ServerList, numServersWanted: number, - includePatterns: string[] = [] + includePatterns: Array = [] ): string[] { if (servers == null || Object.keys(servers).length === 0) { return [] @@ -236,7 +236,14 @@ export class ServerScores { const filter = (server: ServerInfo): boolean => { for (const pattern of includePatterns) { // make sure that the server URL starts with the required pattern - if (server.serverUrl.indexOf(pattern) === 0) return true + if ( + typeof pattern === 'string' && + server.serverUrl.indexOf(pattern) === 0 + ) + return true + // Or make sure that the server URL matches regex + if (pattern instanceof RegExp && pattern.test(server.serverUrl)) + return true } return false } diff --git a/src/common/plugin/types.ts b/src/common/plugin/types.ts index 90c7439d..0b56561c 100644 --- a/src/common/plugin/types.ts +++ b/src/common/plugin/types.ts @@ -23,10 +23,11 @@ import { import * as wif from 'wif' import { asIUTXO, IProcessorTransaction, IUTXO } from '../utxobased/db/types' +import { UtxoInitOptions } from '../utxobased/engine/types' import { ScriptTemplates } from '../utxobased/info/scriptTemplates/types' import { UtxoPicker } from '../utxobased/keymanager/utxopicker' -import { EngineEmitter } from './makeEngineEmitter' -import { PluginState } from './pluginState' +import { EngineEmitter } from './EngineEmitter' +import { PluginState } from './PluginState' export type CurrencyFormat = ReturnType export const asCurrencyFormat = asValue('bip32', 'bip44', 'bip49', 'bip84') @@ -70,6 +71,7 @@ export interface EngineInfo { mempoolSpaceFeeInfoServer?: string defaultFeeInfo: FeeInfo scriptTemplates?: ScriptTemplates + serverConfigs?: ServerConfig[] // Codec Cleaners asBlockbookAddress?: Cleaner // Coin specific transaction handling @@ -79,6 +81,11 @@ export interface EngineInfo { ) => IProcessorTransaction } +export interface ServerConfig { + type: 'blockbook-nownode' + uris: string[] +} + /** * Coin Info */ @@ -196,6 +203,7 @@ export interface EngineConfig { pluginDisklet: Disklet currencyTools: EdgeCurrencyTools options: EngineOptions + initOptions: UtxoInitOptions io: EdgeIo pluginState: PluginState } diff --git a/src/common/utxobased/db/makeBaselets.ts b/src/common/utxobased/db/Baselets.ts similarity index 100% rename from src/common/utxobased/db/makeBaselets.ts rename to src/common/utxobased/db/Baselets.ts diff --git a/src/common/utxobased/db/Models/ProcessorTransaction.ts b/src/common/utxobased/db/Models/ProcessorTransaction.ts index 4bfaa0e5..42933a51 100644 --- a/src/common/utxobased/db/Models/ProcessorTransaction.ts +++ b/src/common/utxobased/db/Models/ProcessorTransaction.ts @@ -4,9 +4,9 @@ import BN from 'bn.js' import { EdgeTransaction, JsonObject } from 'edge-core-js/types' import { PluginInfo } from '../../../plugin/types' -import { UTXOPluginWalletTools } from '../../engine/makeUtxoWalletTools' import { UtxoTxOtherParams } from '../../engine/types' -import { Processor } from '../makeProcessor' +import { UtxoWalletTools } from '../../engine/UtxoWalletTools' +import { Processor } from '../Processor' import { IProcessorTransaction } from '../types' export const fromEdgeTransaction = ( @@ -54,7 +54,7 @@ export const fromEdgeTransaction = ( interface ToEdgeTransactionArgs { walletId: string tx: IProcessorTransaction - walletTools: UTXOPluginWalletTools + walletTools: UtxoWalletTools processor: Processor pluginInfo: PluginInfo } diff --git a/src/common/utxobased/db/makeMutex.ts b/src/common/utxobased/db/Mutex.ts similarity index 100% rename from src/common/utxobased/db/makeMutex.ts rename to src/common/utxobased/db/Mutex.ts diff --git a/src/common/utxobased/db/makeProcessor.ts b/src/common/utxobased/db/Processor.ts similarity index 99% rename from src/common/utxobased/db/makeProcessor.ts rename to src/common/utxobased/db/Processor.ts index 8e6ee2d4..78c651f1 100644 --- a/src/common/utxobased/db/makeProcessor.ts +++ b/src/common/utxobased/db/Processor.ts @@ -6,7 +6,7 @@ import { makeMemlet } from 'memlet' import { unixTime } from '../../../util/unixTime' import { AddressPath, ChangePath } from '../../plugin/types' -import { makeBaselets } from './makeBaselets' +import { makeBaselets } from './Baselets' import { addressPathToPrefix, TxIdByDate } from './Models/baselet' import { IAddress, diff --git a/src/common/utxobased/db/util/utxo.ts b/src/common/utxobased/db/util/utxo.ts index 300d3f5d..07dc07b6 100644 --- a/src/common/utxobased/db/util/utxo.ts +++ b/src/common/utxobased/db/util/utxo.ts @@ -3,7 +3,7 @@ import { BIP43PurposeTypeEnum, ScriptTypeEnum } from '../../keymanager/keymanager' -import { Processor } from '../makeProcessor' +import { Processor } from '../Processor' import { IProcessorTransaction, IUTXO } from '../types' export const utxoFromProcessorTransactionInput = async ( diff --git a/src/common/utxobased/engine/makeServerStates.ts b/src/common/utxobased/engine/ServerStates.ts similarity index 70% rename from src/common/utxobased/engine/makeServerStates.ts rename to src/common/utxobased/engine/ServerStates.ts index 35be1103..bce2c2d6 100644 --- a/src/common/utxobased/engine/makeServerStates.ts +++ b/src/common/utxobased/engine/ServerStates.ts @@ -1,21 +1,26 @@ -import { EdgeLog, EdgeTransaction } from 'edge-core-js/types' +import { EdgeIo, EdgeLog, EdgeTransaction } from 'edge-core-js/types' import { parse } from 'uri-js' -import { EngineEmitter, EngineEvent } from '../../plugin/makeEngineEmitter' -import { PluginState } from '../../plugin/pluginState' +import { EngineEmitter, EngineEvent } from '../../plugin/EngineEmitter' +import { PluginState } from '../../plugin/PluginState' import { PluginInfo } from '../../plugin/types' import { removeItem } from '../../plugin/utils' import { SafeWalletInfo } from '../keymanager/cleaners' -import { BlockBook, makeBlockBook } from '../network/BlockBook' -import { SubscribeAddressResponse } from '../network/BlockBookAPI' +import { Blockbook, makeBlockbook } from '../network/Blockbook' +import { + asBlockbookResponse, + asBroadcastTxResponse, + SubscribeAddressResponse +} from '../network/blockbookApi' import Deferred from '../network/Deferred' -import { SocketEmitter, SocketEvent } from '../network/MakeSocketEmitter' import { WsTask } from '../network/Socket' +import { SocketEmitter, SocketEvent } from '../network/SocketEmitter' import { pushUpdate, removeIdFromQueue } from '../network/socketQueue' import { MAX_CONNECTIONS, NEW_CONNECTIONS } from './constants' +import { UtxoInitOptions } from './types' interface ServerState { - blockbook: BlockBook + blockbook: Blockbook blockSubscriptionStatus: 'unsubscribed' | 'subscribing' | 'subscribed' blockHeight: number txids: Set @@ -24,6 +29,8 @@ interface ServerState { interface ServerStateConfig { engineEmitter: EngineEmitter + initOptions: UtxoInitOptions + io: EdgeIo log: EdgeLog pluginInfo: PluginInfo pluginState: PluginState @@ -58,7 +65,16 @@ interface ServerStatesCache { } export function makeServerStates(config: ServerStateConfig): ServerStates { - const { engineEmitter, log, pluginInfo, pluginState, walletInfo } = config + const { + engineEmitter, + initOptions, + io, + log, + pluginInfo, + pluginState, + walletInfo + } = config + const { serverConfigs = [] } = pluginInfo.engineInfo log('Making server states') const serverStatesCache: ServerStatesCache = {} @@ -122,7 +138,7 @@ export function makeServerStates(config: ServerStateConfig): ServerStates { // eslint-disable-next-line @typescript-eslint/no-explicit-any ) => Promise | undefined> - const makeServerStatesCacheEntry = (blockbook: BlockBook): ServerState => ({ + const makeServerStatesCacheEntry = (blockbook: Blockbook): ServerState => ({ blockbook, blockSubscriptionStatus: 'unsubscribed', txids: new Set(), @@ -208,9 +224,9 @@ export function makeServerStates(config: ServerStateConfig): ServerStates { } // Make new Blockbook instance - const blockbook = makeBlockBook({ - wsAddress: uri, - socketEmitter, + const blockbook = makeBlockbook({ + asAddress: pluginInfo.engineInfo.asBlockbookAddress, + connectionUri: uri, engineEmitter, log, onQueueSpaceCB: async (): Promise< @@ -229,8 +245,8 @@ export function makeServerStates(config: ServerStateConfig): ServerStates { } return task }, - walletId: walletInfo.id, - asAddress: pluginInfo.engineInfo.asBlockbookAddress + socketEmitter, + walletId: walletInfo.id }) // Make new ServerStates instance @@ -304,38 +320,117 @@ export function makeServerStates(config: ServerStateConfig): ServerStates { const broadcastTx = async (transaction: EdgeTransaction): Promise => { return await new Promise((resolve, reject) => { - const uris = Object.keys(serverStatesCache).filter(uri => { - const { blockbook } = serverStatesCache[uri] - if (blockbook == null) return false - return blockbook.isConnected - }) - if (uris == null || uris.length < 1) { - reject( - new Error('No available connections\nCheck your internet signal') - ) - } let resolved = false let bad = 0 - for (const uri of uris) { - const { blockbook } = serverStatesCache[uri] - if (blockbook == null) continue - blockbook - .broadcastTx(transaction) - .then(response => { - if (!resolved) { - resolved = true - resolve(response.result) - } - }) - .catch((e?: Error) => { - if (++bad === uris.length) { - const msg = e != null ? `With error ${e.message}` : '' - log.error( - `broadcastTx fail: ${JSON.stringify(transaction)}\n${msg}` - ) - reject(e) - } + + const wsUris = Object.keys(serverStatesCache).filter( + uri => serverStatesCache[uri].blockbook != null + ) + + // If there are no blockbook instances, reject the promise + if (wsUris.length < 1) { + reject(new Error('Unexpected error. Missing WebSocket connections.')) + // Exit early if there are blockbook instances + return + } + + // Determine if there are any connected blockbook instances + const isAnyBlockbookConnected = wsUris.some( + uri => serverStatesCache[uri].blockbook.isConnected + ) + + if (isAnyBlockbookConnected) { + for (const uri of wsUris) { + const { blockbook } = serverStatesCache[uri] + if (blockbook == null) continue + blockbook + .broadcastTx(transaction) + .then(response => { + if (!resolved) { + resolved = true + resolve(response.result) + } + }) + .catch((e?: Error) => { + if (++bad === wsUris.length) { + const msg = e != null ? `With error ${e.message}` : '' + log.error( + `broadcastTx fail: ${JSON.stringify(transaction)}\n${msg}` + ) + reject(e) + } + }) + } + } + + // Broadcast through any HTTP URI that may be configured, only if no + // blockbook instances are connected. + if (!isAnyBlockbookConnected) { + // This is for the future when we want to HTTP servers from the user + // settings: + // const httpUris = pluginState.getLocalServers(Infinity, [ + // /^http(?:s)?:/i + // ]) + + const { nowNodeApiKey } = initOptions + const nowNodeUris = serverConfigs + .filter(config => config.type === 'blockbook-nownode') + .map(config => config.uris) + .flat(1) + + // If there are no HTTP servers, reject the promise + if (nowNodeUris.length < 1) { + // If no HTTP servers are available, and we had no connected blockbook + // instances, reject the promise with a message indicating no + // available connections. It's clear we have some connection instances + // if we gotten to this point, but we just don't have any of those + // instances connected at this time. + reject( + new Error('No available connections. Check your internet signal.') + ) + return + } + + // If there is no key for the NowNode servers: + if (nowNodeApiKey == null) { + reject(new Error('Missing connection key for fallback servers.')) + return + } + + for (const uri of nowNodeUris) { + // HTTP Fallback + io.fetchCors(`${uri}/api/v2/sendtx/`, { + method: 'POST', + headers: { + 'api-key': nowNodeApiKey + }, + body: transaction.signedTx }) + .then(async response => { + if (!response.ok) { + throw new Error( + `Failed to broadcast transaction via Blockbook: HTTP ${response.status}` + ) + } + const json = await response.json() + return asBlockbookResponse(asBroadcastTxResponse)(json) + }) + .then(response => { + if (!resolved) { + resolved = true + resolve(response.result) + } + }) + .catch((e?: Error) => { + if (++bad === nowNodeUris.length) { + const msg = e != null ? `With error ${e.message}` : '' + log.error( + `broadcastTx fail: ${JSON.stringify(transaction)}\n${msg}` + ) + reject(e) + } + }) + } } }) } diff --git a/src/common/utxobased/engine/makeUtxoEngine.ts b/src/common/utxobased/engine/UtxoEngine.ts similarity index 98% rename from src/common/utxobased/engine/makeUtxoEngine.ts rename to src/common/utxobased/engine/UtxoEngine.ts index 9e790a9b..8cd90164 100644 --- a/src/common/utxobased/engine/makeUtxoEngine.ts +++ b/src/common/utxobased/engine/UtxoEngine.ts @@ -21,15 +21,15 @@ import { import { filterUndefined } from '../../../util/filterUndefined' import { unixTime } from '../../../util/unixTime' import { makeFees } from '../../fees/makeFees' -import { EngineEmitter, EngineEvent } from '../../plugin/makeEngineEmitter' -import { makeMetadata } from '../../plugin/makeMetadata' +import { EngineEmitter, EngineEvent } from '../../plugin/EngineEmitter' +import { makeMetadata } from '../../plugin/Metadata' import { EngineConfig, TxOptions } from '../../plugin/types' import { upgradeMemos } from '../../upgradeMemos' -import { makeProcessor } from '../db/makeProcessor' import { fromEdgeTransaction, toEdgeTransaction } from '../db/Models/ProcessorTransaction' +import { makeProcessor } from '../db/Processor' import { IProcessorTransaction, IUTXO } from '../db/types' import { utxoFromProcessorTransactionInput } from '../db/util/utxo' import { @@ -47,8 +47,6 @@ import { } from '../keymanager/keymanager' import { asMaybeInsufficientFundsErrorPlus } from '../keymanager/types' import { transactionSizeFromHex } from '../keymanager/utxopicker/utils' -import { makeUtxoEngineState, transactionChanged } from './makeUtxoEngineState' -import { makeUtxoWalletTools } from './makeUtxoWalletTools' import { createPayment, getPaymentDetails, sendPayment } from './paymentRequest' import { asUtxoSignMessageOtherParams, @@ -63,6 +61,8 @@ import { pathToPurposeType, sumUtxos } from './utils' +import { makeUtxoEngineState, transactionChanged } from './UtxoEngineState' +import { makeUtxoWalletTools } from './UtxoWalletTools' export async function makeUtxoEngine( config: EngineConfig diff --git a/src/common/utxobased/engine/makeUtxoEngineState.ts b/src/common/utxobased/engine/UtxoEngineState.ts similarity index 98% rename from src/common/utxobased/engine/makeUtxoEngineState.ts rename to src/common/utxobased/engine/UtxoEngineState.ts index ca590e01..999e7b3a 100644 --- a/src/common/utxobased/engine/makeUtxoEngineState.ts +++ b/src/common/utxobased/engine/UtxoEngineState.ts @@ -7,8 +7,8 @@ import { EdgeTransaction } from 'edge-core-js/types' -import { EngineEmitter, EngineEvent } from '../../plugin/makeEngineEmitter' -import { PluginState } from '../../plugin/pluginState' +import { EngineEmitter, EngineEvent } from '../../plugin/EngineEmitter' +import { PluginState } from '../../plugin/PluginState' import { AddressPath, ChangePath, @@ -18,8 +18,8 @@ import { PluginInfo } from '../../plugin/types' import { removeItem } from '../../plugin/utils' -import { Processor } from '../db/makeProcessor' import { toEdgeTransaction } from '../db/Models/ProcessorTransaction' +import { Processor } from '../db/Processor' import { IAddress, IProcessorTransaction, @@ -42,19 +42,19 @@ import { transactionMessage, transactionMessageSpecific, TransactionResponse -} from '../network/BlockBookAPI' +} from '../network/blockbookApi' import Deferred from '../network/Deferred' import { WsTask } from '../network/Socket' import AwaitLock from './await-lock' import { BLOCKBOOK_TXS_PER_PAGE, CACHE_THROTTLE } from './constants' -import { makeServerStates, ServerStates } from './makeServerStates' -import { UTXOPluginWalletTools } from './makeUtxoWalletTools' +import { makeServerStates, ServerStates } from './ServerStates' import { getFormatSupportedBranches, getScriptTypeFromPurposeType, pathToPurposeType, validScriptPubkeyFromAddress } from './utils' +import { UtxoWalletTools } from './UtxoWalletTools' export interface UtxoEngineState { processedPercent: number @@ -86,7 +86,7 @@ export interface UtxoEngineState { } export interface UtxoEngineStateConfig extends EngineConfig { - walletTools: UTXOPluginWalletTools + walletTools: UtxoWalletTools walletInfo: SafeWalletInfo processor: Processor } @@ -95,13 +95,16 @@ export function makeUtxoEngineState( config: UtxoEngineStateConfig ): UtxoEngineState { const { + initOptions, + io, + options, + pluginState, pluginInfo, - walletInfo, - walletTools, - options: { emitter, log }, processor, - pluginState + walletInfo, + walletTools } = config + const { emitter, log } = options const { walletFormats } = walletInfo.keys @@ -178,6 +181,8 @@ export function makeUtxoEngineState( const serverStates = makeServerStates({ engineEmitter: emitter, + initOptions, + io, log, pluginInfo, pluginState, @@ -191,7 +196,7 @@ export function makeUtxoEngineState( emitter, taskCache, updateProgressRatio, - io: config.io, + io, log, serverStates, pluginState, @@ -513,7 +518,7 @@ export function makeUtxoEngineState( interface CommonArgs { pluginInfo: PluginInfo walletInfo: SafeWalletInfo - walletTools: UTXOPluginWalletTools + walletTools: UtxoWalletTools processor: Processor emitter: EngineEmitter taskCache: TaskCache @@ -686,7 +691,7 @@ interface TransactionChangedArgs { walletId: string tx: IProcessorTransaction emitter: EngineEmitter - walletTools: UTXOPluginWalletTools + walletTools: UtxoWalletTools pluginInfo: PluginInfo processor: Processor } @@ -1079,7 +1084,7 @@ const updateTransactions = ( } interface DeriveScriptAddressArgs { - walletTools: UTXOPluginWalletTools + walletTools: UtxoWalletTools engineInfo: EngineInfo processor: Processor format: CurrencyFormat diff --git a/src/common/utxobased/engine/makeUtxoWalletTools.ts b/src/common/utxobased/engine/UtxoWalletTools.ts similarity index 98% rename from src/common/utxobased/engine/makeUtxoWalletTools.ts rename to src/common/utxobased/engine/UtxoWalletTools.ts index ba14e0b7..9cebf59d 100644 --- a/src/common/utxobased/engine/makeUtxoWalletTools.ts +++ b/src/common/utxobased/engine/UtxoWalletTools.ts @@ -32,7 +32,7 @@ export interface WalletToolsConfig { publicKey: PublicKey } -export interface UTXOPluginWalletTools { +export interface UtxoWalletTools { getPubkey: (args: AddressPath) => string getScriptPubkey: (args: AddressPath) => ScriptPubkeyReturn @@ -96,14 +96,14 @@ interface SignMessageArgs { export function makeUtxoWalletTools( config: WalletToolsConfig -): UTXOPluginWalletTools { +): UtxoWalletTools { const { pluginInfo, publicKey } = config const { engineInfo } = pluginInfo const { name: coin } = pluginInfo.coinInfo const xpubKeys = publicKey.publicKeys - const fns: UTXOPluginWalletTools = { + const fns: UtxoWalletTools = { getPubkey(args: AddressPath): string { if (xpubKeys[args.format] == null) { throw new Error( diff --git a/src/common/utxobased/engine/types.ts b/src/common/utxobased/engine/types.ts index 2549f59f..ff1980f1 100644 --- a/src/common/utxobased/engine/types.ts +++ b/src/common/utxobased/engine/types.ts @@ -12,6 +12,11 @@ import { EdgeSpendInfo } from 'edge-core-js/types' import { asTxOptions } from '../../plugin/types' import { Input, Output } from '../keymanager/utxopicker/types' +export type UtxoInitOptions = ReturnType +export const asUtxoInitOptions = asObject({ + nowNodeApiKey: asOptional(asString) +}) + export const asUtxoUserSettings = asObject({ blockbookServers: asMaybe(asArray(asString), []), enableCustomServers: asMaybe(asBoolean, false) diff --git a/src/common/utxobased/engine/util/getOwnUtxosFromTx.ts b/src/common/utxobased/engine/util/getOwnUtxosFromTx.ts index c13092bd..b94c5c16 100644 --- a/src/common/utxobased/engine/util/getOwnUtxosFromTx.ts +++ b/src/common/utxobased/engine/util/getOwnUtxosFromTx.ts @@ -1,5 +1,5 @@ import { EngineInfo } from '../../../plugin/types' -import { Processor } from '../../db/makeProcessor' +import { Processor } from '../../db/Processor' import { IProcessorTransaction, IUTXO } from '../../db/types' import { BIP43PurposeTypeEnum } from '../../keymanager/keymanager' import { getScriptTypeFromPurposeType, pathToPurposeType } from '../utils' diff --git a/src/common/utxobased/info/bitcoin.ts b/src/common/utxobased/info/bitcoin.ts index 9a9ef6c6..09d71ce1 100644 --- a/src/common/utxobased/info/bitcoin.ts +++ b/src/common/utxobased/info/bitcoin.ts @@ -54,6 +54,12 @@ const currencyInfo: EdgeCurrencyInfo = { } const engineInfo: EngineInfo = { + serverConfigs: [ + { + type: 'blockbook-nownode', + uris: ['btcbook.nownodes.io'] + } + ], formats: ['bip49', 'bip84', 'bip44', 'bip32'], forks: ['bitcoincash', 'bitcoingold'], gapLimit: 25, diff --git a/src/common/utxobased/info/bitcoincash.ts b/src/common/utxobased/info/bitcoincash.ts index 7bfe1bbc..ea92c292 100644 --- a/src/common/utxobased/info/bitcoincash.ts +++ b/src/common/utxobased/info/bitcoincash.ts @@ -56,6 +56,12 @@ const currencyInfo: EdgeCurrencyInfo = { } const engineInfo: EngineInfo = { + serverConfigs: [ + { + type: 'blockbook-nownode', + uris: ['bchbook.nownodes.io'] + } + ], formats: ['bip44', 'bip32'], forks: [], // 'bitcoinsv' is currently disabled, so not included in the forks gapLimit: 10, diff --git a/src/common/utxobased/info/dash.ts b/src/common/utxobased/info/dash.ts index b369d256..4c767e2d 100644 --- a/src/common/utxobased/info/dash.ts +++ b/src/common/utxobased/info/dash.ts @@ -49,6 +49,12 @@ const currencyInfo: EdgeCurrencyInfo = { } const engineInfo: EngineInfo = { + serverConfigs: [ + { + type: 'blockbook-nownode', + uris: ['dashbook.nownodes.io'] + } + ], formats: ['bip44', 'bip32'], gapLimit: 10, defaultFee: 10000, diff --git a/src/common/utxobased/info/digibyte.ts b/src/common/utxobased/info/digibyte.ts index d1873ce8..462ce35c 100644 --- a/src/common/utxobased/info/digibyte.ts +++ b/src/common/utxobased/info/digibyte.ts @@ -40,6 +40,12 @@ const currencyInfo: EdgeCurrencyInfo = { } const engineInfo: EngineInfo = { + serverConfigs: [ + { + type: 'blockbook-nownode', + uris: ['dgbbook.nownodes.io'] + } + ], formats: ['bip49', 'bip84', 'bip44', 'bip32'], forks: [], gapLimit: 10, diff --git a/src/common/utxobased/info/dogecoin.ts b/src/common/utxobased/info/dogecoin.ts index 6550afb9..968d0cd8 100644 --- a/src/common/utxobased/info/dogecoin.ts +++ b/src/common/utxobased/info/dogecoin.ts @@ -45,6 +45,12 @@ const currencyInfo: EdgeCurrencyInfo = { } const engineInfo: EngineInfo = { + serverConfigs: [ + { + type: 'blockbook-nownode', + uris: ['https://dogebook.nownodes.io'] + } + ], formats: ['bip44', 'bip32'], gapLimit: 10, defaultFee: 1000, diff --git a/src/common/utxobased/info/groestlcoin.ts b/src/common/utxobased/info/groestlcoin.ts index 93a99353..25c89ee9 100644 --- a/src/common/utxobased/info/groestlcoin.ts +++ b/src/common/utxobased/info/groestlcoin.ts @@ -46,6 +46,12 @@ const currencyInfo: EdgeCurrencyInfo = { } const engineInfo: EngineInfo = { + serverConfigs: [ + { + type: 'blockbook-nownode', + uris: ['grsbook.nownodes.io'] + } + ], formats: ['bip49', 'bip84', 'bip44', 'bip32'], gapLimit: 10, defaultFee: 100000, diff --git a/src/common/utxobased/info/litecoin.ts b/src/common/utxobased/info/litecoin.ts index ce029d3b..119c38da 100644 --- a/src/common/utxobased/info/litecoin.ts +++ b/src/common/utxobased/info/litecoin.ts @@ -52,6 +52,12 @@ export const currencyInfo: EdgeCurrencyInfo = { } export const engineInfo: EngineInfo = { + serverConfigs: [ + { + type: 'blockbook-nownode', + uris: ['ltcbook.nownodes.io'] + } + ], formats: ['bip49', 'bip84', 'bip44', 'bip32'], gapLimit: 10, defaultFee: 50000, diff --git a/src/common/utxobased/network/BlockBook.ts b/src/common/utxobased/network/Blockbook.ts similarity index 84% rename from src/common/utxobased/network/BlockBook.ts rename to src/common/utxobased/network/Blockbook.ts index 2dad4de3..72eea11a 100644 --- a/src/common/utxobased/network/BlockBook.ts +++ b/src/common/utxobased/network/Blockbook.ts @@ -1,7 +1,7 @@ import { Cleaner } from 'cleaners' import { EdgeLog, EdgeTransaction } from 'edge-core-js/types' -import { EngineEmitter, EngineEvent } from '../../plugin/makeEngineEmitter' +import { EngineEmitter, EngineEvent } from '../../plugin/EngineEmitter' import { addressMessage, AddressResponse, @@ -20,17 +20,17 @@ import { SubscribeNewBlockResponse, transactionMessage, TransactionResponse -} from './BlockBookAPI' +} from './blockbookApi' import Deferred from './Deferred' -import { SocketEmitter } from './MakeSocketEmitter' import { makeSocket, OnQueueSpaceCB } from './Socket' +import { SocketEmitter } from './SocketEmitter' export type WatchAddressesCB = ( response: SubscribeAddressResponse ) => void | Promise export type WatchBlocksCB = () => void | Promise -export interface BlockBook { +export interface Blockbook { isConnected: boolean connect: () => Promise @@ -60,29 +60,29 @@ export interface BlockBook { broadcastTx: (transaction: EdgeTransaction) => Promise } -interface BlockBookConfig { - socketEmitter: SocketEmitter +interface BlockbookConfig { + asAddress?: Cleaner + connectionUri: string engineEmitter: EngineEmitter - wsAddress: string log: EdgeLog - walletId: string onQueueSpaceCB: OnQueueSpaceCB - asAddress?: Cleaner + socketEmitter: SocketEmitter + walletId: string } -export function makeBlockBook(config: BlockBookConfig): BlockBook { +export function makeBlockbook(config: BlockbookConfig): Blockbook { const { - wsAddress, - socketEmitter, + asAddress, + connectionUri, engineEmitter, log, onQueueSpaceCB, - walletId, - asAddress + socketEmitter, + walletId } = config - log(`makeBlockBook with uri ${wsAddress}`) + log(`makeBlockbook with uri ${connectionUri}`) - const instance: BlockBook = { + const instance: Blockbook = { isConnected: false, connect, disconnect, @@ -96,7 +96,7 @@ export function makeBlockBook(config: BlockBookConfig): BlockBook { broadcastTx } - const socket = makeSocket(wsAddress, { + const socket = makeSocket(connectionUri, { healthCheck: ping, onQueueSpaceCB, log, @@ -105,7 +105,7 @@ export function makeBlockBook(config: BlockBookConfig): BlockBook { }) async function connect(): Promise { - log(`connecting to blockbook socket with uri ${wsAddress}`) + log(`connecting to blockbook socket with uri ${connectionUri}`) if (instance.isConnected) return await socket.connect() @@ -114,7 +114,7 @@ export function makeBlockBook(config: BlockBookConfig): BlockBook { async function disconnect(): Promise { log( - `disconnecting from blockbook socket with uri ${wsAddress}, currently connected: ${instance.isConnected}` + `disconnecting from blockbook socket with uri ${connectionUri}, currently connected: ${instance.isConnected}` ) if (!instance.isConnected) return @@ -163,7 +163,7 @@ export function makeBlockBook(config: BlockBookConfig): BlockBook { const socketCb = async (res: SubscribeNewBlockResponse): Promise => { engineEmitter.emit( EngineEvent.BLOCK_HEIGHT_CHANGED, - wsAddress, + connectionUri, res.height ) } @@ -180,7 +180,11 @@ export function makeBlockBook(config: BlockBookConfig): BlockBook { deferredAddressSub: Deferred ): void { const socketCb = async (res: SubscribeAddressResponse): Promise => { - engineEmitter.emit(EngineEvent.NEW_ADDRESS_TRANSACTION, wsAddress, res) + engineEmitter.emit( + EngineEvent.NEW_ADDRESS_TRANSACTION, + connectionUri, + res + ) } socket.subscribe({ ...subscribeAddressesMessage(addresses, asAddress), diff --git a/src/common/utxobased/network/Socket.ts b/src/common/utxobased/network/Socket.ts index 09c5af9a..4fa90650 100644 --- a/src/common/utxobased/network/Socket.ts +++ b/src/common/utxobased/network/Socket.ts @@ -3,8 +3,8 @@ import { EdgeLog } from 'edge-core-js/types' import { removeItem } from '../../plugin/utils' import Deferred from './Deferred' -import { SocketEmitter, SocketEvent } from './MakeSocketEmitter' import { setupWS } from './nodejsWS' +import { SocketEmitter, SocketEvent } from './SocketEmitter' import { pushUpdate, removeIdFromQueue } from './socketQueue' import { InnerSocket, InnerSocketCallbacks, ReadyState } from './types' import { setupBrowser } from './windowWS' diff --git a/src/common/utxobased/network/MakeSocketEmitter.ts b/src/common/utxobased/network/SocketEmitter.ts similarity index 100% rename from src/common/utxobased/network/MakeSocketEmitter.ts rename to src/common/utxobased/network/SocketEmitter.ts diff --git a/src/common/utxobased/network/BlockBookAPI.ts b/src/common/utxobased/network/blockbookApi.ts similarity index 100% rename from src/common/utxobased/network/BlockBookAPI.ts rename to src/common/utxobased/network/blockbookApi.ts diff --git a/src/firo.ts b/src/firo.ts index ebe935c8..3f7878d7 100644 --- a/src/firo.ts +++ b/src/firo.ts @@ -1,6 +1,6 @@ import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types' -import { makeCurrencyPlugin } from './common/plugin/makeCurrencyPlugin' +import { makeCurrencyPlugin } from './common/plugin/CurrencyPlugin' import { info } from './common/utxobased/info/zcoin' const plugin = (options: EdgeCorePluginOptions): EdgeCurrencyPlugin => diff --git a/src/ftc.ts b/src/ftc.ts index b6b6a1e8..8e609204 100644 --- a/src/ftc.ts +++ b/src/ftc.ts @@ -1,6 +1,6 @@ import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types' -import { makeCurrencyPlugin } from './common/plugin/makeCurrencyPlugin' +import { makeCurrencyPlugin } from './common/plugin/CurrencyPlugin' import { info } from './common/utxobased/info/feathercoin' const plugin = (options: EdgeCorePluginOptions): EdgeCurrencyPlugin => diff --git a/src/index.ts b/src/index.ts index cc1592f7..928e0b8b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { EdgeCorePluginOptions, EdgeCorePlugins } from 'edge-core-js/types' -import { makeCurrencyPlugin } from './common/plugin/makeCurrencyPlugin' +import { makeCurrencyPlugin } from './common/plugin/CurrencyPlugin' import { all } from './common/utxobased/info/all' const plugins: EdgeCorePlugins = {} diff --git a/src/ltc.ts b/src/ltc.ts index 79b28213..127d8325 100644 --- a/src/ltc.ts +++ b/src/ltc.ts @@ -1,6 +1,6 @@ import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types' -import { makeCurrencyPlugin } from './common/plugin/makeCurrencyPlugin' +import { makeCurrencyPlugin } from './common/plugin/CurrencyPlugin' import { info } from './common/utxobased/info/litecoin' const plugin = (options: EdgeCorePluginOptions): EdgeCurrencyPlugin => diff --git a/src/tbch.ts b/src/tbch.ts index aa33a3da..d6b432ce 100644 --- a/src/tbch.ts +++ b/src/tbch.ts @@ -1,6 +1,6 @@ import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types' -import { makeCurrencyPlugin } from './common/plugin/makeCurrencyPlugin' +import { makeCurrencyPlugin } from './common/plugin/CurrencyPlugin' import { info } from './common/utxobased/info/bitcoincashtestnet' const plugin = (options: EdgeCorePluginOptions): EdgeCurrencyPlugin => diff --git a/src/tbtc.ts b/src/tbtc.ts index 2efcae42..6f0ee210 100644 --- a/src/tbtc.ts +++ b/src/tbtc.ts @@ -1,6 +1,6 @@ import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types' -import { makeCurrencyPlugin } from './common/plugin/makeCurrencyPlugin' +import { makeCurrencyPlugin } from './common/plugin/CurrencyPlugin' import { info } from './common/utxobased/info/bitcointestnet' const plugin = (options: EdgeCorePluginOptions): EdgeCurrencyPlugin => diff --git a/src/tbtg.ts b/src/tbtg.ts index d31dfa03..2c8a9869 100644 --- a/src/tbtg.ts +++ b/src/tbtg.ts @@ -1,6 +1,6 @@ import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types' -import { makeCurrencyPlugin } from './common/plugin/makeCurrencyPlugin' +import { makeCurrencyPlugin } from './common/plugin/CurrencyPlugin' import { info } from './common/utxobased/info/bitcoingoldtestnet' const plugin = (options: EdgeCorePluginOptions): EdgeCurrencyPlugin => diff --git a/test/common/plugin/currencyPlugin.fixtures/common.ts b/test/common/plugin/CurrencyPlugin.fixtures/common.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/common.ts rename to test/common/plugin/CurrencyPlugin.fixtures/common.ts diff --git a/test/common/plugin/currencyPlugin.fixtures/currencies/bitcoin.ts b/test/common/plugin/CurrencyPlugin.fixtures/currencies/bitcoin.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/currencies/bitcoin.ts rename to test/common/plugin/CurrencyPlugin.fixtures/currencies/bitcoin.ts diff --git a/test/common/plugin/currencyPlugin.fixtures/currencies/bitcoincash.ts b/test/common/plugin/CurrencyPlugin.fixtures/currencies/bitcoincash.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/currencies/bitcoincash.ts rename to test/common/plugin/CurrencyPlugin.fixtures/currencies/bitcoincash.ts diff --git a/test/common/plugin/currencyPlugin.fixtures/currencies/bitcoinsv.ts b/test/common/plugin/CurrencyPlugin.fixtures/currencies/bitcoinsv.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/currencies/bitcoinsv.ts rename to test/common/plugin/CurrencyPlugin.fixtures/currencies/bitcoinsv.ts diff --git a/test/common/plugin/currencyPlugin.fixtures/currencies/digibyte.ts b/test/common/plugin/CurrencyPlugin.fixtures/currencies/digibyte.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/currencies/digibyte.ts rename to test/common/plugin/CurrencyPlugin.fixtures/currencies/digibyte.ts diff --git a/test/common/plugin/currencyPlugin.fixtures/currencies/feathercoin.ts b/test/common/plugin/CurrencyPlugin.fixtures/currencies/feathercoin.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/currencies/feathercoin.ts rename to test/common/plugin/CurrencyPlugin.fixtures/currencies/feathercoin.ts diff --git a/test/common/plugin/currencyPlugin.fixtures/currencies/groestlcoin.ts b/test/common/plugin/CurrencyPlugin.fixtures/currencies/groestlcoin.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/currencies/groestlcoin.ts rename to test/common/plugin/CurrencyPlugin.fixtures/currencies/groestlcoin.ts diff --git a/test/common/plugin/currencyPlugin.fixtures/currencies/litecoin.ts b/test/common/plugin/CurrencyPlugin.fixtures/currencies/litecoin.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/currencies/litecoin.ts rename to test/common/plugin/CurrencyPlugin.fixtures/currencies/litecoin.ts diff --git a/test/common/plugin/currencyPlugin.fixtures/currencies/smartcash.ts b/test/common/plugin/CurrencyPlugin.fixtures/currencies/smartcash.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/currencies/smartcash.ts rename to test/common/plugin/CurrencyPlugin.fixtures/currencies/smartcash.ts diff --git a/test/common/plugin/currencyPlugin.fixtures/currencies/zcoin.ts b/test/common/plugin/CurrencyPlugin.fixtures/currencies/zcoin.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/currencies/zcoin.ts rename to test/common/plugin/CurrencyPlugin.fixtures/currencies/zcoin.ts diff --git a/test/common/plugin/currencyPlugin.fixtures/index.ts b/test/common/plugin/CurrencyPlugin.fixtures/index.ts similarity index 100% rename from test/common/plugin/currencyPlugin.fixtures/index.ts rename to test/common/plugin/CurrencyPlugin.fixtures/index.ts diff --git a/test/common/plugin/currencyPlugin.spec.ts b/test/common/plugin/CurrencyPlugin.spec.ts similarity index 99% rename from test/common/plugin/currencyPlugin.spec.ts rename to test/common/plugin/CurrencyPlugin.spec.ts index 0532c3bb..7b7e6bf9 100644 --- a/test/common/plugin/currencyPlugin.spec.ts +++ b/test/common/plugin/CurrencyPlugin.spec.ts @@ -11,7 +11,7 @@ import { before, describe, it } from 'mocha' import edgeCorePlugins from '../../../src/index' import { testLog } from '../../util/testLog' -import { fixtures } from './currencyPlugin.fixtures/index' +import { fixtures } from './CurrencyPlugin.fixtures/index' describe('currencyPlugins.spec', () => { for (const fixture of fixtures) { diff --git a/test/common/plugin/makeMetadata.spec.ts b/test/common/plugin/Metadata.spec.ts similarity index 95% rename from test/common/plugin/makeMetadata.spec.ts rename to test/common/plugin/Metadata.spec.ts index 7ed53126..c7239878 100644 --- a/test/common/plugin/makeMetadata.spec.ts +++ b/test/common/plugin/Metadata.spec.ts @@ -7,8 +7,8 @@ import { EdgeLog } from 'edge-core-js/types' import { EngineEmitter, EngineEvent -} from '../../../src/common/plugin/makeEngineEmitter' -import { makeMetadata, Metadata } from '../../../src/common/plugin/makeMetadata' +} from '../../../src/common/plugin/EngineEmitter' +import { makeMetadata, Metadata } from '../../../src/common/plugin/Metadata' import { makeFakeLog } from '../../utils' chai.should() diff --git a/test/common/plugin/serverScores.spec.ts b/test/common/plugin/ServerScores.spec.ts similarity index 98% rename from test/common/plugin/serverScores.spec.ts rename to test/common/plugin/ServerScores.spec.ts index 9d8be9f3..c68bfdc1 100644 --- a/test/common/plugin/serverScores.spec.ts +++ b/test/common/plugin/ServerScores.spec.ts @@ -3,10 +3,10 @@ import { assert } from 'chai' import { describe, it } from 'mocha' -import { ServerScores } from '../../../src/common/plugin/serverScores' +import { ServerScores } from '../../../src/common/plugin/ServerScores' import { makeFakeLog } from '../../utils' -describe(`ServerCache`, function () { +describe(`ServerScores`, function () { const testLog = makeFakeLog() const callback = (_: string): void => { return diff --git a/test/common/utxobased/db/Processor.spec.ts b/test/common/utxobased/db/Processor.spec.ts index 6ebd4046..1cf5be58 100644 --- a/test/common/utxobased/db/Processor.spec.ts +++ b/test/common/utxobased/db/Processor.spec.ts @@ -6,7 +6,7 @@ import { makeMemoryDisklet } from 'disklet' import { makeProcessor, Processor -} from '../../../../src/common/utxobased/db/makeProcessor' +} from '../../../../src/common/utxobased/db/Processor' import { IAddress, IProcessorTransaction, diff --git a/test/common/utxobased/engine/UtxoWalletTools.spec.ts b/test/common/utxobased/engine/UtxoWalletTools.spec.ts index fd0fe2f7..4fc46600 100644 --- a/test/common/utxobased/engine/UtxoWalletTools.spec.ts +++ b/test/common/utxobased/engine/UtxoWalletTools.spec.ts @@ -1,6 +1,6 @@ import { expect } from 'chai' -import { makeUtxoWalletTools } from '../../../../src/common/utxobased/engine/makeUtxoWalletTools' +import { makeUtxoWalletTools } from '../../../../src/common/utxobased/engine/UtxoWalletTools' import { info as pluginInfo } from '../../../../src/common/utxobased/info/bitcoin' describe('wallet tools tests', () => { diff --git a/test/common/utxobased/network/BlockBook.spec.ts b/test/common/utxobased/network/Blockbook.spec.ts similarity index 84% rename from test/common/utxobased/network/BlockBook.spec.ts rename to test/common/utxobased/network/Blockbook.spec.ts index 25ed9c1a..af6531da 100644 --- a/test/common/utxobased/network/BlockBook.spec.ts +++ b/test/common/utxobased/network/Blockbook.spec.ts @@ -6,25 +6,25 @@ import WS from 'ws' import { EngineEmitter, EngineEvent -} from '../../../../src/common/plugin/makeEngineEmitter' +} from '../../../../src/common/plugin/EngineEmitter' import { - BlockBook, - makeBlockBook -} from '../../../../src/common/utxobased/network/BlockBook' -import { SubscribeAddressResponse } from '../../../../src/common/utxobased/network/BlockBookAPI' + Blockbook, + makeBlockbook +} from '../../../../src/common/utxobased/network/Blockbook' +import { SubscribeAddressResponse } from '../../../../src/common/utxobased/network/blockbookApi' import Deferred from '../../../../src/common/utxobased/network/Deferred' +import { WsTask } from '../../../../src/common/utxobased/network/Socket' import { SocketEmitter, SocketEvent -} from '../../../../src/common/utxobased/network/MakeSocketEmitter' -import { WsTask } from '../../../../src/common/utxobased/network/Socket' +} from '../../../../src/common/utxobased/network/SocketEmitter' import { makeFakeLog } from '../../../utils' chai.should() -describe('BlockBook notifications tests with dummy server', function () { +describe('Blockbook notifications tests with dummy server', function () { let websocketServer: WS.Server - let blockBook: BlockBook + let blockbook: Blockbook let websocketClient: WebSocket let engineEmitter: EngineEmitter @@ -74,26 +74,26 @@ describe('BlockBook notifications tests with dummy server', function () { open = true }) - blockBook = makeBlockBook({ - socketEmitter, + blockbook = makeBlockbook({ + connectionUri: 'ws://localhost:8555', engineEmitter, log, - walletId: '', onQueueSpaceCB, - wsAddress: 'ws://localhost:8555' + socketEmitter, + walletId: '' }) - await blockBook.connect() - blockBook.isConnected.should.be.true + await blockbook.connect() + blockbook.isConnected.should.be.true open.should.be.true }) afterEach(async () => { - await blockBook.disconnect() - blockBook.isConnected.should.be.false + await blockbook.disconnect() + blockbook.isConnected.should.be.false websocketServer.close() }) - it('Test BlockBook watch address and watch block events', async () => { + it('Test Blockbook watch address and watch block events', async () => { let test = false test.should.be.false @@ -104,7 +104,7 @@ describe('BlockBook notifications tests with dummy server', function () { } ) - blockBook.watchBlocks(new Deferred()) + blockbook.watchBlocks(new Deferred()) websocketClient.send( '{"id":"subscribeNewBlock","data":{"height":1916453,"hash":"0000000000000e0444fa7c1540a96e5658898a59733311d08f01292e114e8d5b"}}' ) @@ -127,7 +127,7 @@ describe('BlockBook notifications tests with dummy server', function () { test = true } ) - blockBook.watchAddresses( + blockbook.watchAddresses( ['tb1q8uc93239etekcywh2l0t7aklxwywhaw0xlexld'], new Deferred() ) @@ -145,14 +145,16 @@ describe('BlockBook notifications tests with dummy server', function () { }) }) -describe('BlockBook', function () { +describe('Blockbook', function () { this.timeout(10000) const satoshiAddress = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa' const engineEmitter = new EngineEmitter() const socketEmitter = new SocketEmitter() + const log = makeFakeLog() - let blockBook: BlockBook + + let blockbook: Blockbook const onQueueSpaceCB = async ( _uri: string @@ -161,39 +163,39 @@ describe('BlockBook', function () { } beforeEach(async () => { - blockBook = makeBlockBook({ - socketEmitter, + blockbook = makeBlockbook({ + connectionUri: 'wss://btc1.trezor.io/websocket', engineEmitter, log, - wsAddress: 'wss://btc1.trezor.io/websocket', - walletId: '', - onQueueSpaceCB + onQueueSpaceCB, + socketEmitter, + walletId: '' }) - await blockBook.connect() + await blockbook.connect() }) afterEach(async () => { - await blockBook.disconnect() + await blockbook.disconnect() }) describe('connect', function () { - it('should connect to the BlockBook websocket API', async function () { - blockBook.isConnected.should.be.true + it('should connect to the Blockbook websocket API', async function () { + blockbook.isConnected.should.be.true }) }) describe('disconnect', function () { - it('should disconnect from the BlockBook API', async function () { - blockBook.isConnected.should.be.true - await blockBook.disconnect() - blockBook.isConnected.should.be.false + it('should disconnect from the Blockbook API', async function () { + blockbook.isConnected.should.be.true + await blockbook.disconnect() + blockbook.isConnected.should.be.false }) }) describe('fetchInfo', function () { - it('should fetch the BlockBook server info', async function () { - blockBook.isConnected.should.be.true - const info = await blockBook.fetchInfo() + it('should fetch the Blockbook server info', async function () { + blockbook.isConnected.should.be.true + const info = await blockbook.fetchInfo() info.should.have.keys( 'name', 'shortcut', @@ -210,7 +212,7 @@ describe('BlockBook', function () { describe('fetchAddress', function () { it('should fetch basic address information', async function () { - const info = await blockBook.fetchAddress(satoshiAddress) + const info = await blockbook.fetchAddress(satoshiAddress) info.should.have.property('address', satoshiAddress) info.should.have.property('balance') @@ -221,7 +223,7 @@ describe('BlockBook', function () { info.should.have.property('unconfirmedTxs') }) it('should fetch address information with tx ids', async function () { - const info = await blockBook.fetchAddress(satoshiAddress, { + const info = await blockbook.fetchAddress(satoshiAddress, { details: 'txids' }) @@ -238,7 +240,7 @@ describe('BlockBook', function () { info.should.have.property('txids') }) it('should fetch address information with txs', async function () { - const info = await blockBook.fetchAddress(satoshiAddress, { + const info = await blockbook.fetchAddress(satoshiAddress, { details: 'txs' }) @@ -258,7 +260,7 @@ describe('BlockBook', function () { describe('fetchAddressUtxos', function () { it('should fetch an address UTXOS', async function () { - const utxos = await blockBook.fetchAddressUtxos(satoshiAddress) + const utxos = await blockbook.fetchAddressUtxos(satoshiAddress) utxos.length.should.be.greaterThan(0) utxos[0].should.have.property('txid') @@ -271,7 +273,7 @@ describe('BlockBook', function () { const satoshiHash = '3ed86f1b0a0a6fe180195bc1f93fd9d0801aea8c8ad5018de82c026dc21e2b15' it('should fetch details from a transaction hash', async function () { - const tx = await blockBook.fetchTransaction(satoshiHash) + const tx = await blockbook.fetchTransaction(satoshiHash) tx.txid.should.equal(satoshiHash) tx.fees.should.equal('226')