From 533f2be9eec23a92410970c639a735ccd4381f4f Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 18 Dec 2017 20:21:16 +0100 Subject: [PATCH] accounts/abi: make ToGoType public --- accounts/abi/abi.go | 12 ++++++++++++ accounts/abi/event.go | 4 ++-- accounts/abi/method.go | 4 ++-- accounts/abi/unpack.go | 6 +++--- accounts/usbwallet/hub.go | 2 +- accounts/usbwallet/wallet.go | 2 +- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 205dc300b0..f69ef4d60c 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -20,6 +20,7 @@ import ( "encoding/json" "fmt" "io" + "bytes" ) // The ABI holds information about a contract's context and available @@ -137,3 +138,14 @@ func (abi *ABI) UnmarshalJSON(data []byte) error { return nil } + +// methodById looks up a method by the 4-byte id +// returns nil if none found +func (abi *ABI) MethodById(sigdata []byte) *Method { + for _, method := range abi.Methods{ + if bytes.Equal(method.Id(), sigdata) { + return &method + } + } + return nil +} \ No newline at end of file diff --git a/accounts/abi/event.go b/accounts/abi/event.go index 44ed7b8df2..812d602c5b 100644 --- a/accounts/abi/event.go +++ b/accounts/abi/event.go @@ -75,7 +75,7 @@ func (e Event) tupleUnpack(v interface{}, output []byte) error { // need to move this up because they read sequentially j += input.Type.Size } - marshalledValue, err := toGoType((i+j)*32, input.Type, output) + marshalledValue, err := ToGoType((i+j)*32, input.Type, output) if err != nil { return err } @@ -126,7 +126,7 @@ func (e Event) singleUnpack(v interface{}, output []byte) error { value := valueOf.Elem() - marshalledValue, err := toGoType(0, e.Inputs[0].Type, output) + marshalledValue, err := ToGoType(0, e.Inputs[0].Type, output) if err != nil { return err } diff --git a/accounts/abi/method.go b/accounts/abi/method.go index d8838e9ed6..7b7525ec9d 100644 --- a/accounts/abi/method.go +++ b/accounts/abi/method.go @@ -99,7 +99,7 @@ func (method Method) tupleUnpack(v interface{}, output []byte) error { // need to move this up because they read sequentially j += toUnpack.Type.Size } - marshalledValue, err := toGoType((i+j)*32, toUnpack.Type, output) + marshalledValue, err := ToGoType((i+j)*32, toUnpack.Type, output) if err != nil { return err } @@ -146,7 +146,7 @@ func (method Method) singleUnpack(v interface{}, output []byte) error { value := valueOf.Elem() - marshalledValue, err := toGoType(0, method.Outputs[0].Type, output) + marshalledValue, err := ToGoType(0, method.Outputs[0].Type, output) if err != nil { return err } diff --git a/accounts/abi/unpack.go b/accounts/abi/unpack.go index 57732797b6..e1828dfae1 100644 --- a/accounts/abi/unpack.go +++ b/accounts/abi/unpack.go @@ -127,7 +127,7 @@ func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error) if t.Elem.T == ArrayTy && j != 0 { i = start + t.Elem.Size*32*j } - inter, err := toGoType(i, *t.Elem, output) + inter, err := ToGoType(i, *t.Elem, output) if err != nil { return nil, err } @@ -139,9 +139,9 @@ func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error) return refSlice.Interface(), nil } -// toGoType parses the output bytes and recursively assigns the value of these bytes +// ToGoType parses the output bytes and recursively assigns the value of these bytes // into a go type with accordance with the ABI spec. -func toGoType(index int, t Type, output []byte) (interface{}, error) { +func ToGoType(index int, t Type, output []byte) (interface{}, error) { if index+32 > len(output) { return nil, fmt.Errorf("abi: cannot marshal in to go type: length insufficient %d require %d", len(output), index+32) } diff --git a/accounts/usbwallet/hub.go b/accounts/usbwallet/hub.go index 61fc98ccc8..640320bc91 100644 --- a/accounts/usbwallet/hub.go +++ b/accounts/usbwallet/hub.go @@ -127,7 +127,7 @@ func (hub *Hub) refreshWallets() { // breaking the Ledger protocol if that is waiting for user confirmation. This // is a bug acknowledged at Ledger, but it won't be fixed on old devices so we // need to prevent concurrent comms ourselves. The more elegant solution would - // be to ditch enumeration in favor of hutplug events, but that don't work yet + // be to ditch enumeration in favor of hotplug events, but that don't work yet // on Windows so if we need to hack it anyway, this is more elegant for now. hub.commsLock.Lock() if hub.commsPend > 0 { // A confirmation is pending, don't refresh diff --git a/accounts/usbwallet/wallet.go b/accounts/usbwallet/wallet.go index 8b3b5a5224..6cef6e0fb0 100644 --- a/accounts/usbwallet/wallet.go +++ b/accounts/usbwallet/wallet.go @@ -99,7 +99,7 @@ type wallet struct { // // As such, a hardware wallet needs two locks to function correctly. A state // lock can be used to protect the wallet's software-side internal state, which - // must not be held exlusively during hardware communication. A communication + // must not be held exclusively during hardware communication. A communication // lock can be used to achieve exclusive access to the device itself, this one // however should allow "skipping" waiting for operations that might want to // use the device, but can live without too (e.g. account self-derivation).