From f6d1bfe45bf3709d7bad40bf563b5c09228622e3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 14 Feb 2014 23:56:09 +0100 Subject: The great merge --- ethutil/bytes.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 ethutil/bytes.go (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go new file mode 100644 index 000000000..40903a5f1 --- /dev/null +++ b/ethutil/bytes.go @@ -0,0 +1,64 @@ +package ethutil + +import ( + "bytes" + "encoding/binary" + "fmt" +) + +func NumberToBytes(num interface{}, bits int) []byte { + buf := new(bytes.Buffer) + err := binary.Write(buf, binary.BigEndian, num) + if err != nil { + fmt.Println("NumberToBytes failed:", err) + } + + return buf.Bytes()[buf.Len()-(bits/8):] +} + +func BytesToNumber(b []byte) uint64 { + var number uint64 + + // Make sure the buffer is 64bits + data := make([]byte, 8) + data = append(data[:len(b)], b...) + + buf := bytes.NewReader(data) + err := binary.Read(buf, binary.BigEndian, &number) + if err != nil { + fmt.Println("BytesToNumber failed:", err) + } + + return number +} + +// Read variable integer in big endian +func ReadVarint(reader *bytes.Reader) (ret uint64) { + if reader.Len() == 8 { + var num uint64 + binary.Read(reader, binary.BigEndian, &num) + ret = uint64(num) + } else if reader.Len() == 4 { + var num uint32 + binary.Read(reader, binary.BigEndian, &num) + ret = uint64(num) + } else if reader.Len() == 2 { + var num uint16 + binary.Read(reader, binary.BigEndian, &num) + ret = uint64(num) + } else { + var num uint8 + binary.Read(reader, binary.BigEndian, &num) + ret = uint64(num) + } + + return ret +} + +func BinaryLength(num int) int { + if num == 0 { + return 0 + } + + return 1 + BinaryLength(num>>8) +} -- cgit From 338b6980915c990c6e6287a7249ddd98e6be20eb Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 27 Apr 2014 17:15:44 +0200 Subject: Refactoring and added documentation comments --- ethutil/bytes.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 40903a5f1..957fa254a 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -6,6 +6,9 @@ import ( "fmt" ) +// Number to bytes +// +// Returns the number in bytes with the specified base func NumberToBytes(num interface{}, bits int) []byte { buf := new(bytes.Buffer) err := binary.Write(buf, binary.BigEndian, num) @@ -16,6 +19,9 @@ func NumberToBytes(num interface{}, bits int) []byte { return buf.Bytes()[buf.Len()-(bits/8):] } +// Bytes to number +// +// Attempts to cast a byte slice to a unsigned integer func BytesToNumber(b []byte) uint64 { var number uint64 @@ -32,7 +38,9 @@ func BytesToNumber(b []byte) uint64 { return number } -// Read variable integer in big endian +// Read variable int +// +// Read a variable length number in big endian byte order func ReadVarint(reader *bytes.Reader) (ret uint64) { if reader.Len() == 8 { var num uint64 @@ -55,6 +63,9 @@ func ReadVarint(reader *bytes.Reader) (ret uint64) { return ret } +// Binary length +// +// Returns the true binary length of the given number func BinaryLength(num int) int { if num == 0 { return 0 -- cgit From 38d6b67b5cfbfb63620a244ea01b5b534917128f Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 29 Apr 2014 12:36:27 +0200 Subject: Fixed state problem --- ethutil/bytes.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 957fa254a..500368017 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -73,3 +73,13 @@ func BinaryLength(num int) int { return 1 + BinaryLength(num>>8) } + +// Copy bytes +// +// Returns an exact copy of the provided bytes +func CopyBytes(b []byte) (copiedBytes []byte) { + copiedBytes = make([]byte, len(b)) + copy(copiedBytes, b) + + return +} -- cgit From 14a6e6a9cea48bcc7f6d5286e4f85b1a0cce84d8 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 5 May 2014 15:48:17 +0200 Subject: Added the ability to submit byte code for contracts instead of Mutan code. --- ethutil/bytes.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 500368017..b298675a2 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -83,3 +83,8 @@ func CopyBytes(b []byte) (copiedBytes []byte) { return } + +func IsHex(str string) bool { + l := len(str) + return l >= 4 && l%2 == 0 && str[0:2] == "0x" +} -- cgit From 65722aeeca0fed685a00d660ddd7bb667ac3be9b Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 May 2014 13:14:56 +0200 Subject: Added StringToBytesFunc --- ethutil/bytes.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index b298675a2..075e40b4c 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -88,3 +88,13 @@ func IsHex(str string) bool { l := len(str) return l >= 4 && l%2 == 0 && str[0:2] == "0x" } + +func StringToByteFunc(str string, cb func(str string) []byte) (ret []byte) { + if str[0:2] == "0x" { + ret = FromHex(str[2:]) + } else { + ret = cb(str) + } + + return +} -- cgit From a98e35d7a048850fb77fad49fff7364cf77a9bae Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 May 2014 13:55:32 +0200 Subject: Length checking --- ethutil/bytes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 075e40b4c..1c7a43af8 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -90,7 +90,7 @@ func IsHex(str string) bool { } func StringToByteFunc(str string, cb func(str string) []byte) (ret []byte) { - if str[0:2] == "0x" { + if len(str) > 1 && str[0:2] == "0x" { ret = FromHex(str[2:]) } else { ret = cb(str) -- cgit From 4d987624867fc02a079d8355c28bad620db85f06 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 May 2014 23:16:54 +0200 Subject: Fixed state object gas return --- ethutil/bytes.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 1c7a43af8..bd0df68ec 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "fmt" + "math/big" ) // Number to bytes @@ -98,3 +99,20 @@ func StringToByteFunc(str string, cb func(str string) []byte) (ret []byte) { return } + +func FormatData(data string) []byte { + if len(data) == 0 { + return nil + } + // Simple stupid + d := new(big.Int) + if data[0:1] == "\"" && data[len(data)-1:] == "\"" { + d.SetBytes([]byte(data[1 : len(data)-1])) + } else if len(data) > 1 && data[:2] == "0x" { + d.SetBytes(FromHex(data[2:])) + } else { + d.SetString(data, 0) + } + + return BigToBytes(d, 256) +} -- cgit From 2fbcfd88249de8f55b7f06619d9003fadcc8e1e3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 18 Jun 2014 11:55:05 +0200 Subject: Proper checks for multiple data items. Fixes #80 --- ethutil/bytes.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index bd0df68ec..5e3ee4a6f 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "fmt" "math/big" + "strings" ) // Number to bytes @@ -91,7 +92,7 @@ func IsHex(str string) bool { } func StringToByteFunc(str string, cb func(str string) []byte) (ret []byte) { - if len(str) > 1 && str[0:2] == "0x" { + if len(str) > 1 && str[0:2] == "0x" && !strings.Contains(str, "\n") { ret = FromHex(str[2:]) } else { ret = cb(str) -- cgit From 5c1e0a6dc4e49154c185503ef7c8e96328dd6492 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 29 Jun 2014 15:56:40 +0100 Subject: move ethutil hex conversion functions to bytes --- ethutil/bytes.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 5e3ee4a6f..c2817946b 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -3,6 +3,7 @@ package ethutil import ( "bytes" "encoding/binary" + "encoding/hex" "fmt" "math/big" "strings" @@ -91,9 +92,18 @@ func IsHex(str string) bool { return l >= 4 && l%2 == 0 && str[0:2] == "0x" } +func Bytes2Hex(d []byte) string { + return hex.EncodeToString(d) +} + +func Hex2Bytes(str string) []byte { + h, _ := hex.DecodeString(str) + return h +} + func StringToByteFunc(str string, cb func(str string) []byte) (ret []byte) { if len(str) > 1 && str[0:2] == "0x" && !strings.Contains(str, "\n") { - ret = FromHex(str[2:]) + ret = Hex2Bytes(str[2:]) } else { ret = cb(str) } @@ -110,7 +120,7 @@ func FormatData(data string) []byte { if data[0:1] == "\"" && data[len(data)-1:] == "\"" { d.SetBytes([]byte(data[1 : len(data)-1])) } else if len(data) > 1 && data[:2] == "0x" { - d.SetBytes(FromHex(data[2:])) + d.SetBytes(Hex2Bytes(data[2:])) } else { d.SetString(data, 0) } -- cgit From 28ef7d228c4e8e24315eb585e4e0d03a4c652ccb Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 1 Jul 2014 20:08:48 +0200 Subject: Added Left and Right padding utility functions --- ethutil/bytes.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index c2817946b..5737a75c9 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -118,7 +118,8 @@ func FormatData(data string) []byte { // Simple stupid d := new(big.Int) if data[0:1] == "\"" && data[len(data)-1:] == "\"" { - d.SetBytes([]byte(data[1 : len(data)-1])) + return RightPadBytes([]byte(data), 32) + //d.SetBytes([]byte(data[1 : len(data)-1])) } else if len(data) > 1 && data[:2] == "0x" { d.SetBytes(Hex2Bytes(data[2:])) } else { @@ -127,3 +128,25 @@ func FormatData(data string) []byte { return BigToBytes(d, 256) } + +func LeftPadBytes(slice []byte, l int) []byte { + if l <= len(slice) { + return slice + } + + padded := make([]byte, l) + copy(padded[0:len(slice)], slice) + + return padded +} + +func RightPadBytes(slice []byte, l int) []byte { + if l <= len(slice) { + return slice + } + + padded := make([]byte, l) + copy(padded[l-len(slice):], slice) + + return padded +} -- cgit From d7e396a98ccafb53b4f632228b670634baeb36a0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 1 Jul 2014 23:59:37 +0200 Subject: l <=> r --- ethutil/bytes.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 5737a75c9..ad60e62fd 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -119,7 +119,6 @@ func FormatData(data string) []byte { d := new(big.Int) if data[0:1] == "\"" && data[len(data)-1:] == "\"" { return RightPadBytes([]byte(data), 32) - //d.SetBytes([]byte(data[1 : len(data)-1])) } else if len(data) > 1 && data[:2] == "0x" { d.SetBytes(Hex2Bytes(data[2:])) } else { @@ -129,7 +128,7 @@ func FormatData(data string) []byte { return BigToBytes(d, 256) } -func LeftPadBytes(slice []byte, l int) []byte { +func RightPadBytes(slice []byte, l int) []byte { if l <= len(slice) { return slice } @@ -140,7 +139,7 @@ func LeftPadBytes(slice []byte, l int) []byte { return padded } -func RightPadBytes(slice []byte, l int) []byte { +func LeftPadBytes(slice []byte, l int) []byte { if l <= len(slice) { return slice } -- cgit From 1954ef47e67762f0308544e3a17976e4c3927e32 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 2 Jul 2014 00:06:21 +0200 Subject: Suicide is deferred to update --- ethutil/bytes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index ad60e62fd..d68a69433 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -129,7 +129,7 @@ func FormatData(data string) []byte { } func RightPadBytes(slice []byte, l int) []byte { - if l <= len(slice) { + if l < len(slice) { return slice } @@ -140,7 +140,7 @@ func RightPadBytes(slice []byte, l int) []byte { } func LeftPadBytes(slice []byte, l int) []byte { - if l <= len(slice) { + if l < len(slice) { return slice } -- cgit From 14c4f06100d9f06592097c4ee588d0f83f6b17bd Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 16 Jul 2014 13:20:57 +0200 Subject: Convert a byte slice to address --- ethutil/bytes.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index d68a69433..07584d0bf 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -149,3 +149,13 @@ func LeftPadBytes(slice []byte, l int) []byte { return padded } + +func Address(slice []byte) []byte { + if len(slice) < 20 { + slice = LeftPadBytes(slice, 20) + } else if len(slice) > 20 { + slice = slice[len(slice)-20:] + } + + return slice +} -- cgit From ed3424ff75b396360990725afc124326dea4ab45 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 17 Jul 2014 11:21:18 +0200 Subject: Trie fixes --- ethutil/bytes.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 07584d0bf..d16bd6780 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -150,12 +150,16 @@ func LeftPadBytes(slice []byte, l int) []byte { return padded } -func Address(slice []byte) []byte { +func Address(slice []byte) (addr []byte) { if len(slice) < 20 { - slice = LeftPadBytes(slice, 20) + addr = LeftPadBytes(slice, 20) } else if len(slice) > 20 { - slice = slice[len(slice)-20:] + addr = slice[len(slice)-20:] + } else { + addr = slice } - return slice + addr = CopyBytes(addr) + + return } -- cgit From a626b7ebe1fa5f1029840e25e88a4de426cf64c4 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 17 Jul 2014 17:11:00 +0200 Subject: Fixed string data --- ethutil/bytes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index d16bd6780..34fff7d42 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -118,7 +118,7 @@ func FormatData(data string) []byte { // Simple stupid d := new(big.Int) if data[0:1] == "\"" && data[len(data)-1:] == "\"" { - return RightPadBytes([]byte(data), 32) + return RightPadBytes([]byte(data[1:len(data)-1]), 32) } else if len(data) > 1 && data[:2] == "0x" { d.SetBytes(Hex2Bytes(data[2:])) } else { -- cgit From 41bd38147c2e5968283facf641b2444c09f53d14 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 26 Jul 2014 11:24:44 +0200 Subject: Clean up and util methods --- ethutil/bytes.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 34fff7d42..53b8cf645 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -98,6 +98,7 @@ func Bytes2Hex(d []byte) string { func Hex2Bytes(str string) []byte { h, _ := hex.DecodeString(str) + return h } -- cgit From 6fd2401cdf792996c0183f896412831dd335377a Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 29 Jul 2014 23:33:18 +0200 Subject: Fixed issue with var int reading. Reading uneven byte slices were broken. --- ethutil/bytes.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 53b8cf645..eca2cc366 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -45,15 +45,15 @@ func BytesToNumber(b []byte) uint64 { // // Read a variable length number in big endian byte order func ReadVarint(reader *bytes.Reader) (ret uint64) { - if reader.Len() == 8 { + if reader.Len() > 4 { var num uint64 binary.Read(reader, binary.BigEndian, &num) ret = uint64(num) - } else if reader.Len() == 4 { + } else if reader.Len() > 2 { var num uint32 binary.Read(reader, binary.BigEndian, &num) ret = uint64(num) - } else if reader.Len() == 2 { + } else if reader.Len() > 0 { var num uint16 binary.Read(reader, binary.BigEndian, &num) ret = uint64(num) @@ -66,6 +66,30 @@ func ReadVarint(reader *bytes.Reader) (ret uint64) { return ret } +func ReadVarInt(buff []byte) (ret uint64) { + switch l := len(buff); { + case l > 4: + d := LeftPadBytes(buff, 8) + binary.Read(bytes.NewReader(d), binary.BigEndian, &ret) + case l > 2: + var num uint32 + d := LeftPadBytes(buff, 4) + binary.Read(bytes.NewReader(d), binary.BigEndian, &num) + ret = uint64(num) + case l > 1: + var num uint16 + d := LeftPadBytes(buff, 2) + binary.Read(bytes.NewReader(d), binary.BigEndian, &num) + ret = uint64(num) + default: + var num uint8 + binary.Read(bytes.NewReader(buff), binary.BigEndian, &num) + ret = uint64(num) + } + + return +} + // Binary length // // Returns the true binary length of the given number -- cgit From 5ca29381175d553bb764040e8cd892a4ba370645 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 29 Jul 2014 23:33:33 +0200 Subject: Fixed --- ethutil/bytes.go | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index eca2cc366..4027e3986 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -44,28 +44,6 @@ func BytesToNumber(b []byte) uint64 { // Read variable int // // Read a variable length number in big endian byte order -func ReadVarint(reader *bytes.Reader) (ret uint64) { - if reader.Len() > 4 { - var num uint64 - binary.Read(reader, binary.BigEndian, &num) - ret = uint64(num) - } else if reader.Len() > 2 { - var num uint32 - binary.Read(reader, binary.BigEndian, &num) - ret = uint64(num) - } else if reader.Len() > 0 { - var num uint16 - binary.Read(reader, binary.BigEndian, &num) - ret = uint64(num) - } else { - var num uint8 - binary.Read(reader, binary.BigEndian, &num) - ret = uint64(num) - } - - return ret -} - func ReadVarInt(buff []byte) (ret uint64) { switch l := len(buff); { case l > 4: -- cgit From 5a2d62e4d9e551f16f094216da70b7a6f5d2bf00 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 30 Jul 2014 13:06:59 +0200 Subject: Added better data parser --- ethutil/bytes.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 4027e3986..49fc229d3 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -131,6 +131,26 @@ func FormatData(data string) []byte { return BigToBytes(d, 256) } +func ParseData(data ...interface{}) (ret []byte) { + for _, item := range data { + switch t := item.(type) { + case string: + var str []byte + if IsHex(t) { + str = Hex2Bytes(t[2:]) + } else { + str = []byte(t) + } + + ret = append(ret, RightPadBytes(str, 32)...) + case []byte: + ret = append(ret, LeftPadBytes(t, 32)...) + } + } + + return +} + func RightPadBytes(slice []byte, l int) []byte { if l < len(slice) { return slice -- cgit From 55a2f35a648ef70cdcc88bd751265e30831b54e5 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 20 Aug 2014 13:05:26 +0200 Subject: JS Filter --- ethutil/bytes.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 49fc229d3..63c1606c2 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -173,6 +173,28 @@ func LeftPadBytes(slice []byte, l int) []byte { return padded } +func LeftPadString(str string, l int) string { + if l < len(str) { + return str + } + + zeros := Bytes2Hex(make([]byte, (l-len(str))/2)) + + return zeros + str + +} + +func RightPadString(str string, l int) string { + if l < len(str) { + return str + } + + zeros := Bytes2Hex(make([]byte, (l-len(str))/2)) + + return str + zeros + +} + func Address(slice []byte) (addr []byte) { if len(slice) < 20 { addr = LeftPadBytes(slice, 20) -- cgit From eaa2e8900d1036e09b002c4e20fc6e4f9cd031bb Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 21 Aug 2014 14:47:58 +0200 Subject: PoC 6 networking code. * Added block pool for gathering blocks from the network (chunks) * Re wrote syncing --- ethutil/bytes.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index 63c1606c2..e38f89454 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -208,3 +208,11 @@ func Address(slice []byte) (addr []byte) { return } + +func ByteSliceToInterface(slice [][]byte) (ret []interface{}) { + for _, i := range slice { + ret = append(ret, i) + } + + return +} -- cgit From 33a0dec8a157b9687ca6038f4deb011f3f1f7bdc Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 15 Sep 2014 15:42:12 +0200 Subject: Improved catching up and refactored --- ethutil/bytes.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index e38f89454..f151d16ee 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -9,6 +9,22 @@ import ( "strings" ) +type Bytes []byte + +func (self Bytes) String() string { + return string(self) +} + +func DeleteFromByteSlice(s [][]byte, hash []byte) [][]byte { + for i, h := range s { + if bytes.Compare(h, hash) == 0 { + return append(s[:i], s[i+1:]...) + } + } + + return s +} + // Number to bytes // // Returns the number in bytes with the specified base -- cgit From b55e017e620d8049788eda91424d4944ac934613 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 2 Oct 2014 17:03:36 +0200 Subject: Proper delete --- ethutil/bytes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/bytes.go') diff --git a/ethutil/bytes.go b/ethutil/bytes.go index f151d16ee..bd294f28a 100644 --- a/ethutil/bytes.go +++ b/ethutil/bytes.go @@ -18,7 +18,7 @@ func (self Bytes) String() string { func DeleteFromByteSlice(s [][]byte, hash []byte) [][]byte { for i, h := range s { if bytes.Compare(h, hash) == 0 { - return append(s[:i], s[i+1:]...) + return append(s[:i:i], s[i+1:]...) } } -- cgit