github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/config/unchainedGroup.go (about) 1 package config 2 3 import ( 4 "path/filepath" 5 "strings" 6 "sync" 7 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/configtypes" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/history" 10 "github.com/ethereum/go-ethereum/crypto" 11 ) 12 13 func GetUnchained() configtypes.UnchainedGroup { 14 return GetRootConfig().Unchained 15 } 16 17 func HeaderHash(version string) []byte { 18 return crypto.Keccak256([]byte(version)) 19 } 20 21 func GetPublisher(value string) string { 22 if value == "" { 23 value = GetUnchained().PreferredPublisher 24 if value == "" { 25 value = "publisher.unchainedindex.eth" 26 } 27 } 28 return value 29 } 30 31 // VersionTags allows us to go from the version bytes found in the chunks to a version string 32 var VersionTags = map[string]string{ 33 "0x81ae14ba68e372bc9bd4a295b844abd8e72b1de10fcd706e624647701d911da1": "trueblocks-core@v0.40.0", 34 "0x6fc0c6dd027719f456c1e50a329f6157767325aa937411fa6e7be9359d9e0046": "trueblocks-core@v2.0.0-release", 35 } 36 37 // SpecTags allows us to go from a version string to an IPFS hash pointing to the spec 38 var SpecTags = map[string]string{ 39 "trueblocks-core@v0.40.0": "QmUou7zX2g2tY58LP1A2GyP5RF9nbJsoxKTp299ah3svgb", 40 "trueblocks-core@v2.0.0-release": "QmUyyU8wKW57c3CuwphhMdZb2QA5bsjt9vVfTE6LcBKmE9", 41 } 42 43 func KnownVersionTag(tag string) bool { 44 for _, v := range VersionTags { 45 vShort := strings.Replace(v, "trueblocks-core@", "", -1) 46 if v == tag || vShort == tag { 47 return true 48 } 49 } 50 return false 51 } 52 53 var m sync.Mutex 54 55 func ExpectedVersion() string { 56 if headerVersion == "" { 57 m.Lock() 58 historyFile := filepath.Join(PathToRootConfig(), "unchained.txt") 59 headerVersion = history.FromHistory(historyFile, "headerVersion") 60 if headerVersion == "" { 61 headerVersion = "trueblocks-core@v2.0.0-release" 62 } 63 m.Unlock() 64 } 65 return headerVersion 66 } 67 68 func SetExpectedVersion(version string) { 69 m.Lock() 70 historyFile := filepath.Join(PathToRootConfig(), "unchained.txt") 71 _ = history.ToHistory(historyFile, "headerVersion", version) 72 headerVersion = version 73 m.Unlock() 74 } 75 76 var headerVersion = ""