From f27d87524a059c826a0d4312c67c373650803427 Mon Sep 17 00:00:00 2001 From: nagdahimanshu Date: Tue, 18 Jun 2024 12:56:02 +0200 Subject: [PATCH] :hammer: Code refactoring --- README.md | 32 ++++++++++++++------------ cmd/server.go | 4 ++-- internal/chain/transaction.go | 4 ++-- internal/server/server.go | 2 +- web/index.html | 2 +- web/public/{favicon.png => token.png} | Bin 6 files changed, 23 insertions(+), 21 deletions(-) rename web/public/{favicon.png => token.png} (100%) diff --git a/README.md b/README.md index 48c76895..ccf9670a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ![GitHub issues](https://img.shields.io/github/issues-raw/liskhq/lsk-faucet) ![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/liskhq/lsk-faucet) -LSK faucet is a web application to get Lisk (LSK) tokens on the Lisk Sepolia Testnet. The tokens can be used to test and troubleshoot your decentralized application or protocol before going live on the Lisk Mainnet. +LSK faucet is a web application that can be configured and deployed to get custom ERC20 tokens on any network. The tokens can be used to test and troubleshoot your decentralized application or protocol before going live on the Mainnet. ## Features @@ -32,11 +32,13 @@ cd lsk-faucet ``` 2. Bundle Frontend web with Vite +Please make sure to replace token icon at `web/public/token.png` with the specific ERC20 token icon. + ```bash go generate ``` -3. Build Go project +1. Build Go project ```bash go build -o lsk-faucet ``` @@ -58,12 +60,12 @@ go build -o lsk-faucet ### Configuration Below is a list of environment variables that can be configured. -- `WEB3_PROVIDER`: Endpoint for Lisk JSON-RPC connection. +- `WEB3_PROVIDER`: RPC Endpoint to connect with the network. - `PRIVATE_KEY`: Private key hex to fund user requests with. - `KEYSTORE`: Keystore file to fund user requests with. - `HCAPTCHA_SITEKEY`: hCaptcha sitekey. - `HCAPTCHA_SECRET`: hCaptcha secret. -- `LSK_TOKEN_ADDRESS`: Contract address of LSK token on the Lisk L2. +- `ERC20_TOKEN_ADDRESS`: Contract address of ERC20 token on the above mentioned network, defaults to Lisk L2 token address. You can configure the funder by setting any of the following environment variable instead of command-line flags: ```bash @@ -86,17 +88,17 @@ Then run the faucet application without the wallet command-line flags: The following are the available command-line flags(excluding above wallet flags): -| Flag | Description | Default Value | -| ----------------- | ------------------------------------------------ | ------------------------------------------ | -| -httpport | Listener port to serve HTTP connection | 8080 | -| -proxycount | Count of reverse proxies in front of the server | 0 | -| -token-address | Token contract address | 0x8a21CF9Ba08Ae709D64Cb25AfAA951183EC9FF6D | -| -faucet.amount | Number of LSK to transfer per user request | 1 | -| -faucet.minutes | Number of minutes to wait between funding rounds | 10080 (1 week) | -| -faucet.name | Network name to display on the frontend | sepolia | -| -faucet.symbol | Token symbol to display on the frontend | LSK | -| -hcaptcha.sitekey | hCaptcha sitekey | | -| -hcaptcha.secret | hCaptcha secret | | +| Flag | Description | Default Value | +| ----------------- | --------------------------------------------------- | ------------------------------------------ | +| -httpport | Listener port to serve HTTP connection | 8080 | +| -proxycount | Count of reverse proxies in front of the server | 0 | +| -token-address | Token contract address | 0x8a21CF9Ba08Ae709D64Cb25AfAA951183EC9FF6D | +| -faucet.amount | Number of ERC20 tokens to transfer per user request | 1 | +| -faucet.minutes | Number of minutes to wait between funding rounds | 10080 (1 week) | +| -faucet.name | Network name to display on the frontend | sepolia | +| -faucet.symbol | Token symbol to display on the frontend | LSK | +| -hcaptcha.sitekey | hCaptcha sitekey | | +| -hcaptcha.secret | hCaptcha secret | | ### Docker deployment #### Build docker image diff --git a/cmd/server.go b/cmd/server.go index c14f5582..110f51fd 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -19,13 +19,13 @@ import ( var ( appVersion = "v1.1.0" chainIDMap = map[string]int{"sepolia": 4202} - tokenAddress = flag.String("token-address", os.Getenv("LSK_TOKEN_ADDRESS"), "Contract address of LSK token on the Lisk L2") + tokenAddress = flag.String("token-address", os.Getenv("ERC20_TOKEN_ADDRESS"), "Contract address of ERC20 token") httpPortFlag = flag.Int("httpport", 8080, "Listener port to serve HTTP connection") proxyCntFlag = flag.Int("proxycount", 0, "Count of reverse proxies in front of the server") versionFlag = flag.Bool("version", false, "Print version number") - payoutFlag = flag.Int("faucet.amount", 1, "Number of LSK to transfer per user request") + payoutFlag = flag.Int("faucet.amount", 1, "Number of ERC20 tokens to transfer per user request") intervalFlag = flag.Int("faucet.minutes", 10080, "Number of minutes to wait between funding rounds") netnameFlag = flag.String("faucet.name", "sepolia", "Network name to display on the frontend") symbolFlag = flag.String("faucet.symbol", "LSK", "Token symbol to display on the frontend") diff --git a/internal/chain/transaction.go b/internal/chain/transaction.go index 3a84a005..684e0498 100644 --- a/internal/chain/transaction.go +++ b/internal/chain/transaction.go @@ -21,7 +21,7 @@ import ( type TxBuilder interface { Sender() common.Address TransferETH(ctx context.Context, to string, value *big.Int) (common.Hash, error) - TransferLSK(ctx context.Context, to string, value *big.Int) (common.Hash, error) + TransferERC20(ctx context.Context, to string, value *big.Int) (common.Hash, error) } type TxBuild struct { @@ -96,7 +96,7 @@ func (b *TxBuild) TransferETH(ctx context.Context, to string, value *big.Int) (c return signedTx.Hash(), nil } -func (b *TxBuild) TransferLSK(ctx context.Context, to string, value *big.Int) (common.Hash, error) { +func (b *TxBuild) TransferERC20(ctx context.Context, to string, value *big.Int) (common.Hash, error) { emptyHash := common.Hash{} publicKey := b.privateKey.Public() publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) diff --git a/internal/server/server.go b/internal/server/server.go index 6e37a0d2..6692ff44 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -55,7 +55,7 @@ func (s *Server) handleClaim() http.HandlerFunc { address, _ := readAddress(r) ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) defer cancel() - txHash, err := s.TransferLSK(ctx, address, chain.LSKToWei(int64(s.cfg.payout))) + txHash, err := s.TransferERC20(ctx, address, chain.LSKToWei(int64(s.cfg.payout))) if err != nil { log.WithError(err).Error("Failed to send transaction") renderJSON(w, claimResponse{Message: err.Error()}, http.StatusInternalServerError) diff --git a/web/index.html b/web/index.html index 6711bda5..e8c72a0c 100644 --- a/web/index.html +++ b/web/index.html @@ -2,7 +2,7 @@ - + Vite + Svelte diff --git a/web/public/favicon.png b/web/public/token.png similarity index 100% rename from web/public/favicon.png rename to web/public/token.png