Merge pull request #41 from blackjok3rtt/cleanwalletnotarisations
Cleanwalletnotarisations
This commit is contained in:
@@ -655,7 +655,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK
|
|||||||
return(totalinputs);
|
return(totalinputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid)
|
int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid,int32_t &entropytxs)
|
||||||
{
|
{
|
||||||
char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid;
|
char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid;
|
||||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||||
@@ -734,6 +734,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr,"numentropy tx %d: %.8f\n",n,(double)totalinputs/COIN);
|
fprintf(stderr,"numentropy tx %d: %.8f\n",n,(double)totalinputs/COIN);
|
||||||
|
entropytxs = n;
|
||||||
return(totalinputs);
|
return(totalinputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -826,7 +827,9 @@ UniValue DiceInfo(uint256 diceid)
|
|||||||
result.push_back(Pair("timeoutblocks",timeoutblocks));
|
result.push_back(Pair("timeoutblocks",timeoutblocks));
|
||||||
cp = CCinit(&C,EVAL_DICE);
|
cp = CCinit(&C,EVAL_DICE);
|
||||||
dicepk = GetUnspendable(cp,0);
|
dicepk = GetUnspendable(cp,0);
|
||||||
funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,diceid);
|
int32_t entropytxs = 0;
|
||||||
|
funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,diceid,entropytxs);
|
||||||
|
result.push_back(Pair("entropytxs",entropytxs));
|
||||||
sprintf(numstr,"%.8f",(double)funding/COIN);
|
sprintf(numstr,"%.8f",(double)funding/COIN);
|
||||||
result.push_back(Pair("funding",numstr));
|
result.push_back(Pair("funding",numstr));
|
||||||
return(result);
|
return(result);
|
||||||
@@ -955,7 +958,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet
|
|||||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||||
return("");
|
return("");
|
||||||
}
|
}
|
||||||
if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid)) >= 2*bet*odds+txfee && entropyval != 0 )
|
int32_t entropytxs;
|
||||||
|
if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs)) >= 2*bet*odds+txfee && entropyval != 0 )
|
||||||
{
|
{
|
||||||
if ( myIsutxo_spentinmempool(entropytxid,0) != 0 )
|
if ( myIsutxo_spentinmempool(entropytxid,0) != 0 )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -494,6 +494,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "wallet", "getaccountaddress", &getaccountaddress, true },
|
{ "wallet", "getaccountaddress", &getaccountaddress, true },
|
||||||
{ "wallet", "getaccount", &getaccount, true },
|
{ "wallet", "getaccount", &getaccount, true },
|
||||||
{ "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true },
|
{ "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true },
|
||||||
|
{ "wallet", "cleanwalletnotarisations", &cleanwalletnotarisations, false },
|
||||||
{ "wallet", "getbalance", &getbalance, false },
|
{ "wallet", "getbalance", &getbalance, false },
|
||||||
{ "wallet", "getbalance64", &getbalance64, false },
|
{ "wallet", "getbalance64", &getbalance64, false },
|
||||||
{ "wallet", "getnewaddress", &getnewaddress, true },
|
{ "wallet", "getnewaddress", &getnewaddress, true },
|
||||||
|
|||||||
@@ -299,6 +299,7 @@ extern UniValue signmessage(const UniValue& params, bool fHelp);
|
|||||||
extern UniValue verifymessage(const UniValue& params, bool fHelp);
|
extern UniValue verifymessage(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp);
|
extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp);
|
extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp);
|
||||||
|
extern UniValue cleanwalletnotarisations(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getbalance(const UniValue& params, bool fHelp);
|
extern UniValue getbalance(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getbalance64(const UniValue& params, bool fHelp);
|
extern UniValue getbalance64(const UniValue& params, bool fHelp);
|
||||||
extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp);
|
extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp);
|
||||||
|
|||||||
@@ -1001,6 +1001,134 @@ CAmount GetAccountBalance(const string& strAccount, int nMinDepth, const isminef
|
|||||||
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
|
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue cleanwalletnotarisations(const UniValue& params, bool fHelp)
|
||||||
|
{
|
||||||
|
if (!EnsureWalletIsAvailable(fHelp))
|
||||||
|
return NullUniValue;
|
||||||
|
|
||||||
|
if (fHelp || params.size() > 1 )
|
||||||
|
throw runtime_error(
|
||||||
|
"cleanwalletnotarisations \"txid\"\n"
|
||||||
|
"\nRemove all txs which are totally spent and all notarisations created from them, you can clear all txs bar one, by specifiying a txid.\n"
|
||||||
|
"\nPlease backup your wallet.dat before running this command.\n"
|
||||||
|
"\nArguments:\n"
|
||||||
|
"1. \"txid\" (string, optional) The transaction id to keep.\n"
|
||||||
|
"\nResult:\n"
|
||||||
|
"{\n"
|
||||||
|
" \"total_transactons\" : n, (numeric) Transactions in wallet of " + strprintf("%s",komodo_chainname()) + "\n"
|
||||||
|
" \"remaining_transactons\" : n, (numeric) Transactions in wallet after clean.\n"
|
||||||
|
" \"removed_transactons\" : n, (numeric) The number of transactions removed.\n"
|
||||||
|
"}\n"
|
||||||
|
"\nExamples:\n"
|
||||||
|
+ HelpExampleCli("cleanoldtxs", "")
|
||||||
|
+ HelpExampleCli("cleanoldtxs","\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
|
||||||
|
+ HelpExampleRpc("cleanoldtxs", "")
|
||||||
|
+ HelpExampleRpc("cleanoldtxs","\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
|
||||||
|
);
|
||||||
|
|
||||||
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
|
UniValue ret(UniValue::VOBJ);
|
||||||
|
uint256 exception; int32_t txs = pwalletMain->mapWallet.size();
|
||||||
|
std::vector<uint256> TxToRemove;
|
||||||
|
if (params.size() == 1)
|
||||||
|
{
|
||||||
|
exception.SetHex(params[0].get_str());
|
||||||
|
uint256 tmp_hash; CTransaction tmp_tx;
|
||||||
|
if (GetTransaction(exception,tmp_tx,tmp_hash,false))
|
||||||
|
{
|
||||||
|
if ( !pwalletMain->IsMine(tmp_tx) )
|
||||||
|
{
|
||||||
|
throw runtime_error("\nThe transaction is not yours!\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||||||
|
{
|
||||||
|
txs++;
|
||||||
|
const CWalletTx& wtx = (*it).second;
|
||||||
|
if ( wtx.GetHash() != exception )
|
||||||
|
{
|
||||||
|
TxToRemove.push_back(wtx.GetHash());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw runtime_error("\nThe transaction could not be found!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::vector<CWalletTx> NotarisationTxs;
|
||||||
|
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||||||
|
{
|
||||||
|
const CWalletTx& wtx = (*it).second;
|
||||||
|
if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 50 )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
CCoins coins;
|
||||||
|
if (!pcoinsTip->GetCoins(wtx.GetHash(), coins))
|
||||||
|
{
|
||||||
|
int spents = 0; int mine = 0;
|
||||||
|
for (unsigned int n = 0; n < wtx.vout.size() ; n++)
|
||||||
|
{
|
||||||
|
if ( pwalletMain->IsMine(wtx.vout[n]) )
|
||||||
|
mine++;
|
||||||
|
if ( ((unsigned int)n >= coins.vout.size() || coins.vout[n].IsNull() ) )
|
||||||
|
spents++;
|
||||||
|
}
|
||||||
|
if ( spents == mine )
|
||||||
|
{
|
||||||
|
TxToRemove.push_back(wtx.GetHash());
|
||||||
|
for (unsigned int n = 0; n < wtx.vin.size() ; n++)
|
||||||
|
{
|
||||||
|
if ( pwalletMain->IsMine(wtx.vin[n]) )
|
||||||
|
TxToRemove.push_back(wtx.vin[n].prevout.hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CTxDestination address;
|
||||||
|
// get all notarisations
|
||||||
|
if ( ExtractDestination(wtx.vout[0].scriptPubKey, address) )
|
||||||
|
{
|
||||||
|
if ( strcmp(CBitcoinAddress(address).ToString().c_str(),CRYPTO777_KMDADDR) == 0 )
|
||||||
|
NotarisationTxs.push_back(wtx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erase notarisations spending from fully spent splits.
|
||||||
|
BOOST_FOREACH (CWalletTx& tx, NotarisationTxs)
|
||||||
|
{
|
||||||
|
for (int n = 0; n < tx.vin.size(); n++)
|
||||||
|
{
|
||||||
|
BOOST_FOREACH (uint256& SpentHash, TxToRemove)
|
||||||
|
{
|
||||||
|
if ( SpentHash == tx.vin[n].prevout.hash )
|
||||||
|
{
|
||||||
|
pwalletMain->EraseFromWallet(tx.GetHash());
|
||||||
|
//fprintf(stderr, "ERASED Notarisation: %s\n",tx.GetHash().ToString().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// erase txs
|
||||||
|
BOOST_FOREACH (uint256& hash, TxToRemove)
|
||||||
|
{
|
||||||
|
pwalletMain->EraseFromWallet(hash);
|
||||||
|
//fprintf(stderr, "ERASED spent Tx: %s\n",hash.ToString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// build return JSON for stats.
|
||||||
|
int remaining = pwalletMain->mapWallet.size();
|
||||||
|
ret.push_back(Pair("total_transactons", (int)txs));
|
||||||
|
ret.push_back(Pair("remaining_transactons", (int)remaining));
|
||||||
|
ret.push_back(Pair("removed_transactions", (int)(txs-remaining)));
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
UniValue getbalance(const UniValue& params, bool fHelp)
|
UniValue getbalance(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user