fix fRescan check for callback.
This commit is contained in:
parent
317ff8a6bd
commit
82859274d6
|
@ -4657,6 +4657,9 @@ NAN_METHOD(WalletImportKey) {
|
||||||
|
|
||||||
async_import_key_data *data = new async_import_key_data();
|
async_import_key_data *data = new async_import_key_data();
|
||||||
|
|
||||||
|
data->err_msg = std::string("");
|
||||||
|
data->fRescan = false;
|
||||||
|
|
||||||
Local<Object> options = Local<Object>::Cast(args[0]);
|
Local<Object> options = Local<Object>::Cast(args[0]);
|
||||||
Local<Function> callback;
|
Local<Function> callback;
|
||||||
|
|
||||||
|
@ -4686,13 +4689,15 @@ NAN_METHOD(WalletImportKey) {
|
||||||
strAccount = std::string(*label_);
|
strAccount = std::string(*label_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strAccount == EMPTY) {
|
rescan:
|
||||||
return NanThrowError("No account name provided.");
|
if (data->fRescan) {
|
||||||
}
|
uv_work_t *req = new uv_work_t();
|
||||||
|
req->data = data;
|
||||||
// Call to: EnsureWalletIsUnlocked()
|
int status = uv_queue_work(uv_default_loop(),
|
||||||
if (pwalletMain->IsLocked()) {
|
req, async_import_key,
|
||||||
return NanThrowError("Please enter the wallet passphrase with walletpassphrase first.");
|
(uv_after_work_cb)async_import_key_after);
|
||||||
|
assert(status == 0);
|
||||||
|
NanReturnValue(Undefined());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whether to perform rescan after import
|
// Whether to perform rescan after import
|
||||||
|
@ -4700,16 +4705,45 @@ NAN_METHOD(WalletImportKey) {
|
||||||
? true
|
? true
|
||||||
: false;
|
: false;
|
||||||
|
|
||||||
|
if (strAccount == EMPTY) {
|
||||||
|
if (data->fRescan) {
|
||||||
|
data->err_msg = std::string("No account name provided.");
|
||||||
|
goto rescan;
|
||||||
|
} else {
|
||||||
|
return NanThrowError("No account name provided.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call to: EnsureWalletIsUnlocked()
|
||||||
|
if (pwalletMain->IsLocked()) {
|
||||||
|
if (data->fRescan) {
|
||||||
|
data->err_msg = std::string("Please enter the wallet passphrase with walletpassphrase first.");
|
||||||
|
goto rescan;
|
||||||
|
} else {
|
||||||
|
return NanThrowError("Please enter the wallet passphrase with walletpassphrase first.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CBitcoinSecret vchSecret;
|
CBitcoinSecret vchSecret;
|
||||||
bool fGood = vchSecret.SetString(strSecret);
|
bool fGood = vchSecret.SetString(strSecret);
|
||||||
|
|
||||||
if (!fGood) {
|
if (!fGood) {
|
||||||
return NanThrowError("Invalid private key encoding");
|
if (data->fRescan) {
|
||||||
|
data->err_msg = std::string("Invalid private key encoding");
|
||||||
|
goto rescan;
|
||||||
|
} else {
|
||||||
|
return NanThrowError("Invalid private key encoding");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CKey key = vchSecret.GetKey();
|
CKey key = vchSecret.GetKey();
|
||||||
if (!key.IsValid()) {
|
if (!key.IsValid()) {
|
||||||
return NanThrowError("Private key outside allowed range");
|
if (data->fRescan) {
|
||||||
|
data->err_msg = std::string("Private key outside allowed range");
|
||||||
|
goto rescan;
|
||||||
|
} else {
|
||||||
|
return NanThrowError("Private key outside allowed range");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CPubKey pubkey = key.GetPubKey();
|
CPubKey pubkey = key.GetPubKey();
|
||||||
|
@ -4728,7 +4762,12 @@ NAN_METHOD(WalletImportKey) {
|
||||||
pwalletMain->mapKeyMetadata[vchAddress].nCreateTime = 1;
|
pwalletMain->mapKeyMetadata[vchAddress].nCreateTime = 1;
|
||||||
|
|
||||||
if (!pwalletMain->AddKeyPubKey(key, pubkey)) {
|
if (!pwalletMain->AddKeyPubKey(key, pubkey)) {
|
||||||
return NanThrowError("Error adding key to wallet");
|
if (data->fRescan) {
|
||||||
|
data->err_msg = std::string("Error adding key to wallet");
|
||||||
|
goto rescan;
|
||||||
|
} else {
|
||||||
|
return NanThrowError("Error adding key to wallet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// whenever a key is imported, we need to scan the whole chain
|
// whenever a key is imported, we need to scan the whole chain
|
||||||
|
@ -4752,8 +4791,13 @@ NAN_METHOD(WalletImportKey) {
|
||||||
static void
|
static void
|
||||||
async_import_key(uv_work_t *req) {
|
async_import_key(uv_work_t *req) {
|
||||||
async_import_key_data* data = static_cast<async_import_key_data*>(req->data);
|
async_import_key_data* data = static_cast<async_import_key_data*>(req->data);
|
||||||
// This may take a long time, do it on the libuv thread pool:
|
if (data->err_msg != "") {
|
||||||
pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true);
|
return;
|
||||||
|
}
|
||||||
|
if (data->fRescan) {
|
||||||
|
// This may take a long time, do it on the libuv thread pool:
|
||||||
|
pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue