From f229bf024c137042ee81c10878ececf5081c8777 Mon Sep 17 00:00:00 2001 From: Block Mechanic Date: Sat, 8 Oct 2022 10:14:28 +0200 Subject: [PATCH] hu --- src/chainparams.cpp | 4 ++-- src/consensus/tx_verify.cpp | 13 ++++++------- src/core_write.cpp | 1 + src/primitives/transaction.cpp | 18 ++++++++++-------- src/primitives/transaction.h | 4 ++++ 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 33a85bb..397a7fe 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -301,10 +301,10 @@ class CTestNetParams : public CChainParams { CScript genscript(addrdata.begin(), addrdata.end()); consensus.mandatory_coinbase_destination = genscript; - genesis = CreateGenesisBlock(1664765986, 1228706, 0x1e0ffff0, 1, 10 * COIN, consensus); + genesis = CreateGenesisBlock(1665209637, 1291742, 0x1e0ffff0, 1, 10 * COIN, consensus); consensus.hashGenesisBlock = genesis.GetHash(); //MineNewGenesisBlock(consensus,genesis); - assert(consensus.hashGenesisBlock == uint256S("0x0000088d8804246e37801de245cda22e8a6e3423274ec87e471313c0837e1336")); + assert(consensus.hashGenesisBlock == uint256S("0x0000074199258f0ec4e3581587324f8acb3ff4e757e55292ff5ccbdc2e6de892")); assert(genesis.hashMerkleRoot == uint256S("0x80ad356118a9ab8db192db66ef77146cc36d958f959251feace550e4ca3d1446")); vFixedSeeds.clear(); diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp index 5062a21..bfb51dd 100644 --- a/src/consensus/tx_verify.cpp +++ b/src/consensus/tx_verify.cpp @@ -240,17 +240,17 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state, //Asset exists , check for output rules if (exists && asset != subsidy_asset) { // check asset limited -/* + if(asset.isLimited() && inputAssets.begin()->first != asset) return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-output-asset-is-limited", strprintf("cannot convert other assets to (%s)", asset.getAssetName())); -*/ + // check asset restricted // get contract hash, retrieve contract, get issuer , compare input address to issueraddress const CContract &contract = GetContractByHash(asset.contract_hash); -/* + if(contract.IsEmpty()) return state.Invalid(TxValidationResult::TX_CONSENSUS, "contract-not-found", strprintf("contract retrieval failed %s", asset.contract_hash.ToString())); -*/ + CTxDestination address1; ExtractDestination(input_addresses.front(), address1); if(asset.isRestricted()){ @@ -287,8 +287,8 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state, if(assetNameExists(asset.getAssetName()) || assetNameExists(asset.getShortName())) return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-asset-name", strprintf("asset name/shortname %s / %s already in use", asset.getAssetName(), asset.getShortName())); - // if(asset.nExpiry != 0 && asset.nExpiry < tx.nTime + 84000)// TODO (Why on earth do transactions not have time ? - // return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-asset-expiry"); + if(asset.nExpiry != 0 && asset.nExpiry < tx.nTime)// TODO (Why on earth do transactions not have time ? + return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-asset-expiry"); if(asset.nType == 2){ if(asset.isConvertable()) @@ -296,7 +296,6 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state, if(asset.isInflatable()) return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-unique-asset-inflatable"); } - } } } diff --git a/src/core_write.cpp b/src/core_write.cpp index 3204947..ed33fc0 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -250,6 +250,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, // Transaction version is actually unsigned in consensus checks, just signed in memory, // so cast to unsigned before giving it to the user. entry.pushKV("version", static_cast(static_cast(tx.nVersion))); + entry.pushKV("time", (int64_t)tx.nTime); entry.pushKV("size", (int)::GetSerializeSize(tx, PROTOCOL_VERSION)); entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR); entry.pushKV("weight", GetTransactionWeight(tx)); diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 8a0ddbd..4f9327a 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -9,7 +9,7 @@ #include #include #include - +#include #include std::string GetVersionName(int nVersion) @@ -206,8 +206,8 @@ std::vector DeepCopy(const std::vector &from) return vdata; } -CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nType(TRANSACTION_NORMAL), nLockTime(0) {} -CMutableTransaction::CMutableTransaction(const CTransaction& tx) : vin(tx.vin), vout(tx.vout), vpout(tx.vpout), vdata{DeepCopy(tx.vdata)}, nVersion(tx.nVersion), nType(tx.nType), nLockTime(tx.nLockTime), extraPayload(tx.extraPayload), witness(tx.witness) {} +CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nType(TRANSACTION_NORMAL), nTime(GetTime()), nLockTime(0) {} +CMutableTransaction::CMutableTransaction(const CTransaction& tx) : vin(tx.vin), vout(tx.vout), vpout(tx.vpout), vdata{DeepCopy(tx.vdata)}, nVersion(tx.nVersion), nType(tx.nType), nTime(tx.nTime), nLockTime(tx.nLockTime), extraPayload(tx.extraPayload), witness(tx.witness) {} uint256 CMutableTransaction::GetHash() const { @@ -244,9 +244,9 @@ uint256 CTransaction::GetWitnessOnlyHash() const } /* For backward compatibility, the hash is initialized to 0. TODO: remove the need for this default constructor entirely. */ -CTransaction::CTransaction() : vin(), vout(), nVersion(CTransaction::CURRENT_VERSION), nType(TRANSACTION_NORMAL), nLockTime(0), hash{}, m_witness_hash{} {} -CTransaction::CTransaction(const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), vpout(tx.vpout), vdata{DeepCopy(tx.vdata)}, nVersion(tx.nVersion), nType(tx.nType), nLockTime(tx.nLockTime), extraPayload(tx.extraPayload), witness(tx.witness), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {ComputeHash();} -CTransaction::CTransaction(CMutableTransaction&& tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), vpout(std::move(tx.vpout)), vdata(std::move(tx.vdata)), nVersion(tx.nVersion), nType(tx.nType), nLockTime(tx.nLockTime), extraPayload(tx.extraPayload), witness(std::move(tx.witness)), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {ComputeHash();} +CTransaction::CTransaction() : vin(), vout(), nVersion(CTransaction::CURRENT_VERSION), nType(TRANSACTION_NORMAL), nTime(0), nLockTime(0), hash{}, m_witness_hash{} {} +CTransaction::CTransaction(const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), vpout(tx.vpout), vdata{DeepCopy(tx.vdata)}, nVersion(tx.nVersion), nType(tx.nType), nTime(tx.nTime), nLockTime(tx.nLockTime), extraPayload(tx.extraPayload), witness(tx.witness), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {ComputeHash();} +CTransaction::CTransaction(CMutableTransaction&& tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), vpout(std::move(tx.vpout)), vdata(std::move(tx.vdata)), nVersion(tx.nVersion), nType(tx.nType), nTime(tx.nTime), nLockTime(tx.nLockTime), extraPayload(tx.extraPayload), witness(std::move(tx.witness)), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {ComputeHash();} CAmount CTransaction::GetValueOut() const { @@ -295,10 +295,11 @@ bool CTransaction::IsCoinStake() const std::string CTransaction::ToString() const { std::string str; - str += strprintf("CTransaction(hash=%s, ver=%d, type=%d, vin.size=%u, vout.size=%u, nLockTime=%u, extraPayload.size=%d)\n", + str += strprintf("CTransaction(hash=%s, ver=%d, type=%d, nTime=%d, vin.size=%u, vout.size=%u, nLockTime=%u, extraPayload.size=%d)\n", GetHash().ToString().substr(0,10), nVersion, nType, + nTime, vin.size(), (nVersion >= TX_ELE_VERSION ? vpout.size() : vout.size()), nLockTime, @@ -319,10 +320,11 @@ std::string CTransaction::ToString() const std::string CMutableTransaction::ToString() const { std::string str; - str += strprintf("CTransaction(hash=%s, ver=%d, type=%d, vin.size=%u, vout.size=%u, nLockTime=%u, vExtraPayload.size=%d)\n", + str += strprintf("CTransaction(hash=%s, ver=%d, type=%d, nTime=%d, vin.size=%u, vout.size=%u, nLockTime=%u, vExtraPayload.size=%d)\n", GetHash().ToString().substr(0,10), nVersion, nType, + nTime, vin.size(), (nVersion >= TX_ELE_VERSION ? vpout.size() : vout.size()), nLockTime, diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index b247aa8..19d88ea 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -276,6 +276,7 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) { } else { s >> flags; + s >> tx.nTime; s >> tx.vin; s >> tx.vpout; s >> tx.nLockTime; @@ -343,6 +344,7 @@ inline void SerializeTransaction(const TxType& tx, Stream& s) { } s << flags; + s << tx.nTime; s << tx.vin; s << tx.vpout; s << tx.nLockTime; @@ -377,6 +379,7 @@ class CTransaction // actually immutable; deserialization and assignment are implemented, // and bypass the constness. This is safe, as they update the entire // structure, including the hash. + const uint32_t nTime; const std::vector vin; const std::vector vout; const std::vector vpout; @@ -463,6 +466,7 @@ class CTransaction /** A mutable version of CTransaction. */ struct CMutableTransaction { + uint32_t nTime; std::vector vin; std::vector vout; std::vector vpout;