Skip to content

Commit

Permalink
Light Node
Browse files Browse the repository at this point in the history
  • Loading branch information
unwriter committed Jan 22, 2019
1 parent ff2dcad commit c2e0b5c
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 74 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,20 @@ Let's revisit the example mentioned earlier:
This whole process resembles the unix pipeline system, and no security is breached along the way, thanks to Bitcoin.


# Modes

There are two modes:

**1. Full Node:** Works with your OWN node, which means you need a Bitcoin node.
**2. Light Node:** Works WITHOUT a Bitcoin node. Instead it uses a remote insight endpoint (Default: bchsvexplorer.com)

By default Bitpipe runs as Light node.

If you want to use your own Bitcoin node instead of a remote Insight API, you can add the following line to the `.env` file:

```
LOCAL=true
```


# Usage
Expand Down
24 changes: 24 additions & 0 deletions demo/default/bitchat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
You can filter this transaction with the following bitquery:
{
"v": 3,
"q": {
"find": {
"out.b0": { "op": 106 },
"out.b1": { "op": 0 }
}
}
}
*/
var axios = require('axios')
const host = "https://pipe.bitdb.network"
var datapay = require('datapay')
axios.post(host + "/bitpipe", {
data: [ "", "Hello from Bitpipe"]
})
.then(function(response) {
console.log("response = ", response)
})
.catch(function(e) {
console.log("Error = ", e)
})
20 changes: 20 additions & 0 deletions demo/default/bitchat2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// post multiple consecutive messages
var axios = require('axios')
const host = "https://pipe.bitdb.network"
var datapay = require('datapay')
var seed = "#";
var run = async function(space) {
return axios.post(host + "/bitpipe", {
data: [ "", space + seed ]
})
};
(async function() {
for(i=0; i < 30; i++) {
let space = "#".repeat(i)
let response = await run(space).catch(function(e) {
console.log("Error", e)
})
await new Promise(done => setTimeout(done, 2000));
console.log("response = ", response.data)
}
})();
31 changes: 0 additions & 31 deletions demo/default/multi.js

This file was deleted.

2 changes: 1 addition & 1 deletion demo/default/payload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var axios = require('axios')
const host = "https://bitpipe.bitdb.network"
const host = "https://pipe.bitdb.network"
var datapay = require('datapay')
axios.post(host + "/bitpipe", {
data: [ "0x6d02", "hello from datapay" ]
Expand Down
25 changes: 0 additions & 25 deletions demo/default/single.js

This file was deleted.

48 changes: 32 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const PRIVATE_KEYS = KEYS.filter(function(p) {
var app = null
var current_index = 0

var rpc
var start = function(o) {
var lambda = null
var port = 8081
Expand All @@ -52,14 +53,19 @@ var start = function(o) {
app.use(express.urlencoded({extended: true}));
app.use(express.json())
app.use(express.static('public'))
const rpc = new RpcClient({
'protocol': 'http',
'user': KEY_MAPPING.rpc_user ? KEY_MAPPING.rpc_user : 'root',
'pass': KEY_MAPPING.rpc_pass ? KEY_MAPPING.rpc_pass : 'bitcoin',
'host': KEY_MAPPING.host ? KEY_MAPPING.host : ip.address(),
'port': '8332',
'limit': 15
})
if (KEY_MAPPING.LOCAL) {
// rpc
rpc = new RpcClient({
'protocol': 'http',
'user': KEY_MAPPING.rpc_user ? KEY_MAPPING.rpc_user : 'root',
'pass': KEY_MAPPING.rpc_pass ? KEY_MAPPING.rpc_pass : 'bitcoin',
'host': KEY_MAPPING.host ? KEY_MAPPING.host : ip.address(),
'port': '8332',
'limit': 15
})
} else {
// use remote insight
}
app.get('/', function (req, res) {
res.send('Hello Bitpipe!\n\nMake a POST request to:' + req.protocol + "://" + req.headers.host + req.originalUrl + "/bitpipe with a datapay payload.\n\nMore at https://github.com/unwriter/datapay")
})
Expand Down Expand Up @@ -99,18 +105,28 @@ var run = function(err, payload, res) {
payload.pay = { key : current_key }
}
console.log('payload = ', payload)
datapay.build(payload, function(err, signed_tx) {
console.log("signed tx = ", signed_tx)
rpc.sendRawTransaction(signed_tx, function(err, r) {
if (KEY_MAPPING.LOCAL) {
datapay.build(payload, function(err, signed_tx) {
console.log("signed tx = ", signed_tx)
rpc.sendRawTransaction(signed_tx, function(err, r) {
if (err) {
console.log("error: ", err)
res.json({success: false, message: err.toString()})
} else {
console.log("success: ", r)
res.json({success: true})
}
})
})
} else {
datapay.send(payload, function(err, res) {
if (err) {
console.log("error: ", err)
res.json({success: false, message: err.toString()})
console.log("Error:", err)
} else {
console.log("success: ", r)
res.json({success: true})
console.log("result = ", res)
}
})
})
}
}
}
if (require.main === module) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitpipe",
"version": "0.0.2",
"version": "0.0.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
Binary file modified pipe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c2e0b5c

Please sign in to comment.