Merge pull request #208 from kleetus/errorMessage_todo

Performed lexical cast on the reject code instead of using a sprintf.
This commit is contained in:
Braydon Fuller 2015-09-10 14:24:41 -04:00
commit 8c0ff7ba24
3 changed files with 13 additions and 4 deletions

View File

@ -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() {

View File

@ -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<std::string>(state.GetRejectCode()) + ": " + state.GetRejectReason()).c_str());
} else {
if (fMissingInputs) {
return NanThrowError("Missing inputs");

View File

@ -8,6 +8,7 @@
#include "txdb.h"
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
#include "nan.h"
#include "scheduler.h"
#include "core_io.h"