datahaven/contracts/script/utils/ValidatorsUtils.sol
undercover-cactus 471b5ef76b
refactor: remove duplicate code for calculating merkle root and proof (#124)
We remove `calculateMerkleRootUnsorted` and `buildMerkleProofUnsorted`
and instead introduce a new parameter `sorting`. This parameter
`sorting` will indicate if we need to sort the pair before hashing the
new node.
2025-07-28 18:34:28 +02:00

19 lines
823 B
Solidity

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.27;
import {MerkleUtils} from "../../src/libraries/MerkleUtils.sol";
import {BeefyClient} from "snowbridge/src/BeefyClient.sol";
library ValidatorsUtils {
function _buildValidatorSet(
uint128 id,
bytes32[] memory validators
) internal pure returns (BeefyClient.ValidatorSet memory) {
// Calculate the merkle root from the validators array. We specify to not sort the pair before hashing to be compatible with Beefy Merkle Tree implementation.
bytes32 merkleRoot = MerkleUtils.calculateMerkleRoot(validators, false);
// Create and return the validator set with the calculated merkle root
return
BeefyClient.ValidatorSet({id: id, length: uint128(validators.length), root: merkleRoot});
}
}