ptree_branch::ptree_branch(uint8_t split_pos, const ptree_ptr& p1, const ptree_ptr& p2) : m_branches{ p1, p2 } , m_node_count(p1->node_count() + p2->node_count()) , m_split_pos(split_pos) , m_complete(p1->complete() && p2->complete()) { if (p1->is_proxy()) { // p1 is proxy, p2 must be valid, and branches are in order m_prefix = p2->prefix(); } else if (p2->is_proxy()) { // p2 is proxy, p1 must be valid, and branches are in order m_prefix = p1->prefix(); } else { // Both are valid, but might be out of order m_prefix = p1->prefix(); if (p1->prefix() > p2->prefix()) { swap(m_branches[0], m_branches[1]); } } m_prefix.zero_above(split_pos); m_merkle = make_digest(m_prefix, m_node_count, m_branches[0]->merkle(), m_branches[1]->merkle()); }
static void write_proxy(writable& out, const ptree_ptr& p) { out.write(pid_proxy); out.write(p->node_count()); out.write(p->merkle()); }