Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/compactproofs.h
Show All 25 Lines | |||||
struct ProofId; | struct ProofId; | ||||
struct PrefilledProof { | struct PrefilledProof { | ||||
// Used as an offset since last prefilled proof in CompactProofs | // Used as an offset since last prefilled proof in CompactProofs | ||||
uint32_t index; | uint32_t index; | ||||
avalanche::ProofRef proof; | avalanche::ProofRef proof; | ||||
class Formatter : public DifferenceFormatter { | template <typename Stream> void SerData(Stream &s) { s << proof; } | ||||
public: | template <typename Stream> void UnserData(Stream &s) { s >> proof; } | ||||
template <typename Stream> void Ser(Stream &s, PrefilledProof pp) { | |||||
DifferenceFormatter::Ser(s, pp.index); | |||||
s << pp.proof; | |||||
} | |||||
template <typename Stream> void Unser(Stream &s, PrefilledProof &pp) { | |||||
DifferenceFormatter::Unser(s, pp.index); | |||||
s >> pp.proof; | |||||
} | |||||
}; | |||||
}; | }; | ||||
class CompactProofs { | class CompactProofs { | ||||
private: | private: | ||||
uint64_t shortproofidk0, shortproofidk1; | uint64_t shortproofidk0, shortproofidk1; | ||||
std::vector<uint64_t> shortproofids; | std::vector<uint64_t> shortproofids; | ||||
std::vector<PrefilledProof> prefilledProofs; | std::vector<PrefilledProof> prefilledProofs; | ||||
Show All 14 Lines | std::pair<uint64_t, uint64_t> getKeys() const { | ||||
return std::make_pair(shortproofidk0, shortproofidk1); | return std::make_pair(shortproofidk0, shortproofidk1); | ||||
} | } | ||||
SERIALIZE_METHODS(CompactProofs, obj) { | SERIALIZE_METHODS(CompactProofs, obj) { | ||||
READWRITE( | READWRITE( | ||||
obj.shortproofidk0, obj.shortproofidk1, | obj.shortproofidk0, obj.shortproofidk1, | ||||
Using<VectorFormatter<CustomUintFormatter<SHORTPROOFIDS_LENGTH>>>( | Using<VectorFormatter<CustomUintFormatter<SHORTPROOFIDS_LENGTH>>>( | ||||
obj.shortproofids), | obj.shortproofids), | ||||
Using<VectorFormatter<PrefilledProof::Formatter>>( | Using<VectorFormatter<DifferentialIndexedItemFormatter>>( | ||||
obj.prefilledProofs)); | obj.prefilledProofs)); | ||||
if (ser_action.ForRead() && obj.prefilledProofs.size() > 0) { | if (ser_action.ForRead() && obj.prefilledProofs.size() > 0) { | ||||
// Thanks to the DifferenceFormatter, the index values in the | // Thanks to the DifferenceFormatter, the index values in the | ||||
// deserialized prefilled proofs are absolute and sorted, so the | // deserialized prefilled proofs are absolute and sorted, so the | ||||
// last vector item has the highest index value. | // last vector item has the highest index value. | ||||
uint64_t highestPrefilledIndex = obj.prefilledProofs.back().index; | uint64_t highestPrefilledIndex = obj.prefilledProofs.back().index; | ||||
Show All 22 Lines |