aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-11 09:05:58 +0800
committerobscuren <geffobscura@gmail.com>2014-04-11 09:05:58 +0800
commit7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0 (patch)
treeb529de034a77da5a4a35526eb4800863ddf1fbdb /ethutil
parentd927c154e77027924756d3538139ce0910b1c23a (diff)
parent25dd46061fc3b732056ea87fe4a9696e160179cc (diff)
downloadgo-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar
go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar.gz
go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar.bz2
go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar.lz
go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar.xz
go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar.zst
go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.zip
Merge branch 'split' into develop
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/parsing.go42
-rw-r--r--ethutil/rlp.go7
2 files changed, 22 insertions, 27 deletions
diff --git a/ethutil/parsing.go b/ethutil/parsing.go
index 16ed2d06d..278414982 100644
--- a/ethutil/parsing.go
+++ b/ethutil/parsing.go
@@ -1,8 +1,8 @@
package ethutil
import (
+ _ "fmt"
"math/big"
- "strconv"
)
// Op codes
@@ -51,7 +51,10 @@ var OpCodes = map[string]byte{
"GASLIMIT": 0x45,
// 0x50 range - 'storage' and execution
- "PUSH": 0x50,
+ "PUSH": 0x50,
+
+ "PUSH20": 0x80,
+
"POP": 0x51,
"DUP": 0x52,
"SWAP": 0x53,
@@ -98,11 +101,16 @@ func CompileInstr(s interface{}) ([]byte, error) {
// Assume regular bytes during compilation
if !success {
num.SetBytes([]byte(str))
+ } else {
+ // tmp fix for 32 bytes
+ n := BigToBytes(num, 256)
+ return n, nil
}
return num.Bytes(), nil
case int:
- return big.NewInt(int64(s.(int))).Bytes(), nil
+ num := BigToBytes(big.NewInt(int64(s.(int))), 256)
+ return num, nil
case []byte:
return BigD(s.([]byte)).Bytes(), nil
}
@@ -110,34 +118,16 @@ func CompileInstr(s interface{}) ([]byte, error) {
return nil, nil
}
-func Instr(instr string) (int, []string, error) {
-
- base := new(big.Int)
- base.SetString(instr, 0)
-
- args := make([]string, 7)
- for i := 0; i < 7; i++ {
- // int(int(val) / int(math.Pow(256,float64(i)))) % 256
- exp := BigPow(256, i)
- num := new(big.Int)
- num.Div(base, exp)
-
- args[i] = num.Mod(num, big.NewInt(256)).String()
- }
- op, _ := strconv.Atoi(args[0])
-
- return op, args[1:7], nil
-}
-
// Script compilation functions
// Compiles strings to machine code
-func Assemble(instructions ...interface{}) (script []string) {
- script = make([]string, len(instructions))
+func Assemble(instructions ...interface{}) (script []byte) {
+ //script = make([]string, len(instructions))
- for i, val := range instructions {
+ for _, val := range instructions {
instr, _ := CompileInstr(val)
- script[i] = string(instr)
+ //script[i] = string(instr)
+ script = append(script, instr...)
}
return
diff --git a/ethutil/rlp.go b/ethutil/rlp.go
index e6c75696e..d95ace425 100644
--- a/ethutil/rlp.go
+++ b/ethutil/rlp.go
@@ -186,7 +186,12 @@ func Encode(object interface{}) []byte {
case byte:
buff.Write(Encode(big.NewInt(int64(t))))
case *big.Int:
- buff.Write(Encode(t.Bytes()))
+ // Not sure how this is possible while we check for
+ if t == nil {
+ buff.WriteByte(0xc0)
+ } else {
+ buff.Write(Encode(t.Bytes()))
+ }
case []byte:
if len(t) == 1 && t[0] <= 0x7f {
buff.Write(t)