-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate the calculated Bitcoin deposit address and track it in Sentry #257
Changes from 11 commits
153b00d
35ff5dd
b00b00e
c910b45
5f490ef
36f9549
2bfb6a9
3135d99
c8478b8
d4b0622
6ef50ce
c9b85c0
8f6d09a
94eaec0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import { useCallback } from "react" | ||
import { captureMessage } from "#/sdk/sentry" | ||
import { Primitive } from "@sentry/types" | ||
import { captureMessage } from "#/sentry" | ||
|
||
export const useCaptureMessage = () => | ||
useCallback( | ||
( | ||
message: string, | ||
params?: { [key: string]: unknown }, | ||
tags?: { [key: string]: string }, | ||
tags?: { [key: string]: Primitive }, | ||
) => { | ||
if (import.meta.env.VITE_SENTRY_SUPPORT) { | ||
captureMessage(message, params, tags) | ||
} | ||
const { VITE_SENTRY_SUPPORT } = import.meta.env | ||
|
||
if (VITE_SENTRY_SUPPORT === "false") return | ||
captureMessage(message, params, tags) | ||
}, | ||
[], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useCallback } from "react" | ||
import { DepositReceipt } from "@acre-btc/sdk" | ||
import { verifyDepositAddress } from "#/utils" | ||
import { BITCOIN_NETWORK } from "#/constants" | ||
import { useCaptureMessage } from "./sentry" | ||
|
||
export function useDepositTelemetry() { | ||
const captureMessage = useCaptureMessage() | ||
|
||
return useCallback( | ||
async ( | ||
deposit: DepositReceipt, | ||
depositAddress: string, | ||
ethAddress: string, | ||
) => { | ||
const { status, response } = await verifyDepositAddress( | ||
deposit, | ||
depositAddress, | ||
BITCOIN_NETWORK, | ||
) | ||
|
||
const { | ||
depositor, | ||
blindingFactor, | ||
walletPublicKeyHash, | ||
refundPublicKeyHash, | ||
refundLocktime, | ||
extraData, | ||
} = deposit | ||
|
||
const verificationStatus = { verificationStatus: status } | ||
|
||
captureMessage( | ||
`Generated deposit [${depositAddress}]`, | ||
{ | ||
depositor: depositor.identifierHex, | ||
blindingFactor: blindingFactor.toString(), | ||
walletPublicKeyHash: walletPublicKeyHash.toString(), | ||
refundPublicKeyHash: refundPublicKeyHash.toString(), | ||
refundLocktime: refundLocktime.toString(), | ||
extraData: extraData?.toString(), | ||
verificationStatus: status, | ||
verificationResponse: response, | ||
}, | ||
{ | ||
ethAddress, | ||
...verificationStatus, | ||
}, | ||
) | ||
|
||
return verificationStatus | ||
}, | ||
[captureMessage], | ||
) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||
import { BitcoinNetwork, DepositReceipt } from "@acre-btc/sdk" | ||||||
import axios from "axios" | ||||||
|
||||||
export async function verifyDepositAddress( | ||||||
deposit: DepositReceipt, | ||||||
depositAddress: string, | ||||||
network: BitcoinNetwork, | ||||||
): Promise<{ | ||||||
status: "valid" | "invalid" | "error" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create type for status There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm We don't really use this type anywhere else. Therefore, I wonder if it makes sense. 🤔 This status is strictly related only to |
||||||
response: unknown | ||||||
}> { | ||||||
const endpoint = | ||||||
"https://us-central1-keep-prd-210b.cloudfunctions.net/verify-deposit-address" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's move it out of this function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
||||||
const { | ||||||
depositor, | ||||||
blindingFactor, | ||||||
refundPublicKeyHash, | ||||||
refundLocktime, | ||||||
extraData, | ||||||
} = deposit | ||||||
|
||||||
try { | ||||||
const jsonType = extraData ? "json-extradata" : "json" | ||||||
const baseUrl = `${endpoint}/${jsonType}/${network}/latest/${ | ||||||
depositor.identifierHex | ||||||
}/${blindingFactor.toString()}/${refundPublicKeyHash.toString()}/${refundLocktime.toString()}` | ||||||
|
||||||
const url = extraData ? `${baseUrl}/${extraData.toString()}` : baseUrl | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's create a helper function to generate this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
||||||
const response = await axios.get<{ address: string }>( | ||||||
url, | ||||||
{ timeout: 10000 }, // 10s | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
) | ||||||
|
||||||
const match = response.data.address === depositAddress | ||||||
|
||||||
return { | ||||||
status: match ? "valid" : "invalid", | ||||||
response: response.data, | ||||||
} | ||||||
} catch (err) { | ||||||
return { | ||||||
status: "error", | ||||||
response: err, | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
/// <reference types="vite/client" /> | ||
|
||
interface ImportMetaEnv { | ||
readonly VITE_SENTRY_SUPPORT: boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we remove it? Looks like we use this env variable in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right. However, take a look here. Even though we set the type
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
readonly VITE_SENTRY_DSN: string | ||
readonly VITE_ETH_HOSTNAME_HTTP: string | ||
readonly VITE_REFERRAL: number | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's worth considering on creating one common catalog for Sentry and acre-react if we don't want to keep Sentry longer in the SDK directory., eg. src/vendor/.
CC: @r-czajkowski
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the sentry directory was nested in the SDK directory. I took it a level up simply because it seems to me that the structure will be more clear. But I'm open to all suggestions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentry should not be a part of the acre-react. The dapp should care about the sentry or other integrations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@r-czajkowski I didn't say that it should be part of acre-react, I just thought about putting it in one folder:
src:
-vendor:
-- acre-react
-- sentry