@broxus/js-bridge-essentials
Version:
Bridge JavaScript Essentials library
150 lines (149 loc) • 7.29 kB
JavaScript
import { getFullContractState, resolveTvmAddress } from '@broxus/js-core';
import { tvmTvmEventNativeContract } from '../../models/tvm-tvm-event-native/contracts';
export class TvmTvmEventNativeUtils {
static async approveLimit(provider, eventAddress, args) {
return tvmTvmEventNativeContract(provider, eventAddress)
.methods.approveLimit()
.sendDelayed({ bounce: true, ...args });
}
static async cancel(provider, eventAddress, params, args) {
return tvmTvmEventNativeContract(provider, eventAddress)
.methods.cancel({
_eventPayload: params.eventPayload ?? null,
_expectedGas: params.expectedGas,
_expectedGasReceiver: resolveTvmAddress(params.expectedGasReceiver),
_newRecipient: resolveTvmAddress(params.newRecipient),
_remainingGasTo: resolveTvmAddress(params.remainingGasTo),
})
.sendDelayed({ bounce: true, ...args });
}
static async rejectLimit(provider, eventAddress, expectedGasReceiver, args) {
return tvmTvmEventNativeContract(provider, eventAddress)
.methods.rejectLimit({
_expectedGasReceiver: resolveTvmAddress(expectedGasReceiver),
})
.sendDelayed({ bounce: true, ...args });
}
static async retry(provider, eventAddress, args) {
return tvmTvmEventNativeContract(provider, eventAddress)
.methods.retry()
.sendDelayed({ bounce: true, ...args });
}
static async setBounty(provider, eventAddress, bounty, args) {
return tvmTvmEventNativeContract(provider, eventAddress)
.methods.setBounty({ _bounty: bounty })
.sendDelayed({ bounce: true, ...args });
}
static async getDecodedData(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.getDecodedData({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
amount: result.amount_,
bounty: result.bounty_,
decimals: Number(result.decimals_),
expectedGas: result.expected_gas_,
name: result.name_,
payload: result.payload_,
proxyAddress: result.proxy_,
recipientAddress: result.recipient_,
symbol: result.symbol_,
tokenAddress: result.token_,
tokenWalletAddress: result.tokenWallet_,
value: result.value_,
};
}
static async getDetails(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.getDetails({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
eventInitData: {
chainId: result._eventInitData.chainId,
configuration: result._eventInitData.configuration,
msgHash: result._eventInitData.msgHash,
},
initializer: result._initializer,
meta: result._meta,
status: result._status,
};
}
static async getEventInitData(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.getEventInitData({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
chainId: result.value0.chainId,
configuration: result.value0.configuration,
msgHash: result.value0.msgHash,
};
}
static async bounty(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.bounty()
.call({ cachedState: state });
return result.bounty;
}
static async eventTokenWallet(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.eventTokenWallet()
.call({ cachedState: state });
return result.eventTokenWallet;
}
static async eventInitialBalance(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.eventInitialBalance()
.call({ cachedState: state });
return result.eventInitialBalance;
}
static async expectedGas(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.expected_gas()
.call({ cachedState: state });
return result.expected_gas;
}
static async limitApprover(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.limitApprover()
.call({ cachedState: state });
return result.limitApprover;
}
static async nonce(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.nonce()
.call({ cachedState: state });
return result.nonce;
}
static async recipient(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.recipient()
.call({ cachedState: state });
return result.recipient;
}
static async sender(connection, eventAddress, cachedState) {
const state = cachedState ?? await getFullContractState(connection, eventAddress);
const result = await tvmTvmEventNativeContract(connection, eventAddress)
.methods.sender()
.call({ cachedState: state });
return result.sender;
}
static decodeEvent(connection, eventAddress, args) {
return tvmTvmEventNativeContract(connection, eventAddress).decodeEvent(args);
}
static decodeTransaction(connection, eventAddress, args) {
return tvmTvmEventNativeContract(connection, eventAddress).decodeTransaction(args);
}
static decodeTransactionEvents(connection, eventAddress, transaction) {
return tvmTvmEventNativeContract(connection, eventAddress).decodeTransactionEvents({ transaction });
}
}