|
|
|
@ -6,7 +6,7 @@ function postData(data, cb) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(data.args === undefined) { |
|
|
|
|
data.args = [] |
|
|
|
|
data.args = []; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
navigator.qt.postMessage(JSON.stringify(data)); |
|
|
|
@ -24,11 +24,11 @@ window.eth = { |
|
|
|
|
getBlock: function(numberOrHash, cb) { |
|
|
|
|
var func; |
|
|
|
|
if(typeof numberOrHash == "string") { |
|
|
|
|
func = "getBlockByHash" |
|
|
|
|
func = "getBlockByHash"; |
|
|
|
|
} else { |
|
|
|
|
func = "getBlockByNumber" |
|
|
|
|
func = "getBlockByNumber"; |
|
|
|
|
} |
|
|
|
|
postData({call: func, args: [numberOrHash]}, cb) |
|
|
|
|
postData({call: func, args: [numberOrHash]}, cb); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// Create transaction
|
|
|
|
@ -36,18 +36,51 @@ window.eth = { |
|
|
|
|
// Creates a transaction with the current account
|
|
|
|
|
// If no recipient is set, the Ethereum API will see it as a contract creation
|
|
|
|
|
createTx: function(recipient, value, gas, gasPrice, data, cb) { |
|
|
|
|
postData({call: "createTx", args: [recipient, value, gas, gasPrice, data]}, cb) |
|
|
|
|
postData({call: "createTx", args: [recipient, value, gas, gasPrice, data]}, cb); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getStorage: function(address, storageAddress, cb) { |
|
|
|
|
postData({call: "getStorage", args: [address, storageAddress]}, cb) |
|
|
|
|
postData({call: "getStorage", args: [address, storageAddress]}, cb); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getKey: function(cb) { |
|
|
|
|
postData({call: "getKey"}, cb) |
|
|
|
|
postData({call: "getKey"}, cb); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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++) { |
|
|
|
|
callbacks[i](data); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
window.eth._callbacks = {} |
|
|
|
|
window.eth._onCallbacks = {} |
|
|
|
|
|
|
|
|
|
function debug(/**/) { |
|
|
|
|
var args = arguments; |
|
|
|
@ -66,13 +99,17 @@ function debug(/**/) { |
|
|
|
|
navigator.qt.onmessage = function(ev) { |
|
|
|
|
var data = JSON.parse(ev.data) |
|
|
|
|
|
|
|
|
|
if(data._seed) { |
|
|
|
|
var cb = eth._callbacks[data._seed]; |
|
|
|
|
if(cb) { |
|
|
|
|
// Call the callback
|
|
|
|
|
cb(data.data); |
|
|
|
|
// Remove the "trigger" callback
|
|
|
|
|
delete eth._callbacks[ev._seed]; |
|
|
|
|
if(data._event !== undefined) { |
|
|
|
|
eth.trigger(data._event, data.data); |
|
|
|
|
} else { |
|
|
|
|
if(data._seed) { |
|
|
|
|
var cb = eth._callbacks[data._seed]; |
|
|
|
|
if(cb) { |
|
|
|
|
// Call the callback
|
|
|
|
|
cb(data.data); |
|
|
|
|
// Remove the "trigger" callback
|
|
|
|
|
delete eth._callbacks[ev._seed]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|