Added the ability to submit byte code for contracts instead of Mutan code.

This commit is contained in:
obscuren 2014-05-05 15:48:17 +02:00
parent 3e5a7b34b1
commit 14a6e6a9ce
2 changed files with 22 additions and 6 deletions

View File

@ -103,13 +103,24 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
var tx *ethchain.Transaction var tx *ethchain.Transaction
// Compile and assemble the given data // Compile and assemble the given data
if contractCreation { if contractCreation {
initScript, err := ethutil.Compile(initStr) var initScript, mainScript []byte
if err != nil { var err error
return nil, err if ethutil.IsHex(initStr) {
initScript = ethutil.FromHex(initStr)
} else {
initScript, err = ethutil.Compile(initStr[2:])
if err != nil {
return nil, err
}
} }
mainScript, err := ethutil.Compile(scriptStr)
if err != nil { if ethutil.IsHex(scriptStr) {
return nil, err mainScript = ethutil.FromHex(scriptStr[2:])
} else {
mainScript, err = ethutil.Compile(scriptStr)
if err != nil {
return nil, err
}
} }
tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript) tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript)

View File

@ -83,3 +83,8 @@ func CopyBytes(b []byte) (copiedBytes []byte) {
return return
} }
func IsHex(str string) bool {
l := len(str)
return l >= 4 && l%2 == 0 && str[0:2] == "0x"
}