Skip to content

Commit 81f0256

Browse files
authored
Update add wallet endpoint & wallet nonce creation (#133)
* Update add wallet endpoint for local wallet * Add wallet error message * Fix wallet nonce
1 parent 009070e commit 81f0256

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

server/api/wallet/addWallet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ const requestBodySchema = Type.Object({
5252

5353
requestBodySchema.examples = [
5454
{
55-
walletTye: "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-
walletTye: "gcp_kms",
62+
walletType: "gcp_kms",
6363
gcpKMS: {
6464
keyId: "12345678-1234-1234-1234-123456789012",
6565
versionId: "1",
@@ -152,7 +152,7 @@ export async function addWallet(fastify: FastifyInstance) {
152152
gcpKmsKeyVersionId,
153153
gcpKmsResourcePath,
154154
});
155-
} else if (WalletConfigType.ppk) {
155+
} else if (walletType === WalletConfigType.ppk) {
156156
if (!privateKey) {
157157
throw new Error("privateKey is not defined!");
158158
}

src/db/wallets/createWalletDetails.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ export const createWalletDetails = async ({
2222
}: CreateWalletDetailsParams) => {
2323
const prisma = getPrismaWithPostgresTx(pgtx);
2424

25+
const wallet = await prisma.walletDetails.findUnique({
26+
where: {
27+
address: walletDetails.address.toLowerCase(),
28+
},
29+
});
30+
31+
if (!wallet) {
32+
throw new Error(
33+
`Wallet with address ${walletDetails.address} has already been added!`,
34+
);
35+
}
36+
2537
return prisma.walletDetails.create({
2638
data: {
2739
...walletDetails,

src/db/wallets/getWalletDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const getWalletDetails = async ({
3535
// TODO: Change this!
3636
const walletDetails = await prisma.walletDetails.findUnique({
3737
where: {
38-
address,
38+
address: address.toLowerCase(),
3939
},
4040
});
4141

src/db/wallets/getWalletNonce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const getWalletNonce = async ({
3131
if (!walletNonce) {
3232
const walletDetails = await prisma.walletDetails.findUnique({
3333
where: {
34-
address,
34+
address: address.toLowerCase(),
3535
},
3636
});
3737

0 commit comments

Comments
 (0)