From 3d12d3b03889a3d359f127d8af210a28cc9aaf8b Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Sun, 23 Mar 2014 21:34:52 +0800 Subject: [PATCH] implement and use txOut.scriptPubKey --- src/transaction.js | 7 +++++-- src/wallet.js | 2 +- test/transaction.js | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index 1f14fa6..7401c54 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -433,8 +433,7 @@ var TransactionOut = function (data) { : data.value; }; -TransactionOut.prototype.clone = function () -{ +TransactionOut.prototype.clone = function() { var newTxout = new TransactionOut({ script: this.script.clone(), value: this.value @@ -442,6 +441,10 @@ TransactionOut.prototype.clone = function () return newTxout; }; +TransactionOut.prototype.scriptPubKey = function() { + return convert.bytesToHex(this.script.buffer) +} + module.exports = { Transaction: Transaction, TransactionIn: TransactionIn, diff --git a/src/wallet.js b/src/wallet.js index 1885e00..5475957 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -146,7 +146,7 @@ var Wallet = function (seed, options) { receive: output, value: txOut.value, address: address, - scriptPubKey: convert.bytesToHex(txOut.script.buffer) //TODO: txOut.scriptPubKey() + scriptPubKey: txOut.scriptPubKey() // timestamp: new Date().getTime() / 1000, // pending: true } diff --git a/test/transaction.js b/test/transaction.js index d09af8b..41bcea2 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -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 ECKey = require('../src/eckey').ECKey +var Script = require('../src/script') var assert = require('assert') + var fixtureTxes = require('./fixtures/mainnet_tx') var fixtureTx1Hex = fixtureTxes.prevTx 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") + }) + }) + }) })