From 1138779bed19129a2e6f0e469ba85b30efb5900f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 22 Sep 2014 12:06:55 -0700 Subject: [PATCH] refactor --- src/bitcoindjs.cc | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 070911f2..b2c698d0 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -908,6 +908,7 @@ NAN_METHOD(GetTx) { uint256 hashBlock(blockHash); // uint256 hashBlock = 0; CTransaction tx; + if (!GetTransaction(hash, tx, hashBlock, true)) { Local err = Exception::Error(String::New("Bad Transaction.")); const unsigned argc = 1; @@ -919,27 +920,27 @@ NAN_METHOD(GetTx) { } cb.Dispose(); NanReturnValue(Undefined()); + } else { + CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); + ssTx << tx; + string strHex = HexStr(ssTx.begin(), ssTx.end()); + + Local obj = NanNew(); + obj->Set(NanNew("hex"), NanNew(strHex.c_str())); + + const unsigned argc = 2; + Local argv[argc] = { + Local::New(Null()), + Local::New(obj) + }; + TryCatch try_catch; + cb->Call(Context::GetCurrent()->Global(), argc, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + cb.Dispose(); + NanReturnValue(Undefined()); } - - CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); - ssTx << tx; - string strHex = HexStr(ssTx.begin(), ssTx.end()); - - Local obj = NanNew(); - obj->Set(NanNew("hex"), NanNew(strHex.c_str())); - - const unsigned argc = 2; - Local argv[argc] = { - Local::New(Null()), - Local::New(obj) - }; - TryCatch try_catch; - cb->Call(Context::GetCurrent()->Global(), argc, argv); - if (try_catch.HasCaught()) { - node::FatalException(try_catch); - } - cb.Dispose(); - NanReturnValue(Undefined()); } /**