-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate chain config during block-explorer initialization (#884)
- Loading branch information
1 parent
772f1fa
commit c8afc46
Showing
8 changed files
with
115 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0
migrations/super-schema.sql → migrations/block-explorer/events.sql
100644 → 100755
File renamed without changes.
0
migrations/blockexplorer.sql → migrations/block-explorer/schema.sql
100644 → 100755
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package blockexplorer | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// GenerateChainsYAML generates the YAML content with the given chain_id | ||
// this configuration is used by the block-explorer to index the locally running | ||
// chain | ||
func GenerateChainsYAML(chainID string) string { | ||
template := `local: | ||
chain_id: %s | ||
be_json_rpc_urls: [ "http://host.docker.internal:11100" ] | ||
# disable: true | ||
` | ||
return fmt.Sprintf(template, chainID) | ||
} | ||
|
||
func WriteChainsYAML(filePath, content string) error { | ||
dir := filepath.Dir(filePath) | ||
if err := os.MkdirAll(dir, 0o700); err != nil { | ||
return fmt.Errorf("failed to create directory: %w", err) | ||
} | ||
|
||
file, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o700) | ||
if err != nil { | ||
return fmt.Errorf("failed to create file: %w", err) | ||
} | ||
defer file.Close() | ||
|
||
if _, err := file.WriteString(content); err != nil { | ||
return fmt.Errorf("failed to write to file: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters