diff options
author | Martin Holst Swende <martin@swende.se> | 2019-04-11 18:22:48 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-04-11 18:22:48 +0800 |
commit | 54dfce8af7aa0f4561cd1ede5ea820b15f235ab0 (patch) | |
tree | c86b856123f0395a0f66e28ad7b1e1a1e1b12705 /signer/core | |
parent | 31bc2a2434ed29b6cd020ee712722b4b865f32e1 (diff) | |
download | go-tangerine-54dfce8af7aa0f4561cd1ede5ea820b15f235ab0.tar go-tangerine-54dfce8af7aa0f4561cd1ede5ea820b15f235ab0.tar.gz go-tangerine-54dfce8af7aa0f4561cd1ede5ea820b15f235ab0.tar.bz2 go-tangerine-54dfce8af7aa0f4561cd1ede5ea820b15f235ab0.tar.lz go-tangerine-54dfce8af7aa0f4561cd1ede5ea820b15f235ab0.tar.xz go-tangerine-54dfce8af7aa0f4561cd1ede5ea820b15f235ab0.tar.zst go-tangerine-54dfce8af7aa0f4561cd1ede5ea820b15f235ab0.zip |
cmd/clef: bundle 4byte db into clef, (#19112)
* clef: bundle 4byte db into clef, fix #19048
* clef: add go-generate directive, remove internal abidb parser tool
* cmd/clef: extend go generate to format asset file
Diffstat (limited to 'signer/core')
-rw-r--r-- | signer/core/abihelper.go | 17 | ||||
-rw-r--r-- | signer/core/abihelper_test.go | 2 | ||||
-rw-r--r-- | signer/core/validation.go | 1 |
3 files changed, 9 insertions, 11 deletions
diff --git a/signer/core/abihelper.go b/signer/core/abihelper.go index 88c1da033..1b3cc697d 100644 --- a/signer/core/abihelper.go +++ b/signer/core/abihelper.go @@ -18,6 +18,7 @@ package core import ( "bytes" + "encoding/hex" "encoding/json" "fmt" "io/ioutil" @@ -183,17 +184,13 @@ func NewAbiDBFromFile(path string) (*AbiDb, error) { return db, nil } -// NewAbiDBFromFiles loads both the standard signature database and a custom database. The latter will be used -// to write new values into if they are submitted via the API -func NewAbiDBFromFiles(standard, custom string) (*AbiDb, error) { +// NewAbiDBFromFiles loads both the standard signature database (resource file)and a custom database. +// The latter will be used to write new values into if they are submitted via the API +func NewAbiDBFromFiles(raw []byte, custom string) (*AbiDb, error) { db := &AbiDb{make(map[string]string), make(map[string]string), custom} db.customdbPath = custom - raw, err := ioutil.ReadFile(standard) - if err != nil { - return nil, err - } if err := json.Unmarshal(raw, &db.db); err != nil { return nil, err } @@ -207,7 +204,6 @@ func NewAbiDBFromFiles(standard, custom string) (*AbiDb, error) { return nil, err } } - return db, nil } @@ -217,7 +213,7 @@ func (db *AbiDb) LookupMethodSelector(id []byte) (string, error) { if len(id) < 4 { return "", fmt.Errorf("Expected 4-byte id, got %d", len(id)) } - sig := common.ToHex(id[:4]) + sig := hex.EncodeToString(id[:4]) if key, exists := db.db[sig]; exists { return key, nil } @@ -226,6 +222,7 @@ func (db *AbiDb) LookupMethodSelector(id []byte) (string, error) { } return "", fmt.Errorf("Signature %v not found", sig) } + func (db *AbiDb) Size() int { return len(db.db) } @@ -255,6 +252,6 @@ func (db *AbiDb) AddSignature(selector string, data []byte) error { if err == nil { return nil } - sig := common.ToHex(data[:4]) + sig := hex.EncodeToString(data[:4]) return db.saveCustomAbi(selector, sig) } diff --git a/signer/core/abihelper_test.go b/signer/core/abihelper_test.go index 4a3a2f06d..789ca216e 100644 --- a/signer/core/abihelper_test.go +++ b/signer/core/abihelper_test.go @@ -205,7 +205,7 @@ func TestCustomABI(t *testing.T) { t.Fatal(err) } filename := fmt.Sprintf("%s/4byte_custom.json", d) - abidb, err := NewAbiDBFromFiles("../../cmd/clef/4byte.json", filename) + abidb, err := NewAbiDBFromFiles([]byte(""), filename) if err != nil { t.Fatal(err) } diff --git a/signer/core/validation.go b/signer/core/validation.go index 7c3ec4274..4d64567f6 100644 --- a/signer/core/validation.go +++ b/signer/core/validation.go @@ -38,6 +38,7 @@ type Validator struct { func NewValidator(db *AbiDb) *Validator { return &Validator{db} } + func testSelector(selector string, data []byte) (*decodedCallData, error) { if selector == "" { return nil, fmt.Errorf("selector not found") |