feat:unified naming

This commit is contained in:
songzhibin97 2024-03-02 18:54:17 +08:00
parent 0a2f33946b
commit 01c16b2659
5 changed files with 10 additions and 10 deletions

View file

@ -198,9 +198,9 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
return nil return nil
} }
// MethodById looks up a method by the 4-byte id, // MethodByID looks up a method by the 4-byte id,
// returns nil if none found. // returns nil if none found.
func (abi *ABI) MethodById(sigdata []byte) (*Method, error) { func (abi *ABI) MethodByID(sigdata []byte) (*Method, error) {
if len(sigdata) < 4 { if len(sigdata) < 4 {
return nil, fmt.Errorf("data too short (%d bytes) for abi method lookup", len(sigdata)) return nil, fmt.Errorf("data too short (%d bytes) for abi method lookup", len(sigdata))
} }

View file

@ -983,7 +983,7 @@ func TestABI_MethodById(t *testing.T) {
} }
for name, m := range abi.Methods { for name, m := range abi.Methods {
a := fmt.Sprintf("%v", m) a := fmt.Sprintf("%v", m)
m2, err := abi.MethodById(m.ID) m2, err := abi.MethodByID(m.ID)
if err != nil { if err != nil {
t.Fatalf("Failed to look up ABI method: %v", err) t.Fatalf("Failed to look up ABI method: %v", err)
} }
@ -993,17 +993,17 @@ func TestABI_MethodById(t *testing.T) {
} }
} }
// test unsuccessful lookups // test unsuccessful lookups
if _, err = abi.MethodById(crypto.Keccak256()); err == nil { if _, err = abi.MethodByID(crypto.Keccak256()); err == nil {
t.Error("Expected error: no method with this id") t.Error("Expected error: no method with this id")
} }
// Also test empty // Also test empty
if _, err := abi.MethodById([]byte{0x00}); err == nil { if _, err := abi.MethodByID([]byte{0x00}); err == nil {
t.Errorf("Expected error, too short to decode data") t.Errorf("Expected error, too short to decode data")
} }
if _, err := abi.MethodById([]byte{}); err == nil { if _, err := abi.MethodByID([]byte{}); err == nil {
t.Errorf("Expected error, too short to decode data") t.Errorf("Expected error, too short to decode data")
} }
if _, err := abi.MethodById(nil); err == nil { if _, err := abi.MethodByID(nil); err == nil {
t.Errorf("Expected error, nil is short to decode data") t.Errorf("Expected error, nil is short to decode data")
} }
} }

View file

@ -103,7 +103,7 @@ func parseCallData(calldata []byte, unescapedAbidata string) (*decodedCallData,
if err != nil { if err != nil {
return nil, fmt.Errorf("invalid method signature (%q): %v", unescapedAbidata, err) return nil, fmt.Errorf("invalid method signature (%q): %v", unescapedAbidata, err)
} }
method, err := abispec.MethodById(sigdata) method, err := abispec.MethodByID(sigdata)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -33,7 +33,7 @@ func verify(t *testing.T, jsondata, calldata string, exp []interface{}) {
} }
cd := common.Hex2Bytes(calldata) cd := common.Hex2Bytes(calldata)
sigdata, argdata := cd[:4], cd[4:] sigdata, argdata := cd[:4], cd[4:]
method, err := abispec.MethodById(sigdata) method, err := abispec.MethodByID(sigdata)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -43,7 +43,7 @@ func TestEmbeddedDatabase(t *testing.T) {
t.Errorf("Failed to parse ABI: %v", err) t.Errorf("Failed to parse ABI: %v", err)
continue continue
} }
m, err := abistruct.MethodById(common.Hex2Bytes(id)) m, err := abistruct.MethodByID(common.Hex2Bytes(id))
if err != nil { if err != nil {
t.Errorf("Failed to get method by id (%s): %v", id, err) t.Errorf("Failed to get method by id (%s): %v", id, err)
continue continue