Skip to content

Commit cc4b98f

Browse files
committed
Merge #469: Add TX_TRUE output format, accept in wallet with anyonecanspendaremine
9908f9a Add TX_TRUE output format, accept in wallet with `anyonecanspendaremine` (Gregory Sanders)
2 parents 9196b70 + 9908f9a commit cc4b98f

File tree

9 files changed

+28
-0
lines changed

9 files changed

+28
-0
lines changed

src/chainparams.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class CMainParams : public CChainParams {
106106

107107
consensus.genesis_subsidy = 50*COIN;
108108
consensus.connect_genesis_outputs = false;
109+
anyonecanspend_aremine = false;
109110

110111
/**
111112
* The message start string is designed to be unlikely to occur in normal data.
@@ -223,6 +224,7 @@ class CTestNetParams : public CChainParams {
223224

224225
consensus.genesis_subsidy = 50*COIN;
225226
consensus.connect_genesis_outputs = false;
227+
anyonecanspend_aremine = false;
226228

227229
pchMessageStart[0] = 0x0b;
228230
pchMessageStart[1] = 0x11;
@@ -315,6 +317,7 @@ class CRegTestParams : public CChainParams {
315317

316318
consensus.genesis_subsidy = 50*COIN;
317319
consensus.connect_genesis_outputs = false;
320+
anyonecanspend_aremine = false;
318321

319322
pchMessageStart[0] = 0xfa;
320323
pchMessageStart[1] = 0xbf;
@@ -439,6 +442,8 @@ class CCustomParams : public CRegTestParams {
439442
// Custom chains connect coinbase outputs to db by default
440443
consensus.connect_genesis_outputs = gArgs.GetArg("-con_connect_coinbase", true);
441444

445+
anyonecanspend_aremine = gArgs.GetBoolArg("-anyonecanspendaremine", true);
446+
442447
nPruneAfterHeight = (uint64_t)args.GetArg("-npruneafterheight", nPruneAfterHeight);
443448
fDefaultConsistencyChecks = args.GetBoolArg("-fdefaultconsistencychecks", fDefaultConsistencyChecks);
444449
fMineBlocksOnDemand = args.GetBoolArg("-fmineblocksondemand", fMineBlocksOnDemand);

src/chainparams.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CChainParams
8080
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
8181
const CCheckpointData& Checkpoints() const { return checkpointData; }
8282
const ChainTxData& TxData() const { return chainTxData; }
83+
bool anyonecanspend_aremine;
8384
protected:
8485
CChainParams() {}
8586

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ void SetupServerArgs()
495495
CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE)), false, OptionsCategory::NODE_RELAY);
496496
gArgs.AddArg("-whitelistforcerelay", strprintf("Force relay of transactions from whitelisted peers even if they violate local relay policy (default: %d)", DEFAULT_WHITELISTFORCERELAY), false, OptionsCategory::NODE_RELAY);
497497
gArgs.AddArg("-whitelistrelay", strprintf("Accept relayed transactions received from whitelisted peers even when not relaying transactions (default: %d)", DEFAULT_WHITELISTRELAY), false, OptionsCategory::NODE_RELAY);
498+
gArgs.AddArg("-anyonecanspendaremine", strprintf("Treat OP_TRUE outputs as funds for the wallet. Default true for custom chains."), true, OptionsCategory::DEBUG_TEST);
498499

499500

500501
gArgs.AddArg("-blockmaxweight=<n>", strprintf("Set maximum BIP141 block weight (default: %d)", DEFAULT_BLOCK_MAX_WEIGHT), false, OptionsCategory::BLOCK_CREATION);

src/script/ismine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <keystore.h>
1010
#include <script/script.h>
1111
#include <script/sign.h>
12+
#include <chainparams.h>
1213

1314

1415
typedef std::vector<unsigned char> valtype;
@@ -163,6 +164,10 @@ IsMineResult IsMineInner(const CKeyStore& keystore, const CScript& scriptPubKey,
163164
}
164165
break;
165166
}
167+
case TX_TRUE:
168+
if (Params().anyonecanspend_aremine) {
169+
return IsMineResult::SPENDABLE;
170+
}
166171
}
167172

168173
if (ret == IsMineResult::NO && keystore.HaveWatchOnly(scriptPubKey)) {

src/script/sign.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <script/standard.h>
1212
#include <uint256.h>
1313

14+
#include <chainparams.h>
15+
1416
typedef std::vector<unsigned char> valtype;
1517

1618
MutableTransactionSignatureCreator::MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {}
@@ -157,6 +159,9 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
157159
}
158160
return false;
159161

162+
case TX_TRUE:
163+
return Params().anyonecanspend_aremine;
164+
160165
default:
161166
return false;
162167
}

src/script/standard.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <util.h>
1212
#include <utilstrencodings.h>
1313

14+
#include <chainparams.h>
15+
1416

1517
typedef std::vector<unsigned char> valtype;
1618

@@ -37,6 +39,7 @@ const char* GetTxnOutputType(txnouttype t)
3739
case TX_WITNESS_V0_KEYHASH: return "witness_v0_keyhash";
3840
case TX_WITNESS_V0_SCRIPTHASH: return "witness_v0_scripthash";
3941
case TX_WITNESS_UNKNOWN: return "witness_unknown";
42+
case TX_TRUE: return "true";
4043
}
4144
return nullptr;
4245
}
@@ -91,6 +94,11 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
9194
{
9295
vSolutionsRet.clear();
9396

97+
if (Params().anyonecanspend_aremine && scriptPubKey == CScript() << OP_TRUE) {
98+
typeRet = TX_TRUE;
99+
return true;
100+
}
101+
94102
// Shortcut for pay-to-script-hash, which are more constrained than the other types:
95103
// it is always OP_HASH160 20 [20 byte hash] OP_EQUAL
96104
if (scriptPubKey.IsPayToScriptHash())

src/script/standard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ enum txnouttype
6565
TX_WITNESS_V0_SCRIPTHASH,
6666
TX_WITNESS_V0_KEYHASH,
6767
TX_WITNESS_UNKNOWN, //!< Only for Witness versions not already defined above
68+
TX_TRUE, // For testing purposes only
6869
};
6970

7071
class CNoDestination {

test/bitcoin_functional/functional/test_framework/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def initialize_datadir(dirname, n, chain):
307307
f.write("printtoconsole=0\n")
308308
f.write("con_blocksubsidy=5000000000\n")
309309
f.write("con_connect_coinbase=0\n")
310+
f.write("anyonecanspendaremine=0\n")
310311
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
311312
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
312313
return datadir

test/functional/test_framework/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def initialize_datadir(dirname, n, chain):
307307
f.write("printtoconsole=0\n")
308308
f.write("con_blocksubsidy=5000000000\n")
309309
f.write("con_connect_coinbase=0\n")
310+
f.write("anyonecanspendaremine=0\n")
310311
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
311312
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
312313
return datadir

0 commit comments

Comments
 (0)