UNPKG

@gear-js/api

Version:

A JavaScript library that provides functionality to connect GEAR Component APIs.

72 lines (69 loc) 2.37 kB
import '@polkadot/util'; import { AuthoritySetHashError, ClearTimerError, GetQueueMerkleRootError } from '../errors/ethBridge.errors.js'; class GearEthBridge { api; constructor(api) { this.api = api; } async authoritySetHash() { const result = await this.api.query.gearEthBridge.authoritySetHash(); if (result.isNone) { throw new AuthoritySetHashError(); } return result.unwrap().toHex(); } async clearTimer() { const result = await this.api.query.gearEthBridge.clearTimer(); if (result.isNone) { throw new ClearTimerError(); } return result.unwrap().toNumber(); } async isInitialized() { const result = await this.api.query.gearEthBridge.initialized(); return result.toHuman(); } async getMessageNonce() { const result = await this.api.query.gearEthBridge.messageNonce(); return result.toBigInt(); } async isPaused() { const result = await this.api.query.gearEthBridge.paused(); return result.toHuman(); } async getQueue() { const result = await this.api.query.gearEthBridge.queue(); return result.toArray().map((hash) => hash.toHex()); } async isQueueChanged() { const result = await this.api.query.gearEthBridge.queueChanged(); return result.toHuman(); } async getQueueMerkleRoot() { const result = await this.api.query.gearEthBridge.queueMerkleRoot(); if (result.isNone) { throw new GetQueueMerkleRootError(); } return result.unwrap().toHex(); } async getSessionsTimer() { const result = await this.api.query.gearEthBridge.sessionsTimer(); return result.toNumber(); } sendEthMessage(destination, payload) { return this.api.tx.gearEthBridge.sendEthMessage(destination, payload); } async merkleProof(hash, at) { return this.api.rpc.gearEthBridge.merkleProof(hash, at); } get maxPayloadSize() { return this.api.consts.gearEthBridge.maxPayloadSize.toNumber(); } get queueCapacity() { return this.api.consts.gearEthBridge.queueCapacity.toNumber(); } get sessionsPerEra() { return this.api.consts.gearEthBridge.sessionsPerEra.toNumber(); } } export { GearEthBridge };