github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/core/native/nativehashes/gen.go (about) 1 //go:build ignore 2 3 // This program generates hashes.go. It can be invoked by running 4 // go generate. 5 package main 6 7 import ( 8 "fmt" 9 "log" 10 "os" 11 "text/template" 12 13 "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" 14 "github.com/nspcc-dev/neo-go/pkg/core/state" 15 ) 16 17 // srcTmpl is a nativehashes package template. 18 const srcTmpl = `// Code generated by "go generate go run gen.go"; DO NOT EDIT. 19 20 //go:generate go run gen.go 21 22 // package nativehashes contains hashes of all native contracts in their LE and Uint160 representation. 23 package nativehashes 24 25 import "github.com/nspcc-dev/neo-go/pkg/util" 26 27 // Hashes of all native contracts. 28 var ( 29 {{- range .Natives }} 30 // {{ .Name }} is a hash of native {{ .Name }} contract. 31 {{ .Name }} = {{ .Hash }} 32 {{- end }} 33 ) 34 ` 35 36 type ( 37 // Config contains parameters for the nativehashes package generation. 38 Config struct { 39 Natives []NativeInfo 40 } 41 42 // NativeInfo contains information about native contract needed for 43 // nativehashes package generation. 44 NativeInfo struct { 45 Name string 46 Hash string 47 } 48 ) 49 50 // srcTemplate is a parsed nativehashes package template. 51 var srcTemplate = template.Must(template.New("nativehashes").Parse(srcTmpl)) 52 53 func main() { 54 f, err := os.Create("hashes.go") 55 if err != nil { 56 log.Fatal(err) 57 } 58 defer f.Close() 59 60 var cfg = Config{Natives: make([]NativeInfo, len(nativenames.All))} 61 for i, name := range nativenames.All { 62 var hash = state.CreateNativeContractHash(name) 63 cfg.Natives[i] = NativeInfo{ 64 Name: name, 65 Hash: fmt.Sprintf("%#v", hash), 66 } 67 } 68 69 srcTemplate.Execute(f, cfg) 70 }