mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-06 21:19:35 +01:00
policy: Add OP_1 <0x4e73> as a standard output type
These outputs are called anchors, and allow key-less anchor spends which are vsize-minimized versus keyed anchors which require larger outputs when creating and inputs when spending.
This commit is contained in:
@@ -204,6 +204,23 @@ unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
|
||||
return subscript.GetSigOpCount(true);
|
||||
}
|
||||
|
||||
bool CScript::IsPayToAnchor() const
|
||||
{
|
||||
return (this->size() == 4 &&
|
||||
(*this)[0] == OP_1 &&
|
||||
(*this)[1] == 0x02 &&
|
||||
(*this)[2] == 0x4e &&
|
||||
(*this)[3] == 0x73);
|
||||
}
|
||||
|
||||
bool CScript::IsPayToAnchor(int version, const std::vector<unsigned char>& program)
|
||||
{
|
||||
return version == 1 &&
|
||||
program.size() == 2 &&
|
||||
program[0] == 0x4e &&
|
||||
program[1] == 0x73;
|
||||
}
|
||||
|
||||
bool CScript::IsPayToScriptHash() const
|
||||
{
|
||||
// Extra-fast test for pay-to-script-hash CScripts:
|
||||
|
||||
@@ -533,6 +533,14 @@ public:
|
||||
*/
|
||||
unsigned int GetSigOpCount(const CScript& scriptSig) const;
|
||||
|
||||
/*
|
||||
* OP_1 <0x4e73>
|
||||
*/
|
||||
bool IsPayToAnchor() const;
|
||||
/** Checks if output of IsWitnessProgram comes from a P2A output script
|
||||
*/
|
||||
static bool IsPayToAnchor(int version, const std::vector<unsigned char>& program);
|
||||
|
||||
bool IsPayToScriptHash() const;
|
||||
bool IsPayToWitnessScriptHash() const;
|
||||
bool IsWitnessProgram(int& version, std::vector<unsigned char>& program) const;
|
||||
|
||||
@@ -475,6 +475,9 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
|
||||
|
||||
case TxoutType::WITNESS_V1_TAPROOT:
|
||||
return SignTaproot(provider, creator, WitnessV1Taproot(XOnlyPubKey{vSolutions[0]}), sigdata, ret);
|
||||
|
||||
case TxoutType::ANCHOR:
|
||||
return true;
|
||||
} // no default case, so the compiler can warn about missing cases
|
||||
assert(false);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ std::string GetTxnOutputType(TxoutType t)
|
||||
case TxoutType::SCRIPTHASH: return "scripthash";
|
||||
case TxoutType::MULTISIG: return "multisig";
|
||||
case TxoutType::NULL_DATA: return "nulldata";
|
||||
case TxoutType::ANCHOR: return "anchor";
|
||||
case TxoutType::WITNESS_V0_KEYHASH: return "witness_v0_keyhash";
|
||||
case TxoutType::WITNESS_V0_SCRIPTHASH: return "witness_v0_scripthash";
|
||||
case TxoutType::WITNESS_V1_TAPROOT: return "witness_v1_taproot";
|
||||
@@ -165,6 +166,9 @@ TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned c
|
||||
vSolutionsRet.push_back(std::move(witnessprogram));
|
||||
return TxoutType::WITNESS_V1_TAPROOT;
|
||||
}
|
||||
if (scriptPubKey.IsPayToAnchor()) {
|
||||
return TxoutType::ANCHOR;
|
||||
}
|
||||
if (witnessversion != 0) {
|
||||
vSolutionsRet.push_back(std::vector<unsigned char>{(unsigned char)witnessversion});
|
||||
vSolutionsRet.push_back(std::move(witnessprogram));
|
||||
|
||||
@@ -22,6 +22,7 @@ template <typename C> class Span;
|
||||
enum class TxoutType {
|
||||
NONSTANDARD,
|
||||
// 'standard' transaction types:
|
||||
ANCHOR, //!< anyone can spend script
|
||||
PUBKEY,
|
||||
PUBKEYHASH,
|
||||
SCRIPTHASH,
|
||||
|
||||
Reference in New Issue
Block a user