Skip to content

Commit

Permalink
Merge pull request #124 from BlockMechanic/segwit
Browse files Browse the repository at this point in the history
hu
  • Loading branch information
BlockMechanic authored Oct 8, 2022
2 parents 6bf1e64 + f229bf0 commit 158ee31
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 6 additions & 7 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()){
Expand Down Expand Up @@ -287,16 +287,15 @@ 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())
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-unique-asset-convertable");
if(asset.isInflatable())
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-unique-asset-inflatable");
}

}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(static_cast<uint32_t>(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));
Expand Down
18 changes: 10 additions & 8 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <hash.h>
#include <tinyformat.h>
#include <util/strencodings.h>

#include <util/time.h>
#include <assert.h>

std::string GetVersionName(int nVersion)
Expand Down Expand Up @@ -206,8 +206,8 @@ std::vector<CTxDataBaseRef> DeepCopy(const std::vector<CTxDataBaseRef> &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
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<CTxIn> vin;
const std::vector<CTxOut> vout;
const std::vector<CTxOutAsset> vpout;
Expand Down Expand Up @@ -463,6 +466,7 @@ class CTransaction
/** A mutable version of CTransaction. */
struct CMutableTransaction
{
uint32_t nTime;
std::vector<CTxIn> vin;
std::vector<CTxOut> vout;
std::vector<CTxOutAsset> vpout;
Expand Down

0 comments on commit 158ee31

Please sign in to comment.