block, transaction, uncle by hash and number separately

This commit is contained in:
Marek Kotewicz 2014-10-22 15:58:24 +02:00
parent 5cd93a0618
commit ea3048421f
3 changed files with 8 additions and 9 deletions

View File

@ -4,7 +4,6 @@
this.host = host;
};
//TODO unify the format of object passed to 'send method'
function formatJsonRpcObject(object) {
return {
jsonrpc: '2.0',
@ -14,7 +13,6 @@
}
};
//TODO unify the format of output messages, maybe there should be objects instead
function formatJsonRpcMessage(message) {
var object = JSON.parse(message);

View File

@ -5,7 +5,9 @@
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript" src="websocket.js"></script>
<script type="text/javascript" src="qt.js"></script>
<script type="text/javascript" src="http.js"></script>
<script type="text/javascript">
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8080'));
function registerName() {
var name = document.querySelector("#name").value;
name = web3.fromAscii(name);

13
main.js
View File

@ -49,11 +49,10 @@
eth: {
prototype: Object(),
//TODO solve the issue with numberOrHash impl
block: function(numberOrHash) {
return new Promise(function(resolve, reject) {
var args = typeof numberOrHash === "string" ? [0, numberOrHash] : [numberOrHash, ""];
web3.provider.send({call: "block", args: args}, function(block) {
var call = typeof numberOrHash === "string" ? 'blockByHash' : 'blockByNumber';
web3.provider.send({call: call, args: [numberOrHash]}, function(block) {
if(block)
resolve(block);
else
@ -64,8 +63,8 @@
transaction: function(numberOrHash, nth) {
return new Promise(function(resolve, reject) {
var args = typeof numberOrHash === "string" ? [0, numberOrHash, nth] : [numberOrHash, "", nth];
web3.provider.send({call: "transaction", args: args}, function(block) {
var call = typeof numberOrHash === "string" ? 'transactionByHash' : 'transactonByNumber';
web3.provider.send({call: call, args: [numberOrHash, nth]}, function(block) {
if(block)
resolve(block);
else
@ -76,8 +75,8 @@
uncle: function(numberOrHash, nth) {
return new Promise(function(resolve, reject) {
var args = typeof numberOrHash === "string" ? [0, numberOrHash, nth] : [numberOrHash, "", nth];
web3.provider.send({call: "uncle", args: args}, function(block) {
var call = typeof numberOrHash === "string" ? 'uncleByHash' : 'uncleByNumber';
web3.provider.send({call: call, args: [numberOrHash, nth]}, function(block) {
if(block)
resolve(block);
else