From 14a6e6a9cea48bcc7f6d5286e4f85b1a0cce84d8 Mon Sep 17 00:00:00 2001
From: obscuren <geffobscura@gmail.com>
Date: Mon, 5 May 2014 15:48:17 +0200
Subject: [PATCH] Added the ability to submit byte code for contracts instead
 of Mutan code.

---
 ethpub/pub.go    | 23 +++++++++++++++++------
 ethutil/bytes.go |  5 +++++
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/ethpub/pub.go b/ethpub/pub.go
index 431f173a0..4ec9877b2 100644
--- a/ethpub/pub.go
+++ b/ethpub/pub.go
@@ -103,13 +103,24 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
 	var tx *ethchain.Transaction
 	// Compile and assemble the given data
 	if contractCreation {
-		initScript, err := ethutil.Compile(initStr)
-		if err != nil {
-			return nil, err
+		var initScript, mainScript []byte
+		var err error
+		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 {
-			return nil, err
+
+		if ethutil.IsHex(scriptStr) {
+			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)
diff --git a/ethutil/bytes.go b/ethutil/bytes.go
index 500368017..b298675a2 100644
--- a/ethutil/bytes.go
+++ b/ethutil/bytes.go
@@ -83,3 +83,8 @@ func CopyBytes(b []byte) (copiedBytes []byte) {
 
 	return
 }
+
+func IsHex(str string) bool {
+	l := len(str)
+	return l >= 4 && l%2 == 0 && str[0:2] == "0x"
+}
-- 
GitLab