blockchain-utils-service 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/contractSubscribeWebhook.js +12 -13
- package/src/getEvents.js +1 -0
- package/src/index.js +1 -1
- package/src/writeTransaction.js +0 -2
package/package.json
CHANGED
|
@@ -18,11 +18,10 @@ import axios from "axios";
|
|
|
18
18
|
* @param {string} config.subscriptionType - The type of webhook e.g. "activityType" or "eventType"
|
|
19
19
|
* @returns {Promise<Object>} - Result of the webhook subscription, typically includes subscription ID or status.
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
|
-
export async function contractSubscribeWebhook({
|
|
21
|
+
export async function subscribeContract({
|
|
23
22
|
chainId,
|
|
24
23
|
address,
|
|
25
|
-
|
|
24
|
+
streamingServiceUrl,
|
|
26
25
|
eventSignatures,
|
|
27
26
|
streamingWebhookUrl,
|
|
28
27
|
environment,
|
|
@@ -31,7 +30,7 @@ export async function contractSubscribeWebhook({
|
|
|
31
30
|
streamingPassAuth
|
|
32
31
|
}) {
|
|
33
32
|
try {
|
|
34
|
-
const uri = `${
|
|
33
|
+
const uri = `${streamingServiceUrl}/streams/evm`;
|
|
35
34
|
const body = {
|
|
36
35
|
chainId,
|
|
37
36
|
address,
|
|
@@ -40,15 +39,15 @@ export async function contractSubscribeWebhook({
|
|
|
40
39
|
environment,
|
|
41
40
|
subscriptionType
|
|
42
41
|
};
|
|
43
|
-
const token =
|
|
42
|
+
const token = Buffer.from(`${streamingUserAuth}:${streamingPassAuth}`).toString("base64");
|
|
44
43
|
const headers = {
|
|
45
44
|
"Content-Type": "application/json",
|
|
46
45
|
"Authorization": `Basic ${token}`,
|
|
47
46
|
};
|
|
48
|
-
const
|
|
47
|
+
const response = await axios.post(uri, body, {
|
|
49
48
|
headers: headers
|
|
50
49
|
});
|
|
51
|
-
return { isSuccess: true, data:
|
|
50
|
+
return { isSuccess: true, data: response.data };
|
|
52
51
|
} catch (error) {
|
|
53
52
|
const errData = error.response?.data || error.message;
|
|
54
53
|
return { isSuccess: false, data: `Webhook creation failed: ${JSON.stringify(errData)}` };
|
|
@@ -61,21 +60,21 @@ export async function contractSubscribeWebhook({
|
|
|
61
60
|
*
|
|
62
61
|
* @param {string} subscriptionId – The ID of the webhook to be updated.
|
|
63
62
|
* @param {boolean} disabledFlag – The new status for the webhook, either "true" (to disable) or "false" (to enable).
|
|
64
|
-
* @param {string}
|
|
63
|
+
* @param {string} streamingServiceUrl - The base URL for the Thirdweb Insight API.
|
|
65
64
|
* @returns {Promise<{isSuccess: boolean, data: any}>}
|
|
66
65
|
*/
|
|
67
|
-
export async function
|
|
66
|
+
export async function updateTrackerStatus({
|
|
68
67
|
subscriptionId,
|
|
69
68
|
status,
|
|
70
|
-
|
|
69
|
+
streamingServiceUrl,
|
|
71
70
|
streamingUserAuth,
|
|
72
71
|
streamingPassAuth
|
|
73
72
|
}) {
|
|
74
|
-
if (!subscriptionId || !
|
|
75
|
-
|
|
73
|
+
if (!subscriptionId || !streamingServiceUrl || !status) {
|
|
74
|
+
throw new Error(`Required Key Value Missing!`);
|
|
76
75
|
}
|
|
77
76
|
try {
|
|
78
|
-
const uri = `${
|
|
77
|
+
const uri = `${streamingServiceUrl}/streams/evm/${subscriptionId}/status`;
|
|
79
78
|
const body = { status };
|
|
80
79
|
const token = btoa(`${streamingUserAuth}:${streamingPassAuth}`);
|
|
81
80
|
const headers = {
|
package/src/getEvents.js
CHANGED
|
@@ -62,6 +62,7 @@ export async function fetchContractEvents({
|
|
|
62
62
|
const response = await axios.get(url, { params, headers });
|
|
63
63
|
return response.data;
|
|
64
64
|
} catch (error) {
|
|
65
|
+
// #Recheck that
|
|
65
66
|
throw new Error(`Failed to fetch events: ${error.response?.data?.error || error.message}`);
|
|
66
67
|
}
|
|
67
68
|
}
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { deployNewContract } from "./deploy.js";
|
|
|
2
2
|
export { writeTransaction } from "./writeTransaction.js";
|
|
3
3
|
export { fetchContractEvents } from "./getEvents.js";
|
|
4
4
|
export { hasBlockNumberReached } from "./getBlockNumberReached.js";
|
|
5
|
-
export {
|
|
5
|
+
export { subscribeContract, updateTrackerStatus } from "./contractSubscribeWebhook.js";
|
|
6
6
|
export { getTransactionHash } from "./getTransactionHash.js";
|
|
7
7
|
export { getTokenPrice } from "./getTokenPrice.js";
|
|
8
8
|
export { findDeploymentTxHash } from "./getCreatorTxHash.js";
|
package/src/writeTransaction.js
CHANGED
|
@@ -41,8 +41,6 @@ export async function writeTransaction({
|
|
|
41
41
|
"x-backend-wallet-address": backendWalletAddress,
|
|
42
42
|
"x-idempotency-key": `idemp-${Date.now()}`,
|
|
43
43
|
};
|
|
44
|
-
console.log("AUTH TOKEN RECEIVED:", authorizationToken);
|
|
45
|
-
console.log("HEADERS USED:", headers);
|
|
46
44
|
const body = JSON.stringify({ functionName, args });
|
|
47
45
|
const response = await fetch(writeUrl, { method: "POST", headers, body });
|
|
48
46
|
if (!response.ok) {
|