Skip to content

Commit

Permalink
[DEPLOY] complete deploy contract to ganache
Browse files Browse the repository at this point in the history
[INIT] create gitignore
[INIT] initialize cmd pkg
  • Loading branch information
myth committed May 14, 2024
1 parent e099c7a commit 2076959
Show file tree
Hide file tree
Showing 28 changed files with 726 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
developments/ganache_data
developments/mongo-volume
Empty file added LICENSE
Empty file.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
GEN_COMPOSE := ./developments/docker-compose.gen.yml
COMPOSE := ./developments/docker-compose.yml

gen-contract:
docker compose -f ${GEN_COMPOSE} up generate_contract --build
gen-proto:
docker compose -f ${GEN_COMPOSE} up generate_proto
docker compose -f ${GEN_COMPOSE} up generate_proto
gen-mock:
docker compose -f ${GEN_COMPOSE} up generate_mock
compose:
docker compose -f ${COMPOSE} up -d --build
deploy-contract:
PRIVATE_KEY="8378c4e4383b0ae04a815eb57208e4512aba0e5a9d0badcded84efef05dd98d7" CHAIN_URL="http://localhost:8545" go run deployments/contract/main.go
get-accounts:
docker compose -f ${COMPOSE} exec -it ganache ganache-cli --wallet.accounts
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Available Accounts
==================
(0) 0xBa3Fa2e3AbA0602E62471BdCBbdD2ADD0c43962c (1000 ETH)
(1) 0x00825D455C1CC59De50C172FcEB2663f50f00b51 (1000 ETH)
(2) 0xEF4473b802F813C7e6542257781e465E03D81BCC (1000 ETH)
(3) 0xD0Cf52FFEd4cdb46e35bB1B46eaFfdCF9efc3185 (1000 ETH)
(4) 0x862B76D59bFEE86510Beea68f13B0563f7C40cd2 (1000 ETH)
(5) 0xf780B9c3C757657F9d208d773eC00C6a9499Bf6f (1000 ETH)
(6) 0xEd1fa5FBDE427d6B86150d85787e90741a5d1C35 (1000 ETH)
(7) 0xD2409E5c7BcFc07985b296AA86bEDb650FA4690E (1000 ETH)
(8) 0xf6170516D3199e70c63983A4B3f5E105d578F278 (1000 ETH)
(9) 0xB67480568CF5193e13FB55FB1185444c72545650 (1000 ETH)

Private Keys
==================
(0) 0x8378c4e4383b0ae04a815eb57208e4512aba0e5a9d0badcded84efef05dd98d7
(1) 0xac740835e22cc66664fc9f3c0b75876e21b416f027e775197db09c8d3d1dddf9
(2) 0xb4d3ad5324429e7c38776980447b6aaf694861b066d04d232e447f65900dac60
(3) 0x35dccaa632da5d6a7d6f14c75d771ba3f2fe5dbbedc33527bce144f48d969bd7
(4) 0x7cf185c7c698c52d5dbf292919d1a06311aa01bcf8dcdf36a50978d144cf53db
(5) 0xddff8d02d582c62d5ca09a6e179459b6088fa667ce765523983fc7f94184e7c1
(6) 0x06757123c6a6ba7a4a3cb5a7860c5d72dbcb3e73c9a4eaa10dcdfa84d3c89bd6
(7) 0x8994c3b1a70a9d66320b7bc02eb27e856c01ed45a986c6e524468243a1327dc1
(8) 0xcfead2bc58d41ed402229282a274266be07ef567555518934cfd51b7404eba29
(9) 0x7c3315ee8d88bdf965258b630b15a2041d9cf624340f6061de164a82b66429d7

HD Wallet
==================
Mnemonic: orient tourist lottery extend cover black forget dry stomach quit fabric indoor
Base HD Path: m/44'/60'/0'/0/{account_index}

Default Gas Price
==================
2000000000

BlockGas Limit
==================
30000000

Call Gas Limit
==================
50000000

Chain
==================
Hardfork: shanghai
Id: 1337
40 changes: 40 additions & 0 deletions cmd/gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// gatewayCmd represents the gateway command
var gatewayCmd = &cobra.Command{
Use: "gateway",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("gateway called")
},
}

func init() {
rootCmd.AddCommand(gatewayCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// gatewayCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// gatewayCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
51 changes: 51 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"os"

"github.com/spf13/cobra"
)



// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "blockchain",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.blockchain.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}


40 changes: 40 additions & 0 deletions cmd/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// userCmd represents the user command
var userCmd = &cobra.Command{
Use: "user",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("user called")
},
}

func init() {
rootCmd.AddCommand(userCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// userCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// userCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
40 changes: 40 additions & 0 deletions cmd/watcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// watcherCmd represents the watcher command
var watcherCmd = &cobra.Command{
Use: "watcher",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("watcher called")
},
}

func init() {
rootCmd.AddCommand(watcherCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// watcherCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// watcherCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
14 changes: 14 additions & 0 deletions config/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package config

import "fmt"

// Endpoint represents the configuration for a network endpoint.
type Endpoint struct {
Host string // Host is the IP address or domain name of the endpoint.
Port string // Port is the network port number of the endpoint.
}

// Address returns the formatted address string combining the Host and Port.
func (e *Endpoint) Address() string {
return fmt.Sprintf("%s:%s", e.Host, e.Port)
}
92 changes: 92 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package config

import (
"embed"
"log"

"github.com/spf13/viper"
)

//go:embed config.yaml
var file embed.FS

// Config represents the overall configuration structure.
type Config struct {
PostgresDB *Database
ScyllaDB *Database
OpenSearch *Database
Courier *Database

UserService *Endpoint
BlockchainService *Endpoint
GatewayService *Endpoint

SymetricKey string
FileLogOutPut string
}

// config is a private structure used for unmarshaling the configuration from Viper.
type config struct {
DBHost string `mapstructure:"DB_HOST"`
DBPort string `mapstructure:"DB_PORT"`
DBUser string `mapstructure:"DB_USER"`
DBPassword string `mapstructure:"DB_PASSWORD"`
DBDatabase string `mapstructure:"DB_NAME"`

UserGRPCHost string `mapstructure:"USER_GRPC_HOST"`
UserGRPCPort string `mapstructure:"USER_GRPC_PORT"`

BlockchainGRPCHost string `mapstructure:"BLOCKCHAIN_GRPC_HOST"`
BlockchainGRPCPort string `mapstructure:"BLOCKCHAIN_GRPC_PORT"`

GatewayGRPCHost string `mapstructure:"GATEWAY_GRPC_HOST"`
GatewayGRPCPort string `mapstructure:"GATEWAY_GRPC_PORT"`
SymetricKey string `mapstructure:"SYMETRIC_KEY"`
FileLogOutPut string `mapstructure:"FILE_LOG_OUTPUT"`
}

// LoadConfig loads the configuration from the specified file path and environment.
func LoadConfig() *Config {
// Initialize an instance of the private config structure.
var cfg config
f, err := file.Open("config.yaml")
if err != nil {
log.Fatalf("unable to open config file: %v", err)
}

viper.SetConfigType("yaml")
// Read the configuration from the file.
if err := viper.ReadConfig(f); err != nil {
log.Fatalf("unable to read config file: %w", err)
}

// Unmarshal the configuration into the private config structure.
if err := viper.Unmarshal(&cfg); err != nil {
log.Fatalf("unable to unmarshal config file: %w", err)
}

// Create and return the public Config structure based on the private config.
return &Config{
PostgresDB: &Database{
Host: cfg.DBHost,
Port: cfg.DBPort,
User: cfg.DBUser,
Password: cfg.DBPassword,
Database: cfg.DBDatabase,
},
UserService: &Endpoint{
Host: cfg.UserGRPCHost,
Port: cfg.UserGRPCPort,
},
BlockchainService: &Endpoint{
Host: cfg.BlockchainGRPCHost,
Port: cfg.BlockchainGRPCPort,
},
GatewayService: &Endpoint{
Host: cfg.GatewayGRPCHost,
Port: cfg.GatewayGRPCPort,
},
SymetricKey: cfg.SymetricKey,
FileLogOutPut: cfg.FileLogOutPut,
}
}
25 changes: 25 additions & 0 deletions config/database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package config

import "fmt"

// Database represents the configuration details for a database connection.
type Database struct {
Host string
Port string
User string
Password string
Database string
MaxConnection int32
}

// Address returns the formatted string for the database connection address.
func (e *Database) Address() string {
return fmt.Sprintf(
"host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
e.Host,
e.Port,
e.User,
e.Password,
e.Database,
)
}
Loading

0 comments on commit 2076959

Please sign in to comment.