Skip to content

Commit

Permalink
Use consistent address for mocknet (#3115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar authored Nov 7, 2024
1 parent 08988e3 commit 7720b2f
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2498,32 +2498,23 @@ bool AppInitMain(InitInterfaces& interfaces)
// MN: 0000000000000000000000000000000000000000000000000000000000000000

if (fMockNetwork && HasWallets()) {

CKeyID keyID;
CTxDestination dest;
// Mainnet: df1qmnv9c6jt9fmgmzvynp8r0gjm39awa027hsfzq3
// Test networks: tf1qmnv9c6jt9fmgmzvynp8r0gjm39awa027yqn3q4
const auto rawPrivKey = uint256S("4c0883a69102937d623414e5f791a5a5a4591d899d0e3a1b03f0b7421932b72e");
CKey key;
key.Set(rawPrivKey.begin(), rawPrivKey.end(), true);
const auto pubkey = key.GetPubKey();
const auto keyID = pubkey.GetID();
WitnessV0KeyHash dest(pubkey);

{
auto pwallet = GetWallets()[0];
LOCK(pwallet->cs_wallet);

if (!pwallet->CanGetAddresses()) {
return InitError("Wallet not able to generate address for mocknet");
}

std::string error;

if (!pwallet->GetNewDestination(OutputType::BECH32, "", dest, error)) {
return InitError("Wallet not able to get new destination for mocknet");
}
pwallet->SetAddressBook(dest, "", "receive");
pwallet->ImportPrivKeys({{keyID, key}}, GetTime());
}

// Import privkey
const auto optKeyID = CKeyID::TryFromDestination(dest, KeyType::WPKHashKeyType);
if (!optKeyID) {
return InitError("Not able to get new keyID for mocknet");
}
keyID = *optKeyID;

// Set operator for mining
gArgs.ForceSetArg("-masternode_operator", EncodeDestination(dest));

Expand All @@ -2536,14 +2527,9 @@ bool AppInitMain(InitInterfaces& interfaces)
node.operatorAuthAddress = keyID;
node.version = CMasternode::VERSION0;

const auto time{std::time(nullptr)};

{
LOCK(cs_main);
pcustomcsview->CreateMasternode(uint256S(std::string{64, '0'}), node, CMasternode::ZEROYEAR);
for (uint8_t i{0}; i < SUBNODE_COUNT; ++i) {
pcustomcsview->SetSubNodesBlockTime(node.operatorAuthAddress, chain_active_height, i, time);
}
}
}

Expand Down

0 comments on commit 7720b2f

Please sign in to comment.