diff options
author | obscuren <geffobscura@gmail.com> | 2014-08-14 06:18:37 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-08-14 06:18:37 +0800 |
commit | 95ba340d07a02da40000d4bcf2b1bb24bd7856ef (patch) | |
tree | 79a067c70f5a1624c87b17c8efed02d160a0b0b8 /ethereal/assets/ext | |
parent | d518423b9c493bf5b42e6575db9a32106812e6bc (diff) | |
download | go-tangerine-95ba340d07a02da40000d4bcf2b1bb24bd7856ef.tar go-tangerine-95ba340d07a02da40000d4bcf2b1bb24bd7856ef.tar.gz go-tangerine-95ba340d07a02da40000d4bcf2b1bb24bd7856ef.tar.bz2 go-tangerine-95ba340d07a02da40000d4bcf2b1bb24bd7856ef.tar.lz go-tangerine-95ba340d07a02da40000d4bcf2b1bb24bd7856ef.tar.xz go-tangerine-95ba340d07a02da40000d4bcf2b1bb24bd7856ef.tar.zst go-tangerine-95ba340d07a02da40000d4bcf2b1bb24bd7856ef.zip |
Tweaks and fixes + added webview debugger
* Require better icons .. someone? :-)
Diffstat (limited to 'ethereal/assets/ext')
-rw-r--r-- | ethereal/assets/ext/ethereum.js | 95 | ||||
-rw-r--r-- | ethereal/assets/ext/messaging.js | 117 |
2 files changed, 81 insertions, 131 deletions
diff --git a/ethereal/assets/ext/ethereum.js b/ethereal/assets/ext/ethereum.js index de6fb0255..9970c6379 100644 --- a/ethereal/assets/ext/ethereum.js +++ b/ethereal/assets/ext/ethereum.js @@ -2,30 +2,97 @@ window.eth = { prototype: Object(), + mutan: function(code) { + }, + + toHex: function(str) { + var hex = ""; + for(var i = 0; i < str.length; i++) { + var n = str.charCodeAt(i).toString(16); + hex += n.length < 2 ? '0' + n : n; + } + + return hex; + }, + + toAscii: function(hex) { + // Find termination + var str = ""; + var i = 0, l = hex.length; + for(; i < l; i+=2) { + var code = hex.charCodeAt(i) + if(code == 0) { + break; + } + + str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); + } + + return str; + }, + + fromAscii: function(str, pad) { + if(pad === undefined) { + pad = 32 + } + + var hex = this.toHex(str); + + while(hex.length < pad*2) + hex += "00"; + + return hex + }, + + // 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); - }, + 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); - }, + transact: function(params, cb) { + if(params === undefined) { + params = {}; + } + + if(params.endowment !== undefined) + params.value = params.endowment; + if(params.code !== undefined) + params.data = params.code; + + // Make sure everything is string + var fields = ["to", "from", "value", "gas", "gasPrice"]; + for(var i = 0; i < fields.length; i++) { + if(params[fields[i]] === undefined) { + params[fields[i]] = ""; + } + params[fields[i]] = params[fields[i]].toString(); + } + + var data; + if(typeof params.data === "object") { + data = ""; + for(var i = 0; i < params.data.length; i++) { + data += params.data[i] + } + } else { + data = params.data; + } - create: function(sec, value, gas, gasPrice, init, body, cb) { - postData({call: "create", args: [sec, value, gas, gasPrice, init, body]}, cb); + postData({call: "transact", args: [params.from, params.to, params.value, params.gas, params.gasPrice, "0x"+data]}, cb); }, getStorageAt: function(address, storageAddress, cb) { diff --git a/ethereal/assets/ext/messaging.js b/ethereal/assets/ext/messaging.js deleted file mode 100644 index e7bc63020..000000000 --- a/ethereal/assets/ext/messaging.js +++ /dev/null @@ -1,117 +0,0 @@ -function handleMessage(message) { - console.log("[onMessageReceived]: ", message.data) - // TODO move to messaging.js - var data = JSON.parse(message.data) - - try { - switch(data.call) { - case "getCoinBase": - postData(data._seed, eth.getCoinBase()) - - break - case "getIsListening": - postData(data._seed, eth.getIsListening()) - - break - case "getIsMining": - postData(data._seed, eth.getIsMining()) - - break - case "getPeerCount": - postData(data._seed, eth.getPeerCount()) - - break - - case "getTxCountAt": - require(1) - postData(data._seed, eth.getTxCountAt(data.args[0])) - - break - case "getBlockByNumber": - var block = eth.getBlock(data.args[0]) - postData(data._seed, block) - - break - case "getBlockByHash": - var block = eth.getBlock(data.args[0]) - postData(data._seed, block) - - break - case "transact": - require(5) - - var tx = eth.transact(data.args[0], data.args[1], data.args[2],data.args[3],data.args[4],data.args[5]) - postData(data._seed, tx) - - break - case "create": - postData(data._seed, null) - - break - case "getStorage": - require(2); - - var stateObject = eth.getStateObject(data.args[0]) - var storage = stateObject.getStorage(data.args[1]) - postData(data._seed, storage) - - break - case "getStateKeyVals": - require(1); - var stateObject = eth.getStateObject(data.args[0]).stateKeyVal(true) - postData(data._seed,stateObject) - - break - case "getTransactionsFor": - require(1); - var txs = eth.getTransactionsFor(data.args[0], true) - postData(data._seed, txs) - - break - case "getBalance": - require(1); - - postData(data._seed, eth.getStateObject(data.args[0]).value()); - - break - case "getKey": - var key = eth.getKey().privateKey; - - postData(data._seed, key) - break - case "watch": - require(1) - eth.watch(data.args[0], data.args[1]); - break - case "disconnect": - require(1) - postData(data._seed, null) - break; - case "set": - console.log("'Set' has been depcrecated") - /* - for(var key in data.args) { - if(webview.hasOwnProperty(key)) { - window[key] = data.args[key]; - } - } - */ - break; - case "getSecretToAddress": - require(1) - postData(data._seed, eth.secretToAddress(data.args[0])) - break; - case "debug": - console.log(data.args[0]); - break; - } - } catch(e) { - console.log(data.call + ": " + e) - - postData(data._seed, null); - } -} - -function postData(seed, data) { - webview.experimental.postMessage(JSON.stringify({data: data, _seed: seed})) -} |