Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use consistent address for mocknet #3115

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading