diff --git a/src/index.ts b/src/index.ts index deadc82..1874211 100644 --- a/src/index.ts +++ b/src/index.ts @@ -283,11 +283,11 @@ const updateMultisigImpl = async (multisigAddress: string, multisigInfo: Multisi return true; } -const updateMultisig = async (multisigAddress: string): Promise => { +const updateMultisig = async (multisigAddress: string, isFirst: boolean): Promise => { try { // Load - const multisigInfo = await checkMultisig(Address.parseFriendly(multisigAddress), MULTISIG_CODE, IS_TESTNET, 'aggregate', true); + const multisigInfo = await checkMultisig(Address.parseFriendly(multisigAddress), MULTISIG_CODE, MULTISIG_ORDER_CODE, IS_TESTNET, 'aggregate', isFirst); if (await updateMultisigImpl(multisigAddress, multisigInfo)) { toggle($('#multisig_content'), true); @@ -306,7 +306,7 @@ const updateMultisig = async (multisigAddress: string): Promise => { $('#multisig_error').innerText = e.message; } - updateMultisigTimeoutId = setTimeout(() => updateMultisig(multisigAddress), 5000); + updateMultisigTimeoutId = setTimeout(() => updateMultisig(multisigAddress, false), 5000); return true; } @@ -327,7 +327,7 @@ const setMultisigAddress = async (newMultisigAddress: string, queuedOrderId?: bi toggle($('#multisig_content'), false); toggle($('#multisig_error'), false); - if (await updateMultisig(newMultisigAddress)) { + if (await updateMultisig(newMultisigAddress, true)) { showScreen('multisigScreen'); } } diff --git a/src/multisig/MultisigChecker.ts b/src/multisig/MultisigChecker.ts index e827a19..0df16fc 100644 --- a/src/multisig/MultisigChecker.ts +++ b/src/multisig/MultisigChecker.ts @@ -3,6 +3,7 @@ import {Address, Cell, Dictionary} from "@ton/core"; import {endParse, Multisig, parseMultisigData} from "./Multisig"; import {MyNetworkProvider, sendToIndex} from "../utils/MyNetworkProvider"; import {Op} from "./Constants"; +import {Order} from "./Order"; const parseNewOrderInitStateBody = (cell: Cell) => { const slice = cell.beginParse(); @@ -94,6 +95,7 @@ export interface MultisigInfo { export const checkMultisig = async ( multisigAddress: AddressInfo, multisigCode: Cell, + multisigOrderCode: Cell, isTestnet: boolean, lastOrdersMode: 'none' | 'history' | 'aggregate', needAdditionalChecks: boolean, @@ -176,8 +178,14 @@ export const checkMultisig = async ( const queryId = inBodySlice.loadUintBig(64); const orderId = inBodySlice.loadUintBig(256); const orderAddress = Address.parse(tx.in_msg.source); - const orderAddress2 = await multisigContract.getOrderAddress(provider, orderId) - if (!orderAddress.equals(orderAddress2)) { + + const multisigOrderToCheck = Order.createFromConfig({ + multisig: multisigAddress.address, + orderSeqno: orderId + }, multisigOrderCode); + + + if (!orderAddress.equals(multisigOrderToCheck.address)) { throw new Error('fake order'); } @@ -207,8 +215,14 @@ export const checkMultisig = async ( if (tx.out_msgs.length !== 1) throw new Error('invalid out messages'); const outMsg = tx.out_msgs[0]; const {orderAddress, orderId} = parseNewOrderOutMsg(outMsg); - const orderAddress2 = await multisigContract.getOrderAddress(provider, orderId) - if (!orderAddress.equals(orderAddress2)) { + + const multisigOrderToCheck = Order.createFromConfig({ + multisig: multisigAddress.address, + orderSeqno: orderId + }, multisigOrderCode); + + + if (!orderAddress.equals(multisigOrderToCheck.address)) { throw new Error('fake order'); } diff --git a/src/multisig/MultisigOrderChecker.ts b/src/multisig/MultisigOrderChecker.ts index 7ecf2b5..013ac04 100644 --- a/src/multisig/MultisigOrderChecker.ts +++ b/src/multisig/MultisigOrderChecker.ts @@ -60,8 +60,13 @@ export const checkMultisigOrder = async ( assert(parsedData.multisigAddress.equals(multisigInfo.address.address), "multisig address does not match"); - const multisigOrderAddress2 = await multisigInfo.multisigContract.getOrderAddress(multisigInfo.provider, parsedData.orderSeqno); - assert(multisigOrderAddress2.equals(multisigOrderAddress.address), "fake multisig-order"); + + const multisigOrderToCheck = Order.createFromConfig({ + multisig: multisigInfo.address.address, + orderSeqno: parsedData.orderSeqno + }, multisigOrderCode); + + assert(multisigOrderToCheck.address.equals(multisigOrderAddress.address), "fake multisig-order"); if (!parsedData.isExecuted) { assert(multisigInfo.threshold === parsedData.threshold, "multisig threshold != order threshold");