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
8d1f96cc
Commit
8d1f96cc
authored
Jan 14, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
few comments
parent
422dc05b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
13 deletions
+27
-13
autoprovider.js
lib/autoprovider.js
+10
-0
web3.js
lib/web3.js
+17
-13
No files found.
lib/autoprovider.js
View file @
8d1f96cc
...
...
@@ -33,6 +33,13 @@ if (process.env.NODE_ENV !== 'build') {
var
web3
=
require
(
'./web3'
);
// jshint ignore:line
}
/// Automatically tries to setup correct provider
/// First it checkes if we are ethereum browser (if navigator.qt object is available)
/// if yes, we are using QtProvider
/// if no, we check if it is possible to establish websockets connection with ethereum (ws://localhost:40404/eth is default)
/// if it's not possible, we are using httprpc provider (http://localhost:8080)
/// The constructor allows you to specify uris on which we are trying to connect over http or websockets
/// You can do that by passing objects with fields httrpc and websockets
var
AutoProvider
=
function
(
userOptions
)
{
if
(
web3
.
haveProvider
())
{
return
;
...
...
@@ -81,6 +88,8 @@ var AutoProvider = function (userOptions) {
};
};
/// Sends message forward to the provider, that is being used
/// if provider is not yet set, enqueues the message
AutoProvider
.
prototype
.
send
=
function
(
payload
)
{
if
(
this
.
provider
)
{
this
.
provider
.
send
(
payload
);
...
...
@@ -89,6 +98,7 @@ AutoProvider.prototype.send = function (payload) {
this
.
sendQueue
.
push
(
payload
);
};
/// On incoming message sends the message to the provider that is currently being used
Object
.
defineProperty
(
AutoProvider
.
prototype
,
'onmessage'
,
{
set
:
function
(
handler
)
{
if
(
this
.
provider
)
{
...
...
lib/web3.js
View file @
8d1f96cc
...
...
@@ -254,6 +254,7 @@ var web3 = {
return
hex
;
},
/// @returns ascii string representation of hex value prefixed with 0x
toAscii
:
function
(
hex
)
{
// Find termination
var
str
=
""
;
...
...
@@ -272,6 +273,7 @@ var web3 = {
return
str
;
},
/// @returns hex representation (prefixed by 0x) of ascii string
fromAscii
:
function
(
str
,
pad
)
{
pad
=
pad
===
undefined
?
0
:
pad
;
var
hex
=
this
.
toHex
(
str
);
...
...
@@ -280,14 +282,17 @@ var web3 = {
return
"0x"
+
hex
;
},
/// @returns decimal representaton of hex value prefixed by 0x
toDecimal
:
function
(
val
)
{
return
hexToDec
(
val
.
substring
(
2
));
},
/// @returns hex representation (prefixed by 0x) of decimal value
fromDecimal
:
function
(
val
)
{
return
"0x"
+
decToHex
(
val
);
},
/// used to transform value/string to eth string
toEth
:
function
(
str
)
{
var
val
=
typeof
str
===
"string"
?
str
.
indexOf
(
'0x'
)
===
0
?
parseInt
(
str
.
substr
(
2
),
16
)
:
parseInt
(
str
)
:
str
;
var
unit
=
0
;
...
...
@@ -311,24 +316,24 @@ var web3 = {
return
s
+
' '
+
units
[
unit
];
},
/// eth object prototype
eth
:
{
prototype
:
Object
(),
// jshint ignore:line
watch
:
function
(
params
)
{
return
new
Filter
(
params
,
ethWatch
);
}
},
db
:
{
prototype
:
Object
()
// jshint ignore:line
},
/// db object prototype
db
:
{},
/// shh object prototype
shh
:
{
prototype
:
Object
(),
// jshint ignore:line
watch
:
function
(
params
)
{
return
new
Filter
(
params
,
shhWatch
);
}
},
/// used by filter to register callback with given id
on
:
function
(
event
,
id
,
cb
)
{
if
(
web3
.
_events
[
event
]
===
undefined
)
{
web3
.
_events
[
event
]
=
{};
...
...
@@ -338,6 +343,7 @@ var web3 = {
return
this
;
},
/// used by filter to unregister callback with given id
off
:
function
(
event
,
id
)
{
if
(
web3
.
_events
[
event
]
!==
undefined
)
{
delete
web3
.
_events
[
event
][
id
];
...
...
@@ -346,6 +352,7 @@ var web3 = {
return
this
;
},
/// used to trigger callback registered by filter
trigger
:
function
(
event
,
id
,
data
)
{
var
callbacks
=
web3
.
_events
[
event
];
if
(
!
callbacks
||
!
callbacks
[
id
])
{
...
...
@@ -353,6 +360,11 @@ var web3 = {
}
var
cb
=
callbacks
[
id
];
cb
(
data
);
},
/// @returns true if provider is installed
haveProvider
:
function
()
{
return
!!
web3
.
provider
.
provider
;
}
};
...
...
@@ -375,7 +387,6 @@ var shhWatch = {
setupMethods
(
shhWatch
,
shhWatchMethods
());
web3
.
provider
=
new
ProviderManager
();
web3
.
setProvider
=
function
(
provider
)
{
...
...
@@ -384,13 +395,6 @@ web3.setProvider = function(provider) {
web3
.
provider
.
sendQueued
();
};
/// returns true if provider is installed
web3
.
haveProvider
=
function
()
{
return
!!
web3
.
provider
.
provider
;
};
/// callled when there is new incoming message
function
messageHandler
(
data
)
{
if
(
data
.
_event
!==
undefined
)
{
...
...
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