updateLeaf method

MerkleTree<T> updateLeaf(
  1. int index,
  2. T newData
)

Updates a leaf and recalculates affected hashes

Implementation

MerkleTree<T> updateLeaf(int index, T newData) {
  if (index < 0 || index >= leafCount) {
    throw ArgumentError('Invalid leaf index: $index');
  }

  final newLeaves = List<T>.from(_leaves);
  newLeaves[index] = newData;

  return MerkleTree.fromList(
    newLeaves,
    hashFunction: hashFunction,
    salt: _salt,
  );
}