@gear-js/api
Version:
A JavaScript library that provides functionality to connect GEAR Component APIs.
74 lines (70 loc) • 2.4 kB
JavaScript
;
require('@polkadot/util');
var ethBridge_errors = require('../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 ethBridge_errors.AuthoritySetHashError();
}
return result.unwrap().toHex();
}
async clearTimer() {
const result = await this.api.query.gearEthBridge.clearTimer();
if (result.isNone) {
throw new ethBridge_errors.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 ethBridge_errors.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();
}
}
exports.GearEthBridge = GearEthBridge;