aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/bytes.go
diff options
context:
space:
mode:
Diffstat (limited to 'ethutil/bytes.go')
-rw-r--r--ethutil/bytes.go18
1 files changed, 18 insertions, 0 deletions
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)
+}