Skip to content

Commit

Permalink
PRO-2585-Arka_Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilkumar1612 committed Aug 9, 2024
1 parent 881c856 commit 9e5769b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ Parameters:

- `/deposit` - This url accepts one parameter and returns the submitted transaction hash if successful. This url is used to deposit some funds to the entryPointAddress from the sponsor wallet
1. amount - The amount to be deposited in ETH

- `/whitelist/v2` - This url accepts one parameter and returns a message indicating whether the offchain whitelist was successful. This url is used to whitelist an array of addresses thats needed to be whitelisted for sponsorship. If all the addresses were already whitelisted, an error message will be thrown. If some of the addresses were already whitelisted the rest of the addresses will be whitelisted.
1. address - an array of addresses (max. 10 per request)

- `/removeWhitelist/v2` - This url accepts one parameter and returns a message indicating whether the offchain whitelist removal was successful. This url is used to remove whitelist of an array of addresses. If all the addresses were not whitelisted, an error message will be thrown. If some of the addresses were not whitelisted the rest of the addresses will be removed from whitelist.
1. address - an array of addresses (max. 10 per request)

- `/checkWhitelist/v2` - This url accepts one parameter and returns if the address has been whitelisted or not
1. address - The address which needs to be checked.
2. policyId - Optional policy id.

- `/deposit/v2` - This url accepts one parameter and returns the submitted transaction hash if successful. This url is used to deposit some funds to the entryPointAddress from the sponsor wallet
1. amount - The amount to be deposited in ETH.

- `/getAllWhitelist/v2` - This url accepts optionally one parameter and returns all the addresses which are whitelisted for the apiKey/policyId.
1. policyId - Optional policy id.

## Local Docker Networks

Expand Down
1 change: 1 addition & 0 deletions backend/src/constants/ReturnCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export default {
NOT_FOUND: 404,
INTERNAL_SERVER_ERROR: 500,
NOT_AUTHORIZED: 403,
CONFLICT: 409
}
8 changes: 4 additions & 4 deletions backend/src/routes/whitelist-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
existingWhitelistRecord.addresses.splice(existingWhitelistRecord.addresses.indexOf(ele), 1);
}
});
if (toBeRemoved.length < 1) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.ADDRESS_ALREADY_ADDED });
if (toBeRemoved.length < 1) return reply.code(ReturnCode.CONFLICT).send({ error: ErrorMessage.ADDRESS_NOT_WHITELISTED });

if (existingWhitelistRecord.addresses.length < 1) await server.whitelistRepository.deleteById(existingWhitelistRecord.id);
else await server.whitelistRepository.updateOneById(existingWhitelistRecord);
} else {
throw new Error(ErrorMessage.NO_WHITELIST_FOUND);
}
const result = { message: "Successfully deleted from Whitelist" }
const result = { message: "Successfully removed whitelisted addresses" }
server.log.info(result, 'Response sent: ');
if (body.jsonrpc)
return reply.code(ReturnCode.SUCCESS).send({ jsonrpc: body.jsonrpc, id: body.id, result, error: null })
Expand Down Expand Up @@ -399,7 +399,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
address.filter(ele => {
if (!existingWhitelistRecord.addresses.includes(ele)) toBeAdded.push(ele);
});
if (toBeAdded.length < 1) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.ADDRESS_ALREADY_ADDED });
if (toBeAdded.length < 1) return reply.code(ReturnCode.CONFLICT).send({ error: ErrorMessage.ADDRESS_ALREADY_ADDED });
const allAddresses = toBeAdded.concat(existingWhitelistRecord.addresses);
existingWhitelistRecord.addresses = allAddresses;
await server.whitelistRepository.updateOneById(existingWhitelistRecord);
Expand All @@ -412,7 +412,7 @@ const whitelistRoutes: FastifyPluginAsync = async (server) => {
await server.whitelistRepository.create(addWhitelistDto);

}
const result = { message: "Successfully added to Whitelist" }
const result = { message: "Successfully whitelisted" }
server.log.info(result, 'Response sent: ');
if (body.jsonrpc)
return reply.code(ReturnCode.SUCCESS).send({ jsonrpc: body.jsonrpc, id: body.id, result, error: null })
Expand Down

0 comments on commit 9e5769b

Please sign in to comment.