Skip to content

Commit 9609e30

Browse files
committed
added the private key and the alchemy api url functionality in the init function
1 parent 95a994a commit 9609e30

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ To know about the application in detail, you can visit the [docs](https://github
2525
To get started in flow, you need to have two applications installed on your machine.
2626

2727
1. [Golang](https://go.dev/dl/)
28-
2. [Docker](https://www.docker.com/get-started/)
29-
3. [PostgreSQL](https://www.postgresql.org/)
28+
2. [Cobra Framework](cobra.dev/)
29+
3. [Docker](https://www.docker.com/get-started/)
30+
4. [PostgreSQL](https://www.postgresql.org/)
31+
5. [Alchemy API URL](https://docs.alchemy.com/docs/alchemy-quickstart-guide)
32+
6. Wallet Private key
33+
34+
### How to get Alchemy API URL?
35+
36+
Signup to Alchemy, go to it's dashboad and the app section. Create a new app. If the new app is not allowed to create, then select the existing app, go to the network tab of the app and take the Ethereum Seplia API URL.
3037

3138
## Installation
3239

@@ -56,7 +63,7 @@ Each subcommand has its own set of options and arguments. Here are some examples
5663

5764
```bash
5865
# Initialize the application
59-
flow init -n username -g gmail-id -a app-password -o postgresql-host -p postgresql-port -u postgresql-user -w postgresql-password -d postgresql-dbname -s sslmode
66+
flow init -n username -g gmail-id -a app-password -o postgresql-host -p 5432 -u postgresql-user -w postgresql-password -d postgresql-dbname -s sslmode -k privatekey -i alchemy-url
6067

6168
# Create a budget
6269
flow budget create --category groceries/utilities --amount 300

cmd/init/main.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func initApp(cmd *cobra.Command, args []string) {
4040
postgresDBName, _ := cmd.Flags().GetString("db-name")
4141
sslMode, _ := cmd.Flags().GetString("sslmode")
4242

43+
privateKey, _ := cmd.Flags().GetString("private-key")
44+
alchemyApiURL, _ := cmd.Flags().GetString("alchemy-api-url")
45+
4346
authParams := &entities.AuthVariables{
4447
Username: username,
4548
Gmail: gmail,
@@ -55,12 +58,18 @@ func initApp(cmd *cobra.Command, args []string) {
5558
SSLMode: sslMode,
5659
}
5760

61+
blockchainParams := &entities.BlockchainVariables{
62+
PrivateKey: privateKey,
63+
AlchemyApiURL: alchemyApiURL,
64+
}
65+
5866
if allNonEmpty(
5967
authParams.Username, authParams.Gmail, authParams.AppPassword,
6068
dbParams.Host, dbParams.Port, dbParams.User, dbParams.Password,
61-
dbParams.DBName, dbParams.SSLMode,
69+
dbParams.DBName, dbParams.SSLMode, blockchainParams.PrivateKey,
70+
blockchainParams.AlchemyApiURL,
6271
) {
63-
err := InitializeApplication(authParams, dbParams)
72+
err := InitializeApplication(authParams, dbParams, blockchainParams)
6473
if err != nil {
6574
fmt.Println("Error during initialization:", err)
6675
return
@@ -84,9 +93,9 @@ func takeHandler() *handler.Handler {
8493
return handle
8594
}
8695

87-
func InitializeApplication(authParams *entities.AuthVariables, dbParams *entities.DatabaseVariables) error {
96+
func InitializeApplication(authParams *entities.AuthVariables, dbParams *entities.DatabaseVariables, blockchainParams *entities.BlockchainVariables) error {
8897
h := takeHandler()
89-
err := h.Deps.Init.WriteEnvFile(authParams, dbParams)
98+
err := h.Deps.Init.WriteEnvFile(authParams, dbParams, blockchainParams)
9099
if err != nil {
91100
return fmt.Errorf("error writing to .env file: %v", err)
92101
}
@@ -110,4 +119,6 @@ func init() {
110119
InitCmd.Flags().StringP("db-user", "u", "", "Write the PostgreSQL user")
111120
InitCmd.Flags().StringP("db-name", "d", "", "Write the PostgreSQL DB name")
112121
InitCmd.Flags().StringP("sslmode", "s", "", "Write the PostgreSQL SSLMode")
122+
InitCmd.Flags().StringP("private-key", "k", "", "Write your wallet private key to store in .env file")
123+
InitCmd.Flags().StringP("alchemy-api-url", "i", "", "Write your alchemy api url for sepolia test network")
113124
}

cmd/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
const version = "v0.2.2"
12+
const version = "v0.2.3"
1313

1414
// rootCmd represents the base command when called without any subcommands
1515
var RootCmd = &cobra.Command{

entities/init.go

+5
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ type DatabaseVariables struct {
1414
DBName string
1515
SSLMode string
1616
}
17+
18+
type BlockchainVariables struct {
19+
PrivateKey string
20+
AlchemyApiURL string
21+
}

interfaces/interfaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
type Init interface {
11-
WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVariables) error
11+
WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVariables, bv *entities.BlockchainVariables) error
1212
}
1313

1414
type Connect interface {

usecases/app/init/init.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type MyInit struct {
1212
*handler.Handler
1313
}
1414

15-
func (MyInit) WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVariables) error {
15+
func (MyInit) WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVariables, bv *entities.BlockchainVariables) error {
1616
f, err := os.Create(".env")
1717
if err != nil {
1818
return err
@@ -33,6 +33,9 @@ func (MyInit) WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVari
3333
{"DB_PASSWORD", dv.Password},
3434
{"DB_NAME", dv.DBName},
3535
{"SSL_MODE", dv.SSLMode},
36+
37+
{"PRIVATE_KEY", bv.PrivateKey},
38+
{"ALCHEMY_API_URL", bv.AlchemyApiURL},
3639
}
3740

3841
for _, field := range fields {

0 commit comments

Comments
 (0)