use latest bitcore
This commit is contained in:
parent
78bc054bfa
commit
bf4cec6bf5
@ -5,7 +5,6 @@ var chainlib = require('chainlib');
|
||||
var socketio = require('socket.io');
|
||||
var log = chainlib.log;
|
||||
log.debug = function() {};
|
||||
var utils = require('../lib/utils');
|
||||
|
||||
var configuration = {
|
||||
datadir: process.env.BITCORENODE_DIR || '~/.bitcoin',
|
||||
@ -78,7 +77,7 @@ node.on('ready', function() {
|
||||
}
|
||||
|
||||
if(result) {
|
||||
response.result = utils.expandObject(result);
|
||||
response.result = result;
|
||||
}
|
||||
|
||||
socketCallback(response);
|
||||
@ -111,7 +110,7 @@ node.on('ready', function() {
|
||||
var results = [];
|
||||
|
||||
for(var i = 0; i < arguments.length; i++) {
|
||||
results.push(utils.expandObject(arguments[i]));
|
||||
results.push(arguments[i]);
|
||||
}
|
||||
|
||||
var params = [event.name].concat(results);
|
||||
|
||||
@ -48,7 +48,7 @@ Block.fromBufferReader = function(br) {
|
||||
return new Block(obj);
|
||||
};
|
||||
|
||||
Block.prototype.toObject = function() {
|
||||
Block.prototype.toObject = Block.prototype.toJSON = function() {
|
||||
return {
|
||||
version: this.version,
|
||||
prevHash: this.prevHash,
|
||||
|
||||
@ -65,39 +65,4 @@ Transaction.manyToBuffer = function(transactions) {
|
||||
return BaseTransaction.manyToBuffer(transactions);
|
||||
};
|
||||
|
||||
/**
|
||||
* Override Bitcore's toObject() to include populated inputs and txid
|
||||
*/
|
||||
Transaction.prototype.toObject = function toObject() {
|
||||
var inputs = [];
|
||||
this.inputs.forEach(function(input) {
|
||||
var inputObj = input.toObject();
|
||||
if(input.output) {
|
||||
inputObj.output = input.output.toObject();
|
||||
}
|
||||
inputs.push(inputObj);
|
||||
});
|
||||
var outputs = [];
|
||||
this.outputs.forEach(function(output) {
|
||||
outputs.push(output.toObject());
|
||||
});
|
||||
var obj = {
|
||||
txid: this.id,
|
||||
version: this.version,
|
||||
inputs: inputs,
|
||||
outputs: outputs,
|
||||
nLockTime: this.nLockTime
|
||||
};
|
||||
if (this._changeScript) {
|
||||
obj.changeScript = this._changeScript.toString();
|
||||
}
|
||||
if (!_.isUndefined(this._changeIndex)) {
|
||||
obj.changeIndex = this._changeIndex;
|
||||
}
|
||||
if (!_.isUndefined(this._fee)) {
|
||||
obj.fee = this._fee;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
module.exports = Transaction;
|
||||
|
||||
45
lib/utils.js
45
lib/utils.js
@ -1,45 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var chainlib = require('chainlib');
|
||||
var utils = chainlib.utils;
|
||||
|
||||
/**
|
||||
* Bitcore's API does not implement toJSON in the standard way.
|
||||
* This causes issues when doing a JSON.stringify on an object
|
||||
* which contains Bitcore objects. This custom implmentation
|
||||
* of stringify accounts for Bitcore objects.
|
||||
* @param {Object} obj
|
||||
* @return {String} json
|
||||
*/
|
||||
utils.stringify = function(obj) {
|
||||
return JSON.stringify(utils.expandObject(obj));
|
||||
}
|
||||
|
||||
utils.expandObject = function(obj) {
|
||||
if(Array.isArray(obj)) {
|
||||
var expandedArray = [];
|
||||
for(var i = 0; i < obj.length; i++) {
|
||||
expandedArray.push(utils.expandObject(obj[i]));
|
||||
}
|
||||
|
||||
return expandedArray;
|
||||
} else if(typeof obj === 'function' || typeof obj === 'object') {
|
||||
if(obj.toObject) {
|
||||
return obj.toObject();
|
||||
} else if(obj.toJSON) {
|
||||
return obj.toJSON();
|
||||
} else {
|
||||
var expandedObj = {};
|
||||
|
||||
for(var key in obj) {
|
||||
expandedObj[key] = utils.expandObject(obj[key]);
|
||||
}
|
||||
|
||||
return expandedObj;
|
||||
}
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = utils;
|
||||
@ -44,7 +44,7 @@
|
||||
"dependencies": {
|
||||
"async": "1.3.0",
|
||||
"bindings": "^1.2.1",
|
||||
"bitcore": "^0.12.15",
|
||||
"bitcore": "git+http://github.com/bitpay/bitcore.git#master",
|
||||
"chainlib": "^0.1.1",
|
||||
"errno": "^0.1.2",
|
||||
"memdown": "^1.0.0",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user