cw_multi_test/
checksums.rs

1//! # Implementation of checksum generator
2
3use cosmwasm_std::{Addr, Checksum};
4
5/// This trait defines a method to calculate checksum based on
6/// the creator's address and a unique code identifier.
7pub trait ChecksumGenerator {
8    /// Calculates the checksum for a given contract's code creator
9    /// and code identifier. Returns a hexadecimal binary representation
10    /// of the calculated checksum. There are no assumptions about
11    /// the length of the calculated checksum.
12    fn checksum(&self, creator: &Addr, code_id: u64) -> Checksum;
13}
14
15/// Default checksum generator implementation.
16pub struct SimpleChecksumGenerator;
17
18impl ChecksumGenerator for SimpleChecksumGenerator {
19    /// Calculates the checksum based on code identifier. The resulting
20    /// checksum is 32-byte length SHA2 digest.
21    fn checksum(&self, _creator: &Addr, code_id: u64) -> Checksum {
22        Checksum::generate(format!("contract code {code_id}").as_bytes())
23    }
24}