diff options
author | Maran <maran.hidskes@gmail.com> | 2014-05-02 19:35:44 +0800 |
---|---|---|
committer | Maran <maran.hidskes@gmail.com> | 2014-05-02 19:35:44 +0800 |
commit | 60f9966cd8f991967882dd61e602822a95681d85 (patch) | |
tree | 037e8d0a7a9a546b10ddef65be17a0328b62d551 /ethereal/assets/ethereum.js | |
parent | 3424bf17ca791b97ea512bef5290d1a52c1758af (diff) | |
parent | f1da6f0564696f4fb5a6c04d1b9e24ed12432d63 (diff) | |
download | go-tangerine-60f9966cd8f991967882dd61e602822a95681d85.tar go-tangerine-60f9966cd8f991967882dd61e602822a95681d85.tar.gz go-tangerine-60f9966cd8f991967882dd61e602822a95681d85.tar.bz2 go-tangerine-60f9966cd8f991967882dd61e602822a95681d85.tar.lz go-tangerine-60f9966cd8f991967882dd61e602822a95681d85.tar.xz go-tangerine-60f9966cd8f991967882dd61e602822a95681d85.tar.zst go-tangerine-60f9966cd8f991967882dd61e602822a95681d85.zip |
Merge branch 'develop' into feature/rpc
Diffstat (limited to 'ethereal/assets/ethereum.js')
-rw-r--r-- | ethereal/assets/ethereum.js | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/ethereal/assets/ethereum.js b/ethereal/assets/ethereum.js index fd5091bd1..64a7ff47c 100644 --- a/ethereal/assets/ethereum.js +++ b/ethereal/assets/ethereum.js @@ -19,8 +19,7 @@ window.eth = { // Create transaction // - // Creates a transaction with the current account - // If no recipient is set, the Ethereum API will see it as a contract creation + // 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); }, @@ -71,6 +70,10 @@ window.eth = { 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] = []; @@ -110,7 +113,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] @@ -151,3 +154,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() +} |