@broxus/js-bridge-essentials
Version:
Bridge JavaScript Essentials library
93 lines (92 loc) • 4.66 kB
JavaScript
import { getFullContractState } from '@broxus/js-core';
import { evmTonBaseEventContract } from '../../models/evm-ton-base-event/contracts';
export var EvmTonBaseEventStatus;
(function (EvmTonBaseEventStatus) {
EvmTonBaseEventStatus["Initializing"] = "0";
EvmTonBaseEventStatus["Pending"] = "1";
EvmTonBaseEventStatus["Confirmed"] = "2";
EvmTonBaseEventStatus["Rejected"] = "3";
EvmTonBaseEventStatus["Cancelled"] = "4";
EvmTonBaseEventStatus["LimitReached"] = "5";
EvmTonBaseEventStatus["LiquidityRequested"] = "6";
EvmTonBaseEventStatus["LiquidityProvided"] = "7";
EvmTonBaseEventStatus["Verified"] = "8";
})(EvmTonBaseEventStatus || (EvmTonBaseEventStatus = {}));
export class EvmTonBaseEventUtils {
static async getDetails(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await evmTonBaseEventContract(connection, eventAddress)
.methods.getDetails({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
balance: result.balance,
confirms: result._confirms,
empty: result.empty,
eventInitData: {
chainId: result._eventInitData.chainId,
configuration: result._eventInitData.configuration,
roundDeployer: result._eventInitData.roundDeployer,
voteData: {
eventBlock: Number(result._eventInitData.voteData.eventBlock),
eventBlockNumber: Number(result._eventInitData.voteData.eventBlockNumber),
eventData: result._eventInitData.voteData.eventData,
eventIndex: Number(result._eventInitData.voteData.eventIndex),
eventTransaction: result._eventInitData.voteData.eventTransaction,
},
},
initializer: result._initializer,
meta: result._meta,
rejects: result._rejects,
requiredVotes: Number(result._requiredVotes),
status: result._status,
};
}
static async getEventInitData(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await evmTonBaseEventContract(connection, eventAddress)
.methods.getEventInitData({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
chainId: result.value0.chainId,
configuration: result.value0.configuration,
roundDeployer: result.value0.roundDeployer,
voteData: {
eventBlock: Number(result.value0.voteData.eventBlock),
eventBlockNumber: Number(result.value0.voteData.eventBlockNumber),
eventData: result.value0.voteData.eventData,
eventIndex: Number(result.value0.voteData.eventIndex),
eventTransaction: result.value0.voteData.eventTransaction,
},
};
}
static async nonce(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await evmTonBaseEventContract(connection, eventAddress)
.methods.nonce()
.call({ cachedState: state });
return result.nonce;
}
static async relayRound(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await evmTonBaseEventContract(connection, eventAddress)
.methods.relay_round()
.call({ cachedState: state });
return result.relay_round;
}
static async roundNumber(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await evmTonBaseEventContract(connection, eventAddress)
.methods.round_number()
.call({ cachedState: state });
return Number(result.round_number);
}
static decodeEvent(connection, eventAddress, args) {
return evmTonBaseEventContract(connection, eventAddress).decodeEvent(args);
}
static decodeTransaction(connection, eventAddress, args) {
return evmTonBaseEventContract(connection, eventAddress).decodeTransaction(args);
}
static decodeTransactionEvents(connection, eventAddress, transaction) {
return evmTonBaseEventContract(connection, eventAddress).decodeTransactionEvents({ transaction });
}
}