Skip to content

Commit

Permalink
Merge pull request ethereum#8 from expanse-project/rebase-1.3.2
Browse files Browse the repository at this point in the history
Rebase 1.3.2
  • Loading branch information
chrisfranko committed Dec 16, 2015
2 parents 4af642e + 3ec4e69 commit 80b554f
Show file tree
Hide file tree
Showing 68 changed files with 3,556 additions and 1,747 deletions.
66 changes: 57 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
# with Go source code. If you know what GOPATH is then you probably
# don't need to bother with make.

.PHONY: gexp gexp-cross evm all test travis-test-with-coverage xgo clean
.PHONY: gexp-linux gexp-linux-arm gexp-linux-386 gexp-linux-amd64
.PHONY: gexp-darwin gexp-darwin-386 gexp-darwin-amd64
.PHONY: gexp-windows gexp-windows-386 gexp-windows-amd64
.PHONY: gexp-android gexp-android-16 gexp-android-21

.PHONY: gexp gexp-cross gexp-linux gexp-darwin gexp-windows gexp-android evm all test travis-test-with-coverage xgo clean
GOBIN = build/bin

CROSSDEPS = https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2
GO ?= latest

gexp:
build/env.sh go install -v $(shell build/flags.sh) ./cmd/gexp
@echo "Done building."
Expand All @@ -15,26 +22,67 @@ gexp-cross: gexp-linux gexp-darwin gexp-windows gexp-android
@echo "Full cross compilation done:"
@ls -l $(GOBIN)/gexp-*

gexp-linux: xgo
build/env.sh $(GOBIN)/xgo --dest=$(GOBIN) --deps=https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2 --targets=linux/* -v $(shell build/flags.sh) ./cmd/gexp
gexp-linux: xgo gexp-linux-arm gexp-linux-386 gexp-linux-amd64
@echo "Linux cross compilation done:"
@ls -l $(GOBIN)/gexp-linux-*

gexp-darwin: xgo
build/env.sh $(GOBIN)/xgo --dest=$(GOBIN) --deps=https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2 --targets=darwin/* -v $(shell build/flags.sh) ./cmd/gexp
gexp-linux-arm: xgo
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=linux/arm -v $(shell build/flags.sh) ./cmd/gexp
@echo "Linux ARM cross compilation done:"
@ls -l $(GOBIN)/gexp-linux-* | grep arm

gexp-linux-386: xgo
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=linux/386 -v $(shell build/flags.sh) ./cmd/gexp
@echo "Linux 386 cross compilation done:"
@ls -l $(GOBIN)/gexp-linux-* | grep 386

gexp-linux-amd64: xgo
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=linux/amd64 -v $(shell build/flags.sh) ./cmd/gexp
@echo "Linux amd64 cross compilation done:"
@ls -l $(GOBIN)/gexp-linux-* | grep amd64

gexp-darwin: xgo gexp-darwin-386 gexp-darwin-amd64
@echo "Darwin cross compilation done:"
@ls -l $(GOBIN)/gexp-darwin-*

gexp-windows: xgo
build/env.sh $(GOBIN)/xgo --dest=$(GOBIN) --deps=https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2 --targets=windows/* -v $(shell build/flags.sh) ./cmd/gexp
gexp-darwin-386: xgo
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=darwin/386 -v $(shell build/flags.sh) ./cmd/gexp
@echo "Darwin 386 cross compilation done:"
@ls -l $(GOBIN)/gexp-darwin-* | grep 386

gexp-darwin-amd64: xgo
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=darwin/amd64 -v $(shell build/flags.sh) ./cmd/gexp
@echo "Darwin amd64 cross compilation done:"
@ls -l $(GOBIN)/gexp-darwin-* | grep amd64

gexp-windows: xgo gexp-windows-386 gexp-windows-amd64
@echo "Windows cross compilation done:"
@ls -l $(GOBIN)/gexp-windows-*

gexp-android: xgo
build/env.sh $(GOBIN)/xgo --dest=$(GOBIN) --deps=https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2 --targets=android-16/*,android-21/* -v $(shell build/flags.sh) ./cmd/gexp
gexp-windows-386: xgo
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=windows/386 -v $(shell build/flags.sh) ./cmd/gexp
@echo "Windows 386 cross compilation done:"
@ls -l $(GOBIN)/gexp-windows-* | grep 386

gexp-windows-amd64: xgo
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=windows/amd64 -v $(shell build/flags.sh) ./cmd/gexp
@echo "Windows amd64 cross compilation done:"
@ls -l $(GOBIN)/gexp-windows-* | grep amd64

gexp-android: xgo gexp-android-16 gexp-android-21
@echo "Android cross compilation done:"
@ls -l $(GOBIN)/gexp-android-*

gexp-android-16: xgo
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=android-16/* -v $(shell build/flags.sh) ./cmd/gexp
@echo "Android 16 cross compilation done:"
@ls -l $(GOBIN)/gexp-android-16-*

gexp-android-21: xgo
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=android-21/* -v $(shell build/flags.sh) ./cmd/gexp
@echo "Android 21 cross compilation done:"
@ls -l $(GOBIN)/gexp-android-21-*

evm:
build/env.sh $(GOROOT)/bin/go install -v $(shell build/flags.sh) ./cmd/evm
@echo "Done building."
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.1
1.3.2
12 changes: 6 additions & 6 deletions accounts/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
type Method struct {
Name string
Const bool
Input []Argument
Inputs []Argument
Return Type // not yet implemented
}

Expand All @@ -49,9 +49,9 @@ type Method struct {
// Please note that "int" is substitute for its canonical representation "int256"
func (m Method) String() (out string) {
out += m.Name
types := make([]string, len(m.Input))
types := make([]string, len(m.Inputs))
i := 0
for _, input := range m.Input {
for _, input := range m.Inputs {
types[i] = input.Type.String()
i++
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func (abi ABI) pack(name string, args ...interface{}) ([]byte, error) {

var ret []byte
for i, a := range args {
input := method.Input[i]
input := method.Inputs[i]

packed, err := input.Type.pack(a)
if err != nil {
Expand All @@ -129,8 +129,8 @@ func (abi ABI) Pack(name string, args ...interface{}) ([]byte, error) {
}

// start with argument count match
if len(args) != len(method.Input) {
return nil, fmt.Errorf("argument count mismatch: %d for %d", len(args), len(method.Input))
if len(args) != len(method.Inputs) {
return nil, fmt.Errorf("argument count mismatch: %d for %d", len(args), len(method.Inputs))
}

arguments, err := abi.pack(name, args...)
Expand Down
75 changes: 62 additions & 13 deletions accounts/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,38 @@ package abi

import (
"bytes"
"fmt"
"log"
"math/big"
"reflect"
"strings"
"testing"

"github.com/expanse-project/go-expanse/common"
"github.com/expanse-project/go-expanse/crypto"
)

const jsondata = `
[
{ "name" : "balance", "const" : true },
{ "name" : "send", "const" : false, "input" : [ { "name" : "amount", "type" : "uint256" } ] }
{ "name" : "send", "const" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] }
]`

const jsondata2 = `
[
{ "name" : "balance", "const" : true },
{ "name" : "send", "const" : false, "input" : [ { "name" : "amount", "type" : "uint256" } ] },
{ "name" : "test", "const" : false, "input" : [ { "name" : "number", "type" : "uint32" } ] },
{ "name" : "string", "const" : false, "input" : [ { "name" : "input", "type" : "string" } ] },
{ "name" : "bool", "const" : false, "input" : [ { "name" : "input", "type" : "bool" } ] },
{ "name" : "address", "const" : false, "input" : [ { "name" : "input", "type" : "address" } ] },
{ "name" : "string32", "const" : false, "input" : [ { "name" : "input", "type" : "string32" } ] },
{ "name" : "uint64[2]", "const" : false, "input" : [ { "name" : "input", "type" : "uint64[2]" } ] },
{ "name" : "uint64[]", "const" : false, "input" : [ { "name" : "input", "type" : "uint64[]" } ] },
{ "name" : "foo", "const" : false, "input" : [ { "name" : "input", "type" : "uint32" } ] },
{ "name" : "bar", "const" : false, "input" : [ { "name" : "input", "type" : "uint32" }, { "name" : "string", "type" : "uint16" } ] },
{ "name" : "slice", "const" : false, "input" : [ { "name" : "input", "type" : "uint32[2]" } ] },
{ "name" : "slice256", "const" : false, "input" : [ { "name" : "input", "type" : "uint256[2]" } ] }
{ "name" : "send", "const" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] },
{ "name" : "test", "const" : false, "inputs" : [ { "name" : "number", "type" : "uint32" } ] },
{ "name" : "string", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "string" } ] },
{ "name" : "bool", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "bool" } ] },
{ "name" : "address", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "address" } ] },
{ "name" : "string32", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "string32" } ] },
{ "name" : "uint64[2]", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint64[2]" } ] },
{ "name" : "uint64[]", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint64[]" } ] },
{ "name" : "foo", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32" } ] },
{ "name" : "bar", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32" }, { "name" : "string", "type" : "uint16" } ] },
{ "name" : "slice", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32[2]" } ] },
{ "name" : "slice256", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint256[2]" } ] }
]`

func TestType(t *testing.T) {
Expand Down Expand Up @@ -344,3 +347,49 @@ func TestPackSliceBig(t *testing.T) {
t.Errorf("expected %x got %x", sig, packed)
}
}

func ExampleJSON() {
const definition = `[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"isBar","outputs":[{"name":"","type":"bool"}],"type":"function"}]`

abi, err := JSON(strings.NewReader(definition))
if err != nil {
log.Fatalln(err)
}
out, err := abi.Pack("isBar", common.HexToAddress("01"))
if err != nil {
log.Fatalln(err)
}

fmt.Printf("%x\n", out)
// Output:
// 1f2c40920000000000000000000000000000000000000000000000000000000000000001
}

func TestBytes(t *testing.T) {
const definition = `[
{ "name" : "balance", "const" : true, "inputs" : [ { "name" : "address", "type" : "bytes20" } ] },
{ "name" : "send", "const" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] }
]`

abi, err := JSON(strings.NewReader(definition))
if err != nil {
t.Fatal(err)
}
ok := make([]byte, 20)
_, err = abi.Pack("balance", ok)
if err != nil {
t.Error(err)
}

toosmall := make([]byte, 19)
_, err = abi.Pack("balance", toosmall)
if err != nil {
t.Error(err)
}

toobig := make([]byte, 21)
_, err = abi.Pack("balance", toobig)
if err == nil {
t.Error("expected error")
}
}
14 changes: 12 additions & 2 deletions accounts/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Type struct {
stringKind string // holds the unparsed string for deriving signatures
}

// New type returns a fully parsed Type given by the input string or an error if it can't be parsed.
// NewType returns a fully parsed Type given by the input string or an error if it can't be parsed.
//
// Strings can be in the format of:
//
Expand Down Expand Up @@ -130,6 +130,10 @@ func NewType(t string) (typ Type, err error) {
if vsize > 0 {
typ.Size = 32
}
case "bytes":
typ.Kind = reflect.Slice
typ.Type = byte_ts
typ.Size = vsize
default:
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
}
Expand Down Expand Up @@ -200,7 +204,13 @@ func (t Type) pack(v interface{}) ([]byte, error) {
} else {
return common.LeftPadBytes(common.Big0.Bytes(), 32), nil
}
case reflect.Array:
if v, ok := value.Interface().(common.Address); ok {
return t.pack(v[:])
} else if v, ok := value.Interface().(common.Hash); ok {
return t.pack(v[:])
}
}

panic("unreached")
return nil, fmt.Errorf("ABI: bad input given %T", value.Kind())
}
Loading

0 comments on commit 80b554f

Please sign in to comment.