Detect "claim" type transactions.

Add code to enable a hardfork into witness support, in addition to
possible BIP9 fiddling.
Fix a bug in abandonclaim and abandonsupport that burns coins on
abandon, rather than sending to the intended destination.
This commit is contained in:
lbrynaut 2019-08-06 09:50:52 -05:00 committed by Anthony Fieroni
parent 6651d45ce9
commit 2a78c776b4
9 changed files with 37 additions and 43 deletions

View file

@ -137,6 +137,7 @@ public:
consensus.nNormalizedNameForkHeight = 539940; // targeting 21 March 2019
consensus.nMinTakeoverWorkaroundHeight = 496850;
consensus.nMaxTakeoverWorkaroundHeight = 10000000;
consensus.nWitnessForkHeight = 700000;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 1916; // 95% of a half week
@ -247,6 +248,7 @@ public:
consensus.nNormalizedNameForkHeight = 993380; // targeting, 21 Feb 2019
consensus.nMinTakeoverWorkaroundHeight = 99;
consensus.nMaxTakeoverWorkaroundHeight = 10000000;
consensus.nWitnessForkHeight = 1600000;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
@ -344,6 +346,7 @@ public:
consensus.nNormalizedNameForkHeight = 250; // SDK depends upon this number
consensus.nMinTakeoverWorkaroundHeight = -1;
consensus.nMaxTakeoverWorkaroundHeight = -1;
consensus.nWitnessForkHeight = 150;
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains

View file

@ -59,17 +59,17 @@ public:
*/
CClaimScriptAddOp(const COutPoint& point, CAmount nValue, int nHeight);
/**
* Implamention of OP_CLAIM_NAME handler
* Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName
*/
bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
/**
* Implamention of OP_UPDATE_CLAIM handler
* Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim
*/
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
/**
* Implamention of OP_SUPPORT_CLAIM handler
* Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim
*/
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
@ -100,17 +100,17 @@ public:
*/
CClaimScriptUndoAddOp(const COutPoint& point, int nHeight);
/**
* Implamention of OP_CLAIM_NAME handler
* Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName
*/
bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
/**
* Implamention of OP_UPDATE_CLAIM handler
* Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim
*/
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
/**
* Implamention of OP_SUPPORT_CLAIM handler
* Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim
*/
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
@ -141,17 +141,17 @@ public:
*/
CClaimScriptSpendOp(const COutPoint& point, int nHeight, int& nValidHeight);
/**
* Implamention of OP_CLAIM_NAME handler
* Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName
*/
bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
/**
* Implamention of OP_UPDATE_CLAIM handler
* Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim
*/
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
/**
* Implamention of OP_SUPPORT_CLAIM handler
* Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim
*/
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
@ -184,17 +184,17 @@ public:
*/
CClaimScriptUndoSpendOp(const COutPoint& point, CAmount nValue, int nHeight, int nValidHeight);
/**
* Implamention of OP_CLAIM_NAME handler
* Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName
*/
bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
/**
* Implamention of OP_UPDATE_CLAIM handler
* Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim
*/
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
/**
* Implamention of OP_SUPPORT_CLAIM handler
* Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim
*/
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;

View file

@ -88,6 +88,8 @@ struct Params {
int nMinTakeoverWorkaroundHeight;
int nMaxTakeoverWorkaroundHeight;
int nWitnessForkHeight;
int64_t nPowTargetSpacing;
int64_t nPowTargetTimespan;
/** how long it took claims to expire before the hard fork */

View file

@ -7,6 +7,7 @@
#include <consensus/consensus.h>
#include <consensus/validation.h>
#include <key_io.h>
#include <nameclaim.h>
#include <script/script.h>
#include <script/standard.h>
#include <serialize.h>

View file

@ -6,6 +6,7 @@
#include <script/standard.h>
#include <crypto/sha256.h>
#include <nameclaim.h>
#include <pubkey.h>
#include <script/script.h>
@ -30,6 +31,7 @@ const char* GetTxnOutputType(txnouttype t)
switch (t)
{
case TX_NONSTANDARD: return "nonstandard";
case TX_CLAIM: return "claim";
case TX_PUBKEY: return "pubkey";
case TX_PUBKEYHASH: return "pubkeyhash";
case TX_SCRIPTHASH: return "scripthash";
@ -150,7 +152,10 @@ txnouttype Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned
}
vSolutionsRet.clear();
return TX_NONSTANDARD;
int op;
std::vector<std::vector<unsigned char> > vvchParams;
return (DecodeClaimScript(scriptPubKey, op, vvchParams)) ? TX_CLAIM : TX_NONSTANDARD;
}
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)

View file

@ -56,6 +56,7 @@ static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH;
enum txnouttype
{
TX_NONSTANDARD,
TX_CLAIM,
// 'standard' transaction types:
TX_PUBKEY,
TX_PUBKEYHASH,

View file

@ -187,6 +187,11 @@ public:
ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
{
// Check if we've past a hardfork state for segwit.
if ((pos == Consensus::DEPLOYMENT_SEGWIT) && (pindexPrev != nullptr) &&
(pindexPrev->nHeight + 1 >= params.nWitnessForkHeight))
return ThresholdState::ACTIVE;
return VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params, cache.caches[pos]);
}

View file

@ -327,7 +327,7 @@ static CTransactionRef SendMoney(interfaces::Chain::Lock& locked_chain, CWallet
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
// Parse Bitcoin address
CScript scriptPubKey = prefix + GetScriptForDestination(address);
const CScript scriptPubKey = prefix + GetScriptForDestination(address);
// Create and send the transaction
CAmount nFeeRequired;
@ -369,7 +369,6 @@ thoritative as long as it remains unspent and there are no other greater unspent
"1. \"name\" (string, required) The name to be assigned the value.\n"
"2. \"value\" (string, required) The value to assign to the name encoded in hexadecimal.\n"
"3. \"amount\" (numeric, required) The amount in LBRYcrd to send. eg 0.1\n"
"4. \"address_type\" (string, optional) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is set by -addresstype.\n"
"\nResult:\n"
"\"transactionid\" (string) The transaction id.\n");
auto sName = request.params[0].get_str();
@ -393,13 +392,6 @@ thoritative as long as it remains unspent and there are no other greater unspent
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
OutputType output_type = pwallet->m_default_address_type;
if (request.params.size() > 3 && !request.params[3].isNull()) {
if (!ParseOutputType(request.params[3].get_str(), output_type)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[3].get_str()));
}
}
// pwallet->m_default_address_type == 0 (LEGACY), pwallet->m_default_change_type == 3 (AUTO)
pwallet->LearnRelatedScripts(newKey, output_type);
CTxDestination dest = GetDestinationForKey(newKey, output_type);
@ -427,7 +419,6 @@ UniValue updateclaim(const JSONRPCRequest& request)
"1. \"txid\" (string, required) The transaction containing the unspent txout which should be spent.\n"
"2. \"value\" (string, required) The value to assign to the name encoded in hexadecimal.\n"
"3. \"amount\" (numeric, required) The amount in LBRYcrd to use to bid for the name. eg 0.1\n"
"4. \"address_type\" (string, optional) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is set by -addresstype.\n"
"\nResult:\n"
"\"transactionid\" (string) The new transaction id.\n");
@ -481,11 +472,6 @@ UniValue updateclaim(const JSONRPCRequest& request)
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
OutputType output_type = pwallet->m_default_address_type;
if (request.params.size() > 3 && !request.params[3].isNull()) {
if (!ParseOutputType(request.params[3].get_str(), output_type)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[3].get_str()));
}
}
pwallet->LearnRelatedScripts(newKey, output_type);
CTxDestination dest = GetDestinationForKey(newKey, output_type);
@ -526,8 +512,7 @@ UniValue abandonclaim(const JSONRPCRequest& request)
uint256 hash;
hash.SetHex(request.params[0].get_str());
CKeyID address;
address.SetHex(request.params[1].get_str());
CTxDestination address = DecodeDestination(request.params[1].get_str());
pwallet->BlockUntilSyncedToCurrentChain();
LOCK2(cs_main, pwallet->cs_wallet);
@ -753,7 +738,6 @@ UniValue supportclaim(const JSONRPCRequest& request)
"2. \"claimid\" (string, required) The claimid of the claim to support.\n"
"3. \"amount\" (numeric, required) The amount in LBC to use to support the claim.\n"
"4. \"value\" (string, optional) The metadata of the support encoded in hexadecimal.\n"
"5. \"address_type\" (string, optional) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is set by -addresstype.\n"
"\nResult:\n"
"\"transactionid\" (string) The transaction id of the support.\n");
@ -797,11 +781,6 @@ UniValue supportclaim(const JSONRPCRequest& request)
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
OutputType output_type = pwallet->m_default_address_type;
if (request.params.size() > 4 && !request.params[4].isNull()) {
if (!ParseOutputType(request.params[4].get_str(), output_type)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[4].get_str()));
}
}
pwallet->LearnRelatedScripts(newKey, output_type);
CTxDestination dest = GetDestinationForKey(newKey, output_type);
@ -834,8 +813,7 @@ UniValue abandonsupport(const JSONRPCRequest& request)
uint256 hash;
hash.SetHex(request.params[0].get_str());
CKeyID address;
address.SetHex(request.params[1].get_str());
CTxDestination address = DecodeDestination(request.params[1].get_str());
pwallet->BlockUntilSyncedToCurrentChain();
LOCK2(cs_main, pwallet->cs_wallet);

View file

@ -150,9 +150,8 @@ uint256 AbandonAClaim(const uint256& txid, bool isSupport = false) {
}
void AddClaimSupportThenRemove() {
generateBlock(105);
BOOST_CHECK_EQUAL(AvailableBalance(), 5.0);
generateBlock(155);
BOOST_CHECK_EQUAL(AvailableBalance(), 55.0);
// ops for test: claimname, updateclaim, abandonclaim, listnameclaims, supportclaim, abandonsupport
// order of ops:
@ -170,7 +169,7 @@ void AddClaimSupportThenRemove() {
BOOST_CHECK_EQUAL(looked[0]["value"].get_str(), "deadbeef");
BOOST_CHECK_EQUAL(looked[0]["txid"].get_str(), txid.GetHex());
// udpate it
// update it
auto txid2 = ClaimAName(txid.GetHex(), "deadbeef02", "1.0", true);
auto g2 = generateBlock();
looked = LookupAllNames().get_array();
@ -276,4 +275,4 @@ BOOST_AUTO_TEST_CASE(claim_op_runthrough_bech32)
AddClaimSupportThenRemove();
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()