// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "./Bridge.sol";
contract Federation {
function getBridge() private pure returns (Bridge) {
return Bridge(address(0x01000006));
}
function getFederationSize() private view returns ( int256 ) {
return getBridge().getFederationSize();
}
function getFederatorPublicKeyOfType ( int256 index, string memory atype ) private view returns ( bytes memory ) {
return getBridge().getFederatorPublicKeyOfType(index, atype);
}
function getFederatorKeys() public view returns( bytes[] memory ) {
int256 fedSize = getFederationSize();
bytes[] memory keys = new bytes[](uint(fedSize));
for (int256 i = 0; i < fedSize; i += 1) {
keys[uint(i)] = getFederatorPublicKeyOfType(i, 'rsk');
}
return keys;
}
}
To do this on-chain (in a smart contract), you can create a Solidity function (getFederatorKeys()
in the code above) that does the same thing as
the web3.js answer from @bguiz
which is to call getFederationSize
, and then getFederatorPublicKeyOfType
within a loop.
Note that you will need to modify Bridge.sol
interface,
such that the signature of getFederatorPublicKeyOfType
has view
- function getFederatorPublicKeyOfType ( int256 index, string calldata atype ) external returns ( bytes memory);
+ function getFederatorPublicKeyOfType ( int256 index, string calldata atype ) external view returns ( bytes memory);
Later this function may be called from web3.js like this
const fedPubKeys = await federation.methods.getFederatorKeys().call()