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
0d2cccc2
Commit
0d2cccc2
authored
Jan 21, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http sync api
parent
e1fcffcc
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
286 additions
and
102 deletions
+286
-102
ethereum.js
dist/ethereum.js
+144
-52
ethereum.js.map
dist/ethereum.js.map
+6
-4
ethereum.min.js
dist/ethereum.min.js
+1
-1
balance.html
example/balance.html
+1
-1
index.js
index.js
+2
-0
httpsync.js
lib/httpsync.js
+66
-0
providermanager.js
lib/providermanager.js
+5
-9
web3.js
lib/web3.js
+61
-35
No files found.
dist/ethereum.js
View file @
0d2cccc2
This diff is collapsed.
Click to expand it.
dist/ethereum.js.map
View file @
0d2cccc2
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
0d2cccc2
This diff is collapsed.
Click to expand it.
example/balance.html
View file @
0d2cccc2
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
var
web3
=
require
(
'web3'
);
var
web3
=
require
(
'web3'
);
web3
.
setProvider
(
new
web3
.
providers
.
AutoProvider
(
));
web3
.
setProvider
(
new
web3
.
providers
.
HttpSyncProvider
(
'http://localhost:8080'
));
function
watchBalance
()
{
function
watchBalance
()
{
var
coinbase
=
web3
.
eth
.
coinbase
;
var
coinbase
=
web3
.
eth
.
coinbase
;
...
...
index.js
View file @
0d2cccc2
...
@@ -5,8 +5,10 @@ web3.filter = require('./lib/filter');
...
@@ -5,8 +5,10 @@ web3.filter = require('./lib/filter');
web3
.
providers
.
WebSocketProvider
=
require
(
'./lib/websocket'
);
web3
.
providers
.
WebSocketProvider
=
require
(
'./lib/websocket'
);
web3
.
providers
.
HttpRpcProvider
=
require
(
'./lib/httprpc'
);
web3
.
providers
.
HttpRpcProvider
=
require
(
'./lib/httprpc'
);
web3
.
providers
.
QtProvider
=
require
(
'./lib/qt'
);
web3
.
providers
.
QtProvider
=
require
(
'./lib/qt'
);
web3
.
providers
.
HttpSyncProvider
=
require
(
'./lib/httpsync'
);
web3
.
providers
.
AutoProvider
=
require
(
'./lib/autoprovider'
);
web3
.
providers
.
AutoProvider
=
require
(
'./lib/autoprovider'
);
web3
.
eth
.
contract
=
require
(
'./lib/contract'
);
web3
.
eth
.
contract
=
require
(
'./lib/contract'
);
web3
.
abi
=
require
(
'./lib/abi'
);
web3
.
abi
=
require
(
'./lib/abi'
);
module
.
exports
=
web3
;
module
.
exports
=
web3
;
lib/httpsync.js
0 → 100644
View file @
0d2cccc2
/*
This file is part of ethereum.js.
ethereum.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ethereum.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file httpsync.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* @date 2014
*/
var
HttpSyncProvider
=
function
(
host
)
{
this
.
handlers
=
[];
this
.
host
=
host
;
};
/// Transforms inner message to proper jsonrpc object
/// @param inner message object
/// @returns jsonrpc object
function
formatJsonRpcObject
(
object
)
{
return
{
jsonrpc
:
'2.0'
,
method
:
object
.
call
,
params
:
object
.
args
,
id
:
object
.
_id
};
}
/// Transforms jsonrpc object to inner message
/// @param incoming jsonrpc message
/// @returns inner message object
function
formatJsonRpcMessage
(
message
)
{
var
object
=
JSON
.
parse
(
message
);
return
{
_id
:
object
.
id
,
data
:
object
.
result
,
error
:
object
.
error
};
}
HttpSyncProvider
.
prototype
.
send
=
function
(
payload
)
{
var
data
=
formatJsonRpcObject
(
payload
);
var
request
=
new
XMLHttpRequest
();
request
.
open
(
'POST'
,
this
.
host
,
false
);
request
.
send
(
JSON
.
stringify
(
data
));
// check request.status
return
request
.
responseText
;
};
module
.
exports
=
HttpSyncProvider
;
lib/providermanager.js
View file @
0d2cccc2
...
@@ -56,21 +56,17 @@ var ProviderManager = function() {
...
@@ -56,21 +56,17 @@ var ProviderManager = function() {
};
};
/// sends outgoing requests, if provider is not available, enqueue the request
/// sends outgoing requests, if provider is not available, enqueue the request
ProviderManager
.
prototype
.
send
=
function
(
data
,
cb
)
{
ProviderManager
.
prototype
.
send
=
function
(
data
)
{
data
.
_id
=
this
.
id
;
data
.
_id
=
this
.
id
;
if
(
cb
)
{
web3
.
_callbacks
[
data
.
_id
]
=
cb
;
}
data
.
args
=
data
.
args
||
[];
data
.
args
=
data
.
args
||
[];
this
.
id
++
;
this
.
id
++
;
if
(
this
.
provider
!==
undefined
)
{
if
(
this
.
provider
===
undefined
)
{
this
.
provider
.
send
(
data
);
console
.
error
(
"provider is not set"
);
}
else
{
console
.
warn
(
"provider is not set"
);
this
.
queued
.
push
(
data
);
}
}
return
this
.
provider
.
send
(
data
);
};
};
/// setups provider, which will be used for sending messages
/// setups provider, which will be used for sending messages
...
...
lib/web3.js
View file @
0d2cccc2
...
@@ -169,22 +169,32 @@ var shhWatchMethods = function () {
...
@@ -169,22 +169,32 @@ var shhWatchMethods = function () {
var
setupMethods
=
function
(
obj
,
methods
)
{
var
setupMethods
=
function
(
obj
,
methods
)
{
methods
.
forEach
(
function
(
method
)
{
methods
.
forEach
(
function
(
method
)
{
obj
[
method
.
name
]
=
function
()
{
obj
[
method
.
name
]
=
function
()
{
return
flattenPromise
(
Array
.
prototype
.
slice
.
call
(
arguments
)).
then
(
function
(
args
)
{
var
args
=
Array
.
prototype
.
slice
.
call
(
arguments
);
var
call
=
typeof
method
.
call
===
"function"
?
method
.
call
(
args
)
:
method
.
call
;
var
call
=
typeof
method
.
call
===
'function'
?
method
.
call
(
args
)
:
method
.
call
;
return
{
call
:
call
,
args
:
args
};
var
result
=
web3
.
provider
.
send
({
}).
then
(
function
(
request
)
{
call
:
call
,
return
new
Promise
(
function
(
resolve
,
reject
)
{
args
:
args
web3
.
provider
.
send
(
request
,
function
(
err
,
result
)
{
if
(
!
err
)
{
resolve
(
result
);
return
;
}
reject
(
err
);
});
});
}).
catch
(
function
(
err
)
{
console
.
error
(
err
);
});
});
result
=
JSON
.
parse
(
result
);
return
result
.
result
;
//return flattenPromise(Array.prototype.slice.call(arguments)).then(function (args) {
//var call = typeof method.call === "function" ? method.call(args) : method.call;
//return {call: call, args: args};
//}).then(function (request) {
//return new Promise(function (resolve, reject) {
//web3.provider.send(request, function (err, result) {
//if (!err) {
//resolve(result);
//return;
//}
//reject(err);
//});
//});
//}).catch(function(err) {
//console.error(err);
//});
};
};
});
});
};
};
...
@@ -195,31 +205,47 @@ var setupProperties = function (obj, properties) {
...
@@ -195,31 +205,47 @@ var setupProperties = function (obj, properties) {
properties
.
forEach
(
function
(
property
)
{
properties
.
forEach
(
function
(
property
)
{
var
proto
=
{};
var
proto
=
{};
proto
.
get
=
function
()
{
proto
.
get
=
function
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
result
=
web3
.
provider
.
send
({
web3
.
provider
.
send
({
call
:
property
.
getter
},
function
(
err
,
result
)
{
call
:
property
.
getter
if
(
!
err
)
{
resolve
(
result
);
return
;
}
reject
(
err
);
});
});
});
result
=
JSON
.
parse
(
result
);
return
result
.
result
;
//return new Promise(function(resolve, reject) {
//web3.provider.send({call: property.getter}, function(err, result) {
//if (!err) {
//resolve(result);
//return;
//}
//reject(err);
//});
//});
};
};
if
(
property
.
setter
)
{
if
(
property
.
setter
)
{
proto
.
set
=
function
(
val
)
{
proto
.
set
=
function
(
val
)
{
return
flattenPromise
([
val
]).
then
(
function
(
args
)
{
var
result
=
web3
.
provider
.
send
({
return
new
Promise
(
function
(
resolve
)
{
call
:
property
.
setter
,
web3
.
provider
.
send
({
call
:
property
.
setter
,
args
:
args
},
function
(
err
,
result
)
{
args
:
[
val
]
if
(
!
err
)
{
resolve
(
result
);
return
;
}
reject
(
err
);
});
});
}).
catch
(
function
(
err
)
{
console
.
error
(
err
);
});
});
result
=
JSON
.
parse
(
result
);
return
result
.
result
;
//return flattenPromise([val]).then(function (args) {
//return new Promise(function (resolve) {
//web3.provider.send({call: property.setter, args: args}, function (err, result) {
//if (!err) {
//resolve(result);
//return;
//}
//reject(err);
//});
//});
//}).catch(function (err) {
//console.error(err);
//});
};
};
}
}
Object
.
defineProperty
(
obj
,
property
.
name
,
proto
);
Object
.
defineProperty
(
obj
,
property
.
name
,
proto
);
...
...
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