Skip to content

Commit

Permalink
Merge pull request #155 from BlockMechanic/segwit
Browse files Browse the repository at this point in the history
Major
  • Loading branch information
BlockMechanic authored Oct 27, 2022
2 parents 8443138 + d229760 commit 19d4f8a
Show file tree
Hide file tree
Showing 50 changed files with 816 additions and 371 deletions.
8 changes: 4 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
AC_PREREQ([2.69])
define(_CLIENT_VERSION_MAJOR, 21)
define(_CLIENT_VERSION_MINOR, 99)
define(_CLIENT_VERSION_BUILD, 2)
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 18)
define(_CLIENT_VERSION_BUILD, 64)
define(_CLIENT_VERSION_RC, )
define(_CLIENT_VERSION_IS_RELEASE, false)
define(_COPYRIGHT_YEAR, 2021)
define(_COPYRIGHT_YEAR, 2022)
define(_COPYRIGHT_HOLDERS,[The %s developers])
define(_COPYRIGHT_HOLDERS_SUBSTITUTION,[[Crown Core]])
AC_INIT([Crown Core],m4_join([.], _CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MINOR, _CLIENT_VERSION_BUILD)m4_if(_CLIENT_VERSION_RC, [0], [], [rc]_CLIENT_VERSION_RC),[https://github.com/crown/crown/issues],[crown],[https://crown.org/])
Expand Down
3 changes: 3 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ QT_MOC_CPP = \
qt/moc_utilitydialog.cpp \
qt/moc_walletcontroller.cpp \
qt/moc_walletframe.cpp \
qt/moc_privatekeywidget.cpp \
qt/moc_createsystemnodedialog.cpp \
qt/moc_createmasternodedialog.cpp \
qt/moc_createnodedialog.cpp \
Expand Down Expand Up @@ -164,6 +165,7 @@ CROWN_QT_H = \
qt/masternodelist.h \
qt/systemnodelist.h \
qt/datetablewidgetitem.h \
qt/privatekeywidget.h \
qt/createsystemnodedialog.h \
qt/createmasternodedialog.h \
qt/createnodedialog.h \
Expand Down Expand Up @@ -298,6 +300,7 @@ CROWN_QT_WALLET_CPP = \
qt/walletframe.cpp \
qt/walletmodel.cpp \
qt/walletmodeltransaction.cpp \
qt/privatekeywidget.cpp \
qt/walletview.cpp

CROWN_QT_CPP = $(CROWN_QT_BASE_CPP)
Expand Down
2 changes: 0 additions & 2 deletions src/assetdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <lrucache.h>
#include <dbwrapper.h>

static size_t MAX_DATABASE_RESULTS = 50000;

class CCoinsViewCache;

class CAssetData
Expand Down
10 changes: 6 additions & 4 deletions src/base58.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ NODISCARD static bool DecodeBase58(const char* psz, std::vector<unsigned char>&
int length = 0;
while (*psz == '1') {
zeroes++;
if (zeroes > max_ret_len) return false;
//if (zeroes > max_ret_len) return false;
psz++;
}
// Allocate enough space in big-endian base256 representation.
Expand All @@ -56,8 +56,9 @@ NODISCARD static bool DecodeBase58(const char* psz, std::vector<unsigned char>&
while (*psz && !IsSpace(*psz)) {
// Decode base58 character
int carry = mapBase58[(uint8_t)*psz];
if (carry == -1) // Invalid b58 character
if (carry == -1) { // Invalid b58 character
return false;
}
int i = 0;
for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); (carry != 0 || i < length) && (it != b256.rend()); ++it, ++i) {
carry += 58 * (*it);
Expand All @@ -66,14 +67,15 @@ NODISCARD static bool DecodeBase58(const char* psz, std::vector<unsigned char>&
}
assert(carry == 0);
length = i;
if (length + zeroes > max_ret_len) return false;
//if (length + zeroes > max_ret_len) return false;
psz++;
}
// Skip trailing spaces.
while (IsSpace(*psz))
psz++;
if (*psz != 0)
if (*psz != 0){
return false;
}
// Skip leading zeroes in b256.
std::vector<unsigned char>::iterator it = b256.begin() + (size - length);
// Copy result into output vector.
Expand Down
18 changes: 5 additions & 13 deletions src/blockfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,11 @@ static GCSFilter::ElementSet BasicFilterElements(const CBlock& block,
GCSFilter::ElementSet elements;

for (const CTransactionRef& tx : block.vtx) {
if(tx->nVersion >= TX_ELE_VERSION){
for (const CTxOutAsset& txout : tx->vpout) {
const CScript& script = txout.scriptPubKey;
if (script.empty() || script[0] == OP_RETURN) continue;
elements.emplace(script.begin(), script.end());
}
}
else {
for (const CTxOut& txout : tx->vout) {
const CScript& script = txout.scriptPubKey;
if (script.empty() || script[0] == OP_RETURN) continue;
elements.emplace(script.begin(), script.end());
}
for (size_t o = 0; o < (tx->nVersion >= TX_ELE_VERSION ? tx->vpout.size() : tx->vout.size()); o++) {
const CTxOutAsset &txout = (tx->nVersion >= TX_ELE_VERSION ? tx->vpout[o] : tx->vout[o]);
const CScript& script = txout.scriptPubKey;
if (script.empty() || script[0] == OP_RETURN) continue;
elements.emplace(script.begin(), script.end());
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <util/strencodings.h>
#include <versionbitsinfo.h>
#include <arith_uint256.h>
#include <boost/assign/list_of.hpp>
#include <assert.h>

#include <boost/algorithm/string/classification.hpp>
Expand Down Expand Up @@ -58,7 +59,7 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi
* CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
* CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
* CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
* CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
* CTxOutAsset(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
* vMerkleTree: 4a5e1e
*/
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward, Consensus::Params& consensus)
Expand Down Expand Up @@ -316,9 +317,16 @@ class CTestNetParams : public CChainParams {
vSeeds.emplace_back("92.60.46.29");
vSeeds.emplace_back("92.60.46.30");
vSeeds.emplace_back("92.60.46.31");

base58Prefixes[PUBKEY_ADDRESS] = {0x01, 0x7A, 0xCD, 0x67};
base58Prefixes[SCRIPT_ADDRESS] = {0x01, 0x7A, 0xCD, 0x51};

// Testnet crown addresses start with 'tCRW'
//base58Prefixes[PUBKEY_ADDRESS] = boost::assign::list_of(0x01)(0x7A)(0xCD)(0x67).convert_to_container<std::vector<unsigned char> >();
// Testnet crown script addresses start with 'tCRM'
//base58Prefixes[SCRIPT_ADDRESS] = boost::assign::list_of(0x01)(0x7A)(0xCD)(0x51).convert_to_container<std::vector<unsigned char> >();


base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
Expand Down
11 changes: 10 additions & 1 deletion src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,17 @@ class CChainParams
bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; }
/** Return the network string */
std::string NetworkIDString() const { return strNetworkID; }
const std::vector<unsigned char>& Base58Prefix(Base58Type type, AddressType addressType = NEW_ADDRESS_TYPE) const
{
if (addressType == DEPRECATED_ADDRESS_TYPE)
{
return base58PrefixesOld[type];
}
return base58Prefixes[type];
}
/** Return the list of hostnames to look up for DNS seeds */
const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
//const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
const std::string& Bech32HRP() const { return bech32_hrp; }
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
const CCheckpointData& Checkpoints() const { return checkpointData; }
Expand Down Expand Up @@ -124,6 +132,7 @@ class CChainParams
CAmount nMasternodeCollateral;
CAmount nSystemnodeCollateral;
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
std::vector<unsigned char> base58PrefixesOld[MAX_BASE58_TYPES];
std::string bech32_hrp;
std::string strNetworkID;
CBlock genesis;
Expand Down
4 changes: 1 addition & 3 deletions src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@
*
* Serialized format:
* - VARINT((coinbase ? 1 : 0) | (height << 1))
* - the non-spent CTxOut (via TxOutCompression)
* - the non-spent CTxOutAsset (via TxOutAssetCompression)
*/
class Coin
{
public:
//! unspent transaction output
//CTxOut out;
//! newer unspent transaction output
CTxOutAsset out;

//! whether containing transaction was a coinbase
Expand Down
2 changes: 2 additions & 0 deletions src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ int ParseSighashString(const UniValue& sighash);
// core_write.cpp
UniValue ValueFromAmount(const CAmount& amount);
UniValue ValueFromAmountMap(const CAmountMap& amount);
void AmountMapToUniv(const CAmountMap& balanceOrig, UniValue &entry);

std::string FormatScript(const CScript& script);
std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
std::string SighashToStr(unsigned char sighash_type);
Expand Down
8 changes: 8 additions & 0 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,11 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
entry.pushKV("hex", EncodeHexTx(tx, serialize_flags)); // The hex-encoded transaction. Used the name "hex" to be consistent with the verbose output of "getrawtransaction".
}
}

void AmountMapToUniv(const CAmountMap& balanceOrig, UniValue &entry)
{
// Make sure the policyAsset is always present in the balance map.
for(auto it = balanceOrig.begin(); it != balanceOrig.end(); ++it)
entry.pushKV(it->first.getAssetName(), ValueFromAmount(it->second));

}
2 changes: 0 additions & 2 deletions src/crown/nodewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ void NodeMinter(const CChainParams& chainparams, CConnman& connman)

LogPrintf("%s: Attempting to stake..\n", __func__);

unsigned int nExtraNonce = 0;

//
// Create new block
//
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
DumpContracts();
}, DUMP_BANS_INTERVAL);

node.scheduler->scheduleEvery(std::bind(&ThreadNodeSync, std::ref(*node.connman)), std::chrono::seconds{60});
node.scheduler->scheduleEvery(std::bind(&ThreadNodeSync, std::ref(*node.connman)), std::chrono::seconds{10});
node.scheduler->scheduleEvery(std::bind(&NodeMinter, std::ref(Params()), std::ref(*node.connman)), std::chrono::seconds{60});

#if HAVE_SYSTEM
Expand Down
48 changes: 13 additions & 35 deletions src/insight/addressindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#ifndef CROWN_ADDRESSINDEX_H
#define CROWN_ADDRESSINDEX_H

#include "uint256.h"
#include "amount.h"
#include <primitives/asset.h>
#include <chrono>

enum AddressIndexType {
Expand All @@ -22,19 +21,22 @@ struct CMempoolAddressDelta
{
std::chrono::seconds time;
CAmount amount;
CAsset asset;
uint256 prevhash;
unsigned int prevout;

CMempoolAddressDelta(std::chrono::seconds t, CAmount a, uint256 hash, unsigned int out) {
CMempoolAddressDelta(std::chrono::seconds t, CAmount a, CAsset at, uint256 hash, unsigned int out) {
time = t;
amount = a;
asset = at;
prevhash = hash;
prevout = out;
}

CMempoolAddressDelta(std::chrono::seconds t, CAmount a) {
CMempoolAddressDelta(std::chrono::seconds t, CAmount a, CAsset at) {
time = t;
amount = a;
asset = at;
prevhash.SetNull();
prevout = 0;
}
Expand All @@ -44,66 +46,42 @@ struct CMempoolAddressDeltaKey
{
int type;
uint160 addressBytes;
std::string asset;
uint256 txhash;
unsigned int index;
int spending;

CMempoolAddressDeltaKey(int addressType, uint160 addressHash, std::string sAssetName,
CMempoolAddressDeltaKey(int addressType, uint160 addressHash,
uint256 hash, unsigned int i, int s) {
type = addressType;
addressBytes = addressHash;
asset = sAssetName;
txhash = hash;
index = i;
spending = s;
}

CMempoolAddressDeltaKey(int addressType, uint160 addressHash, uint256 hash, unsigned int i, int s) {
type = addressType;
addressBytes = addressHash;
asset = "";
txhash = hash;
index = i;
spending = s;
}

CMempoolAddressDeltaKey(int addressType, uint160 addressHash, std::string sAssetName) {
type = addressType;
addressBytes = addressHash;
asset = sAssetName;
txhash.SetNull();
index = 0;
spending = 0;
}

CMempoolAddressDeltaKey(int addressType, uint160 addressHash) {
type = addressType;
addressBytes = addressHash;
asset = "";
txhash.SetNull();
index = 0;
spending = 0;
}

};

struct CMempoolAddressDeltaKeyCompare
{
bool operator()(const CMempoolAddressDeltaKey& a, const CMempoolAddressDeltaKey& b) const {
if (a.type == b.type) {
if (a.addressBytes == b.addressBytes) {
if (a.asset == b.asset) {
if (a.txhash == b.txhash) {
if (a.index == b.index) {
return a.spending < b.spending;
} else {
return a.index < b.index;
}
if (a.txhash == b.txhash) {
if (a.index == b.index) {
return a.spending < b.spending;
} else {
return a.txhash < b.txhash;
return a.index < b.index;
}
} else {
return a.asset < b.asset;
return a.txhash < b.txhash;
}
} else {
return a.addressBytes < b.addressBytes;
Expand Down
4 changes: 2 additions & 2 deletions src/insight/balanceindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef PARTICL_INSIGHT_BALANCEINDEX_H
#define PARTICL_INSIGHT_BALANCEINDEX_H
#ifndef CROWN_INSIGHT_BALANCEINDEX_H
#define CROWN_INSIGHT_BALANCEINDEX_H

enum BalanceIndexType {
BAL_IND_PLAIN_ADDED = 0,
Expand Down
10 changes: 5 additions & 5 deletions src/insight/insight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,26 @@ bool HashOnchainActive(const uint256 &hash)
return true;
};

bool GetAddressIndex(uint160 addressHash, int type, std::string sAssetName,
std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex, int start, int end)
bool GetAddressIndex(uint160 addressHash, int type, CAsset asset,
std::vector<std::pair<CAddressIndexKey, CAmountMap> > &addressIndex, int start, int end)
{
if (!fAddressIndex) {
return error("Address index not enabled");
}
if (!pblocktree->ReadAddressIndex(addressHash, type, sAssetName, addressIndex, start, end)) {
if (!pblocktree->ReadAddressIndex(addressHash, type, asset, addressIndex, start, end)) {
return error("Unable to get txids for address");
}

return true;
};

bool GetAddressUnspent(uint160 addressHash, int type, std::string sAssetName,
bool GetAddressUnspent(uint160 addressHash, int type, CAsset asset,
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs)
{
if (!fAddressIndex) {
return error("Address index not enabled");
}
if (!pblocktree->ReadAddressUnspentIndex(addressHash, type, sAssetName, unspentOutputs)) {
if (!pblocktree->ReadAddressUnspentIndex(addressHash, type, asset, unspentOutputs)) {
return error("Unable to get txids for address");
}

Expand Down
6 changes: 3 additions & 3 deletions src/insight/insight.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ bool ExtractIndexInfo(const CTxOutAsset *out, int &scriptType, std::vector<uint8
/** Functions for insight block explorer */
bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, const bool fActiveOnly, std::vector<std::pair<uint256, unsigned int> > &hashes) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value, const CTxMemPool *pmempool);
bool GetAddressIndex(uint160 addressHash, int type, std::string sAssetName,
std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
bool GetAddressIndex(uint160 addressHash, int type, CAsset asset,
std::vector<std::pair<CAddressIndexKey, CAmountMap> > &addressIndex,
int start = 0, int end = 0);
bool GetAddressUnspent(uint160 addressHash, int type, std::string sAssetName,
bool GetAddressUnspent(uint160 addressHash, int type, CAsset asset,
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs);
bool GetBlockBalances(const uint256 &block_hash, BlockBalances &balances);

Expand Down
Loading

0 comments on commit 19d4f8a

Please sign in to comment.