aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ethchain/vm_test.go30
-rw-r--r--ethutil/parsing.go46
2 files changed, 49 insertions, 27 deletions
diff --git a/ethchain/vm_test.go b/ethchain/vm_test.go
index 16cbf51b7..047531e09 100644
--- a/ethchain/vm_test.go
+++ b/ethchain/vm_test.go
@@ -2,7 +2,6 @@ package ethchain
import (
"bytes"
- "fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
"math/big"
@@ -130,27 +129,26 @@ func TestRun3(t *testing.T) {
})
tx := NewTransaction(ContractAddr, ethutil.Big("100000000000000000000000000000000000000000000000000"), script)
addr := tx.Hash()[12:]
- fmt.Printf("addr contract %x\n", addr)
contract := MakeContract(tx, state)
state.UpdateContract(contract)
- callerScript := Compile([]string{
- "PUSH", "1337", // Argument
- "PUSH", "65", // argument mem offset
+ callerScript := ethutil.Compile(
+ "PUSH", 1337, // Argument
+ "PUSH", 65, // argument mem offset
"MSTORE",
- "PUSH", "64", // ret size
- "PUSH", "0", // ret offset
-
- "PUSH", "32", // arg size
- "PUSH", "65", // arg offset
- "PUSH", "1000", /// Gas
- "PUSH", "0", /// value
- "PUSH", string(addr), // Sender
+ "PUSH", 64, // ret size
+ "PUSH", 0, // ret offset
+
+ "PUSH", 32, // arg size
+ "PUSH", 65, // arg offset
+ "PUSH", 1000, /// Gas
+ "PUSH", 0, /// value
+ "PUSH", addr, // Sender
"CALL",
- "PUSH", "64",
- "PUSH", "0",
+ "PUSH", 64,
+ "PUSH", 0,
"RETURN",
- })
+ )
callerTx := NewTransaction(ContractAddr, ethutil.Big("100000000000000000000000000000000000000000000000000"), callerScript)
// Contract addr as test address
diff --git a/ethutil/parsing.go b/ethutil/parsing.go
index f24402623..8929f0829 100644
--- a/ethutil/parsing.go
+++ b/ethutil/parsing.go
@@ -84,20 +84,30 @@ func IsOpCode(s string) bool {
return false
}
-func CompileInstr(s string) ([]byte, error) {
- isOp := IsOpCode(s)
- if isOp {
- return []byte{OpCodes[s]}, nil
- }
+func CompileInstr(s interface{}) ([]byte, error) {
+ switch s.(type) {
+ case string:
+ str := s.(string)
+ isOp := IsOpCode(str)
+ if isOp {
+ return []byte{OpCodes[str]}, nil
+ }
+
+ num := new(big.Int)
+ _, success := num.SetString(str, 0)
+ // Assume regular bytes during compilation
+ if !success {
+ num.SetBytes([]byte(str))
+ }
- num := new(big.Int)
- _, success := num.SetString(s, 0)
- // Assume regular bytes during compilation
- if !success {
- num.SetBytes([]byte(s))
+ return num.Bytes(), nil
+ case int:
+ return big.NewInt(int64(s.(int))).Bytes(), nil
+ case []byte:
+ return BigD(s.([]byte)).Bytes(), nil
}
- return num.Bytes(), nil
+ return nil, nil
}
func Instr(instr string) (int, []string, error) {
@@ -118,3 +128,17 @@ func Instr(instr string) (int, []string, error) {
return op, args[1:7], nil
}
+
+// Script compilation functions
+// Compiles strings to machine code
+func Compile(instructions ...interface{}) (script []string) {
+ script = make([]string, len(instructions))
+
+ for i, val := range instructions {
+ instr, _ := CompileInstr(val)
+
+ script[i] = string(instr)
+ }
+
+ return
+}
upt@FreeBSD.org> 2005-12-16 21:39:58 +0800 committer Emanuel Haupt <ehaupt@FreeBSD.org> 2005-12-16 21:39:58 +0800 - Re-Add misc/bestfit, a utility to Optimally choose files to be put on a' href='/~lantw44/cgit/freebsd-ports-gnome/commit/misc/Makefile?id=b44e761dbcbdda38f8ab94662b51347eea85bef5'>b44e761dbcbd
a904c1be5b70
5b50ce6244d5
054739924919
a1ca5fa19e42
47268027cece
b10246bb6da7
59a5f42547b7
86bcb3e9cc07
1ff350c5944f
16c625af9a30
6c010e0fb389
91eaf1876b3c
15a596e15ffa
1c39d223b7d6
4e4039b3adc2
cfab4519aa49
06f8890db0e1
ae533b0f5986
af3811313c14
d099f7b83bea
134ea8994979
9df2f491d879
fe5573db67a9
f2bb095f1362
1417b8324028
20d003696716
61f6beb74b52
ad13b9f5a2cd
b944373395ab
80cb69953383
6f2ebc56295d
dce849679690
6da594e8cca9
19271a617a4b
173c2250dab2
24d34901c997
fb3b86fcf743
aa2eb5cba452
744f32ac4813
8eb611f997ff
5c4886eb2868
98320db02709
804aa478a1a3
af315351aa9f
2bb716e08359
0c5c3e5dc01e
7c9e53fd345d
15e29a461404
c6d7927bae4a
aebd1b85f646
45881298b1cf
016aba291408
bb57bef7a51e
29fdb91a8af3
c894f47291e2
a6d5f8ab5e10