Skip to content

Commit

Permalink
Merge pull request #18 from ArslanKibria98/develop
Browse files Browse the repository at this point in the history
Dynamic threshold and improvements
  • Loading branch information
zikriya authored Dec 25, 2023
2 parents 08ee03a + 2cf0b81 commit d69955e
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 143 deletions.
3 changes: 0 additions & 3 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
export * as userController from "./user.controller";
export * as securityKeyController from "./securityKey.controller";
export * as jobController from "./job.controller";
19 changes: 0 additions & 19 deletions src/controllers/job.controller.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/controllers/securityKey.controller.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/controllers/user.controller.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/interfaces/job.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Transaction, TransactionReceipt } from '../interfaces';
import { Transaction, TransactionReceipt } from "../interfaces";

export interface JobRequestBody {
name: string;
Expand All @@ -8,6 +8,7 @@ export interface JobRequestBody {
isDestinationNonEVM: boolean;
bridgeAmount: string;
txId: string;
threshold: number;
}

export interface UpdateJobRequestBody {
Expand Down
6 changes: 4 additions & 2 deletions src/middlewares/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ function validateAuth(token: string, req: any): boolean {
function authSecurityKeyApis(token: string): boolean {
if (
token &&
decrypt(token, (global as any).AWS_ENVIRONMENT.API_KEY) ==
(global as any).AWS_ENVIRONMENT.API_KEY
decrypt(
token,
(global as any).AWS_ENVIRONMENT.SECURITY_ROUTER_AUTHORIZATION_KEY
) == (global as any).AWS_ENVIRONMENT.SECURITY_ROUTER_AUTHORIZATION_KEY
) {
return true;
}
Expand Down
27 changes: 0 additions & 27 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
import { Router } from "express";
import userRoute from "./user.route";
import securityKeyRoute from "./securityKey.route";
import jobRoute from "./job.route";

const router = Router();

const defaultRoutes = [
{
path: "/user",
route: userRoute,
},

{
path: "/securityKey",
route: securityKeyRoute,
},
{
path: "/jobs",
route: jobRoute,
},
];

defaultRoutes.forEach((route) => {
router.use(route.path, route.route);
});

export default router;
9 changes: 0 additions & 9 deletions src/routes/job.route.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/routes/securityKey.route.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/routes/user.route.ts

This file was deleted.

5 changes: 1 addition & 4 deletions src/services/cosmWasm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ export const signedTransaction = async (

return {
...txData,
signatures: [
{ signature: payBySig.signatures, hash: payBySig.hash },
{ signature: payBySig.signatures, hash: payBySig.hash },
],
signatures: [{ signature: payBySig.signatures, hash: payBySig.hash }],
hash: payBySig.hash,
address: process.env.PUBLIC_KEY,
};
Expand Down
3 changes: 0 additions & 3 deletions src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export * as userService from "./user.service";
export * as securityKeyService from "./securityKey.service";
export * as web3Service from "./web3.service";
export * as cosmWasmService from "./cosmWasm.service";
export * as axiosService from "./axios.service";
export * as jobService from "./job.service";
8 changes: 0 additions & 8 deletions src/services/job.service.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/services/securityKey.service.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/services/user.service.ts

This file was deleted.

32 changes: 12 additions & 20 deletions src/services/web3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
VERSION,
NETWORKS,
CUDOS_CHAIN_ID,
THRESHOLD,
getPrivateKey,
delay,
} from "../constants/constants";
import {
ecsign,
Expand All @@ -24,17 +24,19 @@ import { add } from "winston";
export const getTransactionReceipt = async (
txId: string,
rpcURL: string,
threshold: number,
tries = 0
): Promise<TransactionReceipt> => {
const web3 = new Web3(rpcURL);
const transaction: TransactionReceipt = await web3.eth.getTransactionReceipt(
txId
);
console.log("transaction", transaction?.status, txId, tries);
if (tries < THRESHOLD) {
if (tries < threshold) {
tries += 1;
if (!transaction || transaction === null || transaction.status === null) {
await getTransactionReceipt(txId, rpcURL, tries);
await delay();
await getTransactionReceipt(txId, rpcURL, threshold, tries);
}
}
return transaction;
Expand All @@ -61,7 +63,9 @@ export const signedTransaction = async (
from: transaction.from,
token: decodedData.sourceToken,
amount: decodedData.sourceAmount,
contractAddress: getFundManagerAddress(decodedData.targetChainId),
fundManagerContractAddress: getFundManagerAddress(
decodedData.targetChainId
),
fiberRouterAddress: getFiberRouterAddress(decodedData.targetChainId),
chainId: decodedData.sourceChainId,
targetChainId: decodedData.targetChainId,
Expand All @@ -78,32 +82,20 @@ export const signedTransaction = async (
txData.salt = Web3.utils.keccak256(
txData.transactionHash.toLocaleLowerCase()
);
const payBySig0 = createSignedPayment(
const payBySig = createSignedPayment(
txData.targetChainId,
txData.targetAddress,
destinationAmountToMachine,
txData.targetToken,
txData.contractAddress,
txData.fundManagerContractAddress,
txData.salt,
web3
);

const payBySig1 = createSignedPayment(
txData.targetChainId,
txData.fiberRouterAddress,
destinationAmountToMachine,
txData.targetToken,
txData.contractAddress,
txData.salt,
web3
);
return {
...txData,
signatures: [
{ signature: payBySig0.signatures, hash: payBySig0.hash },
{ signature: payBySig1.signatures, hash: payBySig1.hash },
],
hash: payBySig0.hash,
signatures: [{ signature: payBySig.signatures, hash: payBySig.hash }],
hash: payBySig.hash,
address: process.env.PUBLIC_KEY,
};
} catch (error) {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/crons/transactionsJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
cosmWasmService,
} from "./../../services/index";
import { JobRequestBody } from "./../../interfaces/index";
import { getThreshold } from "../../constants/constants";
let isProccessRunning = false;
let localTransactionHashes: any = [];

Expand Down Expand Up @@ -65,6 +66,7 @@ async function workerForFetchChainDataFromNetwork(tx: any) {
isDestinationNonEVM: destinationNetwork.isNonEVM,
bridgeAmount: tx.bridgeAmount,
txId: tx.receiveTransactionId,
threshold: sourceNetwork.threshold,
};

let job: any = { data: data, transaction: tx };
Expand All @@ -81,7 +83,8 @@ async function workerForFetchChainDataFromNetwork(tx: any) {
console.log("source is EVM");
job.returnvalue = await web3Service.getTransactionReceipt(
job.data.txId,
job.data.sourceRpcURL
job.data.sourceRpcURL,
getThreshold(job.data.threshold)
);
}

Expand Down

0 comments on commit d69955e

Please sign in to comment.