diff options
-rw-r--r-- | accounts/abi/abi.go | 18 | ||||
-rw-r--r-- | accounts/abi/abi_test.go | 53 | ||||
-rw-r--r-- | accounts/abi/argument.go | 2 | ||||
-rw-r--r-- | accounts/abi/event.go | 8 | ||||
-rw-r--r-- | cmd/disasm/main.go | 9 | ||||
-rw-r--r-- | mobile/params.go | 2 | ||||
-rw-r--r-- | swarm/api/http/server.go | 14 | ||||
-rw-r--r-- | swarm/api/manifest.go | 5 | ||||
-rw-r--r-- | swarm/storage/chunker.go | 7 |
9 files changed, 92 insertions, 26 deletions
diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 2efac1307..4e02ae5f1 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -345,12 +345,13 @@ func (abi ABI) Unpack(v interface{}, name string, output []byte) error { func (abi *ABI) UnmarshalJSON(data []byte) error { var fields []struct { - Type string - Name string - Constant bool - Indexed bool - Inputs []Argument - Outputs []Argument + Type string + Name string + Constant bool + Indexed bool + Anonymous bool + Inputs []Argument + Outputs []Argument } if err := json.Unmarshal(data, &fields); err != nil { @@ -375,8 +376,9 @@ func (abi *ABI) UnmarshalJSON(data []byte) error { } case "event": abi.Events[field.Name] = Event{ - Name: field.Name, - Inputs: field.Inputs, + Name: field.Name, + Anonymous: field.Anonymous, + Inputs: field.Inputs, } } } diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index 85e25f9ea..99c46df0d 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -752,23 +752,58 @@ func TestDefaultFunctionParsing(t *testing.T) { func TestBareEvents(t *testing.T) { const definition = `[ { "type" : "event", "name" : "balance" }, - { "type" : "event", "name" : "name" }]` + { "type" : "event", "name" : "anon", "anonymous" : true}, + { "type" : "event", "name" : "args", "inputs" : [{ "indexed":false, "name":"arg0", "type":"uint256" }, { "indexed":true, "name":"arg1", "type":"address" }] } + ]` + + arg0, _ := NewType("uint256") + arg1, _ := NewType("address") + + expectedEvents := map[string]struct { + Anonymous bool + Args []Argument + }{ + "balance": {false, nil}, + "anon": {true, nil}, + "args": {false, []Argument{ + Argument{Name: "arg0", Type: arg0, Indexed: false}, + Argument{Name: "arg1", Type: arg1, Indexed: true}, + }}, + } abi, err := JSON(strings.NewReader(definition)) if err != nil { t.Fatal(err) } - if len(abi.Events) != 2 { - t.Error("expected 2 events") - } - - if _, ok := abi.Events["balance"]; !ok { - t.Error("expected 'balance' event to be present") + if len(abi.Events) != len(expectedEvents) { + t.Fatalf("invalid number of events after parsing, want %d, got %d", len(expectedEvents), len(abi.Events)) } - if _, ok := abi.Events["name"]; !ok { - t.Error("expected 'name' event to be present") + for name, exp := range expectedEvents { + got, ok := abi.Events[name] + if !ok { + t.Errorf("could not found event %s", name) + continue + } + if got.Anonymous != exp.Anonymous { + t.Errorf("invalid anonymous indication for event %s, want %v, got %v", name, exp.Anonymous, got.Anonymous) + } + if len(got.Inputs) != len(exp.Args) { + t.Errorf("invalid number of args, want %d, got %d", len(exp.Args), len(got.Inputs)) + continue + } + for i, arg := range exp.Args { + if arg.Name != got.Inputs[i].Name { + t.Errorf("events[%s].Input[%d] has an invalid name, want %s, got %s", name, i, arg.Name, got.Inputs[i].Name) + } + if arg.Indexed != got.Inputs[i].Indexed { + t.Errorf("events[%s].Input[%d] has an invalid indexed indication, want %v, got %v", name, i, arg.Indexed, got.Inputs[i].Indexed) + } + if arg.Type.T != got.Inputs[i].Type.T { + t.Errorf("events[%s].Input[%d] has an invalid type, want %x, got %x", name, i, arg.Type.T, got.Inputs[i].Type.T) + } + } } } diff --git a/accounts/abi/argument.go b/accounts/abi/argument.go index 188203a5d..4faafdd3b 100644 --- a/accounts/abi/argument.go +++ b/accounts/abi/argument.go @@ -33,6 +33,7 @@ func (a *Argument) UnmarshalJSON(data []byte) error { var extarg struct { Name string Type string + Indexed bool } err := json.Unmarshal(data, &extarg) if err != nil { @@ -44,6 +45,7 @@ func (a *Argument) UnmarshalJSON(data []byte) error { return err } a.Name = extarg.Name + a.Indexed = extarg.Indexed return nil } diff --git a/accounts/abi/event.go b/accounts/abi/event.go index e74c7c732..51ab84241 100644 --- a/accounts/abi/event.go +++ b/accounts/abi/event.go @@ -25,10 +25,12 @@ import ( ) // Event is an event potentially triggered by the EVM's LOG mechanism. The Event -// holds type information (inputs) about the yielded output +// holds type information (inputs) about the yielded output. Anonymous events +// don't get the signature canonical representation as the first LOG topic. type Event struct { - Name string - Inputs []Argument + Name string + Anonymous bool + Inputs []Argument } // Id returns the canonical representation of the event's signature used by the diff --git a/cmd/disasm/main.go b/cmd/disasm/main.go index ba1295ba1..d792e8ee5 100644 --- a/cmd/disasm/main.go +++ b/cmd/disasm/main.go @@ -21,8 +21,9 @@ import ( "fmt" "io/ioutil" "os" + "encoding/hex" + "strings" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" ) @@ -32,7 +33,11 @@ func main() { fmt.Println(err) os.Exit(1) } - code = common.Hex2Bytes(string(code[:len(code)-1])) + code, err = hex.DecodeString(strings.TrimSpace(string(code[:]))) + if err != nil { + fmt.Printf("Error: %v\n", err) + return + } fmt.Printf("%x\n", code) for pc := uint64(0); pc < uint64(len(code)); pc++ { diff --git a/mobile/params.go b/mobile/params.go index 507c15349..8d5d3edbe 100644 --- a/mobile/params.go +++ b/mobile/params.go @@ -50,7 +50,7 @@ func TestnetChainConfig() *ChainConfig { ChainID: params.TestNetChainID.Int64(), HomesteadBlock: params.TestNetHomesteadBlock.Int64(), DAOForkBlock: 0, - DAOForkSupport: true, + DAOForkSupport: false, EIP150Block: params.TestNetHomesteadGasRepriceBlock.Int64(), EIP150Hash: Hash{params.TestNetHomesteadGasRepriceHash}, EIP155Block: params.TestNetSpuriousDragon.Int64(), diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go index 9be60ef94..f82775f25 100644 --- a/swarm/api/http/server.go +++ b/swarm/api/http/server.go @@ -99,7 +99,7 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { "[BZZ] Swarm: Protocol error in request `%s`.", uri, ) - http.Error(w, "BZZ protocol error", http.StatusBadRequest) + http.Error(w, "Invalid request URL: need access protocol (bzz:/, bzzr:/, bzzi:/) as first element in path.", http.StatusBadRequest) return } } @@ -187,6 +187,12 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { reader := a.Retrieve(key) quitC := make(chan bool) size, err := reader.Size(quitC) + if err != nil { + glog.V(logger.Debug).Infof("Could not determine size: %v", err.Error()) + //An error on call to Size means we don't have the root chunk + http.Error(w, err.Error(), http.StatusNotFound) + return + } glog.V(logger.Debug).Infof("Reading %d bytes.", size) // setting mime type @@ -229,6 +235,12 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) { } quitC := make(chan bool) size, err := reader.Size(quitC) + if err != nil { + glog.V(logger.Debug).Infof("Could not determine size: %v", err.Error()) + //An error on call to Size means we don't have the root chunk + http.Error(w, err.Error(), http.StatusNotFound) + return + } glog.V(logger.Debug).Infof("Served '%s' (%d bytes) as '%s' (status code: %v)", uri, size, mimeType, status) http.ServeContent(w, r, path, forever(), reader) diff --git a/swarm/api/manifest.go b/swarm/api/manifest.go index a289c01f9..d6dc24c48 100644 --- a/swarm/api/manifest.go +++ b/swarm/api/manifest.go @@ -62,6 +62,11 @@ func readManifest(manifestReader storage.LazySectionReader, hash storage.Key, dp // TODO check size for oversized manifests size, err := manifestReader.Size(quitC) + if err != nil { // size == 0 + // can't determine size means we don't have the root chunk + err = fmt.Errorf("Manifest not Found") + return + } manifestData := make([]byte, size) read, err := manifestReader.Read(manifestData) if int64(read) < size { diff --git a/swarm/storage/chunker.go b/swarm/storage/chunker.go index c0f950de5..d55875369 100644 --- a/swarm/storage/chunker.go +++ b/swarm/storage/chunker.go @@ -483,8 +483,11 @@ func (s *LazyChunkReader) Seek(offset int64, whence int) (int64, error) { case 1: offset += s.off case 2: - if s.chunk == nil { - return 0, fmt.Errorf("seek from the end requires rootchunk for size. call Size first") + if s.chunk == nil { //seek from the end requires rootchunk for size. call Size first + _, err := s.Size(nil) + if err != nil { + return 0, fmt.Errorf("can't get size: %v", err) + } } offset += s.chunk.Size } |