aboutsummaryrefslogtreecommitdiffstats
path: root/ethereal
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-16 04:13:04 +0800
committerobscuren <geffobscura@gmail.com>2014-04-16 04:13:04 +0800
commit7cb065489c3d664f5924afad4f72e2a0a3a5c800 (patch)
treeaa158a1ffe40c3e3432d087bd511c8adb472f368 /ethereal
parentd092d05a31554c37f4d7594d96ce9409082b5b20 (diff)
downloadgo-tangerine-7cb065489c3d664f5924afad4f72e2a0a3a5c800.tar.gz
go-tangerine-7cb065489c3d664f5924afad4f72e2a0a3a5c800.tar.zst
go-tangerine-7cb065489c3d664f5924afad4f72e2a0a3a5c800.zip
added init and main functions to script
Diffstat (limited to 'ethereal')
-rw-r--r--ethereal/ui/library.go38
1 files changed, 27 insertions, 11 deletions
diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go
index 42aebcd87..76032f400 100644
--- a/ethereal/ui/library.go
+++ b/ethereal/ui/library.go
@@ -44,6 +44,22 @@ func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) {
return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub)
}
+// General compiler and preprocessor function
+func compile(script string) ([]byte, error) {
+ asm, 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 ethutil.Assemble(asm...), nil
+}
+
func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) {
var hash []byte
var contractCreation bool
@@ -64,19 +80,19 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin
var tx *ethchain.Transaction
// Compile and assemble the given data
if contractCreation {
- asm, errors := mutan.Compile(strings.NewReader(data), false)
- if len(errors) > 0 {
- var errs string
- for _, er := range errors {
- if er != nil {
- errs += er.Error()
- }
- }
- return "", fmt.Errorf(errs)
+ mainInput, initInput := ethutil.PreProcess(data)
+ mainScript, err := compile(mainInput)
+ if err != nil {
+ return "", err
+ }
+ initScript, err := compile(initInput)
+ if err != nil {
+ return "", err
}
- code := ethutil.Assemble(asm...)
- tx = ethchain.NewContractCreationTx(value, gasPrice, code)
+ // TODO
+ fmt.Println(initScript)
+ tx = ethchain.NewContractCreationTx(value, gasPrice, mainScript)
} else {
tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, nil)
}