Skip to main content

createMerkleProof

Generates a Merkle proof for a specific data item (specified by dataIndex) within a data list. This proof demonstrates that the specific item belongs to the original list.

The proof, when combined with the original data item and the Merkle root, allows verification that the item was part of the larger dataset without needing to download or process the entire set.

Parameters

ParameterTypeDescription
dataListconst std::vector<String>&The complete data list from which the proof is generated.
dataIndexsize_tThe index (0-based) of the data item for which to create the proof.
outProofMerkleProof&Output: A MerkleProof structure containing the proof data.

Return Value

  • bool: Returns true if the proof was created successfully, false otherwise.

Example Code (main.cpp)

#include <Arduino.h>
#include <vector>
#include "Infratic-lib.h" // Assume MerkleProof struct is defined here

// This function does not require network connectivity.
Infratic solana(""); // RPC URL not needed

void setup() {
Serial.begin(115200);
delay(1000);

Serial.println("\n=== createMerkleProof Example ===");

std::vector<String> dataList;
dataList.push_back("SensorData:10.5");
dataList.push_back("SensorData:11.2");
dataList.push_back("SensorData:10.9");
dataList.push_back("SensorData:12.1");

size_t dataIndexToProve = 2; // Create proof for "SensorData:10.9"
MerkleProof proof; // This struct is defined in Infratic-lib.h

Serial.println("Creating Merkle proof for '" + dataList[dataIndexToProve] + "' (index 2)...");

if (solana.createMerkleProof(dataList, dataIndexToProve, proof)) {
Serial.println("✅ Merkle proof created successfully!");
// In a real application, you would send the 'proof' object
// to the 'verifyMerkleProof' function or an on-chain program.
// Serial.println(" -> Proof Root: " + proof.root); // Example hypothetical member
} else {
Serial.println("❌ Failed to create Merkle proof.");
}
}

void loop() {
// Can be left empty
}