Skip to content

Commit 822f511

Browse files
authored
Extend transaction timeout & dynamically create nonce (#134)
* Fix wallet nonce bugs * Create new nonce entry when nonce is requested * Fix examples * update
1 parent 81f0256 commit 822f511

File tree

11 files changed

+15
-55
lines changed

11 files changed

+15
-55
lines changed

core/sdk/sdk.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ const getCachedWallet = async (
112112
walletData = await getWalletDetails({
113113
pgtx,
114114
address: walletAddress,
115-
chainId,
116115
});
117116
console.log("Received wallet data:", walletData);
118117
if (walletData) {

docs/UserGuide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Backend wallets are used by the web3-api to execute transactions, you should thi
5151

5252
1.POST /create/wallet
5353
`{
54-
"walletType": "aws_kms | gcp_kms | local"
54+
"walletType": "aws-kms | gcp-kms | local"
5555
}`
5656

5757
#### AWS KMS Wallet

server/api/wallet/addWallet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const requestBodySchema = Type.Object({
1515
walletType: Type.String({
1616
description: "Wallet Type",
1717
// TODO: Support local wallet
18-
examples: ["aws_kms", "gcp_kms", "ppk"],
18+
examples: ["aws-kms", "gcp-kms", "ppk"],
1919
}),
2020
privateKey: Type.Optional(
2121
Type.String({
@@ -52,14 +52,14 @@ const requestBodySchema = Type.Object({
5252

5353
requestBodySchema.examples = [
5454
{
55-
walletType: "aws_kms",
55+
walletType: "aws-kms",
5656
awsKMS: {
5757
keyId: "12345678-1234-1234-1234-123456789012",
5858
arn: "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012",
5959
},
6060
},
6161
{
62-
walletType: "gcp_kms",
62+
walletType: "gcp-kms",
6363
gcpKMS: {
6464
keyId: "12345678-1234-1234-1234-123456789012",
6565
versionId: "1",

server/api/wallet/createEOAWallet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ import { WalletConfigType } from "../../schemas/wallet";
1818
const requestBodySchema = Type.Object({
1919
walletType: Type.String({
2020
description: "Wallet Type",
21-
examples: ["aws_kms", "gcp_kms", "local"],
21+
examples: ["aws-kms", "gcp-kms", "local"],
2222
}),
2323
});
2424

2525
requestBodySchema.examples = [
2626
{
27-
walletType: "aws_kms",
27+
walletType: "aws-kms",
2828
},
2929
{
30-
walletType: "gcp_kms",
30+
walletType: "gcp-kms",
3131
},
3232
];
3333

src/db/wallets/createWalletDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const createWalletDetails = async ({
2828
},
2929
});
3030

31-
if (!wallet) {
31+
if (wallet) {
3232
throw new Error(
3333
`Wallet with address ${walletDetails.address} has already been added!`,
3434
);

src/db/wallets/createWalletNonce.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const createWalletNonce = async ({
2424
const nonce = BigNumber.from(
2525
(await getWalletNonce(address.toLowerCase(), sdk.getProvider())) ?? 0,
2626
).toNumber();
27+
console.log(nonce);
2728

2829
return prisma.walletNonce.create({
2930
data: {

src/db/wallets/getWalletDetails.ts

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,20 @@
11
import { PrismaTransaction } from "../../schema/prisma";
22
import { getPrismaWithPostgresTx } from "../client";
3-
import { WalletWithNonceAndDetails, cleanWallet } from "./cleanWallet";
4-
import { createWalletNonce } from "./createWalletNonce";
53

64
interface GetWalletDetailsParams {
75
pgtx?: PrismaTransaction;
86
address: string;
9-
chainId: number;
10-
isRecursive?: boolean;
117
}
128

139
export const getWalletDetails = async ({
1410
pgtx,
1511
address,
16-
chainId,
17-
isRecursive,
18-
}: GetWalletDetailsParams): Promise<WalletWithNonceAndDetails | null> => {
12+
}: GetWalletDetailsParams) => {
1913
const prisma = getPrismaWithPostgresTx(pgtx);
2014

21-
const wallet = await prisma.walletNonce.findUnique({
15+
return prisma.walletDetails.findUnique({
2216
where: {
23-
address_chainId: {
24-
address: address.toLowerCase(),
25-
chainId,
26-
},
27-
},
28-
include: {
29-
walletDetails: true,
17+
address: address.toLowerCase(),
3018
},
3119
});
32-
33-
if (!wallet) {
34-
if (!isRecursive) {
35-
// TODO: Change this!
36-
const walletDetails = await prisma.walletDetails.findUnique({
37-
where: {
38-
address: address.toLowerCase(),
39-
},
40-
});
41-
42-
// If we have wallet details, but not a wallet nonce for the chain, create one
43-
if (walletDetails) {
44-
await createWalletNonce({
45-
pgtx,
46-
address,
47-
chainId,
48-
});
49-
50-
return getWalletDetails({ pgtx, address, chainId, isRecursive: true });
51-
}
52-
}
53-
54-
return wallet;
55-
}
56-
57-
return cleanWallet(wallet);
5820
};

src/db/wallets/getWalletNonce.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface GetWalletNonceParams {
99
chainId: number;
1010
}
1111

12-
// TODO: Consolidate or evaluate if getWalletDetails is necessary
1312
export const getWalletNonce = async ({
1413
pgtx,
1514
address,

worker/controller/blockchainReader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const checkForMinedTransactionsOnBlockchain = async (
4040
txReceiptData.effectiveGasPrice != BigNumber.from(-1) &&
4141
txReceiptData.timestamp != -1
4242
) {
43-
server.log.debug(
43+
server.log.info(
4444
`Got receipt for tx: ${txReceiptData.txHash}, queueId: ${txReceiptData.queueId}, effectiveGasPrice: ${txReceiptData.effectiveGasPrice}`,
4545
);
4646

worker/controller/processTransaction.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export const processTransaction = async (
5151
address: tx.fromAddress!,
5252
chainId: tx.chainId!,
5353
});
54-
server.log.error(`>>> [Nonce] ${walletNonce?.nonce}`);
5554

5655
const sdk = await getSDK(
5756
tx.chainId!.toString(),
@@ -146,7 +145,7 @@ export const processTransaction = async (
146145
}
147146
},
148147
{
149-
timeout: 30000,
148+
timeout: 5 * 60000,
150149
},
151150
);
152151

worker/controller/retryTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export const retryTransactions = async (server: FastifyInstance) => {
169169
return;
170170
},
171171
{
172-
timeout: 30000,
172+
timeout: 5 * 60000,
173173
},
174174
);
175175

0 commit comments

Comments
 (0)