Allow default asset name to be set via param

This commit is contained in:
wintercooled 2018-07-12 18:51:49 +01:00
parent 5cea189932
commit dd39cc4f80
6 changed files with 13 additions and 11 deletions

View file

@ -37,7 +37,7 @@ void CAssetsDir::SetHex(const std::string& assetHex, const std::string& label)
Set(CAsset(uint256S(assetHex)), AssetMetadata(label));
}
void CAssetsDir::InitFromStrings(const std::vector<std::string>& assetsToInit)
void CAssetsDir::InitFromStrings(const std::vector<std::string>& assetsToInit, const std::string& pegged_asset_name)
{
for (std::string strToSplit : assetsToInit) {
std::vector<std::string> vAssets;
@ -48,7 +48,7 @@ void CAssetsDir::InitFromStrings(const std::vector<std::string>& assetsToInit)
SetHex(vAssets[0], vAssets[1]);
}
// Set "bitcoin" to the pegged asset for tests
Set(Params().GetConsensus().pegged_asset, AssetMetadata("bitcoin"));
Set(Params().GetConsensus().pegged_asset, AssetMetadata(pegged_asset_name));
}
CAsset CAssetsDir::GetAsset(const std::string& label) const

View file

@ -30,7 +30,7 @@ class CAssetsDir
void Set(const CAsset& asset, const AssetMetadata& metadata);
void SetHex(const std::string& assetHex, const std::string& label);
public:
void InitFromStrings(const std::vector<std::string>& assetsToInit);
void InitFromStrings(const std::vector<std::string>& assetsToInit, const std::string& pegged_asset_name);
/**
* @param label A label string

View file

@ -9,7 +9,7 @@
CAssetsDir _gAssetsDir;
const CAssetsDir& gAssetsDir = _gAssetsDir;
void InitGlobalAssetDir(const std::vector<std::string>& assetsToInit)
void InitGlobalAssetDir(const std::vector<std::string>& assetsToInit, const std::string& pegged_asset_name)
{
_gAssetsDir.InitFromStrings(assetsToInit);
_gAssetsDir.InitFromStrings(assetsToInit, pegged_asset_name);
}

View file

@ -12,6 +12,6 @@ class CAssetsDir;
extern const CAssetsDir& gAssetsDir;
void InitGlobalAssetDir(const std::vector<std::string>& assetsToInit);
void InitGlobalAssetDir(const std::vector<std::string>& assetsToInit, const std::string& pegged_asset_name);
#endif // BITCOIN_GLOBAL_COMMON_H

View file

@ -514,6 +514,7 @@ std::string HelpMessage(HelpMessageMode mode)
" " + _(" This creates a new chain with a different genesis block."));
strUsage += HelpMessageOpt("-peginconfirmationdepth", strprintf(_("Pegin claims must be this deep to be considered valid. (default: %d)"), DEFAULT_PEGIN_CONFIRMATION_DEPTH));
strUsage += HelpMessageOpt("-initialfreecoins", strprintf(_("The amount of OP_TRUE coins created in the genesis block. Primarily for testing. (default: %d)"), 0));
strUsage += HelpMessageOpt("-defaultpeggedassetname", strprintf("The name of the default asset created in the genesis block. (default: bitcoin)"));
strUsage += HelpMessageOpt("-parentpubkeyprefix", strprintf(_("The byte prefix, in decimal, of the parent chain's base58 pubkey address. (default: %d)"), 111));
strUsage += HelpMessageOpt("-parentscriptprefix", strprintf(_("The byte prefix, in decimal, of the parent chain's base58 script address. (default: %d)"), 196));
@ -1090,7 +1091,8 @@ bool AppInitParameterInteraction()
nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
try {
InitGlobalAssetDir(mapMultiArgs.count("-assetdir") > 0 ? mapMultiArgs.at("-assetdir") : std::vector<std::string>());
const std::string default_asset_name = GetArg("-defaultpeggedassetname", "bitcoin");
InitGlobalAssetDir(mapMultiArgs.count("-assetdir") > 0 ? mapMultiArgs.at("-assetdir") : std::vector<std::string>(), default_asset_name);
} catch (const std::exception& e) {
return InitError(strprintf("Error in -assetdir: %s\n", e.what()));
}

View file

@ -23,11 +23,11 @@ BOOST_AUTO_TEST_CASE(assetsdirTests)
for (std:: string protectedLabel : protectedLabels) {
std::vector<std::string> assetsToInitProtected = {exampleAssetHex + ":" + protectedLabel};
BOOST_CHECK_THROW(tAssetsDir.InitFromStrings(assetsToInitProtected), std::runtime_error);
BOOST_CHECK_THROW(tAssetsDir.InitFromStrings(assetsToInitProtected, defaultPeggedLabel), std::runtime_error);
}
const std::vector<std::string> exAssetsToInit = {exampleAssetHex + ":other"};
tAssetsDir.InitFromStrings(exAssetsToInit);
tAssetsDir.InitFromStrings(exAssetsToInit, defaultPeggedLabel);
BOOST_CHECK(exampleAsset == tAssetsDir.GetAsset("other"));
BOOST_CHECK_EQUAL("other", tAssetsDir.GetLabel(exampleAsset));
@ -37,10 +37,10 @@ BOOST_AUTO_TEST_CASE(assetsdirTests)
BOOST_CHECK(defaultPeggedAsset == tAssetsDir.GetAsset(tAssetsDir.GetLabel(CAsset(uint256S(defaultPeggedAssetHex)))));
const std::vector<std::string> assetsToInitRepeatedHex = {exampleAssetHex + ":other", exampleAssetHex + ":other2"};
BOOST_CHECK_THROW(tAssetsDir.InitFromStrings(assetsToInitRepeatedHex), std::runtime_error);
BOOST_CHECK_THROW(tAssetsDir.InitFromStrings(assetsToInitRepeatedHex, defaultPeggedLabel), std::runtime_error);
const std::vector<std::string> assetsToInitRepeatedLabel = {exampleAssetHex + ":other", defaultPeggedAssetHex + ":other"};
BOOST_CHECK_THROW(tAssetsDir.InitFromStrings(assetsToInitRepeatedLabel), std::runtime_error);
BOOST_CHECK_THROW(tAssetsDir.InitFromStrings(assetsToInitRepeatedLabel, defaultPeggedLabel), std::runtime_error);
}
BOOST_AUTO_TEST_SUITE_END()