better error messages.

This commit is contained in:
Christopher Jeffrey 2014-11-14 14:51:20 -08:00
parent d250d2a1cd
commit eb9d5d70bc

View File

@ -1580,7 +1580,7 @@ NAN_METHOD(FillTransaction) {
// int64_t nFeeRet = CFeeRate(nAmount, 1000); // int64_t nFeeRet = CFeeRate(nAmount, 1000);
if (pwalletMain->IsLocked()) { if (pwalletMain->IsLocked()) {
return NanThrowError("Error: Wallet locked, unable to create transaction!"); return NanThrowError("Wallet locked, unable to create transaction!");
} }
CCoinControl* coinControl = new CCoinControl(); CCoinControl* coinControl = new CCoinControl();
@ -2072,7 +2072,7 @@ async_get_addrtx(uv_work_t *req) {
CBitcoinAddress address = CBitcoinAddress(data->addr); CBitcoinAddress address = CBitcoinAddress(data->addr);
if (!address.IsValid()) { if (!address.IsValid()) {
data->err_msg = std::string("bad addr"); data->err_msg = std::string("Invalid address.");
return; return;
} }
@ -2210,14 +2210,9 @@ NAN_METHOD(GetBestBlock) {
"Usage: bitcoindjs.getBestBlock()"); "Usage: bitcoindjs.getBestBlock()");
} }
//static CCoinsViewDB *pcoinsdbview = NULL; uint256 hash = pcoinsTip->GetBestBlock();
//pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex);
//uint256 block_hash = pcoinsdbview->GetBestBlock();
//CCoinsViewCache &viewChain = *pcoinsTip; NanReturnValue(NanNew<String>(hash.GetHex()));
uint256 block_hash = pcoinsTip->GetBestBlock();
NanReturnValue(NanNew<String>(block_hash.GetHex()));
} }
/** /**
@ -2306,7 +2301,7 @@ NAN_METHOD(BlockFromHex) {
try { try {
ssData >> cblock; ssData >> cblock;
} catch (std::exception &e) { } catch (std::exception &e) {
NanThrowError("Bad Block decode"); return NanThrowError("Bad Block decode");
} }
Local<Object> jsblock = NanNew<Object>(); Local<Object> jsblock = NanNew<Object>();
@ -2338,7 +2333,7 @@ NAN_METHOD(TxFromHex) {
try { try {
ssData >> ctx; ssData >> ctx;
} catch (std::exception &e) { } catch (std::exception &e) {
NanThrowError("Bad Block decode"); return NanThrowError("Bad Block decode");
} }
Local<Object> jstx = NanNew<Object>(); Local<Object> jstx = NanNew<Object>();
@ -4485,7 +4480,7 @@ NAN_METHOD(WalletBackup) {
std::string strDest = std::string(*path_); std::string strDest = std::string(*path_);
if (!BackupWallet(*pwalletMain, strDest)) { if (!BackupWallet(*pwalletMain, strDest)) {
return NanThrowError("Error: Wallet backup failed!"); return NanThrowError("Wallet backup failed!");
} }
NanReturnValue(Undefined()); NanReturnValue(Undefined());
@ -4511,7 +4506,7 @@ NAN_METHOD(WalletPassphrase) {
std::string strPassphrase = std::string(*passphrase_); std::string strPassphrase = std::string(*passphrase_);
if (!pwalletMain->IsCrypted()) { if (!pwalletMain->IsCrypted()) {
return NanThrowError("Error: running with an unencrypted wallet, but walletpassphrase was called."); return NanThrowError("Running with an unencrypted wallet, but walletpassphrase was called.");
} }
SecureString strWalletPass; SecureString strWalletPass;
@ -4520,12 +4515,10 @@ NAN_METHOD(WalletPassphrase) {
if (strWalletPass.length() > 0) { if (strWalletPass.length() > 0) {
if (!pwalletMain->Unlock(strWalletPass)) { if (!pwalletMain->Unlock(strWalletPass)) {
return NanThrowError("Error: The wallet passphrase entered was incorrect."); return NanThrowError("The wallet passphrase entered was incorrect.");
} }
} else { } else {
return NanThrowError( return NanThrowError("No wallet passphrase provided.");
"walletpassphrase <passphrase> <timeout>\n"
"Stores the wallet decryption key in memory for <timeout> seconds.");
} }
// XXX Do this asynchronously // XXX Do this asynchronously
@ -4557,7 +4550,7 @@ NAN_METHOD(WalletPassphraseChange) {
std::string newPass = std::string(*newPass_); std::string newPass = std::string(*newPass_);
if (!pwalletMain->IsCrypted()) { if (!pwalletMain->IsCrypted()) {
return NanThrowError("Error: running with an unencrypted wallet, but walletpassphrasechange was called."); return NanThrowError("Running with an unencrypted wallet, but walletpassphrasechange was called.");
} }
SecureString strOldWalletPass; SecureString strOldWalletPass;
@ -4569,13 +4562,11 @@ NAN_METHOD(WalletPassphraseChange) {
strNewWalletPass = newPass.c_str(); strNewWalletPass = newPass.c_str();
if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1) { if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1) {
return NanThrowError( return NanThrowError("Passphrases not provided.");
"walletpassphrasechange <oldpassphrase> <newpassphrase>\n"
"Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.");
} }
if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) { if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) {
return NanThrowError("Error: The wallet passphrase entered was incorrect."); return NanThrowError("The wallet passphrase entered was incorrect.");
} }
NanReturnValue(Undefined()); NanReturnValue(Undefined());
@ -4596,7 +4587,7 @@ NAN_METHOD(WalletLock) {
} }
if (!pwalletMain->IsCrypted()) { if (!pwalletMain->IsCrypted()) {
return NanThrowError("Error: running with an unencrypted wallet, but walletlock was called."); return NanThrowError("Running with an unencrypted wallet, but walletlock was called.");
} }
pwalletMain->Lock(); pwalletMain->Lock();
@ -4625,7 +4616,7 @@ NAN_METHOD(WalletEncrypt) {
std::string strPass = std::string(*passphrase_); std::string strPass = std::string(*passphrase_);
if (pwalletMain->IsCrypted()) { if (pwalletMain->IsCrypted()) {
return NanThrowError("Error: running with an encrypted wallet, but encryptwallet was called."); return NanThrowError("Running with an encrypted wallet, but encryptwallet was called.");
} }
SecureString strWalletPass; SecureString strWalletPass;
@ -4633,13 +4624,11 @@ NAN_METHOD(WalletEncrypt) {
strWalletPass = strPass.c_str(); strWalletPass = strPass.c_str();
if (strWalletPass.length() < 1) { if (strWalletPass.length() < 1) {
return NanThrowError( return NanThrowError("No wallet passphrase provided.");
"encryptwallet <passphrase>\n"
"Encrypts the wallet with <passphrase>.");
} }
if (!pwalletMain->EncryptWallet(strWalletPass)) { if (!pwalletMain->EncryptWallet(strWalletPass)) {
return NanThrowError("Error: Failed to encrypt the wallet."); return NanThrowError("Failed to encrypt the wallet.");
} }
// BDB seems to have a bad habit of writing old data into // BDB seems to have a bad habit of writing old data into
@ -5816,7 +5805,7 @@ jstx_to_ctx(const Local<Object> jstx, CTransaction& ctx_) {
try { try {
ssData >> ctx_; ssData >> ctx_;
} catch (std::exception &e) { } catch (std::exception &e) {
NanThrowError("Bad TX decode"); return NanThrowError("Bad TX decode");
} }
return; return;