aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/bytes.go
diff options
context:
space:
mode:
Diffstat (limited to 'ethutil/bytes.go')
-rw-r--r--ethutil/bytes.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/ethutil/bytes.go b/ethutil/bytes.go
index d68a69433..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 {
@@ -149,3 +149,17 @@ func LeftPadBytes(slice []byte, l int) []byte {
return padded
}
+
+func Address(slice []byte) (addr []byte) {
+ if len(slice) < 20 {
+ addr = LeftPadBytes(slice, 20)
+ } else if len(slice) > 20 {
+ addr = slice[len(slice)-20:]
+ } else {
+ addr = slice
+ }
+
+ addr = CopyBytes(addr)
+
+ return
+}