Skip to content

Commit

Permalink
Merge pull request #48 from frokenfreyja/master
Browse files Browse the repository at this point in the history
Updated service system
  • Loading branch information
gstefans authored Sep 14, 2020
2 parents 64f091e + d57952b commit ce7b057
Show file tree
Hide file tree
Showing 35 changed files with 3,112 additions and 824 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ BITCOIN_CORE_H = \
db.h \
richlistdb.h \
servicelistdb.h \
serviceitemlistdb.h \
hash.h \
init.h \
jeeq.h \
Expand Down Expand Up @@ -125,6 +126,7 @@ libbitcoin_server_a_SOURCES = \
noui.cpp \
richlistdb.cpp \
servicelistdb.cpp \
serviceitemlistdb.cpp \
rpcblockchain.cpp \
rpcmining.cpp \
rpcmisc.cpp \
Expand Down
148 changes: 117 additions & 31 deletions src/coins.cpp

Large diffs are not rendered by default.

86 changes: 64 additions & 22 deletions src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,34 @@ class CCoinsView
virtual bool SetAddressInfo(const CScript &key, const std::pair<int64_t,int> &value);

//Retrieve the balance of and height where a given scriptPubKey was last used.
virtual bool GetServiceInfo(const CScript &key, std::tuple<std::string, std::string, std::string> &value);
virtual bool GetServiceInfo(const std::string &key, std::tuple<std::string, std::string, std::string> &value);

//Modify the balance of and height where a given scriptPubKey was last used.
virtual bool SetServiceInfo(const CScript &key, const std::tuple<std::string, std::string, std::string> &value);
virtual bool SetServiceInfo(const std::string &key, const std::tuple<std::string, std::string, std::string> &value);

//Retrieve the balance of and height where a given scriptPubKey was last used - serviceaddressinfo
virtual bool GetServiceAddressInfo(const CScript &key, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);
//Retrieve the balance of and height where a given scriptPubKey was last used - serviceticketlist
virtual bool GetTicketList(const std::string &key, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);

//Modify the balance of and height where a given scriptPubKey was last used - serviceaddressinfo
virtual bool SetServiceAddressInfo(const CScript &key, const std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);
//Modify the balance of and height where a given scriptPubKey was last used - serviceticketlist
virtual bool SetTicketList(const std::string &key, const std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);

//Retrieve the balance of and height where a given scriptPubKey was last used - serviceubilist
virtual bool GetUbiList(const std::string &key, std::tuple<std::string, std::string> &value);

//Modify the balance of and height where a given scriptPubKey was last used - serviceubilist
virtual bool SetUbiList(const std::string &key, const std::tuple<std::string, std::string> &value);

//Retrieve the balance of and height where a given scriptPubKey was last used - servicedexlist
virtual bool GetDexList(const std::string &key, std::tuple<std::string, std::string, std::string> &value);

//Modify the balance of and height where a given scriptPubKey was last used - servicedexlist
virtual bool SetDexList(const std::string &key, const std::tuple<std::string, std::string, std::string> &value);

//Retrieve the balance of and height where a given scriptPubKey was last used - servicebooklist
virtual bool GetBookList(const std::string &key, std::tuple<std::string, std::string, std::string> &value);

//Modify the balance of and height where a given scriptPubKey was last used - servicebooklist
virtual bool SetBookList(const std::string &key, const std::tuple<std::string, std::string, std::string> &value);

//Just check whether we have data for a given txid.
virtual bool HaveCoins(const uint256 &txid);
Expand All @@ -241,8 +259,11 @@ class CCoinsView

//Do a bulk modification (multiple SetCoins + one SetBestBlock)
virtual bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, const std::map<CScript, std::pair<int64_t,int> > &mapAddressInfo,
const std::map<CScript, std::tuple<std::string, std::string, std::string> > &mapServiceInfo,
const std::map<CScript, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> > &mapServiceAddressInfo,
const std::map<std::string, std::tuple<std::string, std::string, std::string> > &mapServiceInfo,
const std::map<std::string, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> > &mapServiceTicketList,
const std::map<std::string, std::tuple<std::string, std::string> > &mapServiceUbiList,
const std::map<std::string, std::tuple<std::string, std::string, std::string> > &mapServiceDexList,
const std::map<std::string, std::tuple<std::string, std::string, std::string> > &mapServiceBookList,
const uint256 &hashBlock);

//Calculate statistics about the unspent transaction output set
Expand All @@ -265,17 +286,26 @@ class CCoinsViewBacked : public CCoinsView
bool SetCoins(const uint256 &txid, const CCoins &coins);
bool GetAddressInfo(const CScript &key, std::pair<int64_t,int> &value);
bool SetAddressInfo(const CScript &key, const std::pair<int64_t,int> &value);
bool GetServiceInfo(const CScript &key, std::tuple<std::string, std::string, std::string> &value);
bool SetServiceInfo(const CScript &key, const std::tuple<std::string, std::string, std::string> &value);
bool GetServiceAddressInfo(const CScript &key, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);
bool SetServiceAddressInfo(const CScript &key, const std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);
bool GetServiceInfo(const std::string &key, std::tuple<std::string, std::string, std::string> &value);
bool SetServiceInfo(const std::string &key, const std::tuple<std::string, std::string, std::string> &value);
bool GetTicketList(const std::string &key, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);
bool SetTicketList(const std::string &key, const std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);
bool GetUbiList(const std::string &key, std::tuple<std::string, std::string> &value);
bool SetUbiList(const std::string &key, const std::tuple<std::string, std::string> &value);
bool GetDexList(const std::string &key, std::tuple<std::string, std::string, std::string> &value);
bool SetDexList(const std::string &key, const std::tuple<std::string, std::string, std::string> &value);
bool GetBookList(const std::string &key, std::tuple<std::string, std::string, std::string> &value);
bool SetBookList(const std::string &key, const std::tuple<std::string, std::string, std::string> &value);
bool HaveCoins(const uint256 &txid);
uint256 GetBestBlock();
bool SetBestBlock(const uint256 &hashBlock);
void SetBackend(CCoinsView &viewIn);
bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, const std::map<CScript, std::pair<int64_t,int> > &mapAddressInfo,
const std::map<CScript, std::tuple<std::string, std::string, std::string> > &mapServiceInfo,
const std::map<CScript, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> > &mapServiceAddressInfo,
const std::map<std::string, std::tuple<std::string, std::string, std::string> > &mapServiceInfo,
const std::map<std::string, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> > &mapServiceTicketList,
const std::map<std::string, std::tuple<std::string, std::string> > &mapServiceUbiList,
const std::map<std::string, std::tuple<std::string, std::string, std::string> > &mapServiceDexList,
const std::map<std::string, std::tuple<std::string, std::string, std::string> > &mapServiceBookList,
const uint256 &hashBlock);
bool GetStats(CCoinsStats &stats);
};
Expand All @@ -288,8 +318,11 @@ class CCoinsViewCache : public CCoinsViewBacked
uint256 hashBlock;
std::map<uint256,CCoins> cacheCoins;
std::map<CScript, std::pair<int64_t,int> > cacheAddressInfo;
std::map<CScript, std::tuple<std::string, std::string, std::string> > cacheServiceInfo;
std::map<CScript, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> > cacheServiceAddressInfo;
std::map<std::string, std::tuple<std::string, std::string, std::string> > cacheServiceInfo;
std::map<std::string, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> > cacheServiceTicketList;
std::map<std::string, std::tuple<std::string, std::string> > cacheServiceUbiList;
std::map<std::string, std::tuple<std::string, std::string, std::string> > cacheServiceDexList;
std::map<std::string, std::tuple<std::string, std::string, std::string> > cacheServiceBookList;

public:
CCoinsViewCache(CCoinsView &baseIn, bool fDummy = false);
Expand All @@ -299,16 +332,25 @@ class CCoinsViewCache : public CCoinsViewBacked
bool SetCoins(const uint256 &txid, const CCoins &coins);
bool GetAddressInfo(const CScript &key, std::pair<int64_t,int> &value);
bool SetAddressInfo(const CScript &key, const std::pair<int64_t,int> &value);
bool GetServiceInfo(const CScript &key, std::tuple<std::string, std::string, std::string> &value);
bool SetServiceInfo(const CScript &key, const std::tuple<std::string, std::string, std::string> &value);
bool GetServiceAddressInfo(const CScript &key, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);
bool SetServiceAddressInfo(const CScript &key, const std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);
bool GetServiceInfo(const std::string &key, std::tuple<std::string, std::string, std::string> &value);
bool SetServiceInfo(const std::string &key, const std::tuple<std::string, std::string, std::string> &value);
bool GetTicketList(const std::string &key, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);
bool SetTicketList(const std::string &key, const std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> &value);
bool GetUbiList(const std::string &key, std::tuple<std::string, std::string> &value);
bool SetUbiList(const std::string &key, const std::tuple<std::string, std::string> &value);
bool GetDexList(const std::string &key, std::tuple<std::string, std::string, std::string> &value);
bool SetDexList(const std::string &key, const std::tuple<std::string, std::string, std::string> &value);
bool GetBookList(const std::string &key, std::tuple<std::string, std::string, std::string> &value);
bool SetBookList(const std::string &key, const std::tuple<std::string, std::string, std::string> &value);
bool HaveCoins(const uint256 &txid);
uint256 GetBestBlock();
bool SetBestBlock(const uint256 &hashBlock);
bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, const std::map<CScript, std::pair<int64_t,int> > &mapAddressInfo,
const std::map<CScript, std::tuple<std::string, std::string, std::string> > &mapServiceInfo,
const std::map<CScript, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> > &mapServiceAddressInfo,
const std::map<std::string, std::tuple<std::string, std::string, std::string> > &mapServiceInfo,
const std::map<std::string, std::tuple<std::string, std::string, std::string, std::string, std::string, std::string> > &mapServiceTicketList,
const std::map<std::string, std::tuple<std::string, std::string> > &mapServiceUbiList,
const std::map<std::string, std::tuple<std::string, std::string, std::string> > &mapServiceDexList,
const std::map<std::string, std::tuple<std::string, std::string, std::string> > &mapServiceBookList,
const uint256 &hashBlock);

//Return a modifiable reference to a CCoins. Check HaveCoins first.
Expand Down
111 changes: 99 additions & 12 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "util.h"
#include "richlistdb.h"
#include "servicelistdb.h"
#include "serviceitemlistdb.h"

#ifdef ENABLE_WALLET
#include "db.h"
Expand Down Expand Up @@ -60,6 +61,7 @@ CWallet* pwalletMain;

CRichList RichList;
CServiceList ServiceList;
CServiceItemList ServiceItemList;

// Used to pass flags to the Bind() function
enum BindFlags {
Expand Down Expand Up @@ -292,7 +294,7 @@ std::string HelpMessage(HelpMessageMode hmm)
strUsage += " -mintxfee=<amt> " + _("Fees smaller than this are considered zero fee (for transaction creation) (default:") + " " + FormatMoney(CTransaction::nMinTxFee) + ")" + "\n";
strUsage += " -minrelaytxfee=<amt> " + _("Fees smaller than this are considered zero fee (for relaying) (default:") + " " + FormatMoney(CTransaction::nMinRelayTxFee) + ")" + "\n";
strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n";
strUsage += " -datacarriersize " + strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY) + "\n";
strUsage += " -datacarriersize=<n> " + strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY) + "\n";
if (GetBoolArg("-help-debug", false))
{
strUsage += " -printblock=<hash> " + _("Print block on startup, if found in block index") + "\n";
Expand Down Expand Up @@ -868,8 +870,24 @@ bool AppInit2(boost::thread_group& threadGroup)
break;
}

if (!InitServiceInfoList(*pcoinsdbview)) {
strLoadError = _("Error initializing service info list. You need to rebuild the database using -reindex");

if (!InitServiceTicketList(*pcoinsdbview)) {
strLoadError = _("Error initializing service ticket list. You need to rebuild the database using -reindex");
break;
}

if (!InitServiceUbiList(*pcoinsdbview)) {
strLoadError = _("Error initializing service ubi list. You need to rebuild the database using -reindex");
break;
}

if (!InitServiceDexList(*pcoinsdbview)) {
strLoadError = _("Error initializing service dex list. You need to rebuild the database using -reindex");
break;
}

if (!InitServiceBookList(*pcoinsdbview)) {
strLoadError = _("Error initializing service book list. You need to rebuild the database using -reindex");
break;
}

Expand All @@ -885,9 +903,27 @@ bool AppInit2(boost::thread_group& threadGroup)
break;
}

// Reading service addresses into memory
if(!pcoinsdbview -> GetServiceAddressInfo(ServiceList)) {
strLoadError = _("Error loading service info list");
// Reading ticket addresses into memory
if(!pcoinsdbview -> GetTicketList(ServiceItemList)) {
strLoadError = _("Error loading service ticket list");
break;
}

// Reading ubi recipient addresses into memory
if(!pcoinsdbview -> GetUbiList(ServiceItemList)) {
strLoadError = _("Error loading service ubi list");
break;
}

// Reading dex addresses into memory
if(!pcoinsdbview -> GetDexList(ServiceItemList)) {
strLoadError = _("Error loading service dex list");
break;
}

// Reading book chapter addresses into memory
if(!pcoinsdbview -> GetBookList(ServiceItemList)) {
strLoadError = _("Error loading service book list");
break;
}

Expand Down Expand Up @@ -917,11 +953,32 @@ bool AppInit2(boost::thread_group& threadGroup)
ServiceList.SetForked(fFork);
}

if(!pblocktree -> ReadServiceInfoListFork(fFork)) {
strLoadError = _("Error reading service info list fork status");
if(!pblocktree -> ReadServiceTicketListFork(fFork)) {
strLoadError = _("Error reading service ticket list fork status");
break;
} else {
ServiceList.SetForked(fFork);
ServiceItemList.SetForked(fFork);
}

if(!pblocktree -> ReadServiceUbiListFork(fFork)) {
strLoadError = _("Error reading service ubi list fork status");
break;
} else {
ServiceItemList.SetForked(fFork);
}

if(!pblocktree -> ReadServiceDexListFork(fFork)) {
strLoadError = _("Error reading service dex list fork status");
break;
} else {
ServiceItemList.SetForked(fFork);
}

if(!pblocktree -> ReadServiceBookListFork(fFork)) {
strLoadError = _("Error reading service book chapter list fork status");
break;
} else {
ServiceItemList.SetForked(fFork);
}

uiInterface.InitMessage(_("Verifying blocks..."));
Expand Down Expand Up @@ -950,14 +1007,44 @@ bool AppInit2(boost::thread_group& threadGroup)
ServiceList.SetForked(false);
}
}

if(fFork) {
if(!ServiceItemList.UpdateTicketListHeights()) {
strLoadError = _("Error rollbacking ticket list heights");
break;
}
else {
ServiceItemList.SetForked(false);
}
}

if(fFork) {
if(!ServiceItemList.UpdateUbiListHeights()) {
strLoadError = _("Error rollbacking ubi list heights");
break;
}
else {
ServiceItemList.SetForked(false);
}
}

if(fFork) {
if(!ServiceItemList.UpdateDexListHeights()) {
strLoadError = _("Error rollbacking dex list heights");
break;
}
else {
ServiceItemList.SetForked(false);
}
}

if(fFork) {
if(!ServiceList.UpdateServiceAddressInfoHeights()) {
strLoadError = _("Error rollbacking service info list heights");
if(!ServiceItemList.UpdateBookListHeights()) {
strLoadError = _("Error rollbacking book chapter list heights");
break;
}
else {
ServiceList.SetForked(false);
ServiceItemList.SetForked(false);
}
}

Expand Down
Loading

0 comments on commit ce7b057

Please sign in to comment.