aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorMaran <maran.hidskes@gmail.com>2014-05-02 20:08:27 +0800
committerMaran <maran.hidskes@gmail.com>2014-05-02 20:08:27 +0800
commit69d83b1da55a2149a402e7fa66721fd98f580801 (patch)
tree0d97a4b4ea74dda35e7995665c1ecc5f9c13f72e /ethutil
parentc54788338aad3897f7c0d5631984eaba5207e657 (diff)
parent1f6df0cd522842095c5ca723d2e11fc6b97b8b6a (diff)
downloaddexon-69d83b1da55a2149a402e7fa66721fd98f580801.tar
dexon-69d83b1da55a2149a402e7fa66721fd98f580801.tar.gz
dexon-69d83b1da55a2149a402e7fa66721fd98f580801.tar.bz2
dexon-69d83b1da55a2149a402e7fa66721fd98f580801.tar.lz
dexon-69d83b1da55a2149a402e7fa66721fd98f580801.tar.xz
dexon-69d83b1da55a2149a402e7fa66721fd98f580801.tar.zst
dexon-69d83b1da55a2149a402e7fa66721fd98f580801.zip
Merge branch 'develop' into feature/rpc
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/script.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/ethutil/script.go b/ethutil/script.go
new file mode 100644
index 000000000..620658025
--- /dev/null
+++ b/ethutil/script.go
@@ -0,0 +1,41 @@
+package ethutil
+
+import (
+ "fmt"
+ "github.com/obscuren/mutan"
+ "strings"
+)
+
+// General compile function
+func Compile(script string) ([]byte, error) {
+ byteCode, errors := mutan.Compile(strings.NewReader(script), false)
+ if len(errors) > 0 {
+ var errs string
+ for _, er := range errors {
+ if er != nil {
+ errs += er.Error()
+ }
+ }
+ return nil, fmt.Errorf("%v", errs)
+ }
+
+ return byteCode, nil
+}
+
+func CompileScript(script string) ([]byte, []byte, error) {
+ // Preprocess
+ mainInput, initInput := mutan.PreProcess(script)
+ // Compile main script
+ mainScript, err := Compile(mainInput)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ // Compile init script
+ initScript, err := Compile(initInput)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ return mainScript, initScript, nil
+}