implement dumpprivkey.
This commit is contained in:
parent
665a87f680
commit
b754237618
@ -731,6 +731,10 @@ Wallet.prototype.isEncrypted = function() {
|
||||
return bitcoindjs.walletEncrypted();
|
||||
};
|
||||
|
||||
Wallet.prototype.dumpPrivKey = function(options) {
|
||||
return bitcoindjs.dumpPrivKey(options || {});
|
||||
};
|
||||
|
||||
Wallet.prototype.setTxFee = function(options) {
|
||||
return bitcoindjs.walletSetTxFee(options || {});
|
||||
};
|
||||
|
||||
@ -193,6 +193,7 @@ NAN_METHOD(WalletPassphraseChange);
|
||||
NAN_METHOD(WalletLock);
|
||||
NAN_METHOD(WalletEncrypt);
|
||||
NAN_METHOD(WalletEncrypted);
|
||||
NAN_METHOD(WalletDumpPrivKey);
|
||||
NAN_METHOD(WalletSetTxFee);
|
||||
NAN_METHOD(WalletImportKey);
|
||||
|
||||
@ -2931,9 +2932,12 @@ NAN_METHOD(WalletListAccounts) {
|
||||
if (!pwalletMain->GetKey(keyID, vchSecret)) {
|
||||
return NanThrowError("Private key for address is not known");
|
||||
}
|
||||
std::string priv = CBitcoinSecret(vchSecret).ToString();
|
||||
a->Set(NanNew<String>("privkeycompressed"), NanNew<Boolean>(vchSecret.IsCompressed()));
|
||||
a->Set(NanNew<String>("privkey"), NanNew<String>(priv));
|
||||
|
||||
if (!pwalletMain->IsCrypted()) {
|
||||
std::string priv = CBitcoinSecret(vchSecret).ToString();
|
||||
a->Set(NanNew<String>("privkeycompressed"), NanNew<Boolean>(vchSecret.IsCompressed()));
|
||||
a->Set(NanNew<String>("privkey"), NanNew<String>(priv));
|
||||
}
|
||||
|
||||
CPubKey vchPubKey;
|
||||
pwalletMain->GetPubKey(keyID, vchPubKey);
|
||||
@ -3188,6 +3192,52 @@ NAN_METHOD(WalletEncrypted) {
|
||||
NanReturnValue(NanNew<Boolean>(isEncrypted));
|
||||
}
|
||||
|
||||
/**
|
||||
* WalletDumpPrivKey()
|
||||
* bitcoindjs.walletDumpPrivKey(options)
|
||||
* Dump private key
|
||||
*/
|
||||
|
||||
NAN_METHOD(WalletDumpPrivKey) {
|
||||
NanScope();
|
||||
|
||||
if (args.Length() < 1 || !args[0]->IsObject()) {
|
||||
return NanThrowError(
|
||||
"Usage: bitcoindjs.walletDumpPrivKey(options)");
|
||||
}
|
||||
|
||||
Local<Object> options = Local<Object>::Cast(args[0]);
|
||||
String::Utf8Value addr_(options->Get(NanNew<String>("address"))->ToString());
|
||||
std::string addr = std::string(*addr_);
|
||||
|
||||
CBitcoinAddress address(addr);
|
||||
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
obj->Set(NanNew<String>("address"), NanNew<String>(address.ToString()));
|
||||
|
||||
CKeyID keyID;
|
||||
if (!address.GetKeyID(keyID)) {
|
||||
return NanThrowError("Address does not refer to a key");
|
||||
}
|
||||
CKey vchSecret;
|
||||
if (!pwalletMain->GetKey(keyID, vchSecret)) {
|
||||
return NanThrowError("Private key for address is not known");
|
||||
}
|
||||
|
||||
if (!pwalletMain->IsCrypted()) {
|
||||
std::string priv = CBitcoinSecret(vchSecret).ToString();
|
||||
obj->Set(NanNew<String>("privkeycompressed"), NanNew<Boolean>(vchSecret.IsCompressed()));
|
||||
obj->Set(NanNew<String>("privkey"), NanNew<String>(priv));
|
||||
}
|
||||
|
||||
CPubKey vchPubKey;
|
||||
pwalletMain->GetPubKey(keyID, vchPubKey);
|
||||
obj->Set(NanNew<String>("pubkeycompressed"), NanNew<Boolean>(vchPubKey.IsCompressed()));
|
||||
obj->Set(NanNew<String>("pubkey"), NanNew<String>(HexStr(vchPubKey)));
|
||||
|
||||
NanReturnValue(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* WalletSetTxFee()
|
||||
* bitcoindjs.walletSetTxFee(options)
|
||||
@ -3733,6 +3783,7 @@ init(Handle<Object> target) {
|
||||
NODE_SET_METHOD(target, "walletLock", WalletLock);
|
||||
NODE_SET_METHOD(target, "walletEncrypt", WalletEncrypt);
|
||||
NODE_SET_METHOD(target, "walletEncrypted", WalletEncrypted);
|
||||
NODE_SET_METHOD(target, "walletDumpPrivKey", WalletDumpPrivKey);
|
||||
NODE_SET_METHOD(target, "walletSetTxFee", WalletSetTxFee);
|
||||
NODE_SET_METHOD(target, "walletImportKey", WalletImportKey);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user