Skip to content

Commit

Permalink
chore: add view function and update annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Dec 15, 2023
1 parent e077181 commit e766fd1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 13 deletions.
12 changes: 6 additions & 6 deletions abi/bscvalidatorset.abi
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@
},
{
"type": "function",
"name": "BURN_ADDRESS",
"name": "BLOCK_FEES_RATIO_SCALE",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "BLOCK_FEES_RATIO_SCALE",
"name": "BURN_ADDRESS",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
Expand Down
34 changes: 34 additions & 0 deletions abi/stakehub.abi
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,40 @@
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getValidators",
"inputs": [
{
"name": "offset",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "limit",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "operatorAddrs",
"type": "address[]",
"internalType": "address[]"
},
{
"name": "creditAddrs",
"type": "address[]",
"internalType": "address[]"
},
{
"name": "totalLength",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "initialize",
Expand Down
43 changes: 37 additions & 6 deletions contracts/BC_fusion/StakeHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ contract StakeHub is System, Initializable {

/*----------------- view functions -----------------*/
/**
* @return is the system paused
* @return whether the system is paused
*/
function isPaused() external view returns (bool) {
return _paused;
Expand All @@ -802,9 +802,39 @@ contract StakeHub is System, Initializable {
return IStakeCredit(_validators[operatorAddress].creditContract).totalPooledBNBRecord(index);
}

/**
* @notice pagination query all validators' operator address and credit contract address
* @return operatorAddrs operator addresses
* @return creditAddrs credit contract addresses
* @return totalLength total number of validators
*/
function getValidators(
uint256 offset,
uint256 limit
) external view returns (address[] memory operatorAddrs, address[] memory creditAddrs, uint256 totalLength) {
totalLength = _validatorSet.length();
if (offset >= totalLength) {
return (operatorAddrs, creditAddrs, totalLength);
}

limit = limit == 0 ? totalLength : limit;
uint256 count = (totalLength - offset) > limit ? limit : (totalLength - offset);
operatorAddrs = new address[](count);
creditAddrs = new address[](count);
for (uint256 i; i < count; ++i) {
operatorAddrs[i] = _validatorSet.at(offset + i);
creditAddrs[i] = _validators[operatorAddrs[i]].creditContract;
}
}

/**
* @notice get the basic info of a validator
* including consensus address, credit contract, created time, vote address, jailed and jailUntil
* @return consensusAddress the consensus address of the validator
* @return creditContract the credit contract address of the validator
* @return createdTime the creation time of the validator
* @return voteAddress the vote address of the validator
* @return jailed whether the validator is jailed
* @return jailUntil the jail time of the validator
*/
function getValidatorBasicInfo(address operatorAddress)
external
Expand Down Expand Up @@ -853,11 +883,12 @@ contract StakeHub is System, Initializable {
}

/**
* @dev this function will be invoked by Parlia consensus engine.
* @dev this function will be used by Parlia consensus engine.
* @notice get the election info of a validator
* including consensus address, voting power and vote address.
* The voting power will be 0 if the validator is jailed.
* This function is for the consensus engine.
* @return consensusAddrs the consensus addresses of the validators
* @return votingPowers the voting powers of the validators. The voting power will be 0 if the validator is jailed.
* @return voteAddrs the vote addresses of the validators
* @return totalLength the total number of validators
*/
function getValidatorElectionInfo(
uint256 offset,
Expand Down
2 changes: 1 addition & 1 deletion test/utils/interface/IBSCValidatorSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface BSCValidatorSet {
receive() external payable;

function BIND_CHANNELID() external view returns (uint8);
function BURN_ADDRESS() external view returns (address);
function BLOCK_FEES_RATIO_SCALE() external view returns (uint256);
function BURN_ADDRESS() external view returns (address);
function CODE_OK() external view returns (uint32);
function CROSS_CHAIN_CONTRACT_ADDR() external view returns (address);
function CROSS_STAKE_CHANNELID() external view returns (uint8);
Expand Down
4 changes: 4 additions & 0 deletions test/utils/interface/IStakeHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ interface StakeHub {
);
function getValidatorRewardRecord(address operatorAddress, uint256 index) external view returns (uint256);
function getValidatorTotalPooledBNBRecord(address operatorAddress, uint256 index) external view returns (uint256);
function getValidators(uint256 offset, uint256 limit)
external
view
returns (address[] memory operatorAddrs, address[] memory creditAddrs, uint256 totalLength);
function initialize() external;
function isPaused() external view returns (bool);
function maliciousVoteSlash(bytes memory voteAddress) external;
Expand Down

0 comments on commit e766fd1

Please sign in to comment.