mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-26 08:55:56 +01:00
REF: electrum
This commit is contained in:
parent
3a679b72ac
commit
b6b8bea05b
2 changed files with 47 additions and 38 deletions
|
@ -5,6 +5,18 @@ let reverse = require('buffer-reverse');
|
|||
|
||||
const storageKey = 'ELECTRUM_PEERS';
|
||||
const defaultPeer = { host: 'electrum.coinucopia.io', tcp: 50001 };
|
||||
const hardcodedPeers = [
|
||||
{ host: 'noveltybobble.coinjoined.com', tcp: '50001' },
|
||||
{ host: 'daedalus.bauerj.eu', tcp: '50001' },
|
||||
{ host: 'elx1.kempken.org', tcp: '50001' },
|
||||
{ host: 'electrum.be', tcp: '50001' },
|
||||
{ host: 'node.ispol.sk', tcp: '50001' }, // SLOW
|
||||
{ host: '139.162.14.142', tcp: '50001' },
|
||||
// { host: 'electrum.coinucopia.io', tcp: '50001' }, // SLOW
|
||||
{ host: 'Bitkoins.nl', tcp: '50001' },
|
||||
{ host: 'fullnode.coinkite.com', tcp: '50001' },
|
||||
{ host: 'preperfect.eleCTruMioUS.com', tcp: '50001' },
|
||||
];
|
||||
|
||||
let mainClient = false;
|
||||
let mainConnected = false;
|
||||
|
@ -45,11 +57,6 @@ connectMain();
|
|||
* @returns {Promise<{tcp, host}|*>}
|
||||
*/
|
||||
async function getRandomHardcodedPeer() {
|
||||
let hardcodedPeers = [
|
||||
{ host: 'node.ispol.sk', tcp: '50001' },
|
||||
{ host: '139.162.14.142', tcp: '50001' },
|
||||
{ host: 'electrum.coinucopia.io', tcp: '50001' },
|
||||
];
|
||||
return hardcodedPeers[(hardcodedPeers.length * Math.random()) | 0];
|
||||
}
|
||||
|
||||
|
@ -186,6 +193,8 @@ module.exports.forceDisconnect = () => {
|
|||
mainClient.close();
|
||||
};
|
||||
|
||||
module.exports.hardcodedPeers = hardcodedPeers;
|
||||
|
||||
/*
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
global.net = require('net');
|
||||
let BlueElectrum = require('./BlueElectrum');
|
||||
let assert = require('assert');
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100 * 1000;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150 * 1000;
|
||||
|
||||
afterAll(() => {
|
||||
// after all tests we close socket so the test suite can actually terminate
|
||||
|
@ -24,41 +24,41 @@ describe('Electrum', () => {
|
|||
it('ElectrumClient can connect and query', async () => {
|
||||
const ElectrumClient = require('electrum-client');
|
||||
let bitcoin = require('bitcoinjs-lib');
|
||||
// let bitcoin = require('bitcoinjs-lib');
|
||||
|
||||
const peer = { host: 'electrum.coinucopia.io', ssl: 50002, tcp: 50001, pruning: null, http: null, https: null };
|
||||
console.log('begin connection:', JSON.stringify(peer));
|
||||
let mainClient = new ElectrumClient(peer.tcp, peer.host, 'tcp');
|
||||
for (let peer of BlueElectrum.hardcodedPeers) {
|
||||
let mainClient = new ElectrumClient(peer.tcp, peer.host, 'tcp');
|
||||
|
||||
try {
|
||||
await mainClient.connect();
|
||||
const ver = await mainClient.server_version('2.7.11', '1.2');
|
||||
console.log('connected to ', ver);
|
||||
} catch (e) {
|
||||
console.log('bad connection:', JSON.stringify(peer));
|
||||
throw new Error();
|
||||
try {
|
||||
await mainClient.connect();
|
||||
await mainClient.server_version('2.7.11', '1.2');
|
||||
} catch (e) {
|
||||
mainClient.reconnect = mainClient.keepAlive = () => {}; // dirty hack to make it stop reconnecting
|
||||
mainClient.close();
|
||||
throw new Error('bad connection: ' + JSON.stringify(peer));
|
||||
}
|
||||
|
||||
let addr4elect = 'bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej';
|
||||
let script = bitcoin.address.toOutputScript(addr4elect);
|
||||
let hash = bitcoin.crypto.sha256(script);
|
||||
let reversedHash = Buffer.from(hash.reverse());
|
||||
let start = +new Date();
|
||||
let balance = await mainClient.blockchainScripthash_getBalance(reversedHash.toString('hex'));
|
||||
let end = +new Date();
|
||||
console.warn(peer.host, 'took', (end - start) / 1000, 'seconds to fetch balance');
|
||||
assert.ok(balance.confirmed > 0);
|
||||
|
||||
addr4elect = '3GCvDBAktgQQtsbN6x5DYiQCMmgZ9Yk8BK';
|
||||
script = bitcoin.address.toOutputScript(addr4elect);
|
||||
hash = bitcoin.crypto.sha256(script);
|
||||
reversedHash = Buffer.from(hash.reverse());
|
||||
balance = await mainClient.blockchainScripthash_getBalance(reversedHash.toString('hex'));
|
||||
assert.ok(balance.confirmed === 51432);
|
||||
|
||||
// let peers = await mainClient.serverPeers_subscribe();
|
||||
// console.log(peers);
|
||||
mainClient.reconnect = mainClient.keepAlive = () => {}; // dirty hack to make it stop reconnecting
|
||||
mainClient.close();
|
||||
}
|
||||
|
||||
let addr4elect = 'bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej';
|
||||
let script = bitcoin.address.toOutputScript(addr4elect);
|
||||
let hash = bitcoin.crypto.sha256(script);
|
||||
let reversedHash = Buffer.from(hash.reverse());
|
||||
let balance = await mainClient.blockchainScripthash_getBalance(reversedHash.toString('hex'));
|
||||
assert.ok(balance.confirmed > 0);
|
||||
|
||||
addr4elect = '3GCvDBAktgQQtsbN6x5DYiQCMmgZ9Yk8BK';
|
||||
script = bitcoin.address.toOutputScript(addr4elect);
|
||||
hash = bitcoin.crypto.sha256(script);
|
||||
reversedHash = Buffer.from(hash.reverse());
|
||||
balance = await mainClient.blockchainScripthash_getBalance(reversedHash.toString('hex'));
|
||||
assert.ok(balance.confirmed === 51432);
|
||||
|
||||
// let peers = await mainClient.serverPeers_subscribe();
|
||||
// console.log(peers);
|
||||
mainClient.keepAlive = () => {}; // dirty hack to make it stop reconnecting
|
||||
mainClient.reconnect = () => {}; // dirty hack to make it stop reconnecting
|
||||
mainClient.close();
|
||||
// setTimeout(()=>process.exit(), 3000);
|
||||
});
|
||||
|
||||
it('BlueElectrum works', async function() {
|
||||
|
|
Loading…
Add table
Reference in a new issue