From 433846558fd8f4ca663eac5be6c5cd8cb9edd273 Mon Sep 17 00:00:00 2001 From: Mael Regnery Date: Fri, 24 Apr 2026 11:14:32 +0200 Subject: [PATCH] fix: make the contract load case-insensitive --- pkg/storage/abi/local.go | 9 +++++---- pkg/storage/contract/local.go | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/storage/abi/local.go b/pkg/storage/abi/local.go index 389ff1b..0d6d912 100644 --- a/pkg/storage/abi/local.go +++ b/pkg/storage/abi/local.go @@ -6,6 +6,7 @@ package abi import ( "os" "path/filepath" + "strings" ) type Local struct { @@ -26,12 +27,12 @@ func NewLocal(storePath string) (*Local, error) { // Write writes the ABI data for a given contract ID. func (l *Local) Write(id string, data string) error { - return os.WriteFile(filepath.Join(l.path, id), []byte(data), 0644) + return os.WriteFile(filepath.Join(l.path, strings.ToLower(id)), []byte(data), 0644) } // Read reads the ABI data for a given contract ID. func (l *Local) Read(id string) (string, error) { - data, err := os.ReadFile(filepath.Join(l.path, id)) + data, err := os.ReadFile(filepath.Join(l.path, strings.ToLower(id))) if err != nil { return "", err } @@ -40,10 +41,10 @@ func (l *Local) Read(id string) (string, error) { } func (l *Local) Delete(id string) error { - return os.Remove(filepath.Join(l.path, id)) + return os.Remove(filepath.Join(l.path, strings.ToLower(id))) } // GetPath returns the file path of the ABI for a given contract ID. func (l *Local) GetPath(id string) string { - return filepath.Join(l.path, id) + return filepath.Join(l.path, strings.ToLower(id)) } diff --git a/pkg/storage/contract/local.go b/pkg/storage/contract/local.go index 6ea4a3f..ff7d7ed 100644 --- a/pkg/storage/contract/local.go +++ b/pkg/storage/contract/local.go @@ -10,6 +10,7 @@ import ( "iter" "os" "path/filepath" + "strings" ) var ( @@ -40,6 +41,7 @@ func NewLocal(storePath string) (*Local, error) { // Add adds a contract func (l *Local) Add(address string, meta []byte) error { + address = strings.ToLower(address) c, err := l.getContracts() if err != nil { return fmt.Errorf("loading contracts: %w", err) @@ -65,6 +67,7 @@ func (l *Local) Add(address string, meta []byte) error { // Get returns a contract info func (l *Local) Get(address string) ([]byte, error) { + address = strings.ToLower(address) c, err := l.getContracts() if err != nil { return nil, fmt.Errorf("loading contracts: %w", err) @@ -84,6 +87,7 @@ func (l *Local) Get(address string) ([]byte, error) { // Update replaces the metadata for an existing contract. func (l *Local) Update(address string, meta []byte) error { + address = strings.ToLower(address) c, err := l.getContracts() if err != nil { return fmt.Errorf("loading contracts: %w", err) @@ -109,6 +113,7 @@ func (l *Local) Update(address string, meta []byte) error { // Delete deletes a contract func (l *Local) Delete(address string) error { + address = strings.ToLower(address) c, err := l.getContracts() if err != nil { return fmt.Errorf("loading contracts: %w", err)