Skip to content

Commit a606729

Browse files
authored
Updates: Multiple-Webhooks support, Low Balance Check Flow, Deploy Examples (#261)
* updates for webhooks to handle multiple, untill we add restrictions * deploy examples updated * cleanup
1 parent d72f1b8 commit a606729

File tree

9 files changed

+99
-89
lines changed

9 files changed

+99
-89
lines changed

server/api/deploy/prebuilts/edition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ requestBodySchema.examples = [
4444
contractMetadata: {
4545
name: "My Edition",
4646
symbol: "ED",
47-
primary_sale_recipient: "0x3EcDBF3B911d0e9052b64850693888b008e18373",
47+
primary_sale_recipient: "<your-wallet-address>",
4848
},
4949
},
5050
];

server/api/deploy/prebuilts/editionDrop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ requestBodySchema.examples = [
4545
contractMetadata: {
4646
name: "My Edition Drop",
4747
symbol: "EDD",
48-
primary_sale_recipient: "0x3EcDBF3B911d0e9052b64850693888b008e18373",
48+
primary_sale_recipient: "<your-wallet-address>",
4949
},
5050
},
5151
];

server/api/deploy/prebuilts/nftDrop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ requestBodySchema.examples = [
4545
contractMetadata: {
4646
name: "My NFT Drop",
4747
symbol: "NFTD",
48-
primary_sale_recipient: "0x3EcDBF3B911d0e9052b64850693888b008e18373",
48+
primary_sale_recipient: "<your-wallet-address>",
4949
},
5050
},
5151
];

server/api/deploy/prebuilts/signatureDrop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ requestBodySchema.examples = [
4545
contractMetadata: {
4646
name: "My NFT Drop",
4747
symbol: "NFTD",
48-
primary_sale_recipient: "0x3EcDBF3B911d0e9052b64850693888b008e18373",
48+
primary_sale_recipient: "<your-wallet-address>",
4949
},
5050
},
5151
];

server/api/deploy/prebuilts/token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ requestBodySchema.examples = [
4141
contractMetadata: {
4242
name: "My Token",
4343
symbol: "TKN",
44-
primary_sale_recipient: "0x3EcDBF3B911d0e9052b64850693888b008e18373",
44+
primary_sale_recipient: "<your-wallet-address>",
4545
},
4646
},
4747
];

server/api/deploy/prebuilts/tokenDrop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ requestBodySchema.examples = [
4343
contractMetadata: {
4444
name: "My Signature Drop",
4545
symbol: "SIGD",
46-
primary_sale_recipient: "0x3EcDBF3B911d0e9052b64850693888b008e18373",
46+
primary_sale_recipient: "<your-wallet-address>",
4747
},
4848
},
4949
];

server/utilities/webhook.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ export const sendTxWebhook = async (data: TxWebookParams): Promise<void> => {
8282
try {
8383
const txData = await getTxById({ queueId: data.id });
8484

85-
let webhookConfig: SanitizedWebHooksSchema | undefined =
85+
let webhookConfig: SanitizedWebHooksSchema[] | undefined =
8686
await getWebhookConfig(WebhooksEventTypes.ALL_TX);
8787

8888
// For Backwards Compatibility
8989
const config = await getConfiguration();
9090
if (config?.webhookUrl && config?.webhookAuthBearerToken) {
91-
webhookConfig = {
91+
const newFormatWebhookData = {
9292
id: 0,
9393
url: config.webhookUrl,
9494
secret: config.webhookAuthBearerToken,
@@ -97,8 +97,7 @@ export const sendTxWebhook = async (data: TxWebookParams): Promise<void> => {
9797
createdAt: new Date().toISOString(),
9898
name: "Legacy Webhook",
9999
};
100-
101-
await sendWebhookRequest(webhookConfig, txData);
100+
await sendWebhookRequest(newFormatWebhookData, txData);
102101
return;
103102
}
104103

@@ -125,12 +124,14 @@ export const sendTxWebhook = async (data: TxWebookParams): Promise<void> => {
125124
}
126125
}
127126

128-
if (!webhookConfig || !webhookConfig?.active) {
129-
logger.server.debug("No Webhook Set or Active, skipping webhook send");
130-
return;
131-
}
127+
webhookConfig?.map(async (config) => {
128+
if (!config || !config?.active) {
129+
logger.server.debug("No Webhook Set or Active, skipping webhook send");
130+
return;
131+
}
132132

133-
await sendWebhookRequest(webhookConfig, txData);
133+
await sendWebhookRequest(config, txData);
134+
});
134135
} catch (error) {
135136
logger.server.error(`[sendWebhook] error: ${error}`);
136137
}
@@ -153,16 +154,23 @@ export const sendBalanceWebhook = async (
153154
WebhooksEventTypes.BACKEND_WALLET_BALANCE,
154155
);
155156

156-
if (!webhookConfig || !webhookConfig.active) {
157+
if (!webhookConfig) {
157158
logger.server.debug("No Webhook set, skipping webhook send");
158159
return;
159160
}
160161

161-
const success = await sendWebhookRequest(webhookConfig, data);
162+
webhookConfig.map(async (config) => {
163+
if (!config || !config.active) {
164+
logger.server.debug("No Webhook set, skipping webhook send");
165+
return;
166+
}
162167

163-
if (success) {
164-
balanceNotificationLastSentAt = Date.now();
165-
}
168+
const success = await sendWebhookRequest(config, data);
169+
170+
if (success) {
171+
balanceNotificationLastSentAt = Date.now();
172+
}
173+
});
166174
} catch (error) {
167175
logger.server.error(`[sendWebhook] error: ${error}`);
168176
}

server/utils/cache/getWebhook.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import {
44
WebhooksEventTypes,
55
} from "../../../src/schema/webhooks";
66

7-
export const webhookCache = new Map<string, SanitizedWebHooksSchema>();
7+
export const webhookCache = new Map<string, SanitizedWebHooksSchema[]>();
88

99
export const getWebhookConfig = async (
1010
eventType: WebhooksEventTypes,
11-
): Promise<SanitizedWebHooksSchema | undefined> => {
11+
): Promise<SanitizedWebHooksSchema[] | undefined> => {
1212
const cacheKey = eventType;
1313
if (webhookCache.has(cacheKey) && webhookCache.get(cacheKey)) {
14-
return webhookCache.get(cacheKey) as SanitizedWebHooksSchema;
14+
return webhookCache.get(cacheKey) as SanitizedWebHooksSchema[];
1515
}
1616

1717
const webhookConfig = await getAllWebhooks();
@@ -26,6 +26,6 @@ export const getWebhookConfig = async (
2626
return undefined;
2727
}
2828

29-
webhookCache.set(cacheKey, eventTypeWebhookDetails[0]);
30-
return eventTypeWebhookDetails[0];
29+
webhookCache.set(cacheKey, eventTypeWebhookDetails);
30+
return eventTypeWebhookDetails;
3131
};

src/worker/tasks/processTx.ts

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -131,78 +131,80 @@ export const processTx = async () => {
131131

132132
await sendBalanceWebhook(walletBalanceData);
133133

134-
throw new Error(message);
135-
} else {
136-
if (!dbNonceData) {
137-
logger.worker.error(
138-
`Could not find nonce or details for wallet ${walletAddress} on chain ${chainId}`,
139-
);
140-
}
134+
logger.worker.warn(
135+
`[Low Wallet Balance] [${walletAddress}]: ` + message,
136+
);
137+
}
141138

142-
// - Take the larger of the nonces, and update database nonce to mepool value if mempool is greater
143-
let startNonce: BigNumber;
144-
const mempoolNonce = BigNumber.from(mempoolNonceData);
145-
const dbNonce = BigNumber.from(dbNonceData?.nonce || 0);
146-
if (mempoolNonce.gt(dbNonce)) {
147-
await updateWalletNonce({
148-
pgtx,
149-
chainId,
150-
address: walletAddress,
151-
nonce: mempoolNonce.toNumber(),
152-
});
139+
if (!dbNonceData) {
140+
logger.worker.error(
141+
`Could not find nonce or details for wallet ${walletAddress} on chain ${chainId}`,
142+
);
143+
}
153144

154-
startNonce = mempoolNonce;
155-
} else {
156-
startNonce = dbNonce;
157-
}
145+
// - Take the larger of the nonces, and update database nonce to mepool value if mempool is greater
146+
let startNonce: BigNumber;
147+
const mempoolNonce = BigNumber.from(mempoolNonceData);
148+
const dbNonce = BigNumber.from(dbNonceData?.nonce || 0);
149+
if (mempoolNonce.gt(dbNonce)) {
150+
await updateWalletNonce({
151+
pgtx,
152+
chainId,
153+
address: walletAddress,
154+
nonce: mempoolNonce.toNumber(),
155+
});
156+
157+
startNonce = mempoolNonce;
158+
} else {
159+
startNonce = dbNonce;
160+
}
158161

159-
let incrementNonce = 0;
162+
let incrementNonce = 0;
160163

161-
// - Wait for transactions to be sent successfully
162-
const txStatuses: SentTxStatus[] = [];
163-
for (const i in txsToSend) {
164-
const tx = txsToSend[i];
165-
const nonce = startNonce.add(i);
164+
// - Wait for transactions to be sent successfully
165+
const txStatuses: SentTxStatus[] = [];
166+
for (const i in txsToSend) {
167+
const tx = txsToSend[i];
168+
const nonce = startNonce.add(i);
166169

167-
try {
168-
logger.worker.info(
169-
`[Transaction] [${tx.queueId}] Sending with nonce '${nonce}'`,
170-
);
171-
const res = await sdk.getSigner()!.sendTransaction({
172-
to: tx.toAddress!,
173-
from: tx.fromAddress!,
174-
data: tx.data!,
175-
value: tx.value!,
176-
nonce,
177-
...gasOverrides,
178-
});
170+
try {
171+
logger.worker.info(
172+
`[Transaction] [${tx.queueId}] Sending with nonce '${nonce}'`,
173+
);
174+
const res = await sdk.getSigner()!.sendTransaction({
175+
to: tx.toAddress!,
176+
from: tx.fromAddress!,
177+
data: tx.data!,
178+
value: tx.value!,
179+
nonce,
180+
...gasOverrides,
181+
});
179182

180-
logger.worker.info(
181-
`[Transaction] [${tx.queueId}] Submitted with nonce '${nonce}' & hash '${res.hash}'`,
182-
);
183+
logger.worker.info(
184+
`[Transaction] [${tx.queueId}] Submitted with nonce '${nonce}' & hash '${res.hash}'`,
185+
);
183186

184-
// - Keep track of the number of transactions that went through successfully
185-
incrementNonce++;
186-
txStatuses.push({
187-
status: TransactionStatusEnum.Submitted,
188-
queueId: tx.queueId!,
189-
res,
190-
sentAtBlockNumber: await sdk.getProvider().getBlockNumber(),
191-
});
192-
} catch (err: any) {
193-
logger.worker.warn(
194-
`[Transaction] [${tx.queueId}] [Nonce: ${nonce}] Failed to send with error - ${err}`,
195-
);
187+
// - Keep track of the number of transactions that went through successfully
188+
incrementNonce++;
189+
txStatuses.push({
190+
status: TransactionStatusEnum.Submitted,
191+
queueId: tx.queueId!,
192+
res,
193+
sentAtBlockNumber: await sdk.getProvider().getBlockNumber(),
194+
});
195+
} catch (err: any) {
196+
logger.worker.warn(
197+
`[Transaction] [${tx.queueId}] [Nonce: ${nonce}] Failed to send with error - ${err}`,
198+
);
196199

197-
txStatuses.push({
198-
status: TransactionStatusEnum.Errored,
199-
queueId: tx.queueId!,
200-
errorMessage:
201-
err?.message ||
202-
err?.toString() ||
203-
`Failed to handle transaction`,
204-
});
205-
}
200+
txStatuses.push({
201+
status: TransactionStatusEnum.Errored,
202+
queueId: tx.queueId!,
203+
errorMessage:
204+
err?.message ||
205+
err?.toString() ||
206+
`Failed to handle transaction`,
207+
});
206208
}
207209

208210
// - After sending transactions, update database for each transaction

0 commit comments

Comments
 (0)