diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-02 18:08:52 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-02 18:08:52 +0800 |
commit | ee04c6ff6790a9b39ea96a630a60bdcf7f261b97 (patch) | |
tree | 8d7fb67e6964727d93669507dc814078cf753239 | |
parent | 5a692b9f2bf265251b6f1faf171f55489b65b3de (diff) | |
download | go-tangerine-ee04c6ff6790a9b39ea96a630a60bdcf7f261b97.tar go-tangerine-ee04c6ff6790a9b39ea96a630a60bdcf7f261b97.tar.gz go-tangerine-ee04c6ff6790a9b39ea96a630a60bdcf7f261b97.tar.bz2 go-tangerine-ee04c6ff6790a9b39ea96a630a60bdcf7f261b97.tar.lz go-tangerine-ee04c6ff6790a9b39ea96a630a60bdcf7f261b97.tar.xz go-tangerine-ee04c6ff6790a9b39ea96a630a60bdcf7f261b97.tar.zst go-tangerine-ee04c6ff6790a9b39ea96a630a60bdcf7f261b97.zip |
Added string conversion API
* bin
* pad
* unpad
* conversion bin/hex/dec
-rw-r--r-- | ethereal/assets/ethereum.js | 59 | ||||
-rw-r--r-- | ethereal/assets/qml/webapp.qml | 2 | ||||
-rw-r--r-- | ethereal/assets/samplecoin/samplecoin.html | 2 |
3 files changed, 61 insertions, 2 deletions
diff --git a/ethereal/assets/ethereum.js b/ethereal/assets/ethereum.js index e5dae9248..1f36f691e 100644 --- a/ethereal/assets/ethereum.js +++ b/ethereal/assets/ethereum.js @@ -114,7 +114,7 @@ function debug(/**/) { var args = arguments; var msg = "" for(var i = 0; i < args.length; i++){ - if(typeof args[i] == "object") { + if(typeof args[i] === "object") { msg += " " + JSON.stringify(args[i]) } else { msg += args[i] @@ -155,3 +155,60 @@ navigator.qt.onmessage = function(ev) { } } } + +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/webapp.qml b/ethereal/assets/qml/webapp.qml index 1c1ac852d..11ccd6998 100644 --- a/ethereal/assets/qml/webapp.qml +++ b/ethereal/assets/qml/webapp.qml @@ -123,6 +123,8 @@ ApplicationWindow { function onObjectChangeCb(stateObject) { postEvent("object:"+stateObject.address(), stateObject) } + function onStorageChangeCb() { + } } Rectangle { diff --git a/ethereal/assets/samplecoin/samplecoin.html b/ethereal/assets/samplecoin/samplecoin.html index ba60cf951..0f61c613a 100644 --- a/ethereal/assets/samplecoin/samplecoin.html +++ b/ethereal/assets/samplecoin/samplecoin.html @@ -21,7 +21,7 @@ function createTransaction() { } function init() { - eth.set({width: 500, title: "Hello world"}) + eth.set({width: 500}) eth.getKey(function(key) { eth.getStorageAt(jefcoinAddr, key, function(storage) { |