From b76b0b22702276875ee52ea3cc61fd90ef0f5202 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Thu, 17 Aug 2017 15:18:25 -0700 Subject: [PATCH] Change network settings commitment to sha2, include in asset type def --- contrib/assets_tutorial/assets_tutorial.py | 2 +- contrib/assets_tutorial/assets_tutorial.sh | 2 +- src/chainparams.cpp | 24 ++++++++++++---------- src/wallet/rpcwallet.cpp | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/contrib/assets_tutorial/assets_tutorial.py b/contrib/assets_tutorial/assets_tutorial.py index 2e55882768..29fdc4c057 100755 --- a/contrib/assets_tutorial/assets_tutorial.py +++ b/contrib/assets_tutorial/assets_tutorial.py @@ -211,7 +211,7 @@ e1.dumpassetlabels() # You can also filter calls using specific asset hex or labels: e1.getwalletinfo("bitcoin") # bitcoin's hex asset type -e1.getwalletinfo("694d95345fcd292329b5fb4e465a48484c7e218f4d4f1f7a3bfea26dd2d8fc3d") +e1.getwalletinfo("b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23") # We can also issue our own assets, 1 asset and 1 reissuance token in this case issue = e1.issueasset(1, 1) diff --git a/contrib/assets_tutorial/assets_tutorial.sh b/contrib/assets_tutorial/assets_tutorial.sh index c058517d15..52f1402672 100755 --- a/contrib/assets_tutorial/assets_tutorial.sh +++ b/contrib/assets_tutorial/assets_tutorial.sh @@ -144,7 +144,7 @@ e1-cli dumpassetlabels # You can also filter calls using specific asset hex or labels: e1-cli getwalletinfo bitcoin # bitcoin's hex asset type -e1-cli getwalletinfo 694d95345fcd292329b5fb4e465a48484c7e218f4d4f1f7a3bfea26dd2d8fc3d +e1-cli getwalletinfo b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23 # We can also issue our own assets, 1 asset and 1 reissuance token in this case ISSUE=$(e1-cli issueasset 1 1) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 1dc9f63693..a0f725d0db 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -11,7 +11,7 @@ #include "util.h" #include "utilstrencodings.h" #include "amount.h" -#include "crypto/ripemd160.h" +#include "crypto/sha256.h" #include @@ -22,13 +22,13 @@ // Safer for users if they load incorrect parameters via arguments. static std::vector CommitToArguments(const Consensus::Params& params, const std::string& networkID, const CScript& signblockscript) { - CRIPEMD160 ripemd; - unsigned char commitment[20]; - ripemd.Write((const unsigned char*)networkID.c_str(), networkID.length()); - ripemd.Write((const unsigned char*)HexStr(params.fedpegScript).c_str(), HexStr(params.fedpegScript).length()); - ripemd.Write((const unsigned char*)HexStr(signblockscript).c_str(), HexStr(signblockscript).length()); - ripemd.Finalize(commitment); - return std::vector(commitment, commitment + 20); + CSHA256 sha2; + unsigned char commitment[32]; + sha2.Write((const unsigned char*)networkID.c_str(), networkID.length()); + sha2.Write((const unsigned char*)HexStr(params.fedpegScript).c_str(), HexStr(params.fedpegScript).length()); + sha2.Write((const unsigned char*)HexStr(signblockscript).c_str(), HexStr(signblockscript).length()); + sha2.Finalize(commitment); + return std::vector(commitment, commitment + 32); } static CScript StrHexToScriptWithDefault(std::string strScript, const CScript defaultScript) @@ -50,9 +50,9 @@ static CBlock CreateGenesisBlock(const Consensus::Params& params, const std::str CMutableTransaction txNew; txNew.nVersion = 1; txNew.vin.resize(1); + txNew.vout.resize(rewardShards); // Any consensus-related values that are command-line set can be added here for anti-footgun txNew.vin[0].scriptSig = CScript(CommitToArguments(params, networkID, scriptChallenge)); - txNew.vout.resize(rewardShards); for (unsigned int i = 0; i < rewardShards; i++) { txNew.vout[i].nValue = genesisReward/rewardShards; txNew.vout[i].nAsset = asset; @@ -145,8 +145,9 @@ public: parentGenesisBlockHash = uint256S("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"); // Generate pegged Bitcoin asset + std::vector commit = CommitToArguments(consensus, strNetworkID, genesisChallengeScript); uint256 entropy; - GenerateAssetEntropy(entropy, COutPoint() /* blank prevout to simulate coinbase */, parentGenesisBlockHash); + GenerateAssetEntropy(entropy, COutPoint(uint256(commit), 0), parentGenesisBlockHash); CalculateAsset(consensus.pegged_asset, entropy); CScript scriptDestination(CScript() << std::vector(parentGenesisBlockHash.begin(), parentGenesisBlockHash.end()) << OP_WITHDRAWPROOFVERIFY); @@ -254,8 +255,9 @@ public: parentGenesisBlockHash = uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"); // Generate pegged Bitcoin asset + std::vector commit = CommitToArguments(consensus, strNetworkID, genesisChallengeScript); uint256 entropy; - GenerateAssetEntropy(entropy, COutPoint() /* blank prevout to simulate coinbase */, parentGenesisBlockHash); + GenerateAssetEntropy(entropy, COutPoint(uint256(commit), 0), parentGenesisBlockHash); CalculateAsset(consensus.pegged_asset, entropy); genesis = CreateGenesisBlock(consensus, strNetworkID, defaultRegtestScript, 1296688602, genesisChallengeScript, 1, MAX_MONEY, 100, consensus.pegged_asset); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bf29c3bc24..095871ee98 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -892,9 +892,9 @@ UniValue getbalance(const JSONRPCRequest& request) "\nThe total amount in the wallet\n" + HelpExampleCli("getbalance", "") + "\nThe total amount in the wallet of the specified asset (leading 3 arguments are ignored)\n" - + HelpExampleCli("getbalance", "\"*\" 6 false \"694d95345fcd292329b5fb4e465a48484c7e218f4d4f1f7a3bfea26dd2d8fc3d\"") + + + HelpExampleCli("getbalance", "\"*\" 6 false \"b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23\"") + "\nAs a json rpc call\n" - + HelpExampleRpc("getbalance", "\"*\", 6 false \"694d95345fcd292329b5fb4e465a48484c7e218f4d4f1f7a3bfea26dd2d8fc3d\"") + + HelpExampleRpc("getbalance", "\"*\", 6 false \"b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23\"") ); LOCK2(cs_main, pwalletMain->cs_wallet);