Skip to content

Commit

Permalink
chore: adds methods to push the txn to db and notify the customer
Browse files Browse the repository at this point in the history
  • Loading branch information
shawakash committed May 2, 2024
1 parent 1fe2680 commit fc888e7
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function NetworkTab({
useEffect(() => {
switch (chain) {
case "Solana":
setSelectObject(SolNets.filter(({value}) => value != "mainnet"))
setSelectObject(SolNets.filter(({value}) => value != "mainnet-beta"))
break;
case "Ethereum":
setSelectObject(EthNets.filter(({value}) => value != "mainnet"))
Expand Down
1 change: 1 addition & 0 deletions backend/indexer/src/index/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class EthIndex {


// /**
//todo: send only when specific format is recieved
// * Publishing the txn payload for que based system
// */
(async () => {
Expand Down
3 changes: 3 additions & 0 deletions backend/notif-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
},
"dependencies": {
"@paybox/backend-common": "*",
"@paybox/blockchain": "*",
"@paybox/common": "*",
"@paybox/zeus": "*",
"@solana/web3.js": "^1.91.7",
"dotenv": "^16.4.5",
"esbuild": "^0.20.2",
"ethers": "^6.12.1",
"express": "^4.19.1",
"kafkajs": "^2.2.4",
"nodemailer": "^6.9.13",
Expand Down
37 changes: 36 additions & 1 deletion backend/notif-worker/src/db/txn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chain } from "@paybox/zeus";
import { HASURA_URL, JWT } from "../config";
import { HASURA_ADMIN_SERCRET, Network, NotifSubType, dbResStatus } from "@paybox/common";
import { HASURA_ADMIN_SERCRET, Network, NotifSubType, TxnType, dbResStatus } from "@paybox/common";

const chain = Chain(HASURA_URL, {
headers: {
Expand Down Expand Up @@ -85,4 +85,39 @@ export const insertCentTxn = async (
return {
status: dbResStatus.Error
}
}

/**
*
* @param txn
* @param clientId
* @returns
*/
export const insertTxn = async (
txn: Omit<TxnType, "id" | "time" | "clientId">,
clientId: string
): Promise<{
status: dbResStatus,
id?: string
}> => {
const response = await chain("mutation")({
insert_transactions_one: [{
object: {
...txn,
clientId,
},
}, {
id: true,
status: true
}]
}, {operationName: "insertTxn"});
if(response.insert_transactions_one?.id) {
return {
id: response.insert_transactions_one.id as string,
status: dbResStatus.Ok
}
}
return {
status: dbResStatus.Error
}
}
7 changes: 5 additions & 2 deletions backend/notif-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ if (cluster.isPrimary) {
(async () => {
await WorkerAdmin.getInstance().init([
{ topicName: TopicTypes.Notif, partitions: 1 },
{ topicName: TopicTypes.Db, partitions: 1 },
{ topicName: TopicTypes.Msg, partitions: 1 },
{ topicName: TopicTypes.Txn, partitions: 1 },
]);

// This can be connected in any service/s
Expand All @@ -94,8 +97,8 @@ if (cluster.isPrimary) {
(async () => {
try {
await ConsumerWorker.getInstance().connectCounsumer(
"notif-group",
[TopicTypes.Notif, TopicTypes.Msg, TopicTypes.Db],
"worker-group",
[TopicTypes.Notif, TopicTypes.Msg, TopicTypes.Db, TopicTypes.Txn],
true
);
await ConsumerWorker.getInstance().runConsumer();
Expand Down
17 changes: 15 additions & 2 deletions backend/notif-worker/src/kafka/consumer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Consumer } from "kafkajs";
import { kafka } from "..";
import { DBTopics, MsgTopics, NotifTopics, TopicTypes } from "@paybox/common";
import {notifyFriendRequest, notifyFriendRequestAccepted, notifyFriendRequestRejected, notifyPaid, notifyReceiveTxn, otpSendProcess, resendOtpProcess} from "../processes";
import { DBTopics, MsgTopics, NotifTopics, TopicTypes, TxnTopic } from "@paybox/common";
import {finalizedTxn, notifyFriendRequest, notifyFriendRequestAccepted, notifyFriendRequestRejected, notifyPaid, notifyReceiveTxn, otpSendProcess, resendOtpProcess} from "../processes";

export class ConsumerWorker {
private consumer!: Consumer;
Expand Down Expand Up @@ -111,6 +111,19 @@ export class ConsumerWorker {
}
break;

case TopicTypes.Txn:
switch(payload.type) {
case TxnTopic.Finalized:
await finalizedTxn({
chain: payload.chain,
from: payload.from,
hash: payload.hash,
to: payload.to
});
break;
}
break;

default:
console.log(`No handler for topic: ${topic}`)
break;
Expand Down
48 changes: 19 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11111,7 +11111,7 @@ dotenv@16.0.3:

dotenv@^16.0.0, dotenv@^16.3.1, dotenv@^16.4.5:
version "16.4.5"
resolved "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

dotenv@~16.3.1:
Expand Down Expand Up @@ -12174,6 +12174,19 @@ ethers@^6.10.0, ethers@^6.11.1:
tslib "2.4.0"
ws "8.5.0"

ethers@^6.12.1:
version "6.12.1"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.12.1.tgz#517ff6d66d4fd5433e38e903051da3e57c87ff37"
integrity sha512-j6wcVoZf06nqEcBbDWkKg8Fp895SS96dSnTCjiXT+8vt2o02raTn4Lo9ERUuIVU5bAjoPYeA+7ytQFexFmLuVw==
dependencies:
"@adraffy/ens-normalize" "1.10.1"
"@noble/curves" "1.2.0"
"@noble/hashes" "1.3.2"
"@types/node" "18.15.13"
aes-js "4.0.0-beta.5"
tslib "2.4.0"
ws "8.5.0"

ev-emitter@^2.0.0:
version "2.1.2"
resolved "https://registry.npmjs.org/ev-emitter/-/ev-emitter-2.1.2.tgz"
Expand Down Expand Up @@ -19316,16 +19329,8 @@ string-env-interpolation@^1.0.1:
resolved "https://registry.npmjs.org/string-env-interpolation/-/string-env-interpolation-1.0.1.tgz"
integrity sha512-78lwMoCcn0nNu8LszbP1UA7g55OeE4v7rCeWnM5B453rnNr4aq+5it3FEYtZrSEiMvHZOZ9Jlqb0OD0M2VInqg==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
name string-width-cjs
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -19430,7 +19435,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand All @@ -19444,13 +19449,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz"
Expand Down Expand Up @@ -21300,7 +21298,8 @@ wrangler@^3.25.0, wrangler@^3.30.1:
optionalDependencies:
fsevents "~2.3.2"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
name wrap-ansi-cjs
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -21327,15 +21326,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz"
Expand Down

0 comments on commit fc888e7

Please sign in to comment.