aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-10 07:57:10 +0800
committerobscuren <geffobscura@gmail.com>2014-05-10 07:57:10 +0800
commit1471585af082632b33eae5bf489d0ae0b277b369 (patch)
treee384ca2962012872d4cdaf3f2108c2eab8cd7ef9
parent0bf2d24cb030ec53abedf483189ecbaa3c9676be (diff)
downloadgo-tangerine-1471585af082632b33eae5bf489d0ae0b277b369.tar
go-tangerine-1471585af082632b33eae5bf489d0ae0b277b369.tar.gz
go-tangerine-1471585af082632b33eae5bf489d0ae0b277b369.tar.bz2
go-tangerine-1471585af082632b33eae5bf489d0ae0b277b369.tar.lz
go-tangerine-1471585af082632b33eae5bf489d0ae0b277b369.tar.xz
go-tangerine-1471585af082632b33eae5bf489d0ae0b277b369.tar.zst
go-tangerine-1471585af082632b33eae5bf489d0ae0b277b369.zip
Moved Ext app js to its own dir
-rw-r--r--ethereal/assets/ethereum.js236
-rw-r--r--ethereal/assets/qml/newTransaction/_new_contract.qml2
-rw-r--r--ethereal/assets/qml/webapp.qml2
-rw-r--r--ethereal/assets/samplecoin/samplecoin.html7
-rw-r--r--ethereal/ui/gui.go7
-rw-r--r--ethereal/ui/ui_lib.go10
6 files changed, 12 insertions, 252 deletions
diff --git a/ethereal/assets/ethereum.js b/ethereal/assets/ethereum.js
deleted file mode 100644
index 8f1a60300..000000000
--- a/ethereal/assets/ethereum.js
+++ /dev/null
@@ -1,236 +0,0 @@
-// Main Ethereum library
-window.eth = {
- prototype: Object(),
-
- // Retrieve block
- //
- // Either supply a number or a string. Type is determent for the lookup method
- // string - Retrieves the block by looking up the hash
- // number - Retrieves the block by looking up the block number
- getBlock: function(numberOrHash, cb) {
- var func;
- if(typeof numberOrHash == "string") {
- func = "getBlockByHash";
- } else {
- func = "getBlockByNumber";
- }
- postData({call: func, args: [numberOrHash]}, cb);
- },
-
- // Create transaction
- //
- // Transact between two state objects
- transact: function(sec, recipient, value, gas, gasPrice, data, cb) {
- postData({call: "transact", args: [sec, recipient, value, gas, gasPrice, data]}, cb);
- },
-
- create: function(sec, value, gas, gasPrice, init, body, cb) {
- postData({call: "create", args: [sec, value, gas, gasPrice, init, body]}, cb);
- },
-
- getStorageAt: function(address, storageAddress, cb) {
- postData({call: "getStorage", args: [address, storageAddress]}, cb);
- },
-
- getKey: function(cb) {
- postData({call: "getKey"}, cb);
- },
-
- getBalanceAt: function(address, cb) {
- postData({call: "getBalance", args: [address]}, cb);
- },
-
- getSecretToAddress: function(sec, cb) {
- postData({call: "getSecretToAddress", args: [sec]}, cb);
- },
-
- watch: function(address, storageAddrOrCb, cb) {
- var ev;
- if(cb === undefined) {
- cb = storageAddrOrCb;
- storageAddrOrCb = "";
- ev = "object:"+address;
- } else {
- ev = "storage:"+address+":"+storageAddrOrCb;
- }
-
- eth.on(ev, cb)
-
- postData({call: "watch", args: [address, storageAddrOrCb]});
- },
-
- disconnect: function(address, storageAddrOrCb, cb) {
- var ev;
- if(cb === undefined) {
- cb = storageAddrOrCb;
- storageAddrOrCb = "";
- ev = "object:"+address;
- } else {
- ev = "storage:"+address+":"+storageAddrOrCb;
- }
-
- eth.off(ev, cb)
-
- postData({call: "disconnect", args: [address, storageAddrOrCb]});
- },
-
- set: function(props) {
- postData({call: "set", args: props});
- },
-
- on: function(event, cb) {
- if(eth._onCallbacks[event] === undefined) {
- eth._onCallbacks[event] = [];
- }
-
- eth._onCallbacks[event].push(cb);
-
- return this
- },
-
- off: function(event, cb) {
- if(eth._onCallbacks[event] !== undefined) {
- var callbacks = eth._onCallbacks[event];
- for(var i = 0; i < callbacks.length; i++) {
- if(callbacks[i] === cb) {
- delete callbacks[i];
- }
- }
- }
-
- return this
- },
-
- trigger: function(event, data) {
- var callbacks = eth._onCallbacks[event];
- if(callbacks !== undefined) {
- for(var i = 0; i < callbacks.length; i++) {
- // Figure out whether the returned data was an array
- // array means multiple return arguments (multiple params)
- if(data instanceof Array) {
- callbacks[i].apply(this, data);
- } else {
- callbacks[i].call(this, data);
- }
- }
- }
- },
-}
-window.eth._callbacks = {}
-window.eth._onCallbacks = {}
-
-function hello() {
- debug("hello")
- window.dataTest = true;
-}
-
-function debug(/**/) {
- var args = arguments;
- var msg = ""
- for(var i = 0; i < args.length; i++){
- if(typeof args[i] === "object") {
- msg += " " + JSON.stringify(args[i])
- } else {
- msg += args[i]
- }
- }
-
- postData({call:"debug", args:[msg]})
- document.getElementById("debug").innerHTML += "<br>" + msg
-}
-
-// Helper function for generating pseudo callbacks and sending data to the QML part of the application
-function postData(data, cb) {
- data._seed = Math.floor(Math.random() * 1000000)
- if(cb) {
- eth._callbacks[data._seed] = cb;
- }
-
- if(data.args === undefined) {
- data.args = [];
- }
-
- navigator.qt.postMessage(JSON.stringify(data));
-}
-
-navigator.qt.onmessage = function(ev) {
- var data = JSON.parse(ev.data)
-
- if(data._event !== undefined) {
- eth.trigger(data._event, data.data);
- } else {
- if(data._seed) {
- var cb = eth._callbacks[data._seed];
- if(cb) {
- // Figure out whether the returned data was an array
- // array means multiple return arguments (multiple params)
- if(data.data instanceof Array) {
- cb.apply(this, data.data)
- } else {
- cb.call(this, data.data)
- }
-
- // Remove the "trigger" callback
- delete eth._callbacks[ev._seed];
- }
- }
- }
-}
-
-window.eth._0 = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
-String.prototype.pad = function(len) {
- var bin = this.bin();
- var l = bin.length;
- if(l < 32) {
- return eth._0.substr(0, 32 - bin.length) + bin;
- }
-
- return bin;
-}
-
-String.prototype.unpad = function() {
- var i, l;
- for(i = 0, l = this.length; i < l; i++) {
- if(this[i] != "\0") {
- return this.substr(i, this.length);
- }
- }
-
- return this.substr(i, this.length);
-}
-
-String.prototype.bin = function() {
- if(this.substr(0, 2) == "0x") {
- return this.hex2bin();
- } else if(/^\d+$/.test(this)) {
- return this.num2bin()
- }
-
- // Otherwise we'll return the "String" object instead of an actual string
- return this.substr(0, this.length)
-}
-
-String.prototype.unbin = function() {
- var i, l, o = '';
- for(i = 0, l = this.length; i < l; i++) {
- var n = this.charCodeAt(i).toString(16);
- o += n.length < 2 ? '0' + n : n;
- }
-
- return "0x" + o;
-}
-
-String.prototype.hex2bin = function() {
- bytes = []
-
- for(var i=2; i< this.length-1; i+=2) {
- bytes.push(parseInt(this.substr(i, 2), 16));
- }
-
- return String.fromCharCode.apply(String, bytes);
-}
-
-String.prototype.num2bin = function() {
- return ("0x"+parseInt(this).toString(16)).bin()
-}
-
diff --git a/ethereal/assets/qml/newTransaction/_new_contract.qml b/ethereal/assets/qml/newTransaction/_new_contract.qml
index f6ed77fb6..f8f3d53a0 100644
--- a/ethereal/assets/qml/newTransaction/_new_contract.qml
+++ b/ethereal/assets/qml/newTransaction/_new_contract.qml
@@ -158,7 +158,7 @@ Component {
mainContractColumn.state = "ERROR"
} else {
txResult.text = "Your transaction has been submitted:\n"
- txOutput.text = res[0]
+ txOutput.text = res[0].address
mainContractColumn.state = "DONE"
}
}
diff --git a/ethereal/assets/qml/webapp.qml b/ethereal/assets/qml/webapp.qml
index d02c9a82e..1f3c3874a 100644
--- a/ethereal/assets/qml/webapp.qml
+++ b/ethereal/assets/qml/webapp.qml
@@ -39,7 +39,7 @@ ApplicationWindow {
experimental.preferences.javascriptEnabled: true
experimental.preferences.navigatorQtObjectEnabled: true
experimental.preferences.developerExtrasEnabled: true
- experimental.userScripts: [ui.assetPath("ethereum.js")]
+ experimental.userScripts: [ui.assetPath("ext/pre.js"), ui.assetPath("ext/big.js"), ui.assetPath("ext/string.js"), ui.assetPath("ext/ethereum.js")]
experimental.onMessageReceived: {
console.log("[onMessageReceived]: ", message.data)
// TODO move to messaging.js
diff --git a/ethereal/assets/samplecoin/samplecoin.html b/ethereal/assets/samplecoin/samplecoin.html
index 50182c136..6330b9ea2 100644
--- a/ethereal/assets/samplecoin/samplecoin.html
+++ b/ethereal/assets/samplecoin/samplecoin.html
@@ -5,19 +5,20 @@
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="bootstrap-theme.min.css">
<link rel="stylesheet" href="samplecoin.css">
-<script src="promise.min.js"></script>
<meta name="viewport" content="minimum-scale=1; maximum-scale=1; initial-scale=1;">
<script type="text/javascript">
-var jefcoinAddr = "136060151ebf11cd82456de1ab9406cc2a762b36"
+var jefcoinAddr = "b7cb72c47ec4f31751d0d628b5a33fd6671bbba0"
var mAddr = ""
function createTransaction() {
var addr = document.querySelector("#addr").value;
var amount = document.querySelector("#amount").value;
- var data = (("0x"+addr).pad(32) + amount.pad(32)).unbin()
+ addr = ("0x"+addr).pad(32)
+ amount = amount.pad(32)
+ var data = (addr + amount).unbin();
eth.transact(mAddr, jefcoinAddr, 0, "10000000", "250", data, function(receipt) {
debug("received tx hash:", reciept.address)
})
diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go
index 39da5f246..25f6e2fed 100644
--- a/ethereal/ui/gui.go
+++ b/ethereal/ui/gui.go
@@ -9,6 +9,7 @@ import (
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil"
"github.com/go-qml/qml"
+ "github.com/obscuren/mutan"
"math/big"
"strings"
)
@@ -220,5 +221,9 @@ func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub.
}
func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) {
- return gui.Transact(recipient, value, gas, gasPrice, data)
+ keyPair := ethutil.Config.Db.GetKeys()[0]
+
+ mainInput, initInput := mutan.PreProcess(data)
+
+ return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, initInput, mainInput)
}
diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go
index 7fe610c6a..35ceb7d79 100644
--- a/ethereal/ui/ui_lib.go
+++ b/ethereal/ui/ui_lib.go
@@ -59,14 +59,6 @@ func (ui *UiLib) OpenHtml(path string) {
go app.run()
}
-func (ui *UiLib) Watch(addr, storageAddr string) {
- if len(storageAddr) == 0 {
- ui.eth.Reactor().Subscribe("storage:"+string(ethutil.FromHex(addr))+":"+string(ethutil.FromHex(storageAddr)), nil)
- } else {
- ui.eth.Reactor().Subscribe("object:"+string(ethutil.FromHex(addr)), nil)
- }
-}
-
func (ui *UiLib) Muted(content string) {
component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml"))
if err != nil {
@@ -78,8 +70,6 @@ func (ui *UiLib) Muted(content string) {
go func() {
path := "file://" + ui.AssetPath("muted/index.html")
win.Set("url", path)
- //debuggerPath := "file://" + ui.AssetPath("muted/debugger.html")
- //win.Set("debugUrl", debuggerPath)
win.Show()
win.Wait()