hacktober fest #214

Closed
Z3N00 wants to merge 304 commits from zeno into master
14 changed files with 331 additions and 128 deletions
Showing only changes of commit f0b2c46d68 - Show all commits

View file

@ -244,6 +244,22 @@ bool CClaimTrie::haveClaim(const std::string& name, const uint256& txhash, uint3
return current->haveValue(txhash, nOut);
}
bool CClaimTrie::haveSupport(const std::string& name, const uint256& txhash, uint32_t nOut) const
{
supportMapNodeType node;
if (!getSupportNode(name, node))
{
return false;
}
for (supportMapNodeType::const_iterator itnode = node.begin(); itnode != node.end(); ++itnode)
{
if (itnode->txhash == txhash && itnode->nOut == nOut)
return true;
}
return false;
}
unsigned int CClaimTrie::getTotalNamesInTrie() const
{
if (empty())
@ -469,6 +485,17 @@ bool CClaimTrie::getSupportNode(std::string name, supportMapNodeType& node)
return db.Read(std::make_pair(SUPPORT, name), node);
}
bool CClaimTrie::getSupportNode(std::string name, supportMapNodeType& node) const
{
supportMapType::const_iterator itNode = dirtySupportNodes.find(name);
if (itNode != dirtySupportNodes.end())
{
node = itNode->second;
return true;
}
return db.Read(std::make_pair(SUPPORT, name), node);
}
bool CClaimTrie::getSupportQueueRow(int nHeight, std::vector<CSupportValueQueueEntry>& row)
{
supportValueQueueType::iterator itQueueRow = dirtySupportQueueRows.find(nHeight);
@ -1387,7 +1414,7 @@ bool CClaimTrieCache::insertSupportIntoMap(const std::string name, CSupportNodeV
return reorderTrieNode(name);
}
bool CClaimTrieCache::removeSupportFromMap(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeight, int& nValidAtHeight) const
bool CClaimTrieCache::removeSupportFromMap(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int& nValidAtHeight) const
{
supportMapType::iterator cachedNode;
cachedNode = supportCache.find(name);
@ -1444,7 +1471,7 @@ supportValueQueueType::iterator CClaimTrieCache::getSupportQueueCacheRow(int nHe
return itQueueRow;
}
bool CClaimTrieCache::addSupportToQueue(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight, int nValidAtHeight) const
bool CClaimTrieCache::addSupportToQueue(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int nValidAtHeight) const
{
LogPrintf("%s: nValidAtHeight: %d\n", __func__, nValidAtHeight);
CSupportNodeValue val(txhash, nOut, supportedTxhash, supportednOut, nAmount, nHeight, nValidAtHeight);
@ -1454,7 +1481,7 @@ bool CClaimTrieCache::addSupportToQueue(const std::string name, uint256 txhash,
return true;
}
bool CClaimTrieCache::removeSupportFromQueue(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeightToCheck, int& nValidAtHeight) const
bool CClaimTrieCache::removeSupportFromQueue(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeightToCheck, int& nValidAtHeight) const
{
supportValueQueueType::iterator itQueueRow = getSupportQueueCacheRow(nHeightToCheck, false);
if (itQueueRow == supportQueueCache.end())
@ -1479,7 +1506,7 @@ bool CClaimTrieCache::removeSupportFromQueue(const std::string name, uint256 txh
return false;
}
bool CClaimTrieCache::addSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight) const
bool CClaimTrieCache::addSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, uint32_t supportednOut, int nHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, supportedTxhash.GetHex(), supportednOut, nHeight, nCurrentHeight);
assert(nHeight == nCurrentHeight);
@ -1495,7 +1522,7 @@ bool CClaimTrieCache::addSupport(const std::string name, uint256 txhash, uint32_
return addSupportToQueue(name, txhash, nOut, nAmount, supportedTxhash, supportednOut, nHeight, nHeight + DEFAULT_DELAY);
}
bool CClaimTrieCache::undoSpendSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight, int nValidAtHeight) const
bool CClaimTrieCache::undoSpendSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int nValidAtHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, supportedTxhash.GetHex(), supportednOut, nHeight, nCurrentHeight);
if (nValidAtHeight < nCurrentHeight)
@ -1510,7 +1537,7 @@ bool CClaimTrieCache::undoSpendSupport(const std::string name, uint256 txhash, u
}
}
bool CClaimTrieCache::removeSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeight, int& nValidAtHeight) const
bool CClaimTrieCache::removeSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int& nValidAtHeight) const
{
bool removed = false;
if (nHeight + DEFAULT_DELAY >= nCurrentHeight)
@ -1525,14 +1552,14 @@ bool CClaimTrieCache::removeSupport(const std::string name, uint256 txhash, uint
return removed;
}
bool CClaimTrieCache::undoAddSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeight) const
bool CClaimTrieCache::undoAddSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, supportedTxhash.GetHex(), supportednOut, nHeight, nCurrentHeight);
int throwaway;
return removeSupport(name, txhash, nOut, supportedTxhash, supportednOut, nHeight, throwaway);
}
bool CClaimTrieCache::spendSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeight, int& nValidAtHeight) const
bool CClaimTrieCache::spendSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int& nValidAtHeight) const
{
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, supportedTxhash.GetHex(), supportednOut, nHeight, nCurrentHeight);
return removeSupport(name, txhash, nOut, supportedTxhash, supportednOut, nHeight, nValidAtHeight);

View file

@ -83,7 +83,7 @@ public:
uint256 txhash;
uint32_t nOut;
uint256 supportTxhash;
int supportnOut;
uint32_t supportnOut;
CAmount nAmount;
int nHeight;
int nValidAtHeight;
@ -234,8 +234,10 @@ public:
bool getQueueRow(int nHeight, std::vector<CValueQueueEntry>& row);
bool getExpirationQueueRow(int nHeight, std::vector<CValueQueueEntry>& row);
bool getSupportNode(std::string name, supportMapNodeType& node);
bool getSupportNode(std::string name, supportMapNodeType& node) const;
bool getSupportQueueRow(int nHeight, std::vector<CSupportValueQueueEntry>& row);
bool haveClaim(const std::string& name, const uint256& txhash, uint32_t nOut) const;
bool haveSupport(const std::string& name, const uint256& txhash, uint32_t nOut) const;
unsigned int getTotalNamesInTrie() const;
unsigned int getTotalClaimsInTrie() const;
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
@ -289,10 +291,10 @@ public:
bool undoAddClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const;
bool spendClaim(const std::string name, uint256 txhash, uint32_t nOut, int nHeight, int& nValidAtHeight) const;
bool undoSpendClaim(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, int nHeight, int nValidAtHeight) const;
bool addSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight) const;
bool undoAddSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeight) const;
bool spendSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeight, int& nValidAtHeight) const;
bool undoSpendSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight, int nValidAtHeight) const;
bool addSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, uint32_t supportednOut, int nHeight) const;
bool undoAddSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight) const;
bool spendSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int& nValidAtHeight) const;
bool undoSpendSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int nValidAtHeight) const;
uint256 getBestBlock();
void setBestBlock(const uint256& hashBlock);
bool incrementBlock(CClaimTrieQueueUndo& insertUndo, CClaimTrieQueueUndo& expireUndo, CSupportValueQueueUndo& insertSupportUndo) const;
@ -323,12 +325,12 @@ private:
void removeFromExpirationQueue(const std::string name, uint256 txhash, uint32_t nOut, int nHeight) const;
valueQueueType::iterator getQueueCacheRow(int nHeight, bool createIfNotExists) const;
valueQueueType::iterator getExpirationQueueCacheRow(int nHeight, bool createIfNotExists) const;
bool removeSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeight, int& nValidAtHeight) const;
bool removeSupportFromMap(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeight, int& nValidAtHeight) const;
bool removeSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int& nValidAtHeight) const;
bool removeSupportFromMap(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int& nValidAtHeight) const;
bool insertSupportIntoMap(const std::string name, CSupportNodeValue val) const;
supportValueQueueType::iterator getSupportQueueCacheRow(int nHeight, bool createIfNotExists) const;
bool addSupportToQueue(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight, int nValidAtHeight) const;
bool removeSupportFromQueue(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeightToCheck, int& nValidAtHeight) const;
bool addSupportToQueue(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, uint32_t supportednOut, int nHeight, int nValidAtHeight) const;
bool removeSupportFromQueue(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, uint32_t supportednOut, int nHeightToCheck, int& nValidAtHeight) const;
uint256 hashBlock;
bool getSupportsForName(const std::string name, supportMapNodeType& node) const;
};

View file

@ -1644,8 +1644,7 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CClaimTr
assert(vvchParams.size() == 3);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint256 supportedTxid(vvchParams[1]);
CScriptNum snOut(vvchParams[2], true);
int supportednOut = snOut.getint();
uint32_t supportednOut = vch_to_uint32_t(vvchParams[2]);;
int nValidHeight = undo.nClaimValidHeight;
if (nValidHeight > 0 && nValidHeight >= coins->nHeight)
{
@ -1729,8 +1728,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
assert(vvchParams.size() == 3);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint256 supportedTxid(vvchParams[1]);
CScriptNum snOut(vvchParams[2], true);
int supportednOut = snOut.getint();
uint32_t supportednOut = vch_to_uint32_t(vvchParams[2]);;
LogPrintf("%s: (txid: %s, nOut: %d) Removing support for %s from txid %s nOut %d due to its block being disconnected\n", __func__, hash.ToString(), i, supportedTxid.ToString(), supportednOut, name.c_str());
if (!trieCache.undoAddSupport(name, hash, i, supportedTxid, supportednOut, pindex->nHeight))
LogPrintf("%s: Something went wrong removing support for name %s in hash %s\n", __func__, name.c_str(), hash.ToString());
@ -2028,8 +2026,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
assert(vvchParams.size() == 3);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint256 supportedTxid(vvchParams[1]);
CScriptNum snOut(vvchParams[2], true);
int supportednOut = snOut.getint();
uint32_t supportednOut = vch_to_uint32_t(vvchParams[2]);;
int nValidAtHeight;
LogPrintf("%s: Removing support for %s in txid %s nOut %d. Tx: %s, nOut: %d\n", __func__, name, supportedTxid.ToString(), supportednOut, txin.prevout.hash.ToString(), txin.prevout.n);
if (trieCache.spendSupport(name, txin.prevout.hash, txin.prevout.n, supportedTxid, supportednOut, coins->nHeight, nValidAtHeight))
@ -2071,8 +2068,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
assert(vvchParams.size() == 3);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint256 supportedTxid(vvchParams[1]);
CScriptNum snOut(vvchParams[2], true);
int supportednOut = snOut.getint();
uint32_t supportednOut = vch_to_uint32_t(vvchParams[2]);;
if (!trieCache.addSupport(name, tx.GetHash(), i, txout.nValue, supportedTxid, supportednOut, pindex->nHeight))
LogPrintf("%s: Something went wrong inserting the support\n", __func__);
}

View file

@ -326,8 +326,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
assert(vvchParams.size() == 3);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint256 supportedTxid(vvchParams[1]);
CScriptNum snOut(vvchParams[2], true);
int supportednOut = snOut.getint();
uint32_t supportednOut = vch_to_uint32_t(vvchParams[2]);
int throwaway;
if (!trieCache.spendSupport(name, txin.prevout.hash, txin.prevout.n, supportedTxid, supportednOut, coins->nHeight, throwaway))
LogPrintf("%s: Something went wrong removing the support\n", __func__);
@ -366,8 +365,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
assert(vvchParams.size() == 3);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint256 supportedTxid(vvchParams[1]);
CScriptNum snOut(vvchParams[2], true);
int supportednOut = snOut.getint();
uint32_t supportednOut = vch_to_uint32_t(vvchParams[2]);
//CScriptNum snOut(vvchParams[2], true);
//int supportednOut = snOut.getint();
if (!trieCache.addSupport(name, tx.GetHash(), i, txout.nValue, supportedTxid, supportednOut, nHeight))
{
LogPrintf("%s: Something went wrong inserting the name\n", __func__);

View file

@ -1,6 +1,29 @@
#include "nameclaim.h"
#include "util.h"
std::vector<unsigned char> uint32_t_to_vch(uint32_t n)
{
std::vector<unsigned char> vchN;
vchN.resize(4);
vchN[0] = n >> 24;
vchN[1] = n >> 16;
vchN[2] = n >> 8;
vchN[3] = n;
return vchN;
}
uint32_t vch_to_uint32_t(std::vector<unsigned char>& vchN)
{
uint32_t n;
if (vchN.size() != 4)
{
LogPrintf("%s() : a vector<unsigned char> with size other than 4 has been given", __func__);
return 0;
}
n = vchN[0] << 24 | vchN[1] << 16 | vchN[2] << 8 | vchN[3];
return n;
}
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams)
{
CScript::const_iterator pc = scriptIn.begin();
@ -41,7 +64,11 @@ bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector
}
if (op == OP_SUPPORT_CLAIM)
{
if (!scriptIn.GetOp(pc, opcode) || opcode < 0 || opcode > OP_PUSHDATA4)
if (!scriptIn.GetOp(pc, opcode, vchParam3) || opcode < 0 || opcode > OP_PUSHDATA4)
{
return false;
}
if (vchParam3.size() != 4)
{
return false;
}
@ -60,6 +87,8 @@ bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector
if (op == OP_SUPPORT_CLAIM)
{
vvchParams.push_back(vchParam3);
if (vchParam2.size() != (256/8))
return false;
}
return true;
@ -68,6 +97,11 @@ bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector
CScript StripClaimScriptPrefix(const CScript& scriptIn)
{
int op;
return StripClaimScriptPrefix(scriptIn, op);
}
CScript StripClaimScriptPrefix(const CScript& scriptIn, int& op)
{
std::vector<std::vector<unsigned char> > vvchParams;
CScript::const_iterator pc = scriptIn.begin();

View file

@ -8,5 +8,8 @@
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams);
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc);
CScript StripClaimScriptPrefix(const CScript& scriptIn);
CScript StripClaimScriptPrefix(const CScript& scriptIn, int& op);
std::vector<unsigned char> uint32_t_to_vch(uint32_t n);
uint32_t vch_to_uint32_t(std::vector<unsigned char>& vchN);
#endif // BITCOIN_NAMECLAIM_H

View file

@ -98,6 +98,10 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "abandonclaim", 2},
{ "listnameclaims", 0},
{ "listnameclaims", 1},
{ "listnameclaims", 2},
{ "supportclaim", 2},
{ "supportclaim", 3},
{ "abandonsupport", 2},
{ "gettotalvalueofclaims", 0},
};

View file

@ -370,6 +370,8 @@ static const CRPCCommand vRPCCommands[] =
{ "wallet", "listnameclaims", &listnameclaims, false },
{ "wallet", "updateclaim", &updateclaim, false },
{ "wallet", "abandonclaim", &abandonclaim, false },
{ "wallet", "supportclaim", &supportclaim, false },
{ "wallet", "abandonsupport", &abandonsupport, false },
{ "wallet", "sendtoaddress", &sendtoaddress, false },
{ "wallet", "setaccount", &setaccount, true },
{ "wallet", "settxfee", &settxfee, true },

View file

@ -181,6 +181,8 @@ extern UniValue claimname(const UniValue& params, bool fHelp);
extern UniValue listnameclaims(const UniValue& params, bool fHelp);
extern UniValue updateclaim(const UniValue& params, bool fHelp);
extern UniValue abandonclaim(const UniValue& params, bool fHelp);
extern UniValue supportclaim(const UniValue& params, bool fHelp);
extern UniValue abandonsupport(const UniValue& params, bool fHelp);
extern UniValue sendtoaddress(const UniValue& params, bool fHelp);
extern UniValue signmessage(const UniValue& params, bool fHelp);
extern UniValue verifymessage(const UniValue& params, bool fHelp);

View file

@ -7,6 +7,7 @@
#include "primitives/transaction.h"
#include "miner.h"
#include "claimtrie.h"
#include "nameclaim.h"
#include "coins.h"
#include "streams.h"
#include <boost/test/unit_test.hpp>
@ -169,23 +170,23 @@ const unsigned int support_nonces1[] = {
55230, 65910, 11530, 7441, 110596, 108561, 71692, 43935, 151361, 79724,
99792, 107989, 82596, 9169, 291679, 112377, 41344, 185047, 7018, 5951,
88404, 140428, 87970, 81004, 152441, 36684, 173721, 3349, 3175, 252786,
32720, 40948, 76930, 9491, 137742, 56954, 358844, 11884, 79338, 1449,
271845, 65895, 3599, 67466, 390374, 92544, 169976, 64804, 22583, 33184,
21846, 126102, 134037, 7743, 68285, 37887, 19122, 58595, 13881, 49513,
59047, 76262, 33652, 176824, 128984, 700, 3132, 46367, 11747, 127193,
41077, 38093, 5491, 325, 79570, 204899, 30771, 366656, 31271, 30585,
158040, 144014, 12649, 23040, 115875, 18196, 50306, 7922, 43930, 19235,
29139, 48803, 44994, 103398, 22128, 20131, 23586, 15249, 2941, 266120,
16186, 104144, 194544, 26703, 80750, 28839, 1190, 24200, 22772, 28085,
74439, 988, 51721, 65257, 48807, 45808, 5972, 44544, 43609, 97247,
338685, 648, 87423, 106088, 31569, 99139, 106419, 69391, 3635, 113533,
10925, 87228, 70748, 56881, 128451, 2366, 68232, 11000, 1853, 153196,
2581, 3875, 54236, 107276, 545, 229067, 76364, 45067, 39982, 68628,
5029, 27839, 67151, 20147, 20111, 47782, 18702, 42648, 5476, 15906,
69026, 289594, 22143, 113896, 30068, 23716, 62821, 67978, 77734, 116084,
88619, 92799, 92576, 25349, 165358, 7728, 80032, 124308, 37356, 49800,
82395, 58213, 61798, 66574, 25471, 29709, 7591, 121781, 75306, 27929,
7698, 69279, 151730, 2691, 33981, 22634, 48722, 610916, 4741, 61336,
32720, 40948, 76930, 20858, 43320, 45434, 68488, 164113, 20916, 239879,
40956, 111839, 68933, 74051, 192633, 25137, 97047, 72680, 153778, 109034,
43666, 16939, 18176, 133058, 32517, 46410, 194708, 40105, 58360, 137048,
10313, 165416, 20483, 7205, 5507, 19765, 3457, 154415, 48932, 82199,
160148, 23694, 55796, 78716, 70039, 164, 41686, 53995, 54996, 67472,
47392, 17816, 214640, 22687, 169977, 101026, 9873, 49577, 10778, 125898,
76370, 34024, 177655, 93657, 24720, 31059, 17496, 111609, 281936, 16678,
7952, 78319, 26740, 34426, 43900, 59040, 93664, 43267, 70771, 4339,
161842, 14987, 68264, 16, 36136, 80695, 13263, 90082, 857, 107417,
161366, 1416, 14466, 10056, 23907, 74171, 5261, 240414, 15976, 56496,
50007, 93917, 101335, 33195, 5902, 26325, 69080, 157373, 51960, 691,
54830, 67430, 33423, 127739, 9219, 62709, 495080, 227830, 73772, 13165,
3613, 117489, 4320, 114186, 132594, 69, 46875, 33889, 172546, 15312,
21267, 85199, 7134, 67319, 76992, 21812, 51259, 9249, 9862, 24484,
59952, 75454, 75256, 2651, 39566, 75408, 38682, 35976, 27900, 43089,
156885, 43435, 193627, 83950, 5709, 60268, 92811, 13408, 15480, 58406,
215450, 28785, 19379, 10100, 44302, 19849, 74044, 26939, 37505, 61336,
20033, 19624, 63951, 6755, 18613, 43297, 180012, 66684, 6631, 121649,
22531, 320516, 74811, 59326, 17935, 39781, 137162, 44383, 33226, 114852,
181180, 67566, 157014, 13412, 166344, 47237, 2946, 1812, 122065, 28047,
@ -215,17 +216,17 @@ const unsigned int support_nonces2[] = {
81635, 191166, 66330, 36626, 94722, 52716, 133306, 20991, 64508, 34170,
88659, 9779, 70051, 123365, 158677, 142215, 165612, 176285, 5277, 69969,
123460, 4739, 25210, 1181, 22451, 147063, 45230, 183496, 50047, 142425,
90173, 10472, 97468, 37034, 93084, 39525, 120266, 84300, 17673, 6804,
97967, 26481, 4194, 17105, 124852, 94454, 27437, 28181, 56705, 41272,
114455, 71194, 57137, 94295, 22075, 71012, 98068, 4972, 3674, 65977,
100267, 85369, 5135, 135988, 72022, 1382, 34686, 147332, 41812, 28748,
67431, 75021, 6087, 1904, 1747, 75216, 32773, 12619, 134365, 122043,
12472, 109146, 40092, 1179, 47114, 60362, 7733, 25120, 32149, 61762,
126194, 2473, 24550, 33741, 22542, 29648, 68799, 372, 14759, 4420,
122218, 115770, 11635, 40806, 5109, 200049, 50072, 135160, 128155, 78683,
250908, 21261, 133847, 188522, 79927, 18060, 121196, 80770, 69660, 30155,
74666, 20550, 18463, 52066, 40764, 36043, 24574, 17210, 55087, 42619,
19320, 6026, 17221, 30996, 52355, 62543, 2856, 308138, 9975, 5428,
90173, 10472, 97468, 2218, 111455, 212848, 2916, 18721, 30825, 190739,
113909, 24856, 8440, 86811, 211, 29718, 17486, 59240, 46915, 20444,
76005, 12477, 16029, 16541, 17049, 3641, 51405, 22015, 102809, 82073,
79420, 20290, 178940, 16336, 11521, 80562, 151537, 24375, 14822, 89007,
168314, 106790, 190447, 9747, 71739, 73323, 223536, 43707, 6166, 53859,
77193, 19913, 180298, 148, 20032, 43052, 68174, 63836, 76626, 45639,
136164, 15480, 66532, 189984, 70371, 46701, 87073, 101098, 13573, 32446,
40411, 3277, 5337, 4480, 33121, 31322, 16519, 46549, 8561, 9329,
15755, 57765, 37039, 52216, 170054, 23913, 3224, 22095, 43992, 66225,
764, 75691, 35599, 5417, 269692, 86253, 90212, 26251, 8874, 16060,
27117, 33737, 203711, 116599, 19914, 62543, 2856, 308138, 9975, 5428,
39726, 1759, 24200, 6970, 154491, 59163, 144476, 46342, 64023, 78238,
71701, 52740, 30958, 122696, 6737, 210973, 32609, 19114, 58624, 92640,
12948, 11073, 16901, 25895, 21842, 9027, 60460, 33030, 67370, 44786,
@ -240,12 +241,12 @@ const unsigned int support_nonces2[] = {
45784, 70172, 44564, 143614, 39200, 75869, 14353, 127113, 70557, 38980,
63364, 14319, 18884, 256, 44183, 16794, 45418, 126627, 31531, 60619,
16674, 99942, 16293, 4961, 57609, 247725, 102578, 76154, 4376, 74861,
27560, 14614, 158129, 126472, 79987, 20773, 61268, 1874, 130509, 870,
57357, 10848, 15044, 9971, 35590, 20488, 13594, 30216, 149806, 1096,
64153, 32166, 114746, 83875, 22065, 53825, 24118, 41806, 236143, 6033,
51233, 82133, 22722, 70053, 24220, 121801, 28752, 106039, 35457, 43791,
99575, 241399, 3328, 39177, 59918, 46609, 2050, 177764, 32959, 44877,
97421, 70882, 86683, 137432, 28277, 4848, 65459, 86324, 11610, 111098,
27560, 14614, 158129, 126472, 79987, 20773, 48122, 116607, 39308, 150466,
64570, 49849, 46186, 23349, 80633, 4727, 45020, 44244, 18138, 9984,
12649, 8930, 343846, 8772, 85447, 20913, 6850, 7148, 35165, 6243,
80328, 15660, 17966, 103914, 37229, 75098, 32367, 137670, 30573, 13861,
99470, 331362, 16339, 294785, 944, 180161, 354424, 29493, 90717, 76017,
157363, 94801, 41689, 285734, 11149, 2512, 17019, 86324, 11610, 111098,
198344, 10291, 83710, 39609, 33945, 11683, 93409, 28102, 20296, 64664,
1384, 23191, 168994, 31248, 81598, 179948, 1255, 7520, 8735, 23643,
27822, 136323, 25917, 18533, 105920, 50395, 98221, 2001, 46451, 191395,
@ -260,17 +261,17 @@ const unsigned int support_nonces2[] = {
11959, 12403, 226703, 60436, 48242, 180368, 20683, 13789, 38857, 72504,
62740, 27778, 16689, 126445, 63668, 135369, 16489, 91265, 87614, 256543,
31608, 63165, 8084, 48884, 60285, 233181, 133145, 67325, 38060, 82702,
274112, 1546, 17121, 72008, 63213, 66714, 4427, 26378, 94263, 36210,
28045, 4909, 57592, 77438, 49088, 85309, 35021, 68525, 64373, 118736,
73554, 33662, 31448, 22889, 9562, 51823, 38785, 93493, 109255, 7238,
107680, 222970, 81756, 128621, 2719, 283622, 231398, 73223, 70508, 11794,
81074, 132458, 79351, 36119, 21610, 28900, 61319, 186803, 78521, 107741,
96212, 63336, 151983, 43585, 9506, 108319, 12565, 72059, 31944, 184186,
72624, 119317, 3929, 69397, 31659, 19319, 76104, 16688, 2118, 101192,
48160, 97739, 20241, 133014, 48221, 19220, 5980, 127621, 18732, 177,
10627, 157980, 7145, 43432, 60647, 132588, 51314, 9458, 22465, 13920,
148416, 16017, 56429, 161205, 49038, 20341, 18729, 66404, 126427, 59051,
93406, 66991, 61963, 23362, 67901, 11674, 96360, 32335, 130778, 39768,
274112, 1546, 17121, 72008, 63213, 66714, 4427, 26378, 293747, 54190,
13609, 46687, 14907, 3925, 54506, 89292, 21048, 52230, 80904, 39484,
199322, 17743, 68138, 19352, 47055, 144457, 19211, 29628, 69986, 131196,
53872, 49387, 152281, 51824, 22041, 33971, 15108, 13337, 162014, 40602,
106200, 8292, 19773, 1304, 55807, 70998, 10637, 83313, 122595, 227472,
24159, 98863, 39656, 10452, 127345, 6191, 68732, 4303, 94547, 52004,
19411, 2513, 229112, 93276, 46105, 94524, 93852, 19074, 7569, 19864,
47459, 121864, 50899, 96723, 197798, 91795, 77069, 26481, 147668, 202302,
5928, 184427, 12000, 56211, 5622, 24665, 22639, 30812, 169494, 83456,
137941, 17169, 2000, 104824, 136832, 71272, 141938, 63227, 28633, 55314,
146418, 373502, 191002, 118787, 8980, 15847, 36560, 30751, 212194, 39768,
75, 11013, 7055, 104552, 9149, 54963, 2738, 28738, 25418, 48211,
39567, 47613, 19398, 177205, 29822, 104444, 115853, 31753, 26932, 48801,
111612, 25639, 44335, 94548, 84888, 14268, 10561, 50159, 37092, 19300,
@ -286,12 +287,12 @@ const unsigned int support_nonces2[] = {
25474, 15522, 87555, 60020, 103660, 41229, 115987, 19328, 69277, 102703,
53647, 113118, 10548, 19783, 27221, 17091, 14797, 61259, 43178, 28954,
123513, 29391, 23953, 70469, 28759, 57824, 19168, 13562, 4571, 26173,
21807, 88451, 42122, 80482, 1114, 29348, 32714, 12145, 45059, 140758,
21086, 1404, 93598, 22266, 38093, 62994, 20323, 25937, 97720, 200142,
37172, 45408, 2590, 4616, 9409, 143829, 38195, 22823, 59868, 79751,
28362, 298864, 29197, 66153, 65205, 118892, 41497, 127505, 44291, 9390,
247172, 112067, 129931, 66836, 36417, 164541, 226592, 4711, 58305, 56688,
95081, 159350, 235037, 123980, 9143, 94471, 73153, 11363, 93164, 63362,
60313, 52354, 9731, 33617, 7708, 116302, 145296, 63414, 79680, 598,
9047, 47056, 37125, 149483, 5432, 89502, 55348, 172980, 8886, 137667,
148918, 23869, 10506, 24099, 238653, 24339, 22464, 7307, 68969, 33856,
34296, 203325, 51164, 7833, 109377, 13562, 126128, 159047, 37659, 67068,
62885, 17276, 198570, 97716, 125203, 163072, 25870, 101965, 163916, 46804,
95510, 41574, 235037, 123980, 9143, 94471, 73153, 11363, 93164, 63362,
86526, 24756, 14070, 16924, 83332, 4100, 317190, 285610, 61499, 27712,
76315, 4835, 40248, 5447, 12097, 81545, 12833, 37877, 242159, 91197,
2425, 26630, 2519, 152473, 65756, 32133, 248062, 4329, 39461, 27326,
@ -301,22 +302,22 @@ const unsigned int support_nonces2[] = {
2874, 24150, 9499, 52916, 14152, 141953, 21624, 22911, 42470, 52998,
1080, 37439, 131336, 59290, 38910, 29273, 94703, 8312, 116959, 51277,
849, 40262, 190652, 11850, 38769, 87731, 143411, 65908, 50669, 4674,
125631, 98358, 39497, 144991, 101800, 44453, 113984, 47609, 2319, 88314,
125631, 98358, 39497, 33785, 54496, 44453, 113984, 47609, 2319, 88314,
22946, 31369, 99638, 7495, 260385, 116804, 136433, 70265, 98192, 31726,
12780, 17332, 3003, 47373, 74798, 26352, 5939, 15375, 8675, 101575,
164102, 100976, 101627, 10537, 54993, 31846, 126637, 20135, 158708, 7478,
25893, 28672, 66730, 39996, 126228, 20288, 77905, 34495, 19051, 12352,
55961, 124354, 58053, 5836, 17005, 28713, 5440, 61023, 67395, 11906,
191543, 46119, 5766, 9724, 136234, 20108, 34132, 113384, 49581, 23655,
55773, 108438, 12770, 2401, 31206, 25771, 1512, 15106, 95593, 18175,
130805, 25440, 214098, 136438, 53509, 290766, 15849, 1552, 65290, 725,
22352, 147274, 29787, 81667, 3047, 1360, 154794, 12339, 21770, 56408,
33675, 129531, 91341, 137661, 37828, 97543, 22518, 69127, 108482, 2514,
12634, 11975, 126573, 142228, 87169, 91641, 146065, 21746, 42517, 19841,
10163, 100527, 174806, 3410, 90965, 152821, 57522, 36897, 113679, 20895,
85751, 74220, 45532, 38417, 83189, 187113, 47798, 84865, 19093, 96824,
10547, 263601, 59486, 86011, 10869, 201270, 68189, 6550, 71153, 51180,
46722, 321280, 28734, 29270, 196742, 36713,
55961, 124354, 58053, 5836, 17005, 3143, 4591, 122833, 14138, 17268,
36030, 16341, 56423, 35558, 107746, 52961, 66136, 211036, 46256, 26463,
33814, 5837, 34306, 99237, 109457, 20216, 136509, 215181, 26837, 7661,
50220, 12966, 89526, 91218, 19980, 120895, 37290, 36883, 18725, 81858,
1600, 23014, 255282, 72423, 100392, 1207, 207156, 11959, 62546, 110928,
18915, 39838, 11316, 61634, 30352, 166281, 4171, 167586, 23141, 107122,
53327, 66841, 15665, 2139, 129790, 152050, 22873, 47846, 46836, 72224,
112396, 10779, 81485, 27048, 3607, 15669, 43750, 36080, 54178, 103924,
23998, 56178, 247600, 41719, 20168, 123337, 367762, 248158, 71843, 71079,
24365, 76, 6585, 64163, 48816, 62945, 91850, 80506, 101195, 93166,
102935, 80953, 18790, 93369, 30499, 88326,
};
BOOST_FIXTURE_TEST_SUITE(claimtrie_tests, TestingSetup)
@ -1306,7 +1307,8 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
CMutableTransaction tx3 = BuildTransaction(coinbases[2]);
uint256 tx1Hash = tx1.GetHash();
std::vector<unsigned char> vchTx1Hash(tx1Hash.begin(), tx1Hash.end());
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1Hash << CScriptNum(0) << OP_2DROP << OP_2DROP << OP_TRUE;
std::vector<unsigned char> vchSupportnOut = uint32_t_to_vch(0);
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1Hash << vchSupportnOut << OP_2DROP << OP_2DROP << OP_TRUE;
tx3.vout[0].nValue = 500000000;
CMutableTransaction tx4 = BuildTransaction(tx1);
@ -1637,7 +1639,8 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
CMutableTransaction tx3 = BuildTransaction(coinbases[2]);
uint256 tx1Hash = tx1.GetHash();
std::vector<unsigned char> vchTx1Hash(tx1Hash.begin(), tx1Hash.end());
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1Hash << CScriptNum(0) << OP_2DROP << OP_2DROP << OP_TRUE;
std::vector<unsigned char> vchSupportnOut = uint32_t_to_vch(0);
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1Hash << vchSupportnOut << OP_2DROP << OP_2DROP << OP_TRUE;
tx3.vout[0].nValue = 500000000;
CMutableTransaction tx4 = BuildTransaction(tx1);

View file

@ -347,7 +347,7 @@ UniValue getaddressesbyaccount(const UniValue& params, bool fHelp)
return ret;
}
void ClaimName(const std::vector<unsigned char> vchName, const std::vector<unsigned char> vchValue, CAmount nAmount, CWalletTx& wtxNew)
void CreateClaim(CScript& claimScript, CAmount nAmount, CWalletTx& wtxNew)
{
// Check amount
if (nAmount <= 0)
@ -360,7 +360,7 @@ void ClaimName(const std::vector<unsigned char> vchName, const std::vector<unsig
if (pwalletMain->IsLocked())
{
strError = "Error: Wallet locked, unable to create transaction!";
LogPrintf("SendMoney() : %s", strError);
LogPrintf("%s() : %s", __func__, strError);
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
@ -370,7 +370,6 @@ void ClaimName(const std::vector<unsigned char> vchName, const std::vector<unsig
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
CScript scriptPubKey = GetScriptForDestination(CTxDestination(newKey.GetID()));
CScript claimScript = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP;
claimScript = claimScript + scriptPubKey;
vector<CRecipient> vecSend;
@ -385,7 +384,7 @@ void ClaimName(const std::vector<unsigned char> vchName, const std::vector<unsig
{
if (nAmount + nFeeRequired > pwalletMain->GetBalance())
strError = strprintf("Error: This transaction requires a transaction fee of at least %s because if its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired));
LogPrintf("ClaimName() : %s\n", strError);
LogPrintf("%s() : %s\n", __func__, strError);
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
if (!pwalletMain->CommitTransaction(wtxNew, reservekey))
@ -419,7 +418,9 @@ UniValue claimname(const UniValue& params, bool fHelp)
EnsureWalletIsUnlocked();
ClaimName(vchName, vchValue, nAmount, wtx);
CScript claimScript = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP;
CreateClaim(claimScript, nAmount, wtx);
return wtx.GetHash().GetHex();
}
@ -438,7 +439,7 @@ void UpdateName(const std::vector<unsigned char> vchName, const std::vector<unsi
if (pwalletMain->IsLocked())
{
strError = "Error: Wallet locked, unable to create transaction!";
LogPrintf("UpdateName() : %s", strError);
LogPrintf("%s() : %s", __func__, strError);
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
@ -463,7 +464,7 @@ void UpdateName(const std::vector<unsigned char> vchName, const std::vector<unsi
{
if (nAmount + nFeeRequired - wtxIn.vout[nTxOut].nValue > pwalletMain->GetBalance())
strError = strprintf("Error: This transaction requires a transaction fee of at leaste %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired));
LogPrintf("ClaimName() : %s\n", strError);
LogPrintf("%s() : %s\n", __func__, strError);
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
if (!pwalletMain->CommitTransaction(wtxNew, reservekey))
@ -527,7 +528,7 @@ UniValue updateclaim(const UniValue& params, bool fHelp)
}
void AbandonName(const CTxDestination &address, CAmount nAmount, CWalletTx& wtxNew, CWalletTx wtxIn, unsigned int nTxOut)
void AbandonClaim(const CTxDestination &address, CAmount nAmount, CWalletTx& wtxNew, CWalletTx wtxIn, unsigned int nTxOut)
{
// Check amount
if (nAmount <= 0)
@ -540,7 +541,7 @@ void AbandonName(const CTxDestination &address, CAmount nAmount, CWalletTx& wtxN
if (pwalletMain->IsLocked())
{
strError = "Error: Wallet locked, unable to create transaction!";
LogPrintf("AbandonName() : %s", strError);
LogPrintf("%s() : %s", __func__, strError);
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
@ -558,7 +559,7 @@ void AbandonName(const CTxDestination &address, CAmount nAmount, CWalletTx& wtxN
{
if (nAmount + nFeeRequired - wtxIn.vout[nTxOut].nValue > pwalletMain->GetBalance())
strError = strprintf("Error: This transaction requires a transaction fee of a least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired));
LogPrintf("AbandonName() : %s\n", strError);
LogPrintf("%s() : %s\n", __func__, strError);
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}
if (!pwalletMain->CommitTransaction(wtxNew, reservekey))
@ -588,7 +589,7 @@ UniValue abandonclaim(const UniValue& params, bool fHelp)
CBitcoinAddress address(params[1].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid LBRYcrd address");
CAmount nAmount = AmountFromValue(params[2]);
@ -610,7 +611,7 @@ UniValue abandonclaim(const UniValue& params, bool fHelp)
if (DecodeClaimScript(wtx.vout[i].scriptPubKey, op, vvchParams))
{
EnsureWalletIsUnlocked();
AbandonName(address.Get(), nAmount, wtxNew, wtx, i);
AbandonClaim(address.Get(), nAmount, wtxNew, wtx, i);
fFound = true;
}
}
@ -648,22 +649,31 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept
vector<vector<unsigned char> > vvchParams;
if (!DecodeClaimScript(scriptPubKey, op, vvchParams))
{
LogPrintf("ListNameClaims(): Txout classified as name claim could not be decoded. Txid: %s", wtx.GetHash().ToString());
LogPrintf("%s(): Txout classified as name claim could not be decoded. Txid: %s", __func__, wtx.GetHash().ToString());
continue;
}
else if (vvchParams.size() != 2)
else if (((op == OP_CLAIM_NAME) && (vvchParams.size() != 2)) || ((op == OP_SUPPORT_CLAIM) && (vvchParams.size() != 3)))
{
LogPrintf("ListNameClaims(): Wrong number of params to name claim script. Got %d, expected 2. Txid: %s", vvchParams.size(), wtx.GetHash().ToString());
LogPrintf("%s(): Wrong number of params to name claim script. Got %d, expected %d. Txid: %s", __func__, vvchParams.size(), ((op == OP_CLAIM_NAME) ? 2 : 3), wtx.GetHash().ToString());
continue;
}
string sName (vvchParams[0].begin(), vvchParams[0].end());
string sValue (vvchParams[1].begin(), vvchParams[1].end());
entry.push_back(Pair("name", sName));
entry.push_back(Pair("value", sValue));
if (op == OP_CLAIM_NAME)
{
string sValue (vvchParams[1].begin(), vvchParams[1].end());
entry.push_back(Pair("value", sValue));
}
else if (op == OP_SUPPORT_CLAIM)
{
uint256 txhash(vvchParams[1]);
entry.push_back(Pair("supported_txid", txhash.GetHex()));
CScriptNum snOut(vvchParams[2], true);
entry.push_back(Pair("supported_nOut", snOut.getint()));
}
entry.push_back(Pair("txid", wtx.GetHash().ToString()));
entry.push_back(Pair("account", strSentAccount));
MaybePushAddress(entry, s.destination);
entry.push_back(Pair("category", "name"));
entry.push_back(Pair("amount", ValueFromAmount(s.amount)));
entry.push_back(Pair("vout", s.vout));
entry.push_back(Pair("fee", ValueFromAmount(nFee)));
@ -688,7 +698,14 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept
}
entry.push_back(Pair("confirmations", wtx.GetDepthInMainChain()));
entry.push_back(Pair("is spent", pwalletMain->IsSpent(wtx.GetHash(), s.vout)));
entry.push_back(Pair("is in name trie", pclaimTrie->haveClaim(sName, wtx.GetHash(), s.vout)));
if (op == OP_CLAIM_NAME)
{
entry.push_back(Pair("is in name trie", pclaimTrie->haveClaim(sName, wtx.GetHash(), s.vout)));
}
else if (op == OP_SUPPORT_CLAIM)
{
entry.push_back(Pair("is in support map", pclaimTrie->haveSupport(sName, wtx.GetHash(), s.vout)));
}
ret.push_back(entry);
}
}
@ -702,18 +719,20 @@ UniValue listnameclaims(const UniValue& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() > 2)
if (fHelp || params.size() > 3)
throw runtime_error(
"listnameclaims activeonly minconf\n"
"Return a list of all transactions claiming names.\n"
"\nArguments\n"
"1. activeonly (bool, optional, not implemented) Whether to only include transactions which are still active, i.e. have not been spent. Default is false.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many time.\n"
"1. includesupports (bool, optional) Whether to also include claim supports. Default is true.\n"
"2. activeonly (bool, optional, not implemented) Whether to only include transactions which are still active, i.e. have not been spent. Default is false.\n"
"3. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many time.\n"
"\nResult:\n"
"[\n"
" {\n"
" \"name\":\"claimedname\", (string) The name that is claimed.\n"
" \"value\":\"value\" (string) The value assigned to the name.\n"
" \"claimtype\":\"claimtype\", (string) CLAIM or SUPPORT.\n"
" \"value\":\"value\" (string) The value assigned to the name, if claimtype is CLAIM.\n"
" \"account\":\"accountname\", (string) The account name associated with the transaction. \n"
" It will be \"\" for the default account.\n"
" \"address\":\"lbrycrdaddress\", (string) The lbrycrd address of the transaction.\n"
@ -735,16 +754,19 @@ UniValue listnameclaims(const UniValue& params, bool fHelp)
);
string strAccount = "*";
bool fListSpent = true;
if (params.size() > 0)
fListSpent = !params[0].get_bool();
isminefilter claim_filter = ISMINE_CLAIM;
if (params.size() < 1 || params[0].get_bool())
claim_filter |= ISMINE_SUPPORT;
bool fListSpent = true;
if (params.size() > 1)
fListSpent = !params[1].get_bool();
// Minimum confirmations
int nMinDepth = 1;
if (params.size() > 1)
nMinDepth = params[1].get_int();
if (params.size() > 2)
nMinDepth = params[2].get_int();
UniValue ret(UniValue::VARR);
@ -771,6 +793,100 @@ UniValue listnameclaims(const UniValue& params, bool fHelp)
}
UniValue supportclaim(const UniValue& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 4)
throw runtime_error(
"supportclaim \"name\" \"txid\" nout amount\n"
"Increase the value of a claim. Whichever claim has the greatest value, including all support values, will be the authoritative claim, according to the rest of the rules. The name is the name which is claimed by the claim that will be supported, the txid is the txid of the claim that will be supported, nout is the transaction output which contains the claim to be supported, and amount is the amount which will be added to the value of the claim. If the claim is currently the authoritative claim, this support will go into effect immediately. Otherwise, it will go into effect after 100 blocks. The support will be in effect until it is spent, and will lose its effect when the claim is spent or expires. The amount is a real and is rounded to the nearest .00000001\n"
+ HelpRequiringPassphrase() +
"\nArguments:\n"
"1. \"name\" (string, required) The name claimed by the claim to support.\n"
"2. \"txid\" (string, required) The transaction id of the claim to support.\n"
"3. \"nout\" (integer, required) The transaction output of the transaction which contains the claim to be supported.\n"
"4. \"amount\" (numeric, required) The amount in LBC to use to support the claim.\n"
"\nResult:\n"
"\"transactionid\" (string) The transaction id of the support.\n"
);
string sName = params[0].get_str();
string sTxid = params[1].get_str();
uint256 txid;
txid.SetHex(sTxid);
std::vector<unsigned char> vchName (sName.begin(), sName.end());
std::vector<unsigned char> vchTxid (txid.begin(), txid.end());
std::vector<unsigned char> vchnOut = uint32_t_to_vch(params[2].get_int());
CAmount nAmount = AmountFromValue(params[3]);
CWalletTx wtx;
EnsureWalletIsUnlocked();
CScript supportScript = CScript() << OP_SUPPORT_CLAIM << vchName << vchTxid << vchnOut << OP_2DROP << OP_2DROP;
CreateClaim(supportScript, nAmount, wtx);
return wtx.GetHash().GetHex();
}
UniValue abandonsupport(const UniValue& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 3)
throw runtime_error(
"abandonsupport \"txid\" \"lbrycrdaddress\" \"amount\"\n"
"Create a transaction which spends a txout which supported a name claim, effectively abandoning that support.\n"
+ HelpRequiringPassphrase() +
"\nArguments:\n"
"1. \"txid\" (string, required) The transaction containing the unspent txout which should be spent.\n"
"2. \"lbrycrdaddress\" (string, required) The lbrycrd address to send to.\n"
"3. \"amount\" (numeric, required) The amount to send to the lbrycrd address. eg 0.1\n"
"\nResult:\n"
"\"transactionid\" (string) The new transaction id.\n"
);
uint256 hash;
hash.SetHex(params[0].get_str());
CBitcoinAddress address(params[1].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid LBRYcrd address");
CAmount nAmount = AmountFromValue(params[2]);
isminefilter filter = ISMINE_SUPPORT;
UniValue entry;
if (!pwalletMain->mapWallet.count(hash))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
int op;
std::vector<std::vector<unsigned char> > vvchParams;
CWalletTx wtxNew;
bool fFound = false;
for (unsigned int i = 0; !fFound && i < wtx.vout.size(); ++i)
{
if (filter & pwalletMain->IsMine(wtx.vout[i]))
{
if (DecodeClaimScript(wtx.vout[i].scriptPubKey, op, vvchParams))
{
EnsureWalletIsUnlocked();
AbandonClaim(address.Get(), nAmount, wtxNew, wtx, i); // not a type, they do the same thing
fFound = true;
}
}
}
if (!fFound)
throw runtime_error("Error: The given transaction contains no support scripts owned by this wallet");
return wtxNew.GetHash().GetHex();
}
static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew)

View file

@ -993,7 +993,7 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
COutputEntry output = {address, txout.nValue, (int)i};
// If we are debited by the transaction, add the output as a "sent" entry
if (nDebit > 0 || filter == ISMINE_CLAIM)
if (nDebit > 0 || filter | ISMINE_CLAIM || filter | ISMINE_SUPPORT)
listSent.push_back(output);
// If we are receiving the output, add it as a "received" entry

View file

@ -40,11 +40,24 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
vector<valtype> vSolutions;
txnouttype whichType;
isminetype spendable_type = ISMINE_SPENDABLE;
int opcode;
CScript strippedScriptPubKey = StripClaimScriptPrefix(scriptPubKey);
CScript strippedScriptPubKey = StripClaimScriptPrefix(scriptPubKey, opcode);
if (strippedScriptPubKey != scriptPubKey)
{
spendable_type = ISMINE_CLAIM;
if (opcode == OP_CLAIM_NAME)
{
spendable_type = ISMINE_CLAIM;
}
else if (opcode == OP_SUPPORT_CLAIM)
{
spendable_type = ISMINE_SUPPORT;
}
else
{
spendable_type = ISMINE_NO;
}
}

View file

@ -19,7 +19,8 @@ enum isminetype
ISMINE_WATCH_ONLY = 1,
ISMINE_SPENDABLE = 2,
ISMINE_CLAIM = 4,
ISMINE_ALL = ISMINE_WATCH_ONLY | ISMINE_SPENDABLE | ISMINE_CLAIM
ISMINE_SUPPORT = 8,
ISMINE_ALL = ISMINE_WATCH_ONLY | ISMINE_SPENDABLE | ISMINE_CLAIM | ISMINE_SUPPORT
};
/** used for bitflags of isminetype */
typedef uint8_t isminefilter;