Skip to content

Commit

Permalink
New SDK methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SvineruS committed Aug 11, 2023
1 parent 63fcc2f commit 74b0772
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airdao/airdao-node-contracts",
"version": "1.0.19",
"version": "1.0.20",
"main": "./dist/src/index.js",
"files": [
"dist/**/*"
Expand Down
18 changes: 5 additions & 13 deletions src/methods/consensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export async function validatorSetGetNodeStake(contracts: Contracts, nodeAddress
return validatorSet.getNodeStake(nodeAddress);
}

export async function validatorSetGetNodeStakeData(contracts: Contracts, nodeAddress: string) {
const validatorSet = contracts.getContractByName(ContractNames.ValidatorSet) as ValidatorSet;
return validatorSet.stakes(nodeAddress);
}

export async function validatorSetGetValidators(contracts: Contracts) {
const validatorSet = contracts.getContractByName(ContractNames.ValidatorSet) as ValidatorSet;
return validatorSet.getValidators();
Expand All @@ -35,19 +40,6 @@ export async function validatorSetGetBlockListeners(contracts: Contracts) {
return validatorSet.getBlockListeners();
}

export async function validatorSetMapAmounts(contracts: Contracts, addresses: string[]) {
const validatorSet = contracts.getContractByName(ContractNames.ValidatorSet) as ValidatorSet;
const result: { [address: string]: BigNumberish } = {}; // not so convenient as [{address, stake}] but can deal with duplicate addresses

await Promise.all(
addresses.map(async (stakeAddress) => {
if (!result[stakeAddress]) result[stakeAddress] = await validatorSet.getNodeStake(stakeAddress);
})
);

return result;
}

// admin methods

export async function validatorSetAddBlockListener(contracts: Contracts, listener: string) {
Expand Down
15 changes: 15 additions & 0 deletions src/methods/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ValidatorSet,
} from "../../typechain-types";
import { submitTransaction2 } from "./internal";
import { validatorSetGetValidators } from "./consensus";

// validator set

Expand Down Expand Up @@ -123,6 +124,20 @@ export async function serverNodesManagerChangeUnstakeLockTime(contracts: Contrac
);
}

export async function serverNodesManagerGetNodesList(contracts: Contracts) {
const serverNodes = contracts.getContractByName(ContractNames.ServerNodesManager) as ServerNodes_Manager;
const nodesAddresses = await serverNodes.getStakesList();
const validators = await validatorSetGetValidators(contracts);

return await Promise.all(
nodesAddresses.map(async (address) => {
const stake = await serverNodes.stakes(address);
const isOnboarded = validators.includes(address);
return { address, isOnboarded, stake };
})
);
}

// rewards bank

type rewardsBankContactNames =
Expand Down

0 comments on commit 74b0772

Please sign in to comment.