mhinprotocol
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).
Overview
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.
Key Features
- Storage Agnostic: Bring your own database by implementing the
MhinStoretrait - Block Parser Agnostic: Works with any source of
bitcoin::Blockdata - Parallel Pre-processing:
pre_process_blockcan be executed in parallel across multiple blocks - Sequential Processing:
process_blockmust be called sequentially, block after block
Installation
Add to your Cargo.toml:
[]
= "0.1"
= "0.32"
Usage
Two-Phase Block Processing
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 ;
// Implement your own store
Configuration
use ;
// Use one of the built-in network constants.
let mainnet = MAINNET;
let testnet = for_network;
// Or describe a fully custom configuration.
let custom = MhinConfig ;
Protocol Summary
Mining MHIN
- Broadcast a Bitcoin transaction whose txid starts with at least 6 zeros
- The best transaction in a block (most leading zeros) earns 4096 MHIN
- Each fewer zero reduces the reward by 16x (256, 16, 1, ...)
- Coinbase transactions are not eligible
Distribution
When MHIN is earned or transferred:
- Single output: receives the entire amount
- Multiple outputs: distributed proportionally by satoshi value (excluding last output)
- Remainder goes to the first output
Custom Distribution
Include an OP_RETURN output with:
- 4-byte prefix:
MHIN - CBOR-encoded
Vec<u64>specifying exact amounts per output
Types
| 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) |
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.