mirror of
https://github.com/mempool/mempool.git
synced 2025-01-18 21:32:55 +01:00
Electrum protocol and tx lookup setting.
This commit is contained in:
parent
7729ad8b79
commit
1a6c2e79e6
@ -9,9 +9,13 @@
|
||||
},
|
||||
"ELECTRS": {
|
||||
"REST_API_URL": "http://127.0.0.1:3000",
|
||||
"POLL_RATE_MS": 2000,
|
||||
"POLL_RATE_MS": 2000
|
||||
},
|
||||
"ELECTRUM": {
|
||||
"HOST": "127.0.0.1",
|
||||
"PORT": 50002
|
||||
"PORT": 50002,
|
||||
"PROTOCOL": "tcl",
|
||||
"TX_LOOKUPS": false
|
||||
},
|
||||
"BITCOIND": {
|
||||
"HOST": "127.0.0.1",
|
||||
|
@ -21,16 +21,16 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
|
||||
const electrumPersistencePolicy = { retryPeriod: 10000, maxRetry: 1000, callback: null };
|
||||
|
||||
const electrumCallbacks = {
|
||||
onConnect: (client, versionInfo) => { logger.info(`Connected to Electrum Server at ${config.ELECTRS.HOST}:${config.ELECTRS.PORT} (${JSON.stringify(versionInfo)})`); },
|
||||
onClose: (client) => { logger.info(`Disconnected from Electrum Server at ${config.ELECTRS.HOST}:${config.ELECTRS.PORT}`); },
|
||||
onConnect: (client, versionInfo) => { logger.info(`Connected to Electrum Server at ${config.ELECTRUM.HOST}:${config.ELECTRUM.PORT} (${JSON.stringify(versionInfo)})`); },
|
||||
onClose: (client) => { logger.info(`Disconnected from Electrum Server at ${config.ELECTRUM.HOST}:${config.ELECTRUM.PORT}`); },
|
||||
onError: (err) => { logger.err(`Electrum error: ${JSON.stringify(err)}`); },
|
||||
onLog: (str) => { logger.debug(str); },
|
||||
};
|
||||
|
||||
this.electrumClient = new ElectrumClient(
|
||||
config.ELECTRS.PORT,
|
||||
config.ELECTRS.HOST,
|
||||
config.ELECTRS.PORT === 50001 ? 'tcp' : 'tls',
|
||||
config.ELECTRUM.PORT,
|
||||
config.ELECTRUM.HOST,
|
||||
config.ELECTRUM.PROTOCOL,
|
||||
null,
|
||||
electrumCallbacks
|
||||
);
|
||||
@ -38,11 +38,14 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
|
||||
this.electrumClient.initElectrum(electrumConfig, electrumPersistencePolicy)
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
logger.err(`Error connecting to Electrum Server at ${config.ELECTRS.HOST}:${config.ELECTRS.PORT}`);
|
||||
logger.err(`Error connecting to Electrum Server at ${config.ELECTRUM.HOST}:${config.ELECTRUM.PORT}`);
|
||||
});
|
||||
}
|
||||
|
||||
async $getRawTransaction(txId: string, skipConversion = false, addPrevout = false): Promise<IEsploraApi.Transaction> {
|
||||
if (!config.ELECTRUM.TX_LOOKUPS) {
|
||||
return super.$getRawTransaction(txId, skipConversion, addPrevout);
|
||||
}
|
||||
const txInMempool = mempool.getMempool()[txId];
|
||||
if (txInMempool && addPrevout) {
|
||||
return this.$addPrevouts(txInMempool);
|
||||
|
@ -12,8 +12,12 @@ interface IConfig {
|
||||
ELECTRS: {
|
||||
REST_API_URL: string;
|
||||
POLL_RATE_MS: number;
|
||||
};
|
||||
ELECTRUM: {
|
||||
HOST: string;
|
||||
PORT: number;
|
||||
PROTOCOL: 'tls' | 'tcp';
|
||||
TX_LOOKUPS: boolean;
|
||||
};
|
||||
BITCOIND: {
|
||||
HOST: string;
|
||||
@ -61,9 +65,13 @@ const defaults: IConfig = {
|
||||
},
|
||||
'ELECTRS': {
|
||||
'REST_API_URL': 'http://127.0.0.1:3000',
|
||||
'POLL_RATE_MS': 2000,
|
||||
'POLL_RATE_MS': 2000
|
||||
},
|
||||
'ELECTRUM': {
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': 3306
|
||||
'PORT': 3306,
|
||||
'PROTOCOL': 'tls',
|
||||
'TX_LOOKUPS': false
|
||||
},
|
||||
'BITCOIND': {
|
||||
'HOST': '127.0.0.1',
|
||||
@ -103,6 +111,7 @@ const defaults: IConfig = {
|
||||
class Config implements IConfig {
|
||||
MEMPOOL: IConfig['MEMPOOL'];
|
||||
ELECTRS: IConfig['ELECTRS'];
|
||||
ELECTRUM: IConfig['ELECTRUM'];
|
||||
BITCOIND: IConfig['BITCOIND'];
|
||||
DATABASE: IConfig['DATABASE'];
|
||||
STATISTICS: IConfig['STATISTICS'];
|
||||
@ -114,6 +123,7 @@ class Config implements IConfig {
|
||||
const configs = this.merge(configFile, defaults);
|
||||
this.MEMPOOL = configs.MEMPOOL;
|
||||
this.ELECTRS = configs.ELECTRS;
|
||||
this.ELECTRUM = configs.ELECTRUM;
|
||||
this.BITCOIND = configs.BITCOIND;
|
||||
this.DATABASE = configs.DATABASE;
|
||||
this.STATISTICS = configs.STATISTICS;
|
||||
|
Loading…
Reference in New Issue
Block a user