From 01ba949274bc9ac5df42af80416fbb9e7628b408 Mon Sep 17 00:00:00 2001 From: valdok Date: Fri, 24 Nov 2023 05:47:05 +0200 Subject: [PATCH] Node: accounts management WIP (6) --- node/node.cpp | 62 ++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/node/node.cpp b/node/node.cpp index 63827232f..2046fe76c 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -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! @@ -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