diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 7dd04867..edb29b60 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -360,10 +360,7 @@ Bitcoin.prototype.getRecipients = function(options) { Bitcoin.prototype.getRecipient = function(options) { options = options || {}; var label = options.label || label; - var recipients = bitcoindjs.getRecipients(options); - return recipients.filter(function(recipient) { - return recipient.label === label; - })[0]; + return bitcoindjs.getRecipients({ _label: label }); }; Bitcoin.prototype.setRecipient = function(options) { diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 12a67b19..b1572491 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -1487,6 +1487,8 @@ NAN_METHOD(GetRecipients) { "Usage: bitcoindjs.getRecipients(options)"); } + Local options = Local::Cast(args[0]); + Local array = NanNew(); int i = 0; @@ -1495,13 +1497,20 @@ NAN_METHOD(GetRecipients) { const string& strName = item.second.name; if (item.second.purpose == "send" && address.IsValid()) { Local recipient = NanNew(); - recipient->Set(NanNew("label"), strName); - recipient->Set(NanNew("address"), address.ToString()); + recipient->Set(NanNew("label"), NanNew(strName)); + recipient->Set(NanNew("address"), NanNew(address.ToString())); array->Set(i, recipient); i++; + if (options->Get(NanNew("_label"))->IsString()) { + break; + } } } + if (options->Get(NanNew("_label"))->IsString()) { + NanReturnValue(array->Get(0)); + } + NanReturnValue(array); } @@ -1519,6 +1528,8 @@ NAN_METHOD(SetRecipient) { "Usage: bitcoindjs.setRecipient(options)"); } + Local options = Local::Cast(args[0]); + String::Utf8Value addr_(options->Get(NanNew("address"))->ToString()); std::string addr = std::string(*addr_); @@ -1546,6 +1557,8 @@ NAN_METHOD(RemoveRecipient) { "Usage: bitcoindjs.removeRecipient(options)"); } + Local options = Local::Cast(args[0]); + String::Utf8Value addr_(options->Get(NanNew("address"))->ToString()); std::string addr = std::string(*addr_);