remove todos. implement WalletGetTransaction.
This commit is contained in:
parent
fdf15b340f
commit
f19bd33fe3
@ -808,11 +808,13 @@ Wallet.prototype.getUnconfirmedBalance = function(options) {
|
|||||||
return bitcoindjs.walletGetUnconfirmedBalance(options || {});
|
return bitcoindjs.walletGetUnconfirmedBalance(options || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// XXX Wallet Transactions
|
||||||
Wallet.prototype.listTransactions =
|
Wallet.prototype.listTransactions =
|
||||||
Wallet.prototype.getTransactions = function(options) {
|
Wallet.prototype.getTransactions = function(options) {
|
||||||
return bitcoindjs.walletListTransactions(options || {});
|
return bitcoindjs.walletListTransactions(options || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// XXX Wallet Transactions
|
||||||
Wallet.prototype.listReceivedByAddress =
|
Wallet.prototype.listReceivedByAddress =
|
||||||
Wallet.prototype.getReceivedByAddress = function(options) {
|
Wallet.prototype.getReceivedByAddress = function(options) {
|
||||||
return bitcoindjs.walletReceivedByAddress(options || {});
|
return bitcoindjs.walletReceivedByAddress(options || {});
|
||||||
@ -823,6 +825,7 @@ Wallet.prototype.getAccounts = function(options) {
|
|||||||
return bitcoindjs.walletListAccounts(options || {});
|
return bitcoindjs.walletListAccounts(options || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// XXX Wallet Transactions
|
||||||
Wallet.prototype.getTransaction = function(options) {
|
Wallet.prototype.getTransaction = function(options) {
|
||||||
return bitcoindjs.walletGetTransaction(options || {});
|
return bitcoindjs.walletGetTransaction(options || {});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4283,8 +4283,7 @@ NAN_METHOD(WalletReceivedByAddress) {
|
|||||||
* WalletListAccounts()
|
* WalletListAccounts()
|
||||||
* bitcoindjs.walletListAccounts(options)
|
* bitcoindjs.walletListAccounts(options)
|
||||||
* This will list all accounts, addresses, balanced, private keys, public keys,
|
* This will list all accounts, addresses, balanced, private keys, public keys,
|
||||||
* and whether these keys are in compressed format. TODO: Only output private
|
* and whether these keys are in compressed format.
|
||||||
* keys if wallet is decrypted.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
NAN_METHOD(WalletListAccounts) {
|
NAN_METHOD(WalletListAccounts) {
|
||||||
@ -4394,8 +4393,7 @@ NAN_METHOD(WalletListAccounts) {
|
|||||||
/**
|
/**
|
||||||
* WalletGetTransaction()
|
* WalletGetTransaction()
|
||||||
* bitcoindjs.walletGetTransaction(options)
|
* bitcoindjs.walletGetTransaction(options)
|
||||||
* Get any transaction pertaining to any owned addresses. NOT YET IMPLEMENTED.
|
* Get any transaction pertaining to any owned addresses.
|
||||||
* XXX TODO
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
NAN_METHOD(WalletGetTransaction) {
|
NAN_METHOD(WalletGetTransaction) {
|
||||||
@ -4408,13 +4406,63 @@ NAN_METHOD(WalletGetTransaction) {
|
|||||||
|
|
||||||
Local<Object> options = Local<Object>::Cast(args[0]);
|
Local<Object> options = Local<Object>::Cast(args[0]);
|
||||||
|
|
||||||
|
std::string txid;
|
||||||
if (options->Get(NanNew<String>("txid"))->IsString()) {
|
if (options->Get(NanNew<String>("txid"))->IsString()) {
|
||||||
String::Utf8Value txid_(options->Get(NanNew<String>("txid"))->ToString());
|
String::Utf8Value txid_(options->Get(NanNew<String>("txid"))->ToString());
|
||||||
std::string txid = std::string(*txid_);
|
txid = std::string(*txid_);
|
||||||
NanReturnValue(NanNew<String>(txid));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// XXX - SLOW
|
||||||
|
Local<Array> txs = WalletListTransactions(args);
|
||||||
|
for (unsigned int i = 0; i < txs->Length(); ti++) {
|
||||||
|
String::Utf8Value id_(txs[i]->Get(NanNew<String>("txid"))->ToString());
|
||||||
|
std::string id = std::string(*id_);
|
||||||
|
if (id == txid) {
|
||||||
|
NanReturnValue(txs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
NanReturnValue(Undefined());
|
NanReturnValue(Undefined());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint256 hash;
|
||||||
|
hash.SetHex(txid);
|
||||||
|
|
||||||
|
isminefilter filter = ISMINE_SPENDABLE;
|
||||||
|
if (options->Get(NanNew<String>("watch"))->IsBoolean()
|
||||||
|
&& options->Get(NanNew<String>("watch"))->IsTrue()) {
|
||||||
|
filter = filter | ISMINE_WATCH_ONLY;
|
||||||
|
}
|
||||||
|
|
||||||
|
Local<Object> entry = NanNew<Object>();
|
||||||
|
if (!pwalletMain->mapWallet.count(hash)) {
|
||||||
|
return NanThrowError("Invalid or non-wallet transaction id");
|
||||||
|
}
|
||||||
|
|
||||||
|
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
|
||||||
|
|
||||||
|
CAmount nCredit = wtx.GetCredit(filter != 0);
|
||||||
|
CAmount nDebit = wtx.GetDebit(filter);
|
||||||
|
CAmount nNet = nCredit - nDebit;
|
||||||
|
CAmount nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
|
||||||
|
|
||||||
|
entry->Set(NanNew<String>("amount"), NanNew<Number>(SatoshiFromAmount(nNet - nFee)));
|
||||||
|
|
||||||
|
if (wtx.IsFromMe(filter)) {
|
||||||
|
entry->Set(NanNew<String>("fee"), NanNew<Number>(SatoshiFromAmount(nFee)));
|
||||||
|
}
|
||||||
|
|
||||||
|
WalletTxToJSON_V8(wtx, entry);
|
||||||
|
|
||||||
|
Local<Array> details = NanNew<Array>();
|
||||||
|
int a_count = 0;
|
||||||
|
ListTransactions_V8(wtx, "*", 0, false, details, filter, &a_count);
|
||||||
|
entry->Set(NanNew<String>("details"), details);
|
||||||
|
|
||||||
|
std::string strHex = EncodeHexTx(static_cast<CTransaction>(wtx));
|
||||||
|
entry->Set(NanNew<String>("hex"), NanNew<String>(strHex));
|
||||||
|
|
||||||
|
NanReturnValue(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user