Skip to content

Instantly share code, notes, and snippets.

View braydonf's full-sized avatar

Braydon Fuller braydonf

View GitHub Profile
@braydonf
braydonf / builderrors.js
Last active August 29, 2015 14:10
BuildErrors
var inherits = require('inherits');
var Point = function(){};
Point.Errors = {};
var defineErrors = function(base, specs){
specs.forEach(function(spec){
var e = function(message){
this.message = message || spec.message;
};
@braydonf
braydonf / test-types
Created December 8, 2014 17:39
performance test
'use strict';
var interations = 10000000;
console.log('\n\n','Running ', interations, ' interations for each:');
console.log(' ===================================================', '\n');
var throwAnError = function(){
throw new Error('Ooops...');
};
@braydonf
braydonf / test-types
Last active August 29, 2015 14:11
test types
Running 10000000 interations for each:
===================================================
Try/Catch Error: 34.292 seconds
Return Error: 32.326 seconds
Return a String: 0.075 seconds
Return a Number: 0.056 seconds
Return an Object: 0.076 seconds
Return a new Object: 0.263 seconds
Try/Catch a new Object: 0.274 seconds
AssertionError: expected [Function] to throw error including 'Address must be an instance of PublicKey.' but got 'Object doesn\'t support property or method \'toBuffer\''
at Assertion.prototype.assert (http://braydon.bp/bitcore/browser/tests.js:32764:7)
at assertThrows (http://braydon.bp/bitcore/browser/tests.js:33988:9)
at ctx[name] (http://braydon.bp/bitcore/browser/tests.js:35508:5)
at Anonymous function (http://braydon.bp/bitcore/browser/tests.js:61073:8)
at callFn (http://braydon.bp/bitcore/node_modules/mocha/mocha.js:4428:5)
at Runnable.prototype.run (http://braydon.bp/bitcore/node_modules/mocha/mocha.js:4421:7)
at Runner.prototype.runTest (http://braydon.bp/bitcore/node_modules/mocha/mocha.js:4823:5)
at Anonymous function (http://braydon.bp/bitcore/node_modules/mocha/mocha.js:4901:7)
at next (http://braydon.bp/bitcore/node_modules/mocha/mocha.js:4748:7)
@braydonf
braydonf / elliptic.js
Last active August 29, 2015 14:12
elliptic.js
// elliptic.js
var EC = require('elliptic').ec
var ec = new EC('secp256k1')
var point = ec.g.mul('f2cc9d2b008927db94b89e04e2f6e70c180e547b3e5e564b06b8215d1c264b53')
// <EC Point x: 495f99aa21d7e60ff3f065f2a14e67612b29b1cb5af7b7fc4738cede6f2d9eba y: 41a2d4539b40a914e755a3a24367ce731195c354480dad4f2ce9e9c8f8003bce>
var point1 = e.curve.pointFromX(true, '495f99aa21d7e60ff3f065f2a14e67612b29b1cb5af7b7fc4738cede6f2d9eba')
// <EC Point x: 495f99aa21d7e60ff3f065f2a14e67612b29b1cb5af7b7fc4738cede6f2d9eba y: 3dc9318f0a7ae59bafbccef98692931dc6a8c28208333e88de5c031766f70777>
@braydonf
braydonf / bitcoredocs.md
Last active August 29, 2015 14:13
Bitcore Documentation Organization

Docs /docs

  • Bitcore
    • Get Started ( /docs/index.html )
    • Address ( /docs/address.html )
    • Block ( /docs/block.html )
    • HD Keys ( /docs/hierarchical.html )
    • Private Key ( /docs/privatekey.html )
    • Public Key ( /docs/publickey.html )
  • Script ( /docs/script.html )
@braydonf
braydonf / reading-blocks.js
Last active February 6, 2019 00:49
Read bitcoin blocks from disk with bitcore
// updated version with bcoin at https://gist.github.com/braydonf/528a51785f0f5641464d172696cd2112
var bitcore = require('bitcore');
var fs = require('fs');
var glob = require('glob');
var async = require('async');
var Block = bitcore.Block;
glob('./blk*.dat', null, function(err, files) {
@braydonf
braydonf / lbbv.js
Created June 25, 2015 23:14
Latest Bitcoin Block Versions
var RpcClient = require('bitcoind-rpc');
var async = require('async');
var config = {
protocol: 'http',
user: 'bitcoin',
pass: 'local321',
host: '127.0.0.1',
port: '8332'
};
@braydonf
braydonf / run-a-fullnode.md
Last active May 12, 2019 06:10
Run A Full Node

Running a Full Node

Before you begin you'll need to have about 100GB of disk space available to store the Bitcoin blockchain plus additional database information. Both 64bit Mac OS X and GNU/Linux are currently supported. The process of downloading the blocks and indexing can take upwards of 4 hours, depending on Internet connection and other factors. So it's suggested to plan accordingly and let the node syncronize while you're away. It's also possible to use an existing Bitcoin data directory, which will speed up the process.

Step 1: Install Node.js v0.12

It's recommended to install the Node Version Manager, as this makes it simple to switch between different Node.js versions. We will specifically need to install and run v0.12. Please follow the directions at https://github.com/creationix/nvm#install-script and then run:

nvm install v0.12.7
@braydonf
braydonf / levelup-stream-memory-test.js
Created December 29, 2015 18:15
LevelUP Read Stream Transform Memory Stress Test
'use strict';
var Transform = require('stream').Transform;
var inherits = require('util').inherits;
var crypto = require('crypto');
var levelup = require('levelup');
var async = require('async');
var maxNumber = 1500000;