Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
5cd93a06
Commit
5cd93a06
authored
Oct 22, 2014
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http provider
parent
eef4cd1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
15 deletions
+70
-15
http.js
http.js
+52
-0
main.js
main.js
+18
-15
No files found.
http.js
0 → 100644
View file @
5cd93a06
(
function
()
{
var
HttpProvider
=
function
(
host
)
{
this
.
handlers
=
[];
this
.
host
=
host
;
};
//TODO unify the format of object passed to 'send method'
function
formatJsonRpcObject
(
object
)
{
return
{
jsonrpc
:
'2.0'
,
method
:
object
.
call
,
params
:
object
.
args
,
id
:
object
.
_id
}
};
//TODO unify the format of output messages, maybe there should be objects instead
function
formatJsonRpcMessage
(
message
)
{
var
object
=
JSON
.
parse
(
message
);
return
JSON
.
stringify
({
_id
:
object
.
id
,
data
:
object
.
result
});
};
HttpProvider
.
prototype
.
send
=
function
(
payload
)
{
var
data
=
formatJsonRpcObject
(
payload
);
var
request
=
new
XMLHttpRequest
();
request
.
open
(
"POST"
,
this
.
host
,
true
);
request
.
send
(
JSON
.
stringify
(
data
));
var
self
=
this
;
request
.
onreadystatechange
=
function
()
{
if
(
request
.
readyState
===
4
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
formatJsonRpcMessage
(
request
.
responseText
));
});
}
}
};
Object
.
defineProperty
(
HttpProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
}
});
if
(
typeof
(
web3
)
!==
"undefined"
&&
web3
.
providers
!==
undefined
)
{
web3
.
providers
.
HttpProvider
=
HttpProvider
;
}
})();
main.js
View file @
5cd93a06
...
@@ -49,37 +49,40 @@
...
@@ -49,37 +49,40 @@
eth
:
{
eth
:
{
prototype
:
Object
(),
prototype
:
Object
(),
//TODO solve the issue with numberOrHash impl
block
:
function
(
numberOrHash
)
{
block
:
function
(
numberOrHash
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
/*
var
args
=
typeof
numberOrHash
===
"string"
?
[
0
,
numberOrHash
]
:
[
numberOrHash
,
""
];
var func;
web3
.
provider
.
send
({
call
:
"block"
,
args
:
args
},
function
(
block
)
{
if(typeof numberOrHash == "string") {
func = "getBlockByHash";
} else {
func = "getBlockByNumber";
}
*/
web3
.
provider
.
send
({
call
:
/*func*/
"block"
,
args
:
[
numberOrHash
]},
function
(
block
)
{
if
(
block
)
if
(
block
)
resolve
(
block
);
resolve
(
block
);
else
else
reject
(
"not found"
);
reject
(
"not found"
);
});
});
});
});
},
},
transaction
:
function
(
numberOrHash
,
nth
)
{
transaction
:
function
(
numberOrHash
,
nth
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
reject
(
"`transaction` not yet implemented"
)
var
args
=
typeof
numberOrHash
===
"string"
?
[
0
,
numberOrHash
,
nth
]
:
[
numberOrHash
,
""
,
nth
];
web3
.
provider
.
send
({
call
:
"transaction"
,
args
:
args
},
function
(
block
)
{
if
(
block
)
resolve
(
block
);
else
reject
(
"not found"
);
});
});
});
},
},
uncle
:
function
(
numberOrHash
,
nth
)
{
uncle
:
function
(
numberOrHash
,
nth
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
reject
(
"`uncle` not yet implemented"
)
var
args
=
typeof
numberOrHash
===
"string"
?
[
0
,
numberOrHash
,
nth
]
:
[
numberOrHash
,
""
,
nth
];
web3
.
provider
.
send
({
call
:
"uncle"
,
args
:
args
},
function
(
block
)
{
if
(
block
)
resolve
(
block
);
else
reject
(
"not found"
);
});
});
});
},
},
...
@@ -128,7 +131,7 @@
...
@@ -128,7 +131,7 @@
return
Promise
.
all
(
promises
).
then
(
function
()
{
return
Promise
.
all
(
promises
).
then
(
function
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
params
.
data
=
params
.
data
.
join
(
""
);
params
.
data
=
params
.
data
.
join
(
""
);
web3
.
provider
.
send
({
call
:
"transact"
,
args
:
[
"0x"
+
params
]},
function
(
data
)
{
web3
.
provider
.
send
({
call
:
"transact"
,
args
:
[
params
]},
function
(
data
)
{
if
(
data
[
1
])
if
(
data
[
1
])
reject
(
data
[
0
]);
reject
(
data
[
0
]);
else
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment