add riaa client sample

This commit is contained in:
you21979
2017-10-30 15:11:20 +09:00
parent d697c70c50
commit 71e7dc3cdf
3 changed files with 53 additions and 3 deletions

View File

@@ -2,6 +2,13 @@
Electrum Protocol Client for Node.js
## what is this
https://electrum.org/
electrum is bitcoin wallet service.
This is a library of Node.js that can communicate with the electrum(x) server.
## install
```
@@ -14,6 +21,8 @@ npm i electrum-client
* TCP / TLS
* JSON-RPC
* Subscribe Message
* High Performance Message
* no dependency for other library
## usage
@@ -34,3 +43,4 @@ const main = async () => {
main()
```

View File

@@ -0,0 +1,38 @@
'use strict';
const ElectrumClient = require('electrum-client');
const createRiaaClient = (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 connect = createRiaaClient(50001, 'electrumx.tamami-foundation.org', '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())

View File

@@ -1,13 +1,12 @@
{
"name": "electrum-client",
"version": "0.0.4",
"version": "0.0.5",
"description": "Electrum protocol client for node.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
},
"dependencies": {},
"repository": {
"type": "git",
"url": "git://github.com/you21979/node-electrum-client.git"
@@ -20,6 +19,9 @@
"electrum",
"bitcoin"
],
"engines": {
"node": ">=6"
},
"author": "Yuki Akiyama",
"license": "MIT"
}