From 1ac02c52765e52c22326596e7ab9af75ab35e1ed Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Wed, 9 Sep 2015 12:28:05 -0400 Subject: [PATCH 1/2] Performed lexical cast on the reject code instead of using a sprintf. --- src/libbitcoind.cc | 5 +---- src/libbitcoind.h | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libbitcoind.cc b/src/libbitcoind.cc index b3e0fd6d..0c3b8758 100644 --- a/src/libbitcoind.cc +++ b/src/libbitcoind.cc @@ -1478,10 +1478,7 @@ NAN_METHOD(SendTransaction) { // Attempt to add the transaction to the mempool if (!AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !allowAbsurdFees)) { if (state.IsInvalid()) { - // TODO: use boost::lexical_cast or C++11 std::to_string - char errorMessage [1024]; - sprintf(errorMessage, "%i: %s", state.GetRejectCode(), state.GetRejectReason().c_str()); - return NanThrowError(errorMessage); + return NanThrowError((boost::lexical_cast(state.GetRejectCode()) + ": " + state.GetRejectReason()).c_str()); } else { if (fMissingInputs) { return NanThrowError("Missing inputs"); diff --git a/src/libbitcoind.h b/src/libbitcoind.h index 12bdc7b5..2d05341f 100644 --- a/src/libbitcoind.h +++ b/src/libbitcoind.h @@ -8,6 +8,7 @@ #include "txdb.h" #include #include +#include #include "nan.h" #include "scheduler.h" #include "core_io.h" From 1c567c981725102c787fb4cf26ecdb938ff425fa Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Thu, 10 Sep 2015 14:01:52 -0400 Subject: [PATCH 2/2] ErrorMessage lexical cast test - sendTransaction will pass through a code and a message when the state comes up as invalid after sending a transaction that isn't signed. --- integration/regtest.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/integration/regtest.js b/integration/regtest.js index 0b693d7c..bf5c7ac5 100644 --- a/integration/regtest.js +++ b/integration/regtest.js @@ -275,6 +275,17 @@ describe('Daemon Binding Functionality', function() { hash.should.equal(tx.hash); }); + it('will throw an error if an unsigned transaction is sent', function() { + + var tx = bitcore.Transaction(); + tx.from(utxos[1]); + tx.change(privateKey.toAddress()); + tx.to(destKey.toAddress(), utxos[1].amount * 1e8 - 1000); + (function() { + bitcoind.sendTransaction(tx.uncheckedSerialize()); + }).should.throw('\x10: mandatory-script-verify-flag-failed (Operation not valid with the current stack size)'); + }); + }); describe('fee estimation', function() {