Skip to content

Commit

Permalink
added the private key and the alchemy api url functionality in the in…
Browse files Browse the repository at this point in the history
…it function
  • Loading branch information
ibilalkayy committed Jun 28, 2024
1 parent 95a994a commit 9609e30
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ To know about the application in detail, you can visit the [docs](https://github
To get started in flow, you need to have two applications installed on your machine.

1. [Golang](https://go.dev/dl/)
2. [Docker](https://www.docker.com/get-started/)
3. [PostgreSQL](https://www.postgresql.org/)
2. [Cobra Framework](cobra.dev/)
3. [Docker](https://www.docker.com/get-started/)
4. [PostgreSQL](https://www.postgresql.org/)
5. [Alchemy API URL](https://docs.alchemy.com/docs/alchemy-quickstart-guide)
6. Wallet Private key

### How to get Alchemy API URL?

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.

## Installation

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

```bash
# Initialize the application
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
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

# Create a budget
flow budget create --category groceries/utilities --amount 300
Expand Down
19 changes: 15 additions & 4 deletions cmd/init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func initApp(cmd *cobra.Command, args []string) {
postgresDBName, _ := cmd.Flags().GetString("db-name")
sslMode, _ := cmd.Flags().GetString("sslmode")

privateKey, _ := cmd.Flags().GetString("private-key")
alchemyApiURL, _ := cmd.Flags().GetString("alchemy-api-url")

authParams := &entities.AuthVariables{
Username: username,
Gmail: gmail,
Expand All @@ -55,12 +58,18 @@ func initApp(cmd *cobra.Command, args []string) {
SSLMode: sslMode,
}

blockchainParams := &entities.BlockchainVariables{
PrivateKey: privateKey,
AlchemyApiURL: alchemyApiURL,
}

if allNonEmpty(
authParams.Username, authParams.Gmail, authParams.AppPassword,
dbParams.Host, dbParams.Port, dbParams.User, dbParams.Password,
dbParams.DBName, dbParams.SSLMode,
dbParams.DBName, dbParams.SSLMode, blockchainParams.PrivateKey,
blockchainParams.AlchemyApiURL,
) {
err := InitializeApplication(authParams, dbParams)
err := InitializeApplication(authParams, dbParams, blockchainParams)
if err != nil {
fmt.Println("Error during initialization:", err)
return
Expand All @@ -84,9 +93,9 @@ func takeHandler() *handler.Handler {
return handle
}

func InitializeApplication(authParams *entities.AuthVariables, dbParams *entities.DatabaseVariables) error {
func InitializeApplication(authParams *entities.AuthVariables, dbParams *entities.DatabaseVariables, blockchainParams *entities.BlockchainVariables) error {
h := takeHandler()
err := h.Deps.Init.WriteEnvFile(authParams, dbParams)
err := h.Deps.Init.WriteEnvFile(authParams, dbParams, blockchainParams)
if err != nil {
return fmt.Errorf("error writing to .env file: %v", err)
}
Expand All @@ -110,4 +119,6 @@ func init() {
InitCmd.Flags().StringP("db-user", "u", "", "Write the PostgreSQL user")
InitCmd.Flags().StringP("db-name", "d", "", "Write the PostgreSQL DB name")
InitCmd.Flags().StringP("sslmode", "s", "", "Write the PostgreSQL SSLMode")
InitCmd.Flags().StringP("private-key", "k", "", "Write your wallet private key to store in .env file")
InitCmd.Flags().StringP("alchemy-api-url", "i", "", "Write your alchemy api url for sepolia test network")
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

const version = "v0.2.2"
const version = "v0.2.3"

// rootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Expand Down
5 changes: 5 additions & 0 deletions entities/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ type DatabaseVariables struct {
DBName string
SSLMode string
}

type BlockchainVariables struct {
PrivateKey string
AlchemyApiURL string
}
2 changes: 1 addition & 1 deletion interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type Init interface {
WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVariables) error
WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVariables, bv *entities.BlockchainVariables) error
}

type Connect interface {
Expand Down
5 changes: 4 additions & 1 deletion usecases/app/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type MyInit struct {
*handler.Handler
}

func (MyInit) WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVariables) error {
func (MyInit) WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVariables, bv *entities.BlockchainVariables) error {
f, err := os.Create(".env")
if err != nil {
return err
Expand All @@ -33,6 +33,9 @@ func (MyInit) WriteEnvFile(av *entities.AuthVariables, dv *entities.DatabaseVari
{"DB_PASSWORD", dv.Password},
{"DB_NAME", dv.DBName},
{"SSL_MODE", dv.SSLMode},

{"PRIVATE_KEY", bv.PrivateKey},
{"ALCHEMY_API_URL", bv.AlchemyApiURL},
}

for _, field := range fields {
Expand Down

0 comments on commit 9609e30

Please sign in to comment.