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