Skip to content

Commit

Permalink
speed-up
Browse files Browse the repository at this point in the history
  • Loading branch information
rise1507 committed Apr 11, 2024
1 parent 69d575a commit e12a2ca
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ const updateMultisigImpl = async (multisigAddress: string, multisigInfo: Multisi
return true;
}

const updateMultisig = async (multisigAddress: string): Promise<boolean> => {
const updateMultisig = async (multisigAddress: string, isFirst: boolean): Promise<boolean> => {
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);
Expand All @@ -306,7 +306,7 @@ const updateMultisig = async (multisigAddress: string): Promise<boolean> => {
$('#multisig_error').innerText = e.message;
}

updateMultisigTimeoutId = setTimeout(() => updateMultisig(multisigAddress), 5000);
updateMultisigTimeoutId = setTimeout(() => updateMultisig(multisigAddress, false), 5000);
return true;
}

Expand All @@ -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');
}
}
Expand Down
22 changes: 18 additions & 4 deletions src/multisig/MultisigChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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');
}

Expand Down
9 changes: 7 additions & 2 deletions src/multisig/MultisigOrderChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit e12a2ca

Please sign in to comment.