aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/bytes.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-07-21 20:26:29 +0800
committerzelig <viktor.tron@gmail.com>2014-07-21 20:26:29 +0800
commit1e4af85a380977233a3bceaf5e2a020a281aa19a (patch)
treeacf6f1506952e9edc400d3b450d153db90ce536e /ethutil/bytes.go
parent017d36e6b2e127084448dfb38bd1b8de7424e1c9 (diff)
parent2762ec22d0693b406ead2f0c07b62e9b66d395e4 (diff)
downloadgo-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar
go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.gz
go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.bz2
go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.lz
go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.xz
go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.tar.zst
go-tangerine-1e4af85a380977233a3bceaf5e2a020a281aa19a.zip
merge upstream
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
+}