From 898c89a5b241db08306e00ef974f826fc209e88e Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 29 Sep 2014 16:47:44 -0700 Subject: [PATCH] refactor option parsing in fill transaction. --- src/bitcoindjs.cc | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index ed763ba1..372ddcbe 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -1238,12 +1238,13 @@ bool SelectCoins(CWallet& wallet, int64_t nTargetValue, NAN_METHOD(FillTransaction) { NanScope(); - if (args.Length() < 1 || !args[0]->IsObject()) { + if (args.Length() < 2 || !args[0]->IsObject() || !args[1]->IsObject()) { return NanThrowError( - "Usage: bitcoindjs.fillTransaction(tx)"); + "Usage: bitcoindjs.fillTransaction(tx, options)"); } Local js_tx = Local::Cast(args[0]); + Local options = Local::Cast(args[1]); String::Utf8Value tx_hex_(js_tx->Get(NanNew("hex"))->ToString()); std::string tx_hex = std::string(*tx_hex_); @@ -1253,16 +1254,12 @@ NAN_METHOD(FillTransaction) { CDataStream ssData(ParseHex(tx_hex), SER_NETWORK, PROTOCOL_VERSION); ssData >> tx; - // Parse options + // Destination output int d_output = 0; - if (args.Length() > 1 && args[1]->IsObject()) { - Local options = Local::Cast(args[1]); - // Destination output - if (options->Get(NanNew("output"))->IsNumber()) { - d_output = options->Get(NanNew("output"))->IntegerValue(); - if (d_output < 0 || d_output >= tx.vout.size()) { - return NanThrowError("Destination output does not exist"); - } + if (options->Get(NanNew("output"))->IsNumber()) { + d_output = options->Get(NanNew("output"))->IntegerValue(); + if (d_output < 0 || d_output >= tx.vout.size()) { + return NanThrowError("Destination output does not exist"); } }