get rid of IS_EMPTY. add WalletIsMine().
This commit is contained in:
parent
eac667e103
commit
89ea984344
|
@ -842,6 +842,10 @@ Wallet.prototype.deleteAccount = function(options) {
|
||||||
return bitcoindjs.walletDeleteAccount(options || {});
|
return bitcoindjs.walletDeleteAccount(options || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Wallet.prototype.isMine = function(options) {
|
||||||
|
return bitcoindjs.walletIsMine(options || {});
|
||||||
|
};
|
||||||
|
|
||||||
Wallet = new Wallet;
|
Wallet = new Wallet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -228,7 +228,6 @@ using namespace node;
|
||||||
using namespace v8;
|
using namespace v8;
|
||||||
|
|
||||||
#define EMPTY ("\\x01")
|
#define EMPTY ("\\x01")
|
||||||
#define IS_EMPTY(addr) ((addr) == "\\x01")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node.js Exposed Function Templates
|
* Node.js Exposed Function Templates
|
||||||
|
@ -293,6 +292,7 @@ NAN_METHOD(WalletDumpWallet);
|
||||||
NAN_METHOD(WalletImportWallet);
|
NAN_METHOD(WalletImportWallet);
|
||||||
NAN_METHOD(WalletChangeLabel);
|
NAN_METHOD(WalletChangeLabel);
|
||||||
NAN_METHOD(WalletDeleteAccount);
|
NAN_METHOD(WalletDeleteAccount);
|
||||||
|
NAN_METHOD(WalletIsMine);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node.js Internal Function Templates
|
* Node.js Internal Function Templates
|
||||||
|
@ -3009,7 +3009,7 @@ NAN_METHOD(WalletSetAccount) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CBitcoinAddress address;
|
CBitcoinAddress address;
|
||||||
if (!IS_EMPTY(strAddress)) {
|
if (strAddress != EMPTY) {
|
||||||
address = CBitcoinAddress(strAddress);
|
address = CBitcoinAddress(strAddress);
|
||||||
if (!address.IsValid()) {
|
if (!address.IsValid()) {
|
||||||
return NanThrowError("Invalid Bitcoin address");
|
return NanThrowError("Invalid Bitcoin address");
|
||||||
|
@ -3033,7 +3033,7 @@ NAN_METHOD(WalletSetAccount) {
|
||||||
strAccount = std::string(*account_);
|
strAccount = std::string(*account_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IS_EMPTY(strAddress)) {
|
if (strAddress != EMPTY) {
|
||||||
// If it isn't our address, create a recipient:
|
// If it isn't our address, create a recipient:
|
||||||
{
|
{
|
||||||
CTxDestination dest = address.Get();
|
CTxDestination dest = address.Get();
|
||||||
|
@ -5119,11 +5119,11 @@ NAN_METHOD(WalletChangeLabel) {
|
||||||
addr = std::string(*addr_);
|
addr = std::string(*addr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_EMPTY(strAccount) && IS_EMPTY(addr)) {
|
if (strAccount == EMPTY && addr == EMPTY) {
|
||||||
return NanThrowError("No address or account name entered.");
|
return NanThrowError("No address or account name entered.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_EMPTY(strAccount) && !IS_EMPTY(addr)) {
|
if (strAccount == EMPTY && addr != EMPTY) {
|
||||||
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook) {
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook) {
|
||||||
const CBitcoinAddress& address = item.first;
|
const CBitcoinAddress& address = item.first;
|
||||||
const string& strName = item.second.name;
|
const string& strName = item.second.name;
|
||||||
|
@ -5134,7 +5134,7 @@ NAN_METHOD(WalletChangeLabel) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_EMPTY(addr) && !IS_EMPTY(strAccount)) {
|
if (addr == EMPTY && strAccount != EMPTY) {
|
||||||
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook) {
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook) {
|
||||||
const CBitcoinAddress& address = item.first;
|
const CBitcoinAddress& address = item.first;
|
||||||
const string& strName = item.second.name;
|
const string& strName = item.second.name;
|
||||||
|
@ -5207,7 +5207,7 @@ NAN_METHOD(WalletDeleteAccount) {
|
||||||
CAccount account;
|
CAccount account;
|
||||||
walletdb.ReadAccount(strAccount, account);
|
walletdb.ReadAccount(strAccount, account);
|
||||||
|
|
||||||
if (IS_EMPTY(strAccount)) {
|
if (strAccount == EMPTY) {
|
||||||
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook) {
|
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook) {
|
||||||
const CBitcoinAddress& address = item.first;
|
const CBitcoinAddress& address = item.first;
|
||||||
const string& strName = item.second.name;
|
const string& strName = item.second.name;
|
||||||
|
@ -5218,8 +5218,8 @@ NAN_METHOD(WalletDeleteAccount) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_EMPTY(strAccount)) {
|
if (strAccount == EMPTY) {
|
||||||
if (IS_EMPTY(addr)) {
|
if (addr == EMPTY) {
|
||||||
return NanThrowError("No account name specified.");
|
return NanThrowError("No account name specified.");
|
||||||
} else {
|
} else {
|
||||||
return NanThrowError("No account tied to specified address.");
|
return NanThrowError("No account tied to specified address.");
|
||||||
|
@ -5239,6 +5239,52 @@ NAN_METHOD(WalletDeleteAccount) {
|
||||||
NanReturnValue(True());
|
NanReturnValue(True());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WalletIsMine()
|
||||||
|
* bitcoindjs.walletIsMine(options)
|
||||||
|
* Check whether address or scriptPubKey is owned by wallet.
|
||||||
|
*/
|
||||||
|
|
||||||
|
NAN_METHOD(WalletIsMine) {
|
||||||
|
NanScope();
|
||||||
|
|
||||||
|
if (args.Length() < 1 || !args[0]->IsObject()) {
|
||||||
|
return NanThrowError(
|
||||||
|
"Usage: bitcoindjs.walletIsMine(options)");
|
||||||
|
}
|
||||||
|
|
||||||
|
Local<Object> options = Local<Object>::Cast(args[0]);
|
||||||
|
|
||||||
|
std::string addr = std::string(EMPTY);
|
||||||
|
std::string spk = std::string(EMPTY);
|
||||||
|
|
||||||
|
if (options->Get(NanNew<String>("address"))->IsString()) {
|
||||||
|
String::Utf8Value s_(options->Get(NanNew<String>("address"))->ToString());
|
||||||
|
addr = std::string(*s_);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options->Get(NanNew<String>("scriptPubKey"))->IsString()) {
|
||||||
|
String::Utf8Value s_(options->Get(NanNew<String>("scriptPubKey"))->ToString());
|
||||||
|
spk = std::string(*s_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bitcoin address
|
||||||
|
CScript scriptPubKey;
|
||||||
|
if (addr != EMPTY) {
|
||||||
|
CBitcoinAddress address = CBitcoinAddress(addr);
|
||||||
|
if (!address.IsValid()) {
|
||||||
|
return NanThrowError("Invalid Bitcoin address");
|
||||||
|
}
|
||||||
|
scriptPubKey = GetScriptForDestination(address.Get());
|
||||||
|
} else {
|
||||||
|
scriptPubKey << ParseHex(spk);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_mine = IsMine(*pwalletMain, scriptPubKey);
|
||||||
|
|
||||||
|
NanReturnValue(NanNew<Boolean>(is_mine));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conversions
|
* Conversions
|
||||||
* cblock_to_jsblock(cblock, cblock_index, jsblock, is_new)
|
* cblock_to_jsblock(cblock, cblock_index, jsblock, is_new)
|
||||||
|
@ -5854,6 +5900,7 @@ init(Handle<Object> target) {
|
||||||
NODE_SET_METHOD(target, "walletImportWallet", WalletImportWallet);
|
NODE_SET_METHOD(target, "walletImportWallet", WalletImportWallet);
|
||||||
NODE_SET_METHOD(target, "walletChangeLabel", WalletChangeLabel);
|
NODE_SET_METHOD(target, "walletChangeLabel", WalletChangeLabel);
|
||||||
NODE_SET_METHOD(target, "walletDeleteAccount", WalletDeleteAccount);
|
NODE_SET_METHOD(target, "walletDeleteAccount", WalletDeleteAccount);
|
||||||
|
NODE_SET_METHOD(target, "walletIsMine", WalletIsMine);
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(bitcoindjs, init)
|
NODE_MODULE(bitcoindjs, init)
|
||||||
|
|
Loading…
Reference in New Issue