Skip to content

Commit

Permalink
Refactor : Genesis Update Pre Launch
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsarwagya committed Jan 28, 2024
1 parent b03f2dc commit f672fcd
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 13 deletions.
11 changes: 10 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ output_dir="builds"
# Ensure the output directory exists
mkdir -p "$output_dir"

# Define a file to store the successful builds
success_file="successful_builds.txt"

# Clear the file or create it if it doesn't exist
echo -n > "$success_file"

# Get the list of all platforms and architectures supported by go tool dist
platforms_and_architectures=$(go tool dist list)

Expand All @@ -22,13 +28,16 @@ for platform_arch in $platforms_and_architectures; do

# Build the program for the current platform
GOOS="$os" GOARCH="$arch" go build -o "$output_dir/$output_name" .
rm -rf "$output_dir/$output_name"

# Check if the build was successful
if [ $? -eq 0 ]; then
echo "Build for $platform_arch completed successfully."
# Write the successful platform to the file
echo "$platform_arch" >> "$success_file"
else
echo "Build for $platform_arch failed."
fi
done

echo "All builds completed."
echo "All builds completed. Successful builds are listed in $success_file."
4 changes: 2 additions & 2 deletions command/polybftsecrets/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (ip *initParams) setFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(
&ip.printPrivateKey,
privateKeyFlag,
false,
true,
"the flag indicating whether Private key is printed",
)

Expand All @@ -113,7 +113,7 @@ func (ip *initParams) setFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(
&ip.output,
outputFlag,
false,
true,
"the flag indicating to output existing secrets",
)
}
Expand Down
50 changes: 50 additions & 0 deletions command/polybftsecrets/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package polybftsecrets

import (
"bytes"
"encoding/json"
"fmt"
"os"

"github.com/esportzvio/frietorchain/command"

Expand Down Expand Up @@ -32,6 +34,20 @@ type SecretsInitResult struct {
Generated string `json:"generated"`
}

func secretsFileExists(filePath string) (bool, error) {
_, err := os.Stat(filePath)
if err == nil {
// File exists
return true, nil
} else if os.IsNotExist(err) {
// File does not exist
return false, nil
} else {
// An error occurred (other than "not exist")
return false, err
}
}

func (r *SecretsInitResult) GetOutput() string {
var buffer bytes.Buffer

Expand Down Expand Up @@ -79,5 +95,39 @@ func (r *SecretsInitResult) GetOutput() string {
buffer.WriteString(helper.FormatKV(vals))
buffer.WriteString("\n")

filePath := "secrets.json"

exists, err := secretsFileExists(filePath)

if err != nil {
fmt.Println(err)
}

data := map[string]string{
"address": r.Address.String(),
"bls_pubkey": r.BLSPubkey,
"node_id": r.NodeID,
"private_key": r.PrivateKey,
"bls_private_key": r.BLSPrivateKey,
"insecure": fmt.Sprintf("%t", r.Insecure),
"generated": r.Generated,
}

// convert data map to json using json.Marshal()
jsonData, err := json.Marshal(data)

if err != nil {
fmt.Println(err)
}

if exists {
// write data to file as json
os.WriteFile(filePath, jsonData, 0644)

Check failure on line 125 in command/polybftsecrets/result.go

View workflow job for this annotation

GitHub Actions / golangci_lint

Error return value of `os.WriteFile` is not checked (errcheck)
} else {
// create file and write buffer data to file as json
os.Create(filePath)

Check failure on line 128 in command/polybftsecrets/result.go

View workflow job for this annotation

GitHub Actions / golangci_lint

Error return value of `os.Create` is not checked (errcheck)
os.WriteFile(filePath, buffer.Bytes(), 0644)

Check failure on line 129 in command/polybftsecrets/result.go

View workflow job for this annotation

GitHub Actions / golangci_lint

Error return value of `os.WriteFile` is not checked (errcheck)
}

return buffer.String()
}
4 changes: 2 additions & 2 deletions command/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/esportzvio/frietorchain/command/helper"
"github.com/esportzvio/frietorchain/command/peers"
"github.com/esportzvio/frietorchain/command/secrets"
"github.com/esportzvio/frietorchain/command/polybftsecrets"
"github.com/esportzvio/frietorchain/command/server"
"github.com/esportzvio/frietorchain/command/status"
"github.com/esportzvio/frietorchain/command/version"
Expand Down Expand Up @@ -36,7 +36,7 @@ func (rc *RootCommand) registerSubCommands() {
rc.baseCmd.AddCommand(
version.GetCommand(),
status.GetCommand(),
secrets.GetCommand(),
polybftsecrets.GetCommand(),
peers.GetCommand(),
server.GetCommand(),
)
Expand Down
10 changes: 5 additions & 5 deletions command/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ func setFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
&params.rawConfig.Network.Libp2pAddr,
libp2pAddressFlag,
defaultConfig.Network.Libp2pAddr,
"0.0.0.0:30301",
"the address and port for the libp2p service",
)

cmd.Flags().StringVar(
&params.rawConfig.Telemetry.PrometheusAddr,
prometheusAddressFlag,
"",
"0.0.0.0:10002",
"the address and port for the prometheus instrumentation service (address:port). "+
"If only port is defined (:port) it will bind to 0.0.0.0:port",
)
Expand Down Expand Up @@ -195,14 +195,14 @@ func setFlags(cmd *cobra.Command) {
cmd.Flags().Uint64Var(
&params.rawConfig.JSONRPCBatchRequestLimit,
jsonRPCBatchRequestLimitFlag,
defaultConfig.JSONRPCBatchRequestLimit,
10000,
"max length to be considered when handling json-rpc batch requests, value of 0 disables it",
)

cmd.Flags().Uint64Var(
&params.rawConfig.JSONRPCBlockRangeLimit,
jsonRPCBlockRangeLimitFlag,
defaultConfig.JSONRPCBlockRangeLimit,
10000,
"max block range to be considered when executing json-rpc requests "+
"that consider fromBlock/toBlock values (e.g. eth_getLogs), value of 0 disables it",
)
Expand All @@ -224,7 +224,7 @@ func setFlags(cmd *cobra.Command) {
cmd.Flags().Uint64Var(
&params.rawConfig.NumBlockConfirmations,
numBlockConfirmationsFlag,
defaultConfig.NumBlockConfirmations,
64,
"minimal number of child blocks required for the parent block to be considered final",
)

Expand Down
15 changes: 12 additions & 3 deletions genesis-saar.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,16 @@
"balance": "0x0"
},
"0x2415d9F108049b8879f0cFE3aE4b39bb971Fa8f3": {
"balance": "0x3e8"
"balance": "0x19D971E4FE8401E74000000"
},
"0x0e774869B113DAa9FC76699291108143b9505626": {
"balance": "0x19D971E4FE8401E74000000"
},
"0xF27539c3E299DD4a5038627aDA2600816FBFDF08": {
"balance": "0x19D971E4FE8401E74000000"
},
"0xF37C65D1918d40a1EA5Df27CDCeD7693ae32CF75": {
"balance": "0xA56FA5B99019A5C8000000"
}
},
"number": "0x0",
Expand Down Expand Up @@ -167,7 +176,7 @@
"stakeTokenAddr": "0x6c59A268c1E196A092C1F91ad292137262dd77A8",
"blsAddr": "0x5F33985b8A9D9E081D617E817525cdd0Eb6C6401",
"bn256G2Addr": "0x41f13F530Fd636Db569c05AcFe7508D08D047E25",
"jsonRPCEndpoint": "https://sepolia.infura.io/v3/b8144f298dba4f2e87a0beeaa2c4a40b",
"jsonRPCEndpoint": "https://rpc2.sepolia.org",
"eventTrackerStartBlocks": {
"0x2178Aef7816450448c17817558d60B770e8272ad": 5153781
}
Expand All @@ -191,7 +200,7 @@
"rewardConfig": {
"rewardTokenAddress": "0x0000000000000000000000000000000000001010",
"rewardWalletAddress": "0x2415d9F108049b8879f0cFE3aE4b39bb971Fa8f3",
"rewardWalletAmount": "0x3e8"
"rewardWalletAmount": "0x0"
},
"blockTimeDrift": 10
}
Expand Down

0 comments on commit f672fcd

Please sign in to comment.