implement and use txOut.scriptPubKey

This commit is contained in:
Wei Lu 2014-03-23 21:34:52 +08:00
parent 5d79b094d4
commit 3d12d3b038
3 changed files with 24 additions and 4 deletions

View file

@ -433,8 +433,7 @@ var TransactionOut = function (data) {
: data.value; : data.value;
}; };
TransactionOut.prototype.clone = function () TransactionOut.prototype.clone = function() {
{
var newTxout = new TransactionOut({ var newTxout = new TransactionOut({
script: this.script.clone(), script: this.script.clone(),
value: this.value value: this.value
@ -442,6 +441,10 @@ TransactionOut.prototype.clone = function ()
return newTxout; return newTxout;
}; };
TransactionOut.prototype.scriptPubKey = function() {
return convert.bytesToHex(this.script.buffer)
}
module.exports = { module.exports = {
Transaction: Transaction, Transaction: Transaction,
TransactionIn: TransactionIn, TransactionIn: TransactionIn,

View file

@ -146,7 +146,7 @@ var Wallet = function (seed, options) {
receive: output, receive: output,
value: txOut.value, value: txOut.value,
address: address, address: address,
scriptPubKey: convert.bytesToHex(txOut.script.buffer) //TODO: txOut.scriptPubKey() scriptPubKey: txOut.scriptPubKey()
// timestamp: new Date().getTime() / 1000, // timestamp: new Date().getTime() / 1000,
// pending: true // pending: true
} }

View file

@ -1,7 +1,12 @@
var Transaction = require('../src/transaction').Transaction var T = require('../src/transaction')
var Transaction = T.Transaction
var TransactionOut = T.TransactionOut
var convert = require('../src/convert') var convert = require('../src/convert')
var ECKey = require('../src/eckey').ECKey var ECKey = require('../src/eckey').ECKey
var Script = require('../src/script')
var assert = require('assert') var assert = require('assert')
var fixtureTxes = require('./fixtures/mainnet_tx') var fixtureTxes = require('./fixtures/mainnet_tx')
var fixtureTx1Hex = fixtureTxes.prevTx var fixtureTx1Hex = fixtureTxes.prevTx
var fixtureTx2Hex = fixtureTxes.tx var fixtureTx2Hex = fixtureTxes.tx
@ -192,5 +197,17 @@ describe('Transaction', function() {
}) })
}) })
describe('TransactionOut', function() {
describe('scriptPubKey', function() {
it('returns hex string', function() {
var txOut = new TransactionOut({
value: 50000,
script: Script.createOutputScript("1AZpKpcfCzKDUeTFBQUL4MokQai3m3HMXv")
})
assert.equal(txOut.scriptPubKey(), "76a91468edf28474ee22f68dfe7e56e76c017c1701b84f88ac")
})
})
})
}) })