aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/rlp.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-18 07:12:51 +0800
committerobscuren <geffobscura@gmail.com>2014-12-18 07:12:51 +0800
commite6fdf0c9f7564b8b08cf428e03af66fc423adcc1 (patch)
tree14fafd42083a9a5d57005b614740294ae0525bef /ethutil/rlp.go
parent52b54631a47dfa46742635be178f2f8d33dd9f41 (diff)
parent4dbdcaecb117d7e1fcaf0869f5d4602312552991 (diff)
downloadgo-tangerine-e6fdf0c9f7564b8b08cf428e03af66fc423adcc1.tar.gz
go-tangerine-e6fdf0c9f7564b8b08cf428e03af66fc423adcc1.tar.zst
go-tangerine-e6fdf0c9f7564b8b08cf428e03af66fc423adcc1.zip
Merge branch 'develop' into poc8
Diffstat (limited to 'ethutil/rlp.go')
-rw-r--r--ethutil/rlp.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/ethutil/rlp.go b/ethutil/rlp.go
index 1fff2b28a..157dd4dd9 100644
--- a/ethutil/rlp.go
+++ b/ethutil/rlp.go
@@ -2,8 +2,10 @@ package ethutil
import (
"bytes"
+ "encoding/binary"
"fmt"
"math/big"
+ "reflect"
)
type RlpEncode interface {
@@ -97,6 +99,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 +178,26 @@ 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 {
+ buff.WriteByte(byte(intlen(int64(blen))) + 0xf7)
+ binary.Write(&buff, binary.BigEndian, int64(blen))
+ }
+ buff.ReadFrom(&b)
+ }
}
} else {
// Empty list for nil