-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
255 additions
and
177 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
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,36 @@ | ||
package node | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func CheckNodesAreReady() { | ||
for { | ||
r, err := http.Get("http://localhost:8732/version") | ||
if err != nil && r.StatusCode != 200 { | ||
log.Println("The node is not running. Waiting 5 minutes...") | ||
time.Sleep(5 * time.Minute) | ||
} | ||
defer r.Body.Close() | ||
if r.StatusCode == 200 { | ||
break | ||
} | ||
} | ||
} | ||
|
||
func GetTezosVersion() string { | ||
reqVersion, err := http.Get("http://localhost:8732/version") | ||
if err != nil { | ||
log.Fatalf("Unable to get node version. %v \n", err) | ||
} | ||
defer reqVersion.Body.Close() | ||
version, err := io.ReadAll(reqVersion.Body) | ||
if err != nil { | ||
log.Fatalf("Unable to read node version. %v \n", err) | ||
} | ||
|
||
return string(version) | ||
} |
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,35 @@ | ||
package snapshot | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
) | ||
|
||
type SnapshotHeader struct { | ||
Version int `json:"version"` | ||
ChaiName string `json:"chain_name"` | ||
Mode string `json:"mode"` | ||
BlockHash string `json:"block_hash"` | ||
Level int `json:"level"` | ||
Timestamp string `json:"timestamp"` | ||
} | ||
|
||
func SnapshotHeaderFromJson(snapshotHeaderOutput string) (*SnapshotHeader, error) { | ||
var snapshotHeader SnapshotHeader | ||
err := json.Unmarshal([]byte(snapshotHeaderOutput), &snapshotHeader) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &snapshotHeader, nil | ||
} | ||
|
||
// Example: TEZOS_MAINNET_2021-01-01_00-00 to mainnet | ||
func (s *SnapshotHeader) SanitizeChainame() string { | ||
parts := strings.Split(s.ChaiName, "_") | ||
chainName := strings.ToLower(parts[len(parts)-1]) | ||
if chainName == "ithacanet" { | ||
chainName = "ghostnet" | ||
} | ||
return chainName | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package util | ||
package store | ||
|
||
import ( | ||
"log" | ||
|
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,46 @@ | ||
package store | ||
|
||
import ( | ||
"log" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/marigold-dev/tezos-snapshot/pkg/snapshot" | ||
) | ||
|
||
type FileInfo struct { | ||
Filename string | ||
ChainName string | ||
HistoryMode snapshot.HistoryModeType | ||
BlockHeight int | ||
BlockHash string | ||
} | ||
|
||
func getInfoFromfilename(filename string) *FileInfo { | ||
chainName := strings.ToLower(strings.Split(strings.Split(filename, "-")[0], "_")[1]) | ||
|
||
if chainName == "ithacanet" { | ||
chainName = "ghostnet" | ||
} | ||
|
||
historyMode := snapshot.HistoryModeType(snapshot.FULL) | ||
|
||
if strings.Contains(filename, "rolling") { | ||
historyMode = snapshot.HistoryModeType(snapshot.ROLLING) | ||
} | ||
|
||
splitedByHyphen := strings.Split(filename, "-") | ||
blockheight, err := strconv.Atoi(strings.Split(splitedByHyphen[len(splitedByHyphen)-1], ".")[0]) | ||
if err != nil { | ||
log.Fatalf("Unable to parse blockheight. %v \n", err) | ||
} | ||
blockhash := splitedByHyphen[len(splitedByHyphen)-2] | ||
|
||
return &FileInfo{ | ||
Filename: filename, | ||
ChainName: chainName, | ||
HistoryMode: historyMode, | ||
BlockHeight: blockheight, | ||
BlockHash: blockhash, | ||
} | ||
} |
Oops, something went wrong.