REF: cleanup

This commit is contained in:
Overtorment 2019-05-23 13:11:04 +01:00
parent 720c70ef99
commit 5e413bf471
8 changed files with 0 additions and 225 deletions

View File

@ -1,24 +0,0 @@
const ElectrumClient = require("..")
const peers = require('electrum-host-parse').getDefaultPeers("BitcoinSegwit").filter(v => v.ssl)
const getRandomPeer = () => peers[peers.length * Math.random() | 0]
const main = async () => {
const peer = getRandomPeer()
console.log('begin connection: ' + JSON.stringify(peer))
const ecl = new ElectrumClient(peer.ssl, peer.host, 'ssl')
await ecl.connect()
try{
const ver = await ecl.server_version("2.7.11", "1.0")
console.log(ver)
const balance = await ecl.blockchainAddress_getBalance("12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX")
console.log(balance)
const unspent = await ecl.blockchainAddress_listunspent("12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX")
console.log(unspent)
}catch(e){
console.log(e)
}
await ecl.close()
}
main().catch(console.log)

View File

@ -1,25 +0,0 @@
const Client = require("..")
const proc = async(cl) => {
try{
const version = await cl.server_version("2.7.11", "1.0")
console.log(version)
const balance = await cl.blockchainAddress_getBalance("MS43dMzRKfEs99Q931zFECfUhdvtWmbsPt")
console.log(balance)
const utxo = await cl.blockchainAddress_listunspent("MS43dMzRKfEs99Q931zFECfUhdvtWmbsPt")
console.log(utxo)
}catch(e){
console.log(e)
}
}
const main = async(port, host) => {
const cl = new Client(port, host);
await cl.connect()
for(let i = 0; i<100; ++i){
await proc(cl)
}
await cl.close()
}
main(4444, "localhost")

View File

@ -1,40 +0,0 @@
'use strict';
const ElectrumClient = require('..');
const createRaiiClient = (port, host, protocol, options) => {
return (params, promise) => {
const name = params.join(':')
const client = new ElectrumClient(port, host, protocol, options)
console.time(name)
return client.connect().then( () => {
return promise(client)
}).catch( e => {
client.close()
console.timeEnd(name)
throw e
}).then( res => {
client.close()
console.timeEnd(name)
return res
})
}
}
const main = async(hex) => {
const hosts = ['electrum-mona.bitbank.cc', 'electrumx.tamami-foundation.org']
const host = hosts[Math.floor(Math.random() * hosts.length)]
const connect = createRaiiClient(50001, host, 'tcp')
await connect(['blockchainTransaction_broadcast', hex], async(client) => {
const ver = await client.server_version('2.7.11', '1.0')
console.log(ver)
const result = await client.blockchainTransaction_broadcast(hex)
console.log(result)
})
}
const getopt = () => {
return process.argv.slice(2)[0]
}
main(getopt()).catch(console.log)

View File

@ -1,40 +0,0 @@
'use strict';
const ElectrumClient = require('..');
const createRaiiClient = (port, host, protocol, options) => {
return (params, promise) => {
const name = params.join(':')
const client = new ElectrumClient(port, host, protocol, options)
console.time(name)
return client.connect().then( () => {
return promise(client)
}).catch( e => {
client.close()
console.timeEnd(name)
throw e
}).then( res => {
client.close()
console.timeEnd(name)
return res
})
}
}
const main = async(hex) => {
const hosts = ['electrum-mona.bitbank.cc', 'electrumx.tamami-foundation.org']
const host = hosts[Math.floor(Math.random() * hosts.length)]
const connect = createRaiiClient(50000, host, 'tcp')
await connect(['blockchainTransaction_broadcast', hex], async(client) => {
const ver = await client.server_version('2.7.11', '1.0')
console.log(ver)
const result = await client.blockchainTransaction_broadcast(hex)
console.log(result)
})
}
const getopt = () => {
return process.argv.slice(2)[0]
}
main(getopt()).catch(console.log)

View File

@ -1,22 +0,0 @@
const ElectrumClient = require('..')
const main = async () => {
const ecl = new ElectrumClient(50002, 'bitcoins.sk', 'tls')
await ecl.connect()
try{
const ver = await ecl.server_version("3.0.5", "1.1")
console.log(ver)
const balance = await ecl.blockchainScripthash_getBalance("676ca8550e249787290b987e12cebdb2e9b26d88c003d836ffb1cb03ffcbea7c")
console.log(balance)
const unspent = await ecl.blockchainScripthash_listunspent("676ca8550e249787290b987e12cebdb2e9b26d88c003d836ffb1cb03ffcbea7c")
console.log(unspent)
const history = await ecl.blockchainScripthash_getHistory("676ca8550e249787290b987e12cebdb2e9b26d88c003d836ffb1cb03ffcbea7c")
console.log(history)
const mempool = await ecl.blockchainScripthash_getMempool("676ca8550e249787290b987e12cebdb2e9b26d88c003d836ffb1cb03ffcbea7c")
console.log(mempool)
}catch(e){
console.log(e)
}
await ecl.close()
}
main().catch(console.log)

View File

@ -1,22 +0,0 @@
const ElectrumClient = require('..')
const main = async () => {
const ecl = new ElectrumClient(995, 'btc.smsys.me', 'tls')
await ecl.connect()
try{
const ver = await ecl.server_version("0", "0.9")
console.log(ver)
const balance = await ecl.blockchainAddress_getBalance("12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX")
console.log(balance)
const unspent = await ecl.blockchainAddress_listunspent("12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX")
console.log(unspent)
const tx1 = await ecl.blockchainTransaction_get("f91d0a8a78462bc59398f2c5d7a84fcff491c26ba54c4833478b202796c8aafd", false)
console.log(tx1)
const tx2 = await ecl.blockchainTransaction_get("f91d0a8a78462bc59398f2c5d7a84fcff491c26ba54c4833478b202796c8aafd", true)
console.log(tx2)
}catch(e){
console.log(e)
}
await ecl.close()
}
main().catch(console.log)

View File

@ -1,22 +0,0 @@
const ElectrumClient = require('..')
const main = async () => {
const ecl = new ElectrumClient(995, 'btc.smsys.me', 'tls')
await ecl.connect()
try{
const ver = await ecl.server_version("0", "1.2")
console.log(ver)
const balance = await ecl.blockchainAddress_getBalance("12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX")
console.log(balance)
const unspent = await ecl.blockchainAddress_listunspent("12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX")
console.log(unspent)
const tx1 = await ecl.blockchainTransaction_get("f91d0a8a78462bc59398f2c5d7a84fcff491c26ba54c4833478b202796c8aafd", false)
console.log(tx1)
const tx2 = await ecl.blockchainTransaction_get("f91d0a8a78462bc59398f2c5d7a84fcff491c26ba54c4833478b202796c8aafd", true)
console.log(JSON.stringify(tx2, null, 2))
}catch(e){
console.log(e)
}
await ecl.close()
}
main().catch(console.log)

View File

@ -1,30 +0,0 @@
const ElectrumClient = require('..')
const sleep = (ms) => new Promise((resolve,_) => setTimeout(() => resolve(), ms))
const main = async () => {
try{
const ecl = new ElectrumClient(50002, 'bitcoins.sk', 'tls')
ecl.subscribe.on('server.peers.subscribe', console.log)
ecl.subscribe.on('blockchain.numblocks.subscribe', console.log)
ecl.subscribe.on('blockchain.headers.subscribe', console.log)
ecl.subscribe.on('blockchain.address.subscribe', console.log)
ecl.subscribe.on('blockchain.scripthash.subscribe', console.log)
await ecl.connect()
await ecl.server_version("3.0.5", "1.1")
const p1 = await ecl.serverPeers_subscribe()
const p2 = await ecl.blockchainHeaders_subscribe()
// Note: blockchain.numblocks.subscribe is deprecated in protocol version 1.1
const p3 = await ecl.blockchainAddress_subscribe('1BK45iaPrrd26gKagrXytvz6anrj3hQ2pQ')
// Subscribe to corresponding scripthash for the above address
const p4 = await ecl.blockchainScripthash_subscribe('f3aa57a41424146327e5c88c25db8953dd16c6ab6273cdb74a4404ed4d0f5714')
while(true){
await sleep(1000)
const ver = await ecl.server_version("3.0.5", "1.1")
}
await ecl.close()
}catch(e){
console.log("error")
console.log(e)
}
}
main()