diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 377b6b5af5b7..2d7910e34672 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -260,6 +260,9 @@ class CMainParams : public CChainParams { // Dash BIP32 prvkeys start with 'xprv' (Bitcoin defaults) base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4}; + // DIP-18 Dash Platform address HRP (bech32m) + bech32_platform_hrp = "dash"; + // Dash BIP44 coin type is '5' nExtCoinType = 5; @@ -452,6 +455,9 @@ class CTestNetParams : public CChainParams { // Testnet Dash BIP32 prvkeys start with 'tprv' (Bitcoin defaults) base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94}; + // DIP-18 Dash Platform address HRP (bech32m) + bech32_platform_hrp = "tdash"; + // Testnet Dash BIP44 coin type is '1' (All coin's testnet default) nExtCoinType = 1; @@ -625,6 +631,9 @@ class CDevNetParams : public CChainParams { // Testnet Dash BIP32 prvkeys start with 'tprv' (Bitcoin defaults) base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94}; + // DIP-18 Dash Platform address HRP (bech32m) + bech32_platform_hrp = "tdash"; + // Testnet Dash BIP44 coin type is '1' (All coin's testnet default) nExtCoinType = 1; @@ -900,6 +909,9 @@ class CRegTestParams : public CChainParams { // Regtest Dash BIP32 prvkeys start with 'tprv' (Bitcoin defaults) base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94}; + // DIP-18 Dash Platform address HRP (bech32m) + bech32_platform_hrp = "tdash"; + // Regtest Dash BIP44 coin type is '1' (All coin's testnet default) nExtCoinType = 1; diff --git a/src/chainparams.h b/src/chainparams.h index 7b5528b9b550..058570124306 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -124,6 +124,8 @@ class CChainParams /** Return the list of hostnames to look up for DNS seeds */ const std::vector& DNSSeeds() const { return vSeeds; } const std::vector& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; } + /** DIP-18 Platform address bech32m HRP: "dash" on mainnet, "tdash" on test chains */ + const std::string& Bech32PlatformHRP() const { return bech32_platform_hrp; } int ExtCoinType() const { return nExtCoinType; } const std::vector& FixedSeeds() const { return vFixedSeeds; } const CCheckpointData& Checkpoints() const { return checkpointData; } @@ -164,6 +166,7 @@ class CChainParams uint64_t m_assumed_chain_state_size; std::vector vSeeds; std::vector base58Prefixes[MAX_BASE58_TYPES]; + std::string bech32_platform_hrp; int nExtCoinType; std::string strNetworkID; CBlock genesis; diff --git a/src/evo/assetlocktx.cpp b/src/evo/assetlocktx.cpp index dace5ae1113d..2e391388f55b 100644 --- a/src/evo/assetlocktx.cpp +++ b/src/evo/assetlocktx.cpp @@ -23,25 +23,10 @@ using node::BlockManager; -/** - * Common code for Asset Lock and Asset Unlock - */ -bool CheckAssetLockUnlockTx(const BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null pindexPrev, const std::optional& indexes, TxValidationState& state) -{ - switch (tx.nType) { - case TRANSACTION_ASSET_LOCK: - return CheckAssetLockTx(tx, state); - case TRANSACTION_ASSET_UNLOCK: - return CheckAssetUnlockTx(blockman, qman, tx, pindexPrev, indexes, state); - default: - return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-not-asset-locks-at-all"); - } -} - /** * Asset Lock Transaction */ -bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state) +bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state, bool is_v24_active) { if (tx.nType != TRANSACTION_ASSET_LOCK) { return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-type"); @@ -71,6 +56,9 @@ bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state) if (opt_assetLockTx->getVersion() == 0 || opt_assetLockTx->getVersion() > CAssetLockPayload::CURRENT_VERSION) { return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-version"); } + if (!is_v24_active && opt_assetLockTx->getVersion() == CAssetLockPayload::CURRENT_VERSION) { + return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-version-2"); + } if (opt_assetLockTx->getCreditOutputs().empty()) { return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-emptycreditoutputs"); @@ -83,8 +71,14 @@ bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state) } creditOutputsAmount += out.nValue; - if (!out.scriptPubKey.IsPayToPublicKeyHash()) { - return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-pubKeyHash"); + if (opt_assetLockTx->getVersion() >= 2) { + if (!out.scriptPubKey.IsPayToPublicKeyHash() && !out.scriptPubKey.IsPayToScriptHash()) { + return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-script-pubkey"); + } + } else { + if (!out.scriptPubKey.IsPayToPublicKeyHash()) { + return state.Invalid(TxValidationResult::TX_BAD_SPECIAL, "bad-assetlocktx-pubKeyHash"); + } } } if (creditOutputsAmount != returnAmount) { diff --git a/src/evo/assetlocktx.h b/src/evo/assetlocktx.h index 0f3c688cd83c..09462734e1e4 100644 --- a/src/evo/assetlocktx.h +++ b/src/evo/assetlocktx.h @@ -28,7 +28,8 @@ class BlockManager; class CAssetLockPayload { public: - static constexpr uint8_t CURRENT_VERSION = 1; + static constexpr uint8_t INITIAL_VERSION = 1; + static constexpr uint8_t CURRENT_VERSION = 2; static constexpr auto SPECIALTX_TYPE = TRANSACTION_ASSET_LOCK; private: @@ -36,8 +37,8 @@ class CAssetLockPayload std::vector creditOutputs; public: - explicit CAssetLockPayload(const std::vector& creditOutputs) : - creditOutputs(creditOutputs) + explicit CAssetLockPayload(const std::vector& creditOutputs, uint8_t nVersion = CURRENT_VERSION) : + nVersion(nVersion), creditOutputs(creditOutputs) {} CAssetLockPayload() = default; @@ -154,9 +155,8 @@ class CAssetUnlockPayload } }; -bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state); +bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state, bool is_v24_active = false); bool CheckAssetUnlockTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null pindexPrev, const std::optional& indexes, TxValidationState& state); -bool CheckAssetLockUnlockTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null pindexPrev, const std::optional& indexes, TxValidationState& state); bool GetAssetUnlockFee(const CTransaction& tx, CAmount& txfee, TxValidationState& state); #endif // BITCOIN_EVO_ASSETLOCKTX_H diff --git a/src/evo/core_write.cpp b/src/evo/core_write.cpp index 1ccfc998840b..1f019b1cfecb 100644 --- a/src/evo/core_write.cpp +++ b/src/evo/core_write.cpp @@ -16,7 +16,9 @@ #include #include +#include #include +#include