UNPKG

@river-build/web3

Version:

Dapps for our Space and Registry contracts

64 lines 2.82 kB
import { INodeOperatorShim } from './INodeOperatorShim'; import { IEntitlementCheckerShim } from './IEntitlementCheckerShim'; import { ISpaceDelegationShim } from './ISpaceDelegationShim'; import { IERC721AShim } from './IERC721AShim'; export class BaseRegistry { config; provider; nodeOperator; entitlementChecker; spaceDelegation; erc721A; constructor(config, provider) { this.config = config; this.provider = provider; this.nodeOperator = new INodeOperatorShim(config.addresses.baseRegistry, provider); this.entitlementChecker = new IEntitlementCheckerShim(config.addresses.baseRegistry, provider); this.spaceDelegation = new ISpaceDelegationShim(config.addresses.baseRegistry, provider); this.erc721A = new IERC721AShim(config.addresses.baseRegistry, provider); } async getOperatorStatus(operator) { return this.nodeOperator.read.getOperatorStatus(operator); } async getOperators() { const operatorAddresses = await this.nodeOperator.read.getOperators(); const operatorStatusPromises = operatorAddresses.map((operatorAddress) => this.getOperatorStatus(operatorAddress)); const operatorsStatus = await Promise.all(operatorStatusPromises); const operators = operatorAddresses.map((operatorAddress, index) => ({ operatorAddress, status: operatorsStatus[index], })); return operators; } async getNodeCount() { return this.entitlementChecker.read.getNodeCount(); } async getNodeAtIndex(index) { return this.entitlementChecker.read.getNodeAtIndex(index); } async getNodes() { const nodeCountBigInt = await this.getNodeCount(); const nodeCount = Number(nodeCountBigInt); const zeroToNodeCount = Array.from(Array(nodeCount).keys()); const nodeAtIndexPromises = zeroToNodeCount.map((index) => this.getNodeAtIndex(index)); const nodes = await Promise.all(nodeAtIndexPromises); return nodes; } async getNodesWithOperators() { const operators = await this.getOperators(); const nodesByOperatorPromises = operators.map((operator) => this.entitlementChecker.read.getNodesByOperator(operator.operatorAddress)); const nodesByOperator = await Promise.all(nodesByOperatorPromises); const operatorsWithNodes = operators.map((operator, index) => ({ operator, nodes: nodesByOperator[index], })); const nodesWithOperators = []; operatorsWithNodes.forEach(({ operator, nodes }) => { nodes.forEach((node) => { nodesWithOperators.push({ node, operator }); }); }); return nodesWithOperators; } } //# sourceMappingURL=BaseRegistry.js.map