Skip to content

Commit

Permalink
chore: 'npm run fmt' to apply style rules
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Jun 20, 2023
1 parent 8b3d4e5 commit 62c994d
Show file tree
Hide file tree
Showing 53 changed files with 5,702 additions and 5,685 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Dashcore Node
============
# Dashcore Node

A Dash full node for building applications and services with Node.js. A node is extensible and can be configured to run additional services. At the minimum a node has an interface to [Dash Core (dashd) v0.13.0](https://github.com/dashpay/dash/tree/v0.13.0.x) for more advanced address queries. Additional services can be enabled to make a node more useful such as exposing new APIs, running a block explorer and wallet service.

Expand All @@ -23,6 +22,7 @@ Some plugins are available :
- Insight-UI : `./bin/dashcore-node addservice @dashevo/insight-ui`

You also might want to add these index to your dash.conf file :

```
-addressindex
-timestampindex
Expand All @@ -36,25 +36,25 @@ npm install @dashevo/dashcore-node
```

```javascript
const dashcore = require('@dashevo/dashcore-node');
const config = require('./dashcore-node.json');
const dashcore = require("@dashevo/dashcore-node");
const config = require("./dashcore-node.json");

let node = dashcore.scaffold.start({ path: "", config: config });
node.on('ready', function () {
console.log("Dash core started");
node.services.dashd.on('tx', function(txData) {
let tx = new dashcore.lib.Transaction(txData);
console.log(tx);
});
node.on("ready", function () {
console.log("Dash core started");

node.services.dashd.on("tx", function (txData) {
let tx = new dashcore.lib.Transaction(txData);
console.log(tx);
});
});
```

## Prerequisites

- Dash Core (dashd) (v0.13.0) with support for additional indexing *(see above)*
- Dash Core (dashd) (v0.13.0) with support for additional indexing _(see above)_
- Node.js v8+
- ZeroMQ *(libzmq3-dev for Ubuntu/Debian or zeromq on OSX)*
- ZeroMQ _(libzmq3-dev for Ubuntu/Debian or zeromq on OSX)_
- ~50GB of disk storage
- ~1GB of RAM

Expand Down Expand Up @@ -95,7 +95,6 @@ There are several add-on services available to extend the functionality of Bitco
- [Bus](docs/bus.md) - Overview of the event bus constructor
- [Release Process](docs/release.md) - Information about verifying a release and the release process.


## Setting up dev environment (with Insight)

Prerequisite : Having a dashd node already runing `dashd --daemon`.
Expand All @@ -105,13 +104,15 @@ Insight-api (optional) : `git clone https://github.com/dashevo/insight-api -b de
Insight-UI (optional) : `git clone https://github.com/dashevo/insight-ui -b develop`

Install them :

```
cd dashcore-node && npm install \
&& cd ../insight-ui && npm install \
&& cd ../insight-api && npm install && cd ..
```

Symbolic linking in parent folder :

```
npm link ../insight-api
npm link ../insight-ui
Expand Down
245 changes: 123 additions & 122 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
@@ -1,169 +1,170 @@
'use strict';
"use strict";

var benchmark = require('benchmark');
var dashdRPC = require('@dashevo/dashd-rpc');
var async = require('async');
var benchmark = require("benchmark");
var dashdRPC = require("@dashevo/dashd-rpc");
var async = require("async");
var maxTime = 20;

console.log('Dash Service native interface vs. Dash JSON RPC interface');
console.log('----------------------------------------------------------------------');
console.log("Dash Service native interface vs. Dash JSON RPC interface");
console.log("----------------------------------------------------------------------");

// To run the benchmarks a fully synced Dash Core directory is needed. The RPC comands
// can be modified to match the settings in dash.conf.

var fixtureData = {
blockHashes: [
'00000000fa7a4acea40e5d0591d64faf48fd862fa3561d111d967fc3a6a94177',
'000000000017e9e0afc4bc55339f60ffffb9cbe883f7348a9fbc198a486d5488',
'000000000019ddb889b534c5d85fca2c91a73feef6fd775cd228dea45353bae1',
'0000000000977ac3d9f5261efc88a3c2d25af92a91350750d00ad67744fa8d03'
"00000000fa7a4acea40e5d0591d64faf48fd862fa3561d111d967fc3a6a94177",
"000000000017e9e0afc4bc55339f60ffffb9cbe883f7348a9fbc198a486d5488",
"000000000019ddb889b534c5d85fca2c91a73feef6fd775cd228dea45353bae1",
"0000000000977ac3d9f5261efc88a3c2d25af92a91350750d00ad67744fa8d03",
],
txHashes: [
'5523b432c1bd6c101bee704ad6c560fd09aefc483f8a4998df6741feaa74e6eb',
'ff48393e7731507c789cfa9cbfae045b10e023ce34ace699a63cdad88c8b43f8',
'5d35c5eebf704877badd0a131b0a86588041997d40dbee8ccff21ca5b7e5e333',
'88842f2cf9d8659c3434f6bc0c515e22d87f33e864e504d2d7117163a572a3aa',
]
"5523b432c1bd6c101bee704ad6c560fd09aefc483f8a4998df6741feaa74e6eb",
"ff48393e7731507c789cfa9cbfae045b10e023ce34ace699a63cdad88c8b43f8",
"5d35c5eebf704877badd0a131b0a86588041997d40dbee8ccff21ca5b7e5e333",
"88842f2cf9d8659c3434f6bc0c515e22d87f33e864e504d2d7117163a572a3aa",
],
};

var dashd = require('../').services.Dash({
var dashd = require("../").services.Dash({
node: {
datadir: process.env.HOME + '/.dash',
datadir: process.env.HOME + "/.dash",
network: {
name: 'testnet'
}
}
name: "testnet",
},
},
});

dashd.on('error', function(err) {
dashd.on("error", function (err) {
console.error(err.message);
});

dashd.start(function(err) {
dashd.start(function (err) {
if (err) {
throw err;
}
console.log('Dash Core started');
console.log("Dash Core started");
});

dashd.on('ready', function() {

console.log('Dash Core ready');
dashd.on("ready", function () {
console.log("Dash Core ready");

var client = new dashdRPC({
host: 'localhost',
host: "localhost",
port: 18332,
user: 'dash',
pass: 'local321'
user: "dash",
pass: "local321",
});

async.series([
function(next) {

var c = 0;
var hashesLength = fixtureData.blockHashes.length;
var txLength = fixtureData.txHashes.length;
async.series(
[
function (next) {
var c = 0;
var hashesLength = fixtureData.blockHashes.length;
var txLength = fixtureData.txHashes.length;

function dashdGetBlockNative(deffered) {
if (c >= hashesLength) {
c = 0;
}
var hash = fixtureData.blockHashes[c];
dashd.getBlock(hash, function(err, block) {
if (err) {
throw err;
function dashdGetBlockNative(deffered) {
if (c >= hashesLength) {
c = 0;
}
deffered.resolve();
});
c++;
}

function dashdGetBlockJsonRpc(deffered) {
if (c >= hashesLength) {
c = 0;
var hash = fixtureData.blockHashes[c];
dashd.getBlock(hash, function (err, block) {
if (err) {
throw err;
}
deffered.resolve();
});
c++;
}
var hash = fixtureData.blockHashes[c];
client.getBlock(hash, false, function(err, block) {
if (err) {
throw err;
}
deffered.resolve();
});
c++;
}

function dashGetTransactionNative(deffered) {
if (c >= txLength) {
c = 0;
}
var hash = fixtureData.txHashes[c];
dashd.getTransaction(hash, true, function(err, tx) {
if (err) {
throw err;
function dashdGetBlockJsonRpc(deffered) {
if (c >= hashesLength) {
c = 0;
}
deffered.resolve();
});
c++;
}
var hash = fixtureData.blockHashes[c];
client.getBlock(hash, false, function (err, block) {
if (err) {
throw err;
}
deffered.resolve();
});
c++;
}

function dashGetTransactionJsonRpc(deffered) {
if (c >= txLength) {
c = 0;
function dashGetTransactionNative(deffered) {
if (c >= txLength) {
c = 0;
}
var hash = fixtureData.txHashes[c];
dashd.getTransaction(hash, true, function (err, tx) {
if (err) {
throw err;
}
deffered.resolve();
});
c++;
}
var hash = fixtureData.txHashes[c];
client.getRawTransaction(hash, function(err, tx) {
if (err) {
throw err;

function dashGetTransactionJsonRpc(deffered) {
if (c >= txLength) {
c = 0;
}
deffered.resolve();
});
c++;
}
var hash = fixtureData.txHashes[c];
client.getRawTransaction(hash, function (err, tx) {
if (err) {
throw err;
}
deffered.resolve();
});
c++;
}

var suite = new benchmark.Suite();
var suite = new benchmark.Suite();

suite.add('dashd getblock (native)', dashdGetBlockNative, {
defer: true,
maxTime: maxTime
});
suite.add("dashd getblock (native)", dashdGetBlockNative, {
defer: true,
maxTime: maxTime,
});

suite.add('dashd getblock (json rpc)', dashdGetBlockJsonRpc, {
defer: true,
maxTime: maxTime
});
suite.add("dashd getblock (json rpc)", dashdGetBlockJsonRpc, {
defer: true,
maxTime: maxTime,
});

suite.add('dashd gettransaction (native)', dashGetTransactionNative, {
defer: true,
maxTime: maxTime
});
suite.add("dashd gettransaction (native)", dashGetTransactionNative, {
defer: true,
maxTime: maxTime,
});

suite.add('dashd gettransaction (json rpc)', dashGetTransactionJsonRpc, {
defer: true,
maxTime: maxTime
});
suite.add("dashd gettransaction (json rpc)", dashGetTransactionJsonRpc, {
defer: true,
maxTime: maxTime,
});

suite
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
console.log('----------------------------------------------------------------------');
next();
})
.run();
}
], function(err) {
if (err) {
throw err;
}
console.log('Finished');
dashd.stop(function(err) {
suite
.on("cycle", function (event) {
console.log(String(event.target));
})
.on("complete", function () {
console.log("Fastest is " + this.filter("fastest").pluck("name"));
console.log("----------------------------------------------------------------------");
next();
})
.run();
},
],
function (err) {
if (err) {
console.error('Fail to stop services: ' + err);
process.exit(1);
throw err;
}
process.exit(0);
});
});
console.log("Finished");
dashd.stop(function (err) {
if (err) {
console.error("Fail to stop services: " + err);
process.exit(1);
}
process.exit(0);
});
}
);
});
9 changes: 4 additions & 5 deletions docs/bus.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Bus

The bus provides a way to subscribe to events from any of the services running. It's implemented abstract from transport specific implementation. The primary use of the bus in Bitcore Node is for subscribing to events via a web socket.

## Opening/Closing

```javascript

// a node is needed to be able to open a bus
var node = new Node(configuration);

Expand All @@ -18,13 +18,12 @@ bus.close();
## Subscribing/Unsubscribing

```javascript

// subscribe to all transaction events
bus.subscribe('bitcoind/rawtransaction');
bus.subscribe("bitcoind/rawtransaction");

// to subscribe to new block hashes
bus.subscribe('bitcoind/hashblock');
bus.subscribe("bitcoind/hashblock");

// unsubscribe
bus.unsubscribe('bitcoind/rawtransaction');
bus.unsubscribe("bitcoind/rawtransaction");
```
Loading

0 comments on commit 62c994d

Please sign in to comment.