diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2014-12-22 01:42:32 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2014-12-22 01:42:32 +0800 |
commit | 1360f027d9e365242466ca346b2b56f421729d91 (patch) | |
tree | a30ff7292e87583781b682b47d851d0f6e1925fc /ethutil | |
parent | b3629c6f62bd3774eb8858819a8ee07dfb775b73 (diff) | |
parent | 795b14330ad4399ef292835eac452d258dcd7464 (diff) | |
download | dexon-1360f027d9e365242466ca346b2b56f421729d91.tar dexon-1360f027d9e365242466ca346b2b56f421729d91.tar.gz dexon-1360f027d9e365242466ca346b2b56f421729d91.tar.bz2 dexon-1360f027d9e365242466ca346b2b56f421729d91.tar.lz dexon-1360f027d9e365242466ca346b2b56f421729d91.tar.xz dexon-1360f027d9e365242466ca346b2b56f421729d91.tar.zst dexon-1360f027d9e365242466ca346b2b56f421729d91.zip |
Merge pull request #216 from ethereum/develop
Update tests branch from develop
Diffstat (limited to 'ethutil')
-rw-r--r-- | ethutil/rlp.go | 34 | ||||
-rw-r--r-- | ethutil/rlp_test.go | 10 | ||||
-rw-r--r-- | ethutil/script_unix.go | 42 | ||||
-rw-r--r-- | ethutil/script_windows.go | 23 | ||||
-rw-r--r-- | ethutil/value.go | 2 |
5 files changed, 52 insertions, 59 deletions
diff --git a/ethutil/rlp.go b/ethutil/rlp.go index 1fff2b28a..1bc1a58a7 100644 --- a/ethutil/rlp.go +++ b/ethutil/rlp.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "math/big" + "reflect" ) type RlpEncode interface { @@ -97,6 +98,14 @@ var ( zeroRlp = big.NewInt(0x0) ) +func intlen(i int64) (length int) { + for i > 0 { + i = i >> 8 + length++ + } + return +} + func Encode(object interface{}) []byte { var buff bytes.Buffer @@ -168,6 +177,31 @@ func Encode(object interface{}) []byte { } WriteSliceHeader(len(b.Bytes())) buff.Write(b.Bytes()) + default: + // This is how it should have been from the start + // needs refactoring (@fjl) + v := reflect.ValueOf(t) + switch v.Kind() { + case reflect.Slice: + var b bytes.Buffer + for i := 0; i < v.Len(); i++ { + b.Write(Encode(v.Index(i).Interface())) + } + + blen := b.Len() + if blen < 56 { + buff.WriteByte(byte(blen) + 0xc0) + } else { + ilen := byte(intlen(int64(blen))) + buff.WriteByte(ilen + 0xf7) + t := make([]byte, ilen) + for i := byte(0); i < ilen; i++ { + t[ilen-i-1] = byte(blen >> (i * 8)) + } + buff.Write(t) + } + buff.ReadFrom(&b) + } } } else { // Empty list for nil diff --git a/ethutil/rlp_test.go b/ethutil/rlp_test.go index 90057ab42..ff98d3269 100644 --- a/ethutil/rlp_test.go +++ b/ethutil/rlp_test.go @@ -7,6 +7,16 @@ import ( "testing" ) +func TestNonInterfaceSlice(t *testing.T) { + vala := []string{"value1", "value2", "value3"} + valb := []interface{}{"value1", "value2", "value3"} + resa := Encode(vala) + resb := Encode(valb) + if !bytes.Equal(resa, resb) { + t.Errorf("expected []string & []interface{} to be equal") + } +} + func TestRlpValueEncoding(t *testing.T) { val := EmptyValue() val.AppendList().Append(1).Append(2).Append(3) diff --git a/ethutil/script_unix.go b/ethutil/script_unix.go index 6827d4e2f..9250dda57 100644 --- a/ethutil/script_unix.go +++ b/ethutil/script_unix.go @@ -2,47 +2,17 @@ package ethutil -import ( - "fmt" - "strings" - - "github.com/ethereum/serpent-go" - "github.com/obscuren/mutan" - "github.com/obscuren/mutan/backends" -) +import "github.com/ethereum/serpent-go" // General compile function func Compile(script string, silent bool) (ret []byte, err error) { if len(script) > 2 { - line := strings.Split(script, "\n")[0] - - if len(line) > 1 && line[0:2] == "#!" { - switch line { - case "#!serpent": - byteCode, err := serpent.Compile(script) - if err != nil { - return nil, err - } - - return byteCode, nil - } - } else { - - compiler := mutan.NewCompiler(backend.NewEthereumBackend()) - compiler.Silent = silent - byteCode, errors := compiler.Compile(strings.NewReader(script)) - if len(errors) > 0 { - var errs string - for _, er := range errors { - if er != nil { - errs += er.Error() - } - } - return nil, fmt.Errorf("%v", errs) - } - - return byteCode, nil + byteCode, err := serpent.Compile(script) + if err != nil { + return nil, err } + + return byteCode, nil } return nil, nil diff --git a/ethutil/script_windows.go b/ethutil/script_windows.go index ef239cd51..1dedc5f60 100644 --- a/ethutil/script_windows.go +++ b/ethutil/script_windows.go @@ -2,31 +2,10 @@ package ethutil -import ( - "fmt" - "strings" - - "github.com/obscuren/mutan" - "github.com/obscuren/mutan/backends" -) - // General compile function func Compile(script string, silent bool) (ret []byte, err error) { if len(script) > 2 { - compiler := mutan.NewCompiler(backend.NewEthereumBackend()) - compiler.Silent = silent - byteCode, errors := compiler.Compile(strings.NewReader(script)) - if len(errors) > 0 { - var errs string - for _, er := range errors { - if er != nil { - errs += er.Error() - } - } - return nil, fmt.Errorf("%v", errs) - } - - return byteCode, nil + return nil, nil } return nil, nil diff --git a/ethutil/value.go b/ethutil/value.go index 6417b0008..7d4a7d98c 100644 --- a/ethutil/value.go +++ b/ethutil/value.go @@ -397,5 +397,5 @@ func (it *ValueIterator) Value() *Value { } func (it *ValueIterator) Idx() int { - return it.idx + return it.idx - 1 } |