@broxus/js-bridge-essentials
Version:
Bridge JavaScript Essentials library
79 lines (78 loc) • 4 kB
JavaScript
import { getFullContractState } from '@broxus/js-core';
import { tokenTransferTvmSolEventContract } from '../../models/token-transfer-tvm-sol-event/contracts';
export var TokenTransferTvmSolStatus;
(function (TokenTransferTvmSolStatus) {
TokenTransferTvmSolStatus["Initializing"] = "0";
TokenTransferTvmSolStatus["Pending"] = "1";
TokenTransferTvmSolStatus["Confirmed"] = "2";
TokenTransferTvmSolStatus["Rejected"] = "3";
})(TokenTransferTvmSolStatus || (TokenTransferTvmSolStatus = {}));
/**
* @deprecated Use TvmSolBaseEventUtils instead
*/
export class TokenTransferTvmSolEventUtils {
static async getEventInitData(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tokenTransferTvmSolEventContract(connection, eventAddress)
.methods.getEventInitData({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
configuration: result.value0.configuration,
staking: result.value0.staking,
voteData: {
eventData: result.value0.voteData.eventData,
eventTimestamp: Number(result.value0.voteData.eventTimestamp),
eventTransactionLt: result.value0.voteData.eventTransactionLt,
executeAccounts: result.value0.voteData.executeAccounts,
executePayloadAccounts: result.value0.voteData.executePayloadAccounts,
executePayloadNeeded: result.value0.voteData.executePayloadNeeded,
},
};
}
static async getDecodedData(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tokenTransferTvmSolEventContract(connection, eventAddress)
.methods.getDecodedData({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
senderAddress: result.senderAddress,
solanaOwnerAddress: result.solanaOwnerAddress,
tokens: result.tokens,
};
}
static async getDetails(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tokenTransferTvmSolEventContract(connection, eventAddress)
.methods.getDetails({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
balance: result.balance,
confirms: result._confirms,
empty: result.empty,
eventInitData: {
configuration: result._eventInitData.configuration,
staking: result._eventInitData.staking,
voteData: {
eventData: result._eventInitData.voteData.eventData,
eventTimestamp: Number(result._eventInitData.voteData.eventTimestamp),
eventTransactionLt: result._eventInitData.voteData.eventTransactionLt,
executeAccounts: result._eventInitData.voteData.executeAccounts,
executePayloadAccounts: result._eventInitData.voteData.executePayloadAccounts,
executePayloadNeeded: result._eventInitData.voteData.executePayloadNeeded,
},
},
initializer: result._initializer,
meta: result._meta,
rejects: result._rejects,
requiredVotes: Number(result._requiredVotes),
status: result._status,
};
}
static async roundNumber(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tokenTransferTvmSolEventContract(connection, eventAddress)
.methods.round_number()
.call({ cachedState: state });
return Number(result.round_number);
}
}