2013-02-17 06:39:15 +01:00
|
|
|
var BigInteger = require('./jsbn/jsbn');
|
|
|
|
var Script = require('./script');
|
|
|
|
var util = require('./util');
|
2014-03-11 02:52:48 +01:00
|
|
|
var convert = require('./convert');
|
2014-01-04 19:26:03 +01:00
|
|
|
var ECKey = require('./eckey').ECKey;
|
2013-10-08 12:45:13 +02:00
|
|
|
var ECDSA = require('./ecdsa');
|
|
|
|
var Address = require('./address');
|
2014-03-08 06:02:40 +01:00
|
|
|
var Message = require('./message');
|
2014-03-16 03:02:04 +01:00
|
|
|
var SHA256 = require('crypto-js/sha256');
|
2013-02-17 06:39:15 +01:00
|
|
|
|
|
|
|
var Transaction = function (doc) {
|
2014-01-10 21:17:53 +01:00
|
|
|
if (!(this instanceof Transaction)) { return new Transaction(doc); }
|
2013-11-02 11:20:09 +01:00
|
|
|
this.version = 1;
|
2014-03-17 09:31:35 +01:00
|
|
|
this.locktime = 0;
|
2013-11-02 11:20:09 +01:00
|
|
|
this.ins = [];
|
|
|
|
this.outs = [];
|
2014-03-20 23:40:07 +01:00
|
|
|
this.defaultSequence = [255, 255, 255, 255] // 0xFFFFFFFF
|
2014-03-09 06:46:20 +01:00
|
|
|
|
2013-11-02 11:20:09 +01:00
|
|
|
if (doc) {
|
2014-03-03 04:27:19 +01:00
|
|
|
if (typeof doc == "string" || Array.isArray(doc)) {
|
2013-11-02 11:20:09 +01:00
|
|
|
doc = Transaction.deserialize(doc)
|
|
|
|
}
|
|
|
|
if (doc.hash) this.hash = doc.hash;
|
|
|
|
if (doc.version) this.version = doc.version;
|
2014-03-17 09:31:35 +01:00
|
|
|
if (doc.locktime) this.locktime = doc.locktime;
|
2013-11-02 11:20:09 +01:00
|
|
|
if (doc.ins && doc.ins.length) {
|
|
|
|
for (var i = 0; i < doc.ins.length; i++) {
|
|
|
|
this.addInput(new TransactionIn(doc.ins[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (doc.outs && doc.outs.length) {
|
|
|
|
for (var i = 0; i < doc.outs.length; i++) {
|
|
|
|
this.addOutput(new TransactionOut(doc.outs[i]));
|
|
|
|
}
|
|
|
|
}
|
2014-03-17 09:31:35 +01:00
|
|
|
|
|
|
|
this.hash = this.hash || this.getHash()
|
2012-01-11 02:40:45 +01:00
|
|
|
}
|
2013-02-17 06:39:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new txin.
|
|
|
|
*
|
2013-10-21 20:07:38 +02:00
|
|
|
* Can be called with any of:
|
|
|
|
*
|
2014-03-17 10:49:37 +01:00
|
|
|
* - An existing TransactionIn object
|
2013-10-21 20:07:38 +02:00
|
|
|
* - A transaction and an index
|
|
|
|
* - A transaction hash and an index
|
|
|
|
* - A single string argument of the form txhash:index
|
2013-02-17 06:39:15 +01:00
|
|
|
*
|
|
|
|
* Note that this method does not sign the created input.
|
|
|
|
*/
|
|
|
|
Transaction.prototype.addInput = function (tx, outIndex) {
|
2013-10-21 20:07:38 +02:00
|
|
|
if (arguments[0] instanceof TransactionIn) {
|
|
|
|
this.ins.push(arguments[0]);
|
2014-03-09 06:46:20 +01:00
|
|
|
}
|
2013-10-21 20:07:38 +02:00
|
|
|
else if (arguments[0].length > 65) {
|
|
|
|
var args = arguments[0].split(':');
|
|
|
|
return this.addInput(args[0], args[1]);
|
2014-03-09 06:46:20 +01:00
|
|
|
}
|
2013-10-21 20:07:38 +02:00
|
|
|
else {
|
2014-03-17 10:49:37 +01:00
|
|
|
var hash = typeof tx === "string" ? tx : tx.hash
|
|
|
|
var hash = Array.isArray(hash) ? convert.bytesToHex(hash) : hash
|
2013-10-21 20:07:38 +02:00
|
|
|
this.ins.push(new TransactionIn({
|
|
|
|
outpoint: {
|
2014-03-17 10:49:37 +01:00
|
|
|
hash: hash,
|
2013-10-21 20:07:38 +02:00
|
|
|
index: outIndex
|
|
|
|
},
|
|
|
|
script: new Script(),
|
2014-03-20 23:40:07 +01:00
|
|
|
sequence: this.defaultSequence
|
2013-10-21 20:07:38 +02:00
|
|
|
}));
|
|
|
|
}
|
2013-02-17 06:39:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new txout.
|
|
|
|
*
|
2013-11-02 11:51:27 +01:00
|
|
|
* Can be called with:
|
|
|
|
*
|
|
|
|
* i) An existing TransactionOut object
|
|
|
|
* ii) An address object or an address and a value
|
|
|
|
* iii) An address:value string
|
|
|
|
*
|
2013-02-17 06:39:15 +01:00
|
|
|
*/
|
|
|
|
Transaction.prototype.addOutput = function (address, value) {
|
2013-10-14 13:41:21 +02:00
|
|
|
if (arguments[0] instanceof TransactionOut) {
|
|
|
|
this.outs.push(arguments[0]);
|
2013-11-02 11:51:27 +01:00
|
|
|
return;
|
2012-01-11 02:40:45 +01:00
|
|
|
}
|
2013-11-02 11:51:27 +01:00
|
|
|
if (arguments[0].indexOf(':') >= 0) {
|
|
|
|
var args = arguments[0].split(':');
|
|
|
|
address = args[0];
|
|
|
|
value = parseInt(args[1]);
|
2014-03-09 06:46:20 +01:00
|
|
|
}
|
2013-11-02 11:51:27 +01:00
|
|
|
this.outs.push(new TransactionOut({
|
|
|
|
value: value,
|
|
|
|
script: Script.createOutputScript(address)
|
|
|
|
}));
|
2013-02-17 06:39:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Serialize this transaction.
|
|
|
|
*
|
|
|
|
* Returns the transaction as a byte array in the standard Bitcoin binary
|
|
|
|
* format. This method is byte-perfect, i.e. the resulting byte array can
|
|
|
|
* be hashed to get the transaction's standard Bitcoin hash.
|
|
|
|
*/
|
2013-12-02 03:52:07 +01:00
|
|
|
Transaction.prototype.serialize = function () {
|
|
|
|
var buffer = [];
|
2014-03-11 02:52:48 +01:00
|
|
|
buffer = buffer.concat(convert.numToBytes(parseInt(this.version),4));
|
|
|
|
buffer = buffer.concat(convert.numToVarInt(this.ins.length));
|
2013-12-02 03:52:07 +01:00
|
|
|
for (var i = 0; i < this.ins.length; i++) {
|
|
|
|
var txin = this.ins[i];
|
2013-03-02 18:00:14 +01:00
|
|
|
|
2013-12-02 03:52:07 +01:00
|
|
|
// Why do blockchain.info, blockexplorer.com, sx and just about everybody
|
|
|
|
// else use little-endian hashes? No idea...
|
2014-03-11 02:52:48 +01:00
|
|
|
buffer = buffer.concat(convert.hexToBytes(txin.outpoint.hash).reverse());
|
2013-03-02 18:00:14 +01:00
|
|
|
|
2014-03-11 02:52:48 +01:00
|
|
|
buffer = buffer.concat(convert.numToBytes(parseInt(txin.outpoint.index),4));
|
2013-12-02 03:52:07 +01:00
|
|
|
var scriptBytes = txin.script.buffer;
|
2014-03-11 02:52:48 +01:00
|
|
|
buffer = buffer.concat(convert.numToVarInt(scriptBytes.length));
|
2013-12-02 03:52:07 +01:00
|
|
|
buffer = buffer.concat(scriptBytes);
|
2014-03-20 23:40:07 +01:00
|
|
|
buffer = buffer.concat(txin.sequence);
|
2013-12-02 03:52:07 +01:00
|
|
|
}
|
2014-03-11 02:52:48 +01:00
|
|
|
buffer = buffer.concat(convert.numToVarInt(this.outs.length));
|
2013-12-02 03:52:07 +01:00
|
|
|
for (var i = 0; i < this.outs.length; i++) {
|
|
|
|
var txout = this.outs[i];
|
2014-03-11 02:52:48 +01:00
|
|
|
buffer = buffer.concat(convert.numToBytes(txout.value,8));
|
2013-12-02 03:52:07 +01:00
|
|
|
var scriptBytes = txout.script.buffer;
|
2014-03-11 02:52:48 +01:00
|
|
|
buffer = buffer.concat(convert.numToVarInt(scriptBytes.length));
|
2013-12-02 03:52:07 +01:00
|
|
|
buffer = buffer.concat(scriptBytes);
|
|
|
|
}
|
2014-03-17 09:31:35 +01:00
|
|
|
buffer = buffer.concat(convert.numToBytes(parseInt(this.locktime),4));
|
2013-02-17 06:39:15 +01:00
|
|
|
|
2013-12-02 03:52:07 +01:00
|
|
|
return buffer;
|
2013-02-17 06:39:15 +01:00
|
|
|
};
|
|
|
|
|
2013-11-20 19:00:49 +01:00
|
|
|
Transaction.prototype.serializeHex = function() {
|
2014-03-11 02:52:48 +01:00
|
|
|
return convert.bytesToHex(this.serialize());
|
2013-11-20 19:00:49 +01:00
|
|
|
}
|
|
|
|
|
2013-02-17 06:39:15 +01:00
|
|
|
var OP_CODESEPARATOR = 171;
|
|
|
|
|
|
|
|
var SIGHASH_ALL = 1;
|
|
|
|
var SIGHASH_NONE = 2;
|
|
|
|
var SIGHASH_SINGLE = 3;
|
|
|
|
var SIGHASH_ANYONECANPAY = 80;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hash transaction for signing a specific input.
|
|
|
|
*
|
|
|
|
* Bitcoin uses a different hash for each signed transaction input. This
|
|
|
|
* method copies the transaction, makes the necessary changes based on the
|
|
|
|
* hashType, serializes and finally hashes the result. This hash can then be
|
|
|
|
* used to sign the transaction input in question.
|
|
|
|
*/
|
|
|
|
Transaction.prototype.hashTransactionForSignature =
|
|
|
|
function (connectedScript, inIndex, hashType)
|
|
|
|
{
|
|
|
|
var txTmp = this.clone();
|
|
|
|
|
|
|
|
// In case concatenating two scripts ends up with two codeseparators,
|
|
|
|
// or an extra one at the end, this prevents all those possible
|
|
|
|
// incompatibilities.
|
|
|
|
/*scriptCode = scriptCode.filter(function (val) {
|
|
|
|
return val !== OP_CODESEPARATOR;
|
|
|
|
});*/
|
|
|
|
|
|
|
|
// Blank out other inputs' signatures
|
|
|
|
for (var i = 0; i < txTmp.ins.length; i++) {
|
|
|
|
txTmp.ins[i].script = new Script();
|
|
|
|
}
|
|
|
|
|
|
|
|
txTmp.ins[inIndex].script = connectedScript;
|
|
|
|
|
2014-03-21 03:15:15 +01:00
|
|
|
// Blank out some of the outputs
|
|
|
|
if ((hashType & 0x1f) == SIGHASH_NONE) {
|
|
|
|
txTmp.outs = [];
|
|
|
|
|
|
|
|
// Let the others update at will
|
|
|
|
for (var i = 0; i < txTmp.ins.length; i++)
|
|
|
|
if (i != inIndex)
|
|
|
|
txTmp.ins[i].sequence = 0;
|
|
|
|
} else if ((hashType & 0x1f) == SIGHASH_SINGLE) {
|
|
|
|
// TODO: Implement
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blank out other inputs completely, not recommended for open transactions
|
|
|
|
if (hashType & SIGHASH_ANYONECANPAY) {
|
|
|
|
txTmp.ins = [txTmp.ins[inIndex]];
|
|
|
|
}
|
|
|
|
|
2013-02-17 06:39:15 +01:00
|
|
|
var buffer = txTmp.serialize();
|
|
|
|
|
2014-03-11 02:52:48 +01:00
|
|
|
buffer = buffer.concat(convert.numToBytes(parseInt(hashType),4));
|
2013-02-17 06:39:15 +01:00
|
|
|
|
2014-03-16 02:42:49 +01:00
|
|
|
buffer = convert.bytesToWordArray(buffer);
|
|
|
|
return convert.wordArrayToBytes(SHA256(SHA256(buffer)));
|
2013-02-17 06:39:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate and return the transaction's hash.
|
2013-10-08 19:41:20 +02:00
|
|
|
* Reverses hash since blockchain.info, blockexplorer.com and others
|
|
|
|
* use little-endian hashes for some stupid reason
|
2013-02-17 06:39:15 +01:00
|
|
|
*/
|
|
|
|
Transaction.prototype.getHash = function ()
|
|
|
|
{
|
2014-03-16 02:42:49 +01:00
|
|
|
var buffer = convert.bytesToWordArray(this.serialize());
|
|
|
|
return convert.wordArrayToBytes(SHA256(SHA256(buffer))).reverse();
|
2013-02-17 06:39:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a copy of this transaction object.
|
|
|
|
*/
|
|
|
|
Transaction.prototype.clone = function ()
|
|
|
|
{
|
|
|
|
var newTx = new Transaction();
|
|
|
|
newTx.version = this.version;
|
2014-03-17 09:31:35 +01:00
|
|
|
newTx.locktime = this.locktime;
|
2013-02-17 06:39:15 +01:00
|
|
|
for (var i = 0; i < this.ins.length; i++) {
|
|
|
|
var txin = this.ins[i].clone();
|
|
|
|
newTx.addInput(txin);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.outs.length; i++) {
|
|
|
|
var txout = this.outs[i].clone();
|
|
|
|
newTx.addOutput(txout);
|
|
|
|
}
|
|
|
|
return newTx;
|
|
|
|
};
|
|
|
|
|
2013-10-07 21:27:19 +02:00
|
|
|
/**
|
|
|
|
* Converts a serialized transaction into a transaction object
|
|
|
|
*/
|
|
|
|
|
2013-10-07 14:21:00 +02:00
|
|
|
Transaction.deserialize = function(buffer) {
|
2013-11-02 11:20:09 +01:00
|
|
|
if (typeof buffer == "string") {
|
2014-03-11 02:52:48 +01:00
|
|
|
buffer = convert.hexToBytes(buffer)
|
2013-11-02 11:20:09 +01:00
|
|
|
}
|
2013-10-07 14:21:00 +02:00
|
|
|
var pos = 0;
|
|
|
|
var readAsInt = function(bytes) {
|
|
|
|
if (bytes == 0) return 0;
|
|
|
|
pos++;
|
|
|
|
return buffer[pos-1] + readAsInt(bytes-1) * 256;
|
|
|
|
}
|
|
|
|
var readVarInt = function() {
|
|
|
|
pos++;
|
|
|
|
if (buffer[pos-1] < 253) {
|
|
|
|
return buffer[pos-1];
|
|
|
|
}
|
|
|
|
return readAsInt(buffer[pos-1] - 251);
|
|
|
|
}
|
|
|
|
var readBytes = function(bytes) {
|
|
|
|
pos += bytes;
|
|
|
|
return buffer.slice(pos - bytes, pos);
|
|
|
|
}
|
|
|
|
var readVarString = function() {
|
|
|
|
var size = readVarInt();
|
|
|
|
return readBytes(size);
|
|
|
|
}
|
|
|
|
var obj = {
|
|
|
|
ins: [],
|
|
|
|
outs: []
|
|
|
|
}
|
|
|
|
obj.version = readAsInt(4);
|
|
|
|
var ins = readVarInt();
|
|
|
|
for (var i = 0; i < ins; i++) {
|
|
|
|
obj.ins.push({
|
|
|
|
outpoint: {
|
2014-03-11 02:52:48 +01:00
|
|
|
hash: convert.bytesToHex(readBytes(32).reverse()),
|
2013-10-07 14:21:00 +02:00
|
|
|
index: readAsInt(4)
|
|
|
|
},
|
|
|
|
script: new Script(readVarString()),
|
2014-03-20 23:40:07 +01:00
|
|
|
sequence: readBytes(4)
|
2013-10-07 14:21:00 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
var outs = readVarInt();
|
|
|
|
for (var i = 0; i < outs; i++) {
|
|
|
|
obj.outs.push({
|
2014-03-11 02:52:48 +01:00
|
|
|
value: convert.bytesToNum(readBytes(8)),
|
2013-10-07 14:21:00 +02:00
|
|
|
script: new Script(readVarString())
|
|
|
|
});
|
|
|
|
}
|
|
|
|
obj.locktime = readAsInt(4);
|
2014-03-09 06:46:20 +01:00
|
|
|
|
2013-10-07 14:21:00 +02:00
|
|
|
return new Transaction(obj);
|
|
|
|
}
|
|
|
|
|
2013-10-07 21:27:19 +02:00
|
|
|
/**
|
|
|
|
* Signs a standard output at some index with the given key
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transaction.prototype.sign = function(index, key, type) {
|
|
|
|
type = type || SIGHASH_ALL;
|
2013-10-08 12:45:13 +02:00
|
|
|
key = new ECKey(key);
|
2014-03-20 23:40:07 +01:00
|
|
|
|
|
|
|
// TODO: getPub is slow, sha256ripe160 probably is too.
|
|
|
|
// This could be sped up a lot by providing these as inputs.
|
2014-01-04 19:26:03 +01:00
|
|
|
var pub = key.getPub().export('bytes'),
|
2013-10-08 12:45:13 +02:00
|
|
|
hash160 = util.sha256ripe160(pub),
|
|
|
|
script = Script.createOutputScript(new Address(hash160)),
|
2013-10-07 21:27:19 +02:00
|
|
|
hash = this.hashTransactionForSignature( script, index, type),
|
|
|
|
sig = key.sign(hash).concat([type]);
|
2013-10-08 12:48:31 +02:00
|
|
|
this.ins[index].script = Script.createInputScript(sig,pub);
|
2013-10-07 21:27:19 +02:00
|
|
|
}
|
|
|
|
|
2013-10-21 20:00:31 +02:00
|
|
|
// Takes outputs of the form [{ output: 'txhash:index', address: 'address' },...]
|
|
|
|
Transaction.prototype.signWithKeys = function(keys, outputs, type) {
|
|
|
|
type = type || SIGHASH_ALL;
|
|
|
|
var addrdata = keys.map(function(key) {
|
2013-10-21 21:33:35 +02:00
|
|
|
key = new ECKey(key);
|
2013-10-21 20:00:31 +02:00
|
|
|
return {
|
|
|
|
key: key,
|
|
|
|
address: key.getBitcoinAddress().toString()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var hmap = {};
|
|
|
|
for (var o in outputs) {
|
|
|
|
hmap[outputs[o].output] = outputs[o];
|
|
|
|
}
|
|
|
|
for (var i = 0; i < this.ins.length; i++) {
|
|
|
|
var outpoint = this.ins[i].outpoint.hash+':'+this.ins[i].outpoint.index,
|
|
|
|
histItem = hmap[outpoint];
|
|
|
|
if (!histItem) continue;
|
|
|
|
var thisInputAddrdata = addrdata.filter(function(a) {
|
|
|
|
return a.address == histItem.address;
|
|
|
|
});
|
|
|
|
if (thisInputAddrdata.length == 0) continue;
|
|
|
|
this.sign(i,thisInputAddrdata[0].key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-07 21:27:19 +02:00
|
|
|
/**
|
|
|
|
* Signs a P2SH output at some index with the given key
|
|
|
|
*/
|
|
|
|
|
|
|
|
Transaction.prototype.p2shsign = function(index, script, key, type) {
|
2013-10-08 12:45:13 +02:00
|
|
|
script = new Script(script);
|
|
|
|
key = new ECKey(key);
|
2013-10-07 21:27:19 +02:00
|
|
|
type = type || SIGHASH_ALL;
|
|
|
|
var hash = this.hashTransactionForSignature(script, index, type),
|
|
|
|
sig = key.sign(hash).concat([type]);
|
|
|
|
return sig;
|
|
|
|
}
|
|
|
|
|
|
|
|
Transaction.prototype.multisign = Transaction.prototype.p2shsign;
|
|
|
|
|
2013-11-02 11:20:09 +01:00
|
|
|
Transaction.prototype.applyMultisigs = function(index, script, sigs, type) {
|
|
|
|
this.ins[index].script = Script.createMultiSigInputScript(sigs, script);
|
|
|
|
}
|
|
|
|
|
2013-10-21 20:00:31 +02:00
|
|
|
Transaction.prototype.validateSig = function(index, script, sig, pub) {
|
2013-10-08 12:45:13 +02:00
|
|
|
script = new Script(script);
|
2013-10-08 12:48:31 +02:00
|
|
|
var hash = this.hashTransactionForSignature(script,index,1);
|
2014-03-11 02:52:48 +01:00
|
|
|
return ECDSA.verify(hash, convert.coerceToBytes(sig),
|
|
|
|
convert.coerceToBytes(pub));
|
2013-10-08 08:55:52 +02:00
|
|
|
}
|
2013-10-07 21:27:19 +02:00
|
|
|
|
2013-10-21 20:00:31 +02:00
|
|
|
var TransactionIn = function (data) {
|
|
|
|
if (typeof data == "string")
|
|
|
|
this.outpoint = { hash: data.split(':')[0], index: data.split(':')[1] }
|
|
|
|
else if (data.outpoint)
|
|
|
|
this.outpoint = data.outpoint
|
|
|
|
else
|
2014-03-09 06:46:20 +01:00
|
|
|
this.outpoint = { hash: data.hash, index: data.index }
|
2013-10-21 20:00:31 +02:00
|
|
|
|
|
|
|
if (data.scriptSig)
|
|
|
|
this.script = Script.fromScriptSig(data.scriptSig)
|
2014-03-09 06:46:20 +01:00
|
|
|
else if (data.script)
|
|
|
|
this.script = data.script
|
2013-10-21 20:00:31 +02:00
|
|
|
else
|
|
|
|
this.script = new Script(data.script)
|
|
|
|
|
2014-03-20 23:40:07 +01:00
|
|
|
this.sequence = data.sequence || this.defaultSequence
|
2013-02-17 06:39:15 +01:00
|
|
|
};
|
|
|
|
|
2013-10-21 20:00:31 +02:00
|
|
|
TransactionIn.prototype.clone = function () {
|
|
|
|
return new TransactionIn({
|
|
|
|
outpoint: {
|
|
|
|
hash: this.outpoint.hash,
|
|
|
|
index: this.outpoint.index
|
|
|
|
},
|
|
|
|
script: this.script.clone(),
|
|
|
|
sequence: this.sequence
|
|
|
|
});
|
2013-02-17 06:39:15 +01:00
|
|
|
};
|
|
|
|
|
2013-10-14 13:41:21 +02:00
|
|
|
var TransactionOut = function (data) {
|
|
|
|
this.script =
|
2013-10-15 07:24:13 +02:00
|
|
|
data.script instanceof Script ? data.script.clone()
|
2014-03-03 04:27:19 +01:00
|
|
|
: Array.isArray(data.script) ? new Script(data.script)
|
2014-03-11 02:52:48 +01:00
|
|
|
: typeof data.script == "string" ? new Script(convert.hexToBytes(data.script))
|
2013-10-14 13:41:21 +02:00
|
|
|
: data.scriptPubKey ? Script.fromScriptSig(data.scriptPubKey)
|
2013-10-21 20:00:31 +02:00
|
|
|
: data.address ? Script.createOutputScript(data.address)
|
2013-10-14 13:41:21 +02:00
|
|
|
: new Script();
|
|
|
|
|
2013-10-21 20:00:31 +02:00
|
|
|
if (this.script.buffer.length > 0) this.address = this.script.toAddress();
|
|
|
|
|
2014-03-09 06:46:20 +01:00
|
|
|
this.value =
|
2014-03-11 02:52:48 +01:00
|
|
|
Array.isArray(data.value) ? convert.bytesToNum(data.value)
|
2013-10-14 13:41:21 +02:00
|
|
|
: "string" == typeof data.value ? parseInt(data.value)
|
|
|
|
: data.value instanceof BigInteger ? parseInt(data.value.toString())
|
|
|
|
: data.value;
|
2013-02-17 06:39:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TransactionOut.prototype.clone = function ()
|
|
|
|
{
|
|
|
|
var newTxout = new TransactionOut({
|
|
|
|
script: this.script.clone(),
|
2013-10-14 13:41:21 +02:00
|
|
|
value: this.value
|
2013-02-17 06:39:15 +01:00
|
|
|
});
|
|
|
|
return newTxout;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.Transaction = Transaction;
|
|
|
|
module.exports.TransactionIn = TransactionIn;
|
|
|
|
module.exports.TransactionOut = TransactionOut;
|