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') 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 v1.2.3