Skip to content

Commit

Permalink
Validatorset multisig (#15)
Browse files Browse the repository at this point in the history
* feat: add validatorset methods to multisig

* feat: delete redundant methods

* feat: delete redundant comments

* fix: implementation due to comments

* feat: add admin methods to multisig

* feat: delete redundant import

* feat: add getBlockListener method

* feat: add exports to consensus multisig methods

* feat: add validatorSetGetStakesBalancesByManager method

* fix: validatorSetGetStakesBalancesByManager method
  • Loading branch information
serezhaolshan authored Aug 9, 2023
1 parent 444a471 commit f034cb6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/multisig/methods/consensus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Contracts } from "../../contracts/contracts";
import { ValidatorSet } from "../../../typechain-types";
import { ContractNames } from "../../contracts/names";
import { submitTransaction2 } from "./internal";

// view methods
export async function validatorSetGetNodeStake(contracts: Contracts, nodeAddress: string) {
const validatorSet = contracts.getContractByName(ContractNames.ValidatorSet) as ValidatorSet;
return validatorSet.getNodeStake(nodeAddress);
}

export async function validatorSetGetValidators(contracts: Contracts) {
const validatorSet = contracts.getContractByName(ContractNames.ValidatorSet) as ValidatorSet;
return validatorSet.getValidators();
}

export async function validatorSetGetTopStakes(contracts: Contracts) {
const validatorSet = contracts.getContractByName(ContractNames.ValidatorSet) as ValidatorSet;
return validatorSet.getTopStakes();
}

export async function validatorSetGetQueuedStakes(contracts: Contracts) {
const validatorSet = contracts.getContractByName(ContractNames.ValidatorSet) as ValidatorSet;
return validatorSet.getQueuedStakes();
}

export async function validatorSetGetStakesByManager(contracts: Contracts, managerAddress: string) {
const validatorSet = contracts.getContractByName(ContractNames.ValidatorSet) as ValidatorSet;
return validatorSet.getStakesByManager(managerAddress);
}

export async function validatorSetGetBlockListeners(contracts: Contracts) {
const validatorSet = contracts.getContractByName(ContractNames.ValidatorSet) as ValidatorSet;
return validatorSet.listeners();
}

export async function validatorSetGetStakesBalancesByManager(contracts: Contracts, contractName: ContractNames) {
const validatorSet = contracts.getContractByName(ContractNames.ValidatorSet) as ValidatorSet;
const manager = contracts.getContractByName(contractName);
const stakes = await validatorSetGetStakesByManager(contracts, manager.address);
return await Promise.all(
stakes.map((stakeAddress) => ({ address: stakeAddress, stake: validatorSet.getNodeStake(stakeAddress) }))
);
}

// admin methods

export async function validatorSetAddBlockListener(contracts: Contracts, listener: string) {
return await submitTransaction2<ValidatorSet>(contracts, ContractNames.ValidatorSet, 0, (validatorSet) =>
validatorSet.addBlockListener(listener)
);
}

export async function validatorSetRemoveBlockListener(contracts: Contracts, listener: string) {
return await submitTransaction2<ValidatorSet>(contracts, ContractNames.ValidatorSet, 0, (validatorSet) =>
validatorSet.removeBlockListener(listener)
);
}
2 changes: 2 additions & 0 deletions src/multisig/methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as finance from "./finance";
import * as staking from "./staking";
import * as multisigs from "./multisigs";
import * as consensus from "./consensus";

const Methods = {
...multisigs,
...finance,
...staking,
...consensus,
};

export default Methods;

0 comments on commit f034cb6

Please sign in to comment.