comments. more style consistency.
This commit is contained in:
parent
5ece45091b
commit
1e802c152f
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* bcoin - javascript bitcoin library
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License).
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var bcoin = exports;
|
||||
var elliptic = require('elliptic');
|
||||
|
||||
|
||||
@ -1,7 +1,17 @@
|
||||
/**
|
||||
* block.js - block object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var bcoin = require('../bcoin');
|
||||
var utils = bcoin.utils;
|
||||
var constants = bcoin.protocol.constants;
|
||||
|
||||
/**
|
||||
* Block
|
||||
*/
|
||||
|
||||
function Block(data, subtype) {
|
||||
var self = this;
|
||||
|
||||
@ -264,4 +274,8 @@ Block.fromJSON = function fromJSON(json) {
|
||||
return block;
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = Block;
|
||||
|
||||
@ -1,6 +1,16 @@
|
||||
/**
|
||||
* bloom.js - bloom filter for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var bcoin = require('../bcoin');
|
||||
var utils = bcoin.utils;
|
||||
|
||||
/**
|
||||
* Bloom
|
||||
*/
|
||||
|
||||
function Bloom(size, n, tweak) {
|
||||
if (!(this instanceof Bloom))
|
||||
return new Bloom(size, n, tweak);
|
||||
@ -160,4 +170,8 @@ function hash(data, seed) {
|
||||
|
||||
Bloom.hash = hash;
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = Bloom;
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* chain.js - blockchain management for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var inherits = require('inherits');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
/**
|
||||
* hd.js - hierarchical determistic seeds and keys (BIP32, BIP39)
|
||||
* hd.js - hd seeds and keys (BIP32, BIP39) for bcoin.
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
* https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
|
||||
* https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
|
||||
*/
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* peer.js - peer object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var inherits = require('inherits');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
@ -12,6 +18,10 @@ try {
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Peer
|
||||
*/
|
||||
|
||||
function Peer(pool, createSocket, options) {
|
||||
var self = this;
|
||||
|
||||
@ -533,4 +543,8 @@ Peer.prototype.loadBlocks = function loadBlocks(hashes, stop) {
|
||||
this._write(this.framer.getBlocks(hashes, stop));
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = Peer;
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* pool.js - peer management for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var async = require('async');
|
||||
var inherits = require('inherits');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
@ -7,6 +13,10 @@ var utils = bcoin.utils;
|
||||
var assert = utils.assert;
|
||||
var network = bcoin.protocol.network;
|
||||
|
||||
/**
|
||||
* Pool
|
||||
*/
|
||||
|
||||
function Pool(options) {
|
||||
var self = this;
|
||||
|
||||
@ -1095,4 +1105,8 @@ LoadRequest.prototype.addCallback = function addCallback(cb) {
|
||||
this.cbs.push(cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = Pool;
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* constants.js - bitcoin constants for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var bcoin = require('../../bcoin');
|
||||
var utils = bcoin.utils;
|
||||
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* framer.js - packet framer for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var bcoin = require('../../bcoin');
|
||||
var network = require('./network');
|
||||
var constants = require('./constants');
|
||||
@ -8,6 +14,10 @@ var version = require('../../../package.json').version;
|
||||
var writeU32 = utils.writeU32;
|
||||
var writeAscii = utils.writeAscii;
|
||||
|
||||
/**
|
||||
* Framer
|
||||
*/
|
||||
|
||||
function Framer(options) {
|
||||
if (!(this instanceof Framer))
|
||||
return new Framer(options);
|
||||
@ -115,26 +125,31 @@ Framer.prototype.verack = function verack() {
|
||||
function varint(arr, value, off) {
|
||||
if (!off)
|
||||
off = 0;
|
||||
|
||||
if (value < 0xfd) {
|
||||
arr[off] = value;
|
||||
return 1;
|
||||
} else if (value <= 0xffff) {
|
||||
}
|
||||
|
||||
if (value <= 0xffff) {
|
||||
arr[off] = 0xfd;
|
||||
arr[off + 1] = value & 0xff;
|
||||
arr[off + 2] = value >>> 8;
|
||||
return 3;
|
||||
} else if (value <= 0xffffffff) {
|
||||
}
|
||||
|
||||
if (value <= 0xffffffff) {
|
||||
arr[off] = 0xfe;
|
||||
arr[off + 1] = value & 0xff;
|
||||
arr[off + 2] = (value >>> 8) & 0xff;
|
||||
arr[off + 3] = (value >>> 16) & 0xff;
|
||||
arr[off + 4] = value >>> 24;
|
||||
return 5;
|
||||
} else {
|
||||
arr[off] = 0xff;
|
||||
utils.writeU64(arr, value, off + 1);
|
||||
return 9;
|
||||
}
|
||||
|
||||
arr[off] = 0xff;
|
||||
utils.writeU64(arr, value, off + 1);
|
||||
return 9;
|
||||
}
|
||||
|
||||
Framer.prototype._inv = function _inv(command, items) {
|
||||
@ -402,4 +417,8 @@ Framer.prototype.addr = function addr(peers) {
|
||||
return this.packet('addr', p);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = Framer;
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* protocol/index.js - bitcoin protocol for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var protocol = exports;
|
||||
|
||||
protocol.constants = require('./constants');
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* network.js - bitcoin networks for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var bcoin = require('../../bcoin');
|
||||
var utils = bcoin.utils;
|
||||
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* parser.js - packet parser for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var inherits = require('inherits');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var bn = require('bn.js');
|
||||
@ -11,6 +17,10 @@ var network = require('./network');
|
||||
var readU32 = utils.readU32;
|
||||
var readU64 = utils.readU64;
|
||||
|
||||
/**
|
||||
* Parser
|
||||
*/
|
||||
|
||||
function Parser() {
|
||||
if (!(this instanceof Parser))
|
||||
return new Parser();
|
||||
@ -110,22 +120,29 @@ Parser.prototype.parseHeader = function parseHeader(h) {
|
||||
Parser.prototype.parsePayload = function parsePayload(cmd, p) {
|
||||
if (cmd === 'version')
|
||||
return this.parseVersion(p);
|
||||
else if (cmd === 'getdata' || cmd === 'inv' || cmd === 'notfound')
|
||||
|
||||
if (cmd === 'getdata' || cmd === 'inv' || cmd === 'notfound')
|
||||
return this.parseInvList(p);
|
||||
else if (cmd === 'merkleblock')
|
||||
|
||||
if (cmd === 'merkleblock')
|
||||
return this.parseMerkleBlock(p);
|
||||
else if (cmd === 'headers')
|
||||
|
||||
if (cmd === 'headers')
|
||||
return this.parseHeaders(p);
|
||||
else if (cmd === 'block')
|
||||
|
||||
if (cmd === 'block')
|
||||
return this.parseBlock(p);
|
||||
else if (cmd === 'tx')
|
||||
|
||||
if (cmd === 'tx')
|
||||
return this.parseTX(p);
|
||||
else if (cmd === 'reject')
|
||||
|
||||
if (cmd === 'reject')
|
||||
return this.parseReject(p);
|
||||
else if (cmd === 'addr')
|
||||
|
||||
if (cmd === 'addr')
|
||||
return this.parseAddr(p);
|
||||
else
|
||||
return p;
|
||||
|
||||
return p;
|
||||
};
|
||||
|
||||
Parser.prototype.parseVersion = function parseVersion(p) {
|
||||
@ -524,4 +541,8 @@ Parser.prototype.parseAddr = function parseAddr(p) {
|
||||
return addrs;
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = Parser;
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* script.js - script interpreter for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var bcoin = require('../bcoin');
|
||||
var bn = require('bn.js');
|
||||
var constants = bcoin.protocol.constants;
|
||||
@ -5,6 +11,10 @@ var utils = bcoin.utils;
|
||||
var assert = bcoin.utils.assert;
|
||||
var script = exports;
|
||||
|
||||
/**
|
||||
* Script
|
||||
*/
|
||||
|
||||
script.decode = function decode(s) {
|
||||
if (!s)
|
||||
return [];
|
||||
@ -149,14 +159,14 @@ script.subscript = function subscript(s, lastSep) {
|
||||
if (lastSep == null) {
|
||||
lastSep = -1;
|
||||
for (i = 0; i < s.length; i++) {
|
||||
if (s[i] === 'codesep')
|
||||
lastSep = i;
|
||||
else if (s[i] === 'checksig'
|
||||
if (s[i] === 'checksig'
|
||||
|| s[i] === 'checksigverify'
|
||||
|| s[i] === 'checkmultisig'
|
||||
|| s[i] === 'checkmultisigverify') {
|
||||
break;
|
||||
}
|
||||
if (s[i] === 'codesep')
|
||||
lastSep = i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,18 +203,23 @@ script._next = function(to, s, pc) {
|
||||
|
||||
while (s[pc]) {
|
||||
o = s[pc];
|
||||
|
||||
if (o === 'if_' || o === 'notif')
|
||||
depth++;
|
||||
else if (o === 'else_')
|
||||
depth--;
|
||||
else if (o === 'endif')
|
||||
depth--;
|
||||
|
||||
if (depth < 0)
|
||||
break;
|
||||
|
||||
if (depth === 0 && o === to)
|
||||
return pc;
|
||||
|
||||
if (o === 'else_')
|
||||
depth++;
|
||||
|
||||
pc++;
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,19 @@
|
||||
/**
|
||||
* tx-pool.js - transaction pool for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var bn = require('bn.js');
|
||||
var inherits = require('inherits');
|
||||
var bcoin = require('../bcoin');
|
||||
var assert = bcoin.utils.assert;
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
/**
|
||||
* TXPool
|
||||
*/
|
||||
|
||||
function TXPool(wallet) {
|
||||
if (!(this instanceof TXPool))
|
||||
return new TXPool(wallet);
|
||||
@ -291,4 +301,8 @@ TXPool.prototype.fromJSON = function fromJSON(json) {
|
||||
}, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = TXPool;
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* tx.js - transaction object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var bn = require('bn.js');
|
||||
|
||||
var bcoin = require('../bcoin');
|
||||
@ -5,6 +11,10 @@ var utils = bcoin.utils;
|
||||
var assert = utils.assert;
|
||||
var constants = bcoin.protocol.constants;
|
||||
|
||||
/**
|
||||
* TX
|
||||
*/
|
||||
|
||||
function TX(data, block) {
|
||||
if (!(this instanceof TX))
|
||||
return new TX(data, block);
|
||||
@ -1069,4 +1079,8 @@ TX.fromJSON = function fromJSON(json) {
|
||||
return tx;
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = TX;
|
||||
|
||||
@ -1,9 +1,19 @@
|
||||
/**
|
||||
* utils.js - utils for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var utils = exports;
|
||||
|
||||
var bn = require('bn.js');
|
||||
var hash = require('hash.js');
|
||||
var util = require('util');
|
||||
|
||||
/**
|
||||
* Utils
|
||||
*/
|
||||
|
||||
function toArray(msg, enc) {
|
||||
if (Array.isArray(msg))
|
||||
return msg.slice();
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* wallet.js - wallet object for bcoin
|
||||
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
|
||||
* https://github.com/indutny/bcoin
|
||||
*/
|
||||
|
||||
var bcoin = require('../bcoin');
|
||||
var hash = require('hash.js');
|
||||
var bn = require('bn.js');
|
||||
@ -8,6 +14,10 @@ var assert = utils.assert;
|
||||
var constants = bcoin.protocol.constants;
|
||||
var network = bcoin.protocol.network;
|
||||
|
||||
/**
|
||||
* Wallet
|
||||
*/
|
||||
|
||||
function Wallet(options, passphrase) {
|
||||
if (!(this instanceof Wallet))
|
||||
return new Wallet(options, passphrase);
|
||||
@ -653,4 +663,8 @@ Wallet.fromJSON = function fromJSON(json, decrypt) {
|
||||
return w;
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
module.exports = Wallet;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user