|
22 | 22 | #include <script/script.h> |
23 | 23 | #include <uint256.h> |
24 | 24 | #include <util/chaintype.h> |
| 25 | +#include <util/moneystr.h> |
25 | 26 | #include <util/strencodings.h> |
26 | 27 | #include <issuance.h> |
27 | 28 | #include <deploymentinfo.h> |
@@ -249,6 +250,8 @@ class CMainParams : public CChainParams { |
249 | 250 | multi_data_permitted = false; |
250 | 251 | accept_discount_ct = false; |
251 | 252 | create_discount_ct = false; |
| 253 | + pegin_subsidy = PeginSubsidy(); |
| 254 | + pegin_minimum = PeginMinimum(); |
252 | 255 | consensus.has_parent_chain = false; |
253 | 256 | g_signed_blocks = false; |
254 | 257 | g_con_elementsmode = false; |
@@ -394,6 +397,8 @@ class CTestNetParams : public CChainParams { |
394 | 397 | multi_data_permitted = false; |
395 | 398 | accept_discount_ct = false; |
396 | 399 | create_discount_ct = false; |
| 400 | + pegin_subsidy = PeginSubsidy(); |
| 401 | + pegin_minimum = PeginMinimum(); |
397 | 402 | consensus.has_parent_chain = false; |
398 | 403 | g_signed_blocks = false; |
399 | 404 | g_con_elementsmode = false; |
@@ -557,6 +562,8 @@ class SigNetParams : public CChainParams { |
557 | 562 | multi_data_permitted = false; |
558 | 563 | accept_discount_ct = false; |
559 | 564 | create_discount_ct = false; |
| 565 | + pegin_subsidy = PeginSubsidy(); |
| 566 | + pegin_minimum = PeginMinimum(); |
560 | 567 | consensus.has_parent_chain = false; |
561 | 568 | g_signed_blocks = false; // lol |
562 | 569 | g_con_elementsmode = false; |
@@ -669,6 +676,8 @@ class CRegTestParams : public CChainParams |
669 | 676 | multi_data_permitted = false; |
670 | 677 | accept_discount_ct = false; |
671 | 678 | create_discount_ct = false; |
| 679 | + pegin_subsidy = PeginSubsidy(); |
| 680 | + pegin_minimum = PeginMinimum(); |
672 | 681 | consensus.has_parent_chain = false; |
673 | 682 | g_signed_blocks = false; |
674 | 683 | g_con_elementsmode = false; |
@@ -837,6 +846,38 @@ void UpdateActivationParametersFromArgs(const ArgsManager& args, Consensus::Par |
837 | 846 | } |
838 | 847 | } |
839 | 848 | } |
| 849 | +// ELEMENTS |
| 850 | +PeginSubsidy ParsePeginSubsidy(const ArgsManager& args) { |
| 851 | + PeginSubsidy pegin_subsidy; |
| 852 | + |
| 853 | + pegin_subsidy.height = args.GetIntArg("-peginsubsidyheight", std::numeric_limits<int>::max()); |
| 854 | + if (pegin_subsidy.height < 0) { |
| 855 | + throw std::runtime_error(strprintf("Invalid block height (%d) for -peginsubsidyheight. Must be positive.", pegin_subsidy.height)); |
| 856 | + } |
| 857 | + if (std::optional<CAmount> amount = ParseMoney(args.GetArg("-peginsubsidythreshold", "0"))) { |
| 858 | + pegin_subsidy.threshold = amount.value(); |
| 859 | + } else { |
| 860 | + throw std::runtime_error("Invalid -peginsubsidythreshold"); |
| 861 | + } |
| 862 | + |
| 863 | + return pegin_subsidy; |
| 864 | +}; |
| 865 | + |
| 866 | +PeginMinimum ParsePeginMinimum(const ArgsManager& args) { |
| 867 | + PeginMinimum pegin_minimum; |
| 868 | + |
| 869 | + pegin_minimum.height = args.GetIntArg("-peginminheight", std::numeric_limits<int>::max()); |
| 870 | + if (pegin_minimum.height < 0) { |
| 871 | + throw std::runtime_error(strprintf("Invalid block height (%d) for -peginminheight. Must be positive.", pegin_minimum.height)); |
| 872 | + } |
| 873 | + if (std::optional<CAmount> amount = ParseMoney(args.GetArg("-peginminamount", "0"))) { |
| 874 | + pegin_minimum.amount = amount.value(); |
| 875 | + } else { |
| 876 | + throw std::runtime_error("Invalid -peginminamount"); |
| 877 | + } |
| 878 | + |
| 879 | + return pegin_minimum; |
| 880 | +}; |
840 | 881 |
|
841 | 882 | /** |
842 | 883 | * Custom params for testing. |
@@ -976,6 +1017,11 @@ class CCustomParams : public CRegTestParams { |
976 | 1017 | consensus.start_p2wsh_script = args.GetIntArg("-con_start_p2wsh_script", consensus.start_p2wsh_script); |
977 | 1018 | create_discount_ct = args.GetBoolArg("-creatediscountct", create_discount_ct); |
978 | 1019 | accept_discount_ct = args.GetBoolArg("-acceptdiscountct", accept_discount_ct) || create_discount_ct; |
| 1020 | + pegin_subsidy = ParsePeginSubsidy(args); |
| 1021 | + pegin_minimum = ParsePeginMinimum(args); |
| 1022 | + if (pegin_subsidy.threshold < pegin_minimum.amount) { |
| 1023 | + throw std::runtime_error(strprintf("Peg-in subsidy threshold (%s) must be greater than or equal to peg-in minimum amount (%s)", FormatMoney(pegin_subsidy.threshold), FormatMoney(pegin_minimum.amount))); |
| 1024 | + } |
979 | 1025 |
|
980 | 1026 | // Calculate pegged Bitcoin asset |
981 | 1027 | std::vector<unsigned char> commit = CommitToArguments(consensus, m_chain_type.chain_name); |
@@ -1219,6 +1265,11 @@ class CLiquidV1Params : public CChainParams { |
1219 | 1265 | multi_data_permitted = true; |
1220 | 1266 | create_discount_ct = args.GetBoolArg("-creatediscountct", false); |
1221 | 1267 | accept_discount_ct = args.GetBoolArg("-acceptdiscountct", true) || create_discount_ct; |
| 1268 | + pegin_subsidy = ParsePeginSubsidy(args); |
| 1269 | + pegin_minimum = ParsePeginMinimum(args); |
| 1270 | + if (pegin_subsidy.threshold < pegin_minimum.amount) { |
| 1271 | + throw std::runtime_error(strprintf("Peg-in subsidy threshold (%s) must be greater than or equal to peg-in minimum amount (%s)", FormatMoney(pegin_subsidy.threshold), FormatMoney(pegin_minimum.amount))); |
| 1272 | + } |
1222 | 1273 |
|
1223 | 1274 | parentGenesisBlockHash = uint256S("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"); |
1224 | 1275 | const bool parent_genesis_is_null = parentGenesisBlockHash == uint256(); |
@@ -1574,6 +1625,11 @@ class CLiquidV1TestParams : public CLiquidV1Params { |
1574 | 1625 | multi_data_permitted = args.GetBoolArg("-multi_data_permitted", multi_data_permitted); |
1575 | 1626 | create_discount_ct = args.GetBoolArg("-creatediscountct", create_discount_ct); |
1576 | 1627 | accept_discount_ct = args.GetBoolArg("-acceptdiscountct", accept_discount_ct) || create_discount_ct; |
| 1628 | + pegin_subsidy = ParsePeginSubsidy(args); |
| 1629 | + pegin_minimum = ParsePeginMinimum(args); |
| 1630 | + if (pegin_subsidy.threshold < pegin_minimum.amount) { |
| 1631 | + throw std::runtime_error(strprintf("Peg-in subsidy threshold (%s) must be greater than or equal to peg-in minimum amount (%s)", FormatMoney(pegin_subsidy.threshold), FormatMoney(pegin_minimum.amount))); |
| 1632 | + } |
1577 | 1633 |
|
1578 | 1634 | if (args.IsArgSet("-parentgenesisblockhash")) { |
1579 | 1635 | parentGenesisBlockHash = uint256S(args.GetArg("-parentgenesisblockhash", "")); |
|
0 commit comments