forked from cerc-io/plugeth
added init and main functions to script
This commit is contained in:
parent
d092d05a31
commit
7cb065489c
@ -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)
|
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) {
|
func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) {
|
||||||
var hash []byte
|
var hash []byte
|
||||||
var contractCreation bool
|
var contractCreation bool
|
||||||
@ -64,19 +80,19 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin
|
|||||||
var tx *ethchain.Transaction
|
var tx *ethchain.Transaction
|
||||||
// Compile and assemble the given data
|
// Compile and assemble the given data
|
||||||
if contractCreation {
|
if contractCreation {
|
||||||
asm, errors := mutan.Compile(strings.NewReader(data), false)
|
mainInput, initInput := ethutil.PreProcess(data)
|
||||||
if len(errors) > 0 {
|
mainScript, err := compile(mainInput)
|
||||||
var errs string
|
if err != nil {
|
||||||
for _, er := range errors {
|
return "", err
|
||||||
if er != nil {
|
}
|
||||||
errs += er.Error()
|
initScript, err := compile(initInput)
|
||||||
}
|
if err != nil {
|
||||||
}
|
return "", err
|
||||||
return "", fmt.Errorf(errs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code := ethutil.Assemble(asm...)
|
// TODO
|
||||||
tx = ethchain.NewContractCreationTx(value, gasPrice, code)
|
fmt.Println(initScript)
|
||||||
|
tx = ethchain.NewContractCreationTx(value, gasPrice, mainScript)
|
||||||
} else {
|
} else {
|
||||||
tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, nil)
|
tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, nil)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user