pub fn generate_proof_for_wallet(
participants: &[DailyParticipantData],
wallet_address: &str,
) -> Option<MerkleProof>
Expand description
Generate merkle proof for a wallet address.
This convenience function combines wallet address lookup and proof generation. It finds the participant by wallet address and generates their merkle proof in one step. Useful for user-facing applications where you have the wallet address but need the proof for claiming.
§Parameters
participants
: Vector of daily participant datawallet_address
: Base58 encoded Solana wallet address
§Returns
Some(MerkleProof)
if participant foundNone
if participant not found
§Example
use miracle_api::{sdk, prelude::{DailyParticipantData, MerkleTree, EpochClaimData}};
use solana_program::pubkey::Pubkey;
let participants = vec![
DailyParticipantData::new([1u8; 32], 1723680000, 1723766400, [1u8; 8], [2u8; 8], 5, 0),
DailyParticipantData::new([2u8; 32], 1723680000, 1723766400, [3u8; 8], [4u8; 8], 10, 1),
];
let wallet = "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM";
if let Some(proof) = sdk::generate_proof_for_wallet(&participants, wallet) {
println!("Generated proof with {} path nodes", proof.length());
// Use proof for claim
let merkle_tree = sdk::create_merkle_tree(participants);
let customer_wallet = Pubkey::new_unique();
let beneficiary = Pubkey::new_unique();
let epoch = 0u64;
let activity_count = 5u32;
let participant_type = 0u8;
let payment_proof = proof;
let seal_proof = sdk::SealProof::new_for_verification(vec![[2u8; 32]], vec![true], merkle_tree.root());
let claim_ix = sdk::claim(
customer_wallet,
beneficiary,
epoch,
DailyParticipantData::new([1u8; 32], 1723680000, 1723766400, [1u8; 8], [2u8; 8], 5, 0),
payment_proof.path,
payment_proof.indices,
seal_proof.path,
seal_proof.indices,
seal_proof.payment_root,
EpochClaimData {
customer_reward_pool: 1000000u64.to_le_bytes(),
merchant_reward_pool: 500000u64.to_le_bytes(),
total_customer_activity: 0u64.to_le_bytes(),
total_merchant_activity: 0u64.to_le_bytes(),
},
participant_type,
None, // social_data (no social claim)
);
}