| Crates.io | mhinprotocol |
| lib.rs | mhinprotocol |
| version | 0.2.3 |
| created_at | 2025-11-29 22:36:46.149515+00 |
| updated_at | 2025-12-04 22:00:24.019015+00 |
| description | Reference Rust implementation of the MY HASH IS NICE (MHIN) protocol. |
| homepage | https://github.com/ouziel-slama/mhinprotocol |
| repository | https://github.com/ouziel-slama/mhinprotocol |
| max_upload_size | |
| id | 1957618 |
| size | 125,434 |
A Rust implementation of the MY HASH IS NICE (MHIN) protocol — a system that rewards Bitcoin transactions with aesthetically pleasing transaction IDs (those starting with leading zeros).
This library provides a database-agnostic and block parser-agnostic implementation of the MHIN protocol. It focuses purely on the protocol logic, allowing you to integrate it with any Bitcoin block source and any storage backend.
For the complete protocol specification, see docs/protocol.pdf.
MhinStore traitbitcoin::Block datapre_process_block can be executed in parallel across multiple blocksprocess_block must be called sequentially, block after blockAdd to your Cargo.toml:
[dependencies]
mhinprotocol = "0.1"
bitcoin = "0.32"
The protocol processes blocks in two phases:
Pre-processing (pre_process_block): Extracts all MHIN-relevant data from a Bitcoin block. This phase is parallelizable — you can pre-process multiple blocks concurrently.
Processing (process_block): Updates MHIN balances in the store. This phase is sequential — blocks must be processed in order, one after another.
use mhinprotocol::{MhinProtocol, MhinConfig, MhinNetwork, MhinStore, Amount, UtxoKey};
// Implement your own store
struct MyStore { /* ... */ }
impl MhinStore for MyStore {
fn get(&mut self, key: &UtxoKey) -> Amount {
// Fetch MHIN balance for the given UTXO key
}
fn pop(&mut self, key: &UtxoKey) -> Amount {
// Remove the entry for the given UTXO key, returning the balance
}
fn set(&mut self, key: UtxoKey, value: Amount) {
// Store MHIN balance for the given UTXO key
}
}
fn main() {
// Create protocol instance with mainnet parameters
let protocol = MhinProtocol::new(MhinConfig::for_network(MhinNetwork::Mainnet));
let mut store = MyStore::new();
// Fetch blocks from your Bitcoin source
let blocks: Vec<bitcoin::Block> = fetch_blocks();
// Phase 1: Pre-process blocks (can be parallelized)
let mhin_blocks: Vec<_> = blocks
.par_iter() // Using rayon for parallelism
.map(|block| protocol.pre_process_block(block))
.collect();
// Phase 2: Process blocks sequentially
for mhin_block in &mhin_blocks {
protocol.process_block(mhin_block, &mut store);
}
}
use mhinprotocol::{MhinConfig, MhinNetwork};
// Use one of the built-in network constants.
let mainnet = MhinConfig::MAINNET;
let testnet = MhinConfig::for_network(MhinNetwork::Testnet4);
// Or describe a fully custom configuration.
let custom = MhinConfig {
min_zero_count: 8,
base_reward: 8_192,
mhin_prefix: b"MHN8",
};
When MHIN is earned or transferred:
Include an OP_RETURN output with:
MHINVec<u64> specifying exact amounts per output| Type | Description |
|---|---|
MhinProtocol |
Main entry point for processing blocks |
MhinConfig |
Protocol configuration parameters (per network) |
MhinNetwork |
Supported Bitcoin networks for MHIN constants |
MhinStore |
Trait for storage backend implementation |
PreProcessedMhinBlock |
Pre-processed block data |
MhinTransaction |
Transaction with MHIN-relevant fields |
UtxoKey |
8-byte key identifying a UTXO ([u8; 8]) |
Amount |
MHIN balance type (u64) |
Licensed under either of:
at your option.