Skip to content

Commit

Permalink
Update generate_balances script to accept file path instead of URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Eela Nagaraj committed Sep 22, 2023
1 parent 5e5ecf4 commit 8d60be8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,11 @@ rosetta-cli check:data --configuration-file $PATH_TO_ROSETTA/rosetta-cli-conf/$N

### How to generate `bootstrap_balances.json`

This is only necessary for running the data checks if it has not already been created for the particular network. Here's how to generate this for alfajores (for another network, specify the appropriate genesis block URL and output path):
This is only necessary for running the data checks if it has not already been created for the particular network. Here's how to generate this for alfajores (for another network, specify the appropriate genesis block filepath and output path):

```sh
go run examples/generate_balances/main.go \
https://storage.googleapis.com/genesis_blocks/alfajores \
rosetta-cli-conf/testnet/bootstrap_balances.json
$PATH_TO_GENESIS_FILE rosetta-cli-conf/mycelo/bootstrap_balances.json
```

### Running Rosetta with a mycelo testnet
Expand Down
20 changes: 6 additions & 14 deletions examples/generate_balances/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"

"github.com/celo-org/celo-blockchain/core"
Expand All @@ -34,26 +32,20 @@ type BootstrapBalance struct {

func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: generate_balances <genesisURL> <outputFile>")
fmt.Println("Usage: generate_balances <pathToGenesis> <outputFile>")
os.Exit(1)
}
genesisURL := os.Args[1]
genesisPath := os.Args[1]
bootstrapBalancesFile := os.Args[2]
// Get Genesis File
resp, err := http.Get(genesisURL)
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
data, err := os.ReadFile(genesisPath)
if err != nil {
log.Fatalln(err)
}
genesis := &core.Genesis{}
if err := json.Unmarshal(body, genesis); err != nil {
if err := json.Unmarshal(data, genesis); err != nil {
log.Fatalln(err)
}
log.Printf("%+v\n", genesis.Alloc)
log.Println("Loaded genesis file, writing allocation file")
// Write to file
balances := []*BootstrapBalance{}
for k, v := range genesis.Alloc {
Expand All @@ -76,7 +68,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile(bootstrapBalancesFile, file, os.FileMode(0600)); err != nil {
if err := os.WriteFile(bootstrapBalancesFile, file, os.FileMode(0600)); err != nil {
log.Fatal(err)
}
log.Printf("Bootstrap file contains %d balances\n", len(balances))
Expand Down

0 comments on commit 8d60be8

Please sign in to comment.