Add PaymentSplitter.payeesLength()
🧐 Motivation
I want to list all payees of a PaymentSplitter contract.
📝 Details
PaymentSplitter has a .payee(index) method but it is hard to use it without knowing how many payees are there.
Consider adding this to the PaymentSplitter contract:
function payeesLength() public view returns (uint256) {
return _payees.length;
}
Hi,
Can you add more details to the motivation? Whoever deploys the contracts provides the payee array, meaning, they already know how many are there, and the payees are only added during deployment. Although there would be other ways to get the total list (like listening to the contract PayeeAdded), I would like to know the exact use case payeesLength might be applied.
I want to show the list of payees on a website. I can fetch each payee address one by one using .payee(index) but I need to know what is the last index, so I know when to stop. I want something like this:
async function getPayees(paymentSplitter: PaymentSplitter): Promise<string[]> {
const len = await paymentSplitter.payeesLength(); // missing this
const payees: string[] = [];
for (let i = 0; i < len.toNumber(); i++) {
payees.push(await paymentSplitter.payee(i));
}
return payees;
}
Note that you can iterate until payee returns a zero address.
It might still make sense to add a getter for the length.