Skip to content

Commit

Permalink
Change network settings commitment to sha2, include in asset type def
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Aug 24, 2017
1 parent 8c1ba39 commit b76b0b2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion contrib/assets_tutorial/assets_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def sync_all(e1, e2):
# 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)
Expand Down
2 changes: 1 addition & 1 deletion contrib/assets_tutorial/assets_tutorial.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 13 additions & 11 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "util.h"
#include "utilstrencodings.h"
#include "amount.h"
#include "crypto/ripemd160.h"
#include "crypto/sha256.h"

#include <assert.h>

Expand All @@ -22,13 +22,13 @@
// Safer for users if they load incorrect parameters via arguments.
static std::vector<unsigned char> 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<unsigned char>(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<unsigned char>(commitment, commitment + 32);
}

static CScript StrHexToScriptWithDefault(std::string strScript, const CScript defaultScript)
Expand All @@ -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;
Expand Down Expand Up @@ -145,8 +145,9 @@ class CElementsParams : public CChainParams {
parentGenesisBlockHash = uint256S("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943");

// Generate pegged Bitcoin asset
std::vector<unsigned char> 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<unsigned char>(parentGenesisBlockHash.begin(), parentGenesisBlockHash.end()) << OP_WITHDRAWPROOFVERIFY);
Expand Down Expand Up @@ -254,8 +255,9 @@ class CRegTestParams : public CChainParams {
parentGenesisBlockHash = uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206");

// Generate pegged Bitcoin asset
std::vector<unsigned char> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b76b0b2

Please sign in to comment.