|
|
@ -27,7 +27,7 @@ var spec = [ |
|
|
|
{ "method": "storageAt", "params": { "a": "", "x": "" }, "order": ["a", "x"], "returns" : "" }, |
|
|
|
{ "method": "txCountAt", "params": { "a": "" },"order": ["a"], "returns" : "" }, |
|
|
|
{ "method": "isContractAt", "params": { "a": "" }, "order": ["a"], "returns" : false }, |
|
|
|
{ "method": "create", "params": { "sec": "", "xEndowment": "", "bCode": "", "xGas": "", "xGasPrice": "" }, "order": ["sec", "xEndowment", "bCode", "xGas", "xGasPrice"] , "returns": {} }, |
|
|
|
{ "method": "create", "params": { "sec": "", "xEndowment": "", "bCode": "", "xGas": "", "xGasPrice": "" }, "order": ["sec", "xEndowment", "bCode", "xGas", "xGasPrice"] , "returns": "" }, |
|
|
|
{ "method": "transact", "params": { "sec": "", "xValue": "", "aDest": "", "bData": "", "xGas": "", "xGasPrice": "" }, "order": ["sec", "xValue", "aDest", "bData", "xGas", "xGasPrice"], "returns": {} }, |
|
|
|
{ "method": "secretToAddress", "params": { "a": "" }, "order": ["a"], "returns" : "" }, |
|
|
|
{ "method": "lll", "params": { "s": "" }, "order": ["s"], "returns" : "" } |
|
|
@ -36,24 +36,25 @@ var spec = [ |
|
|
|
window.eth = (function ethScope() { |
|
|
|
var m_reqId = 0 |
|
|
|
var ret = {} |
|
|
|
function reformat(m, d) { return m == "lll" ? d.bin() : d; } |
|
|
|
function reqSync(m, p) { |
|
|
|
var req = { "jsonrpc": "2.0", "method": m, "params": p, "id": m_reqId } |
|
|
|
m_reqId++ |
|
|
|
var request = new XMLHttpRequest(); |
|
|
|
request.open("POST", "http://localhost:8080", false); |
|
|
|
request.open("POST", "http://localhost:8080", false) |
|
|
|
// console.log("Sending " + JSON.stringify(req))
|
|
|
|
request.send(JSON.stringify(req)); |
|
|
|
return JSON.parse(request.responseText).result; |
|
|
|
request.send(JSON.stringify(req)) |
|
|
|
return reformat(m, JSON.parse(request.responseText).result) |
|
|
|
} |
|
|
|
function reqAsync(m, p, f) { |
|
|
|
var req = { "jsonrpc": "2.0", "method": m, "params": p, "id": m_reqId } |
|
|
|
m_reqId++ |
|
|
|
var request = new XMLHttpRequest(); |
|
|
|
request.open("POST", "http://localhost:8080", true); |
|
|
|
request.send(JSON.stringify(req)); |
|
|
|
request.open("POST", "http://localhost:8080", true) |
|
|
|
request.send(JSON.stringify(req)) |
|
|
|
request.onreadystatechange = function() { |
|
|
|
if (request.readyState === 4) |
|
|
|
f(JSON.parse(request.responseText).result) |
|
|
|
f(reformat(m, JSON.parse(request.responseText).result)) |
|
|
|
}; |
|
|
|
} |
|
|
|
function isEmpty(obj) { |
|
|
@ -74,14 +75,19 @@ window.eth = (function ethScope() { |
|
|
|
p[s.order[j]] = (s.order[j][0] === "b") ? a[j].unbin() : a[j] |
|
|
|
return p |
|
|
|
}; |
|
|
|
ret[am] = function() { return reqAsync(m, getParams(arguments), arguments[s.order.length]) } |
|
|
|
if (s.params) |
|
|
|
ret[m] = function() { return reqSync(m, getParams(arguments)) } |
|
|
|
else |
|
|
|
Object.defineProperty(ret, m, { |
|
|
|
get: function() { return reqSync(m, {}); }, |
|
|
|
set: function(v) {} |
|
|
|
if (m == "create" || m == "transact") |
|
|
|
ret[m] = function() { return reqAsync(m, getParams(arguments), arguments[s.order.length]) } |
|
|
|
else |
|
|
|
{ |
|
|
|
ret[am] = function() { return reqAsync(m, getParams(arguments), arguments[s.order.length]) } |
|
|
|
if (s.params) |
|
|
|
ret[m] = function() { return reqSync(m, getParams(arguments)) } |
|
|
|
else |
|
|
|
Object.defineProperty(ret, m, { |
|
|
|
get: function() { return reqSync(m, {}); }, |
|
|
|
set: function(v) {} |
|
|
|
}) |
|
|
|
} |
|
|
|
})(spec[si]); |
|
|
|
|
|
|
|
ret.check = function(force) { |
|
|
|