diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-10 08:00:18 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-10 08:00:18 +0800 |
commit | f73a5f067a3f135fa87f887606939ff52afd9258 (patch) | |
tree | 976d23ec43adefe54b75c53eff1f64c3e636ba77 /ethereal/assets/ext/ethereum.js | |
parent | 1471585af082632b33eae5bf489d0ae0b277b369 (diff) | |
download | go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar.gz go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar.bz2 go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar.lz go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar.xz go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar.zst go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.zip |
fxed
Diffstat (limited to 'ethereal/assets/ext/ethereum.js')
-rw-r--r-- | ethereal/assets/ext/ethereum.js | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/ethereal/assets/ext/ethereum.js b/ethereal/assets/ext/ethereum.js new file mode 100644 index 000000000..f565e58bd --- /dev/null +++ b/ethereal/assets/ext/ethereum.js @@ -0,0 +1,121 @@ +// 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 = {} + |