Skip to content

Commit

Permalink
Merge pull request #396 from EdgeApp/sam/http-blockbook
Browse files Browse the repository at this point in the history
Add fallbackServers to EngineInfo
  • Loading branch information
samholmes authored Apr 8, 2024
2 parents d089927 + fe9e6aa commit db70a29
Show file tree
Hide file tree
Showing 57 changed files with 347 additions and 173 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bch.ts
Original file line number Diff line number Diff line change
@@ -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 =>
Expand Down
2 changes: 1 addition & 1 deletion src/bsv.ts
Original file line number Diff line number Diff line change
@@ -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 =>
Expand Down
2 changes: 1 addition & 1 deletion src/btc.ts
Original file line number Diff line number Diff line change
@@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ 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(
pluginOptions: EdgeCorePluginOptions,
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({
Expand All @@ -43,6 +46,7 @@ export function makeCurrencyPlugin(
pluginInfo,
pluginDisklet,
currencyTools,
initOptions: asUtxoInitOptions(initOptions),
io,
options: {
...pluginOptions,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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: ((
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,7 +51,7 @@ export interface PluginState {
clearCache: () => Promise<void>
getLocalServers: (
numServersWanted: number,
includePatterns: string[]
includePatterns?: Array<string | RegExp>
) => string[]
refreshServers: () => Promise<void>
updateServers: (settings: UtxoUserSettings) => Promise<void>
Expand Down Expand Up @@ -209,7 +209,7 @@ export function makePluginState(settings: PluginStateSettings): PluginState {

getLocalServers(
numServersWanted: number,
includePatterns: string[] = []
includePatterns: Array<string | RegExp> = []
): string[] {
return serverScores.getServers(
knownServers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class ServerScores {
getServers(
servers: ServerList,
numServersWanted: number,
includePatterns: string[] = []
includePatterns: Array<string | RegExp> = []
): string[] {
if (servers == null || Object.keys(servers).length === 0) {
return []
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 10 additions & 2 deletions src/common/plugin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof asCurrencyFormat>
export const asCurrencyFormat = asValue('bip32', 'bip44', 'bip49', 'bip84')
Expand Down Expand Up @@ -70,6 +71,7 @@ export interface EngineInfo {
mempoolSpaceFeeInfoServer?: string
defaultFeeInfo: FeeInfo
scriptTemplates?: ScriptTemplates
serverConfigs?: ServerConfig[]
// Codec Cleaners
asBlockbookAddress?: Cleaner<string>
// Coin specific transaction handling
Expand All @@ -79,6 +81,11 @@ export interface EngineInfo {
) => IProcessorTransaction
}

export interface ServerConfig {
type: 'blockbook-nownode'
uris: string[]
}

/**
* Coin Info
*/
Expand Down Expand Up @@ -196,6 +203,7 @@ export interface EngineConfig {
pluginDisklet: Disklet
currencyTools: EdgeCurrencyTools
options: EngineOptions
initOptions: UtxoInitOptions
io: EdgeIo
pluginState: PluginState
}
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/common/utxobased/db/Models/ProcessorTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -54,7 +54,7 @@ export const fromEdgeTransaction = (
interface ToEdgeTransactionArgs {
walletId: string
tx: IProcessorTransaction
walletTools: UTXOPluginWalletTools
walletTools: UtxoWalletTools
processor: Processor
pluginInfo: PluginInfo
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/common/utxobased/db/util/utxo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Loading

0 comments on commit db70a29

Please sign in to comment.