Skip to content

Commit

Permalink
Node: accounts management WIP (6)
Browse files Browse the repository at this point in the history
  • Loading branch information
valdok committed Nov 24, 2023
1 parent d111b37 commit 01ba949
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,36 +1127,45 @@ struct Node::AccountRefreshCtx

void AddAccount(const Key::IPKdf::Ptr&, Key::IPKdf*);
void InsertAccount(const NodeProcessor::Account&);

void get_AccountOwnerID(Merkle::Hash&, const Key::IPKdf::Ptr& pOwner, Key::IPKdf* pMiner);
};

void Node::AccountRefreshCtx::AddAccount(const Key::IPKdf::Ptr& pOwner, Key::IPKdf* pMiner)
void Node::AccountRefreshCtx::get_AccountOwnerID(Merkle::Hash& hv, const Key::IPKdf::Ptr& pOwner, Key::IPKdf* pMiner)
{
auto& accs = m_This.m_Processor.m_vAccounts; // alias
ECC::Hash::Processor hp;
hp << uint32_t(4); // change this whenever we change the format of the saved events

// check if this account already exists
if (!m_Map.empty())
ECC::Hash::Value hv1(Zero);

ECC::Scalar::Native sk;
pOwner->DerivePKey(sk, hv1);
hp << sk;

if (pMiner)
{
ECC::Hash::Processor hp;
hp << uint32_t(4); // change this whenever we change the format of the saved events
// rescan also when miner subkey changes, to recover possible decoys that were rejected earlier
pMiner->DerivePKey(sk, hv1);
hp
<< m_This.m_Keys.m_nMinerSubIndex
<< sk;
}

ECC::Hash::Value hv0, hv1(Zero);
hp >> hv;
}

ECC::Scalar::Native sk;
pOwner->DerivePKey(sk, hv1);
hp << sk;

if (pMiner)
{
// rescan also when miner subkey changes, to recover possible decoys that were rejected earlier
pMiner->DerivePKey(sk, hv1);
hp
<< m_This.m_Keys.m_nMinerSubIndex
<< sk;
}
void Node::AccountRefreshCtx::AddAccount(const Key::IPKdf::Ptr& pOwner, Key::IPKdf* pMiner)
{
auto& accs = m_This.m_Processor.m_vAccounts; // alias

hp >> hv0;
// check if this account already exists
if (!m_Map.empty())
{
Merkle::Hash hv;
get_AccountOwnerID(hv, pOwner, pMiner);

auto it = m_Map.find(hv0);
auto it = m_Map.find(hv);
if (m_Map.end() != it)
{
// found!
Expand Down Expand Up @@ -1329,16 +1338,13 @@ void Node::RefreshAccounts()
m_Processor.RescanAccounts(nAdd);
}

if (!accs.empty())
{
std::ostringstream os;
os << "Owned accounts : ";
std::ostringstream os;
os << "Owned accounts :" << std::endl;

for (const auto& acc : accs)
os << '\t' << acc.get_Endpoint() << std::endl;
for (const auto& acc : accs)
os << '\t' << acc.get_Endpoint() << std::endl;

LOG_INFO() << os.str();
}
LOG_INFO() << os.str();
}

bool Node::Bbs::IsInLimits() const
Expand Down

0 comments on commit 01ba949

Please sign in to comment.