From 17586c97231233241aadf91e1faea0950810a480 Mon Sep 17 00:00:00 2001 From: you21979 Date: Mon, 12 Mar 2018 16:35:42 +0900 Subject: [PATCH] fix example --- example/bitcoin.js | 3 ++- example/ex.js | 2 +- example/{simple.js => simple_v09.js} | 6 +++++- example/simple_v12.js | 22 ++++++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) rename example/{simple.js => simple_v09.js} (59%) create mode 100644 example/simple_v12.js diff --git a/example/bitcoin.js b/example/bitcoin.js index d478656..8fd38d7 100644 --- a/example/bitcoin.js +++ b/example/bitcoin.js @@ -1,4 +1,5 @@ -const ElectrumClient = require('..') +const ElectrumClient = require("..") + const peers = require('electrum-host-parse').getDefaultPeers("BitcoinSegwit").filter(v => v.ssl) const getRandomPeer = () => peers[peers.length * Math.random() | 0] diff --git a/example/ex.js b/example/ex.js index 9ee12a8..c5e4a42 100644 --- a/example/ex.js +++ b/example/ex.js @@ -1,4 +1,4 @@ -const Client = require("../lib/electrum_cli") +const Client = require("..") const proc = async(cl) => { try{ diff --git a/example/simple.js b/example/simple_v09.js similarity index 59% rename from example/simple.js rename to example/simple_v09.js index 06c99a1..fee402c 100644 --- a/example/simple.js +++ b/example/simple_v09.js @@ -4,12 +4,16 @@ const main = async () => { const ecl = new ElectrumClient(995, 'btc.smsys.me', 'tls') await ecl.connect() try{ - const ver = await ecl.server_version("2.7.11", "1.0") + 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) } diff --git a/example/simple_v12.js b/example/simple_v12.js new file mode 100644 index 0000000..04c189e --- /dev/null +++ b/example/simple_v12.js @@ -0,0 +1,22 @@ +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)