initial release

This commit is contained in:
Siavash Sameni
2025-08-29 08:17:52 +04:00
commit f55b4468b3
8 changed files with 690 additions and 0 deletions

43
internal/config/config.go Normal file
View File

@@ -0,0 +1,43 @@
package config
import (
"errors"
"io"
"os"
yaml "gopkg.in/yaml.v3"
)
type Contract struct {
Network string `yaml:"network"`
Address string `yaml:"address"`
MaxTokenId string `yaml:"max_token_id"`
FromBlock string `yaml:"from_block"` // kept for backward compatibility, maps to MaxTokenId
}
type File struct {
Contracts map[string]Contract `yaml:"contracts"`
}
func Load(path string) (*File, error) {
if path == "" { return &File{Contracts: map[string]Contract{}}, nil }
f, err := os.Open(path)
if err != nil { return nil, err }
defer f.Close()
b, err := io.ReadAll(f)
if err != nil { return nil, err }
var cfg File
if err := yaml.Unmarshal(b, &cfg); err != nil { return nil, err }
if cfg.Contracts == nil { cfg.Contracts = map[string]Contract{} }
return &cfg, nil
}
func (f *File) Get(name string) (Contract, bool) {
c, ok := f.Contracts[name]
return c, ok
}
func (c Contract) Validate() error {
if c.Network == "" || c.Address == "" { return errors.New("missing network or address") }
return nil
}