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
15088d7e
Commit
15088d7e
authored
Nov 05, 2014
by
Marian Oancea
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed indent
Fixed indent so we can compare differences in PR.
parent
4be4db5e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
946 additions
and
962 deletions
+946
-962
ethereum.js
dist/ethereum.js
+475
-483
httprpc.js
lib/httprpc.js
+53
-53
main.js
lib/main.js
+364
-372
qt.js
lib/qt.js
+17
-17
websocket.js
lib/websocket.js
+37
-37
No files found.
dist/ethereum.js
View file @
15088d7e
...
@@ -63,69 +63,69 @@ if (XMLHttpRequest) xhr.prototype = XMLHttpRequest.prototype;
...
@@ -63,69 +63,69 @@ if (XMLHttpRequest) xhr.prototype = XMLHttpRequest.prototype;
var
XMLHttpRequest
=
require
(
'xmlhttprequest'
).
XMLHttpRequest
;
// jshint ignore:line
var
XMLHttpRequest
=
require
(
'xmlhttprequest'
).
XMLHttpRequest
;
// jshint ignore:line
var
HttpRpcProvider
=
function
(
host
)
{
var
HttpRpcProvider
=
function
(
host
)
{
this
.
handlers
=
[];
this
.
handlers
=
[];
this
.
host
=
host
;
this
.
host
=
host
;
};
function
formatJsonRpcObject
(
object
)
{
return
{
jsonrpc
:
'2.0'
,
method
:
object
.
call
,
params
:
object
.
args
,
id
:
object
.
_id
};
};
}
function
formatJsonRpcMessage
(
message
)
{
function
formatJsonRpcObject
(
object
)
{
var
object
=
JSON
.
parse
(
message
);
return
{
jsonrpc
:
'2.0'
,
method
:
object
.
call
,
params
:
object
.
args
,
id
:
object
.
_id
};
}
return
{
function
formatJsonRpcMessage
(
message
)
{
_id
:
object
.
id
,
var
object
=
JSON
.
parse
(
message
);
data
:
object
.
result
};
}
HttpRpcProvider
.
prototype
.
sendRequest
=
function
(
payload
,
cb
)
{
return
{
var
data
=
formatJsonRpcObject
(
payload
);
_id
:
object
.
id
,
data
:
object
.
result
};
}
var
request
=
new
XMLHttpRequest
();
HttpRpcProvider
.
prototype
.
sendRequest
=
function
(
payload
,
cb
)
{
request
.
open
(
"POST"
,
this
.
host
,
true
);
var
data
=
formatJsonRpcObject
(
payload
);
request
.
send
(
JSON
.
stringify
(
data
));
request
.
onreadystatechange
=
function
()
{
var
request
=
new
XMLHttpRequest
();
if
(
request
.
readyState
===
4
&&
cb
)
{
request
.
open
(
"POST"
,
this
.
host
,
true
);
cb
(
request
);
request
.
send
(
JSON
.
stringify
(
data
));
}
request
.
onreadystatechange
=
function
()
{
if
(
request
.
readyState
===
4
&&
cb
)
{
cb
(
request
);
}
};
};
};
};
HttpRpcProvider
.
prototype
.
send
=
function
(
payload
)
{
HttpRpcProvider
.
prototype
.
send
=
function
(
payload
)
{
var
self
=
this
;
var
self
=
this
;
this
.
sendRequest
(
payload
,
function
(
request
)
{
this
.
sendRequest
(
payload
,
function
(
request
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
formatJsonRpcMessage
(
request
.
responseText
));
handler
.
call
(
self
,
formatJsonRpcMessage
(
request
.
responseText
));
});
});
});
});
};
};
HttpRpcProvider
.
prototype
.
poll
=
function
(
payload
,
id
)
{
HttpRpcProvider
.
prototype
.
poll
=
function
(
payload
,
id
)
{
var
self
=
this
;
var
self
=
this
;
this
.
sendRequest
(
payload
,
function
(
request
)
{
this
.
sendRequest
(
payload
,
function
(
request
)
{
var
parsed
=
JSON
.
parse
(
request
.
responseText
);
var
parsed
=
JSON
.
parse
(
request
.
responseText
);
if
(
parsed
.
result
instanceof
Array
?
parsed
.
result
.
length
===
0
:
!
parsed
.
result
)
{
if
(
parsed
.
result
instanceof
Array
?
parsed
.
result
.
length
===
0
:
!
parsed
.
result
)
{
return
;
return
;
}
}
self
.
handlers
.
forEach
(
function
(
handler
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
{
_event
:
payload
.
call
,
_id
:
id
,
data
:
parsed
.
result
});
handler
.
call
(
self
,
{
_event
:
payload
.
call
,
_id
:
id
,
data
:
parsed
.
result
});
});
});
});
});
};
};
Object
.
defineProperty
(
HttpRpcProvider
.
prototype
,
"onmessage"
,
{
Object
.
defineProperty
(
HttpRpcProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
handler
)
{
set
:
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
this
.
handlers
.
push
(
handler
);
}
}
});
});
module
.
exports
=
HttpRpcProvider
;
module
.
exports
=
HttpRpcProvider
;
...
@@ -155,437 +155,429 @@ along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
...
@@ -155,437 +155,429 @@ along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/
*/
function
isPromise
(
o
)
{
function
isPromise
(
o
)
{
return
o
instanceof
Promise
;
return
o
instanceof
Promise
;
}
function
flattenPromise
(
obj
)
{
if
(
obj
instanceof
Promise
)
{
return
Promise
.
resolve
(
obj
);
}
}
if
(
obj
instanceof
Array
)
{
function
flattenPromise
(
obj
)
{
return
new
Promise
(
function
(
resolve
)
{
if
(
obj
instanceof
Promise
)
{
var
promises
=
obj
.
map
(
function
(
o
)
{
return
Promise
.
resolve
(
obj
);
return
flattenPromise
(
o
);
}
});
return
Promise
.
all
(
promises
).
then
(
function
(
res
)
{
if
(
obj
instanceof
Array
)
{
for
(
var
i
=
0
;
i
<
obj
.
length
;
i
++
)
{
return
new
Promise
(
function
(
resolve
)
{
obj
[
i
]
=
res
[
i
];
var
promises
=
obj
.
map
(
function
(
o
)
{
}
return
flattenPromise
(
o
);
resolve
(
obj
);
});
});
});
}
if
(
obj
instanceof
Object
)
{
return
Promise
.
all
(
promises
).
then
(
function
(
res
)
{
return
new
Promise
(
function
(
resolve
)
{
for
(
var
i
=
0
;
i
<
obj
.
length
;
i
++
)
{
var
keys
=
Object
.
keys
(
obj
);
obj
[
i
]
=
res
[
i
];
var
promises
=
keys
.
map
(
function
(
key
)
{
}
return
flattenPromise
(
obj
[
key
]);
resolve
(
obj
);
});
});
});
}
return
Promise
.
all
(
promises
).
then
(
function
(
res
)
{
if
(
obj
instanceof
Object
)
{
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
return
new
Promise
(
function
(
resolve
)
{
obj
[
keys
[
i
]]
=
res
[
i
];
var
keys
=
Object
.
keys
(
obj
);
}
var
promises
=
keys
.
map
(
function
(
key
)
{
resolve
(
obj
);
return
flattenPromise
(
obj
[
key
]);
});
return
Promise
.
all
(
promises
).
then
(
function
(
res
)
{
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
obj
[
keys
[
i
]]
=
res
[
i
];
}
resolve
(
obj
);
});
});
});
});
}
return
Promise
.
resolve
(
obj
);
}
}
return
Promise
.
resolve
(
obj
);
var
ethMethods
=
function
()
{
}
var
blockCall
=
function
(
args
)
{
return
typeof
args
[
0
]
===
"string"
?
"blockByHash"
:
"blockByNumber"
;
};
var
ethMethods
=
function
()
{
var
transactionCall
=
function
(
args
)
{
var
blockCall
=
function
(
args
)
{
return
typeof
args
[
0
]
===
"string"
?
'transactionByHash'
:
'transactionByNumber'
;
return
typeof
args
[
0
]
===
"string"
?
"blockByHash"
:
"blockByNumber"
;
};
var
transactionCall
=
function
(
args
)
{
return
typeof
args
[
0
]
===
"string"
?
'transactionByHash'
:
'transactionByNumber'
;
};
var
uncleCall
=
function
(
args
)
{
return
typeof
args
[
0
]
===
"string"
?
'uncleByHash'
:
'uncleByNumber'
;
};
var
methods
=
[
{
name
:
'balanceAt'
,
call
:
'balanceAt'
},
{
name
:
'stateAt'
,
call
:
'stateAt'
},
{
name
:
'countAt'
,
call
:
'countAt'
},
{
name
:
'codeAt'
,
call
:
'codeAt'
},
{
name
:
'transact'
,
call
:
'transact'
},
{
name
:
'call'
,
call
:
'call'
},
{
name
:
'block'
,
call
:
blockCall
},
{
name
:
'transaction'
,
call
:
transactionCall
},
{
name
:
'uncle'
,
call
:
uncleCall
},
{
name
:
'compile'
,
call
:
'compile'
}
];
return
methods
;
};
var
ethProperties
=
function
()
{
return
[
{
name
:
'coinbase'
,
getter
:
'coinbase'
,
setter
:
'setCoinbase'
},
{
name
:
'listening'
,
getter
:
'listening'
,
setter
:
'setListening'
},
{
name
:
'mining'
,
getter
:
'mining'
,
setter
:
'setMining'
},
{
name
:
'gasPrice'
,
getter
:
'gasPrice'
},
{
name
:
'account'
,
getter
:
'account'
},
{
name
:
'accounts'
,
getter
:
'accounts'
},
{
name
:
'peerCount'
,
getter
:
'peerCount'
},
{
name
:
'defaultBlock'
,
getter
:
'defaultBlock'
,
setter
:
'setDefaultBlock'
},
{
name
:
'number'
,
getter
:
'number'
}
];
};
var
dbMethods
=
function
()
{
return
[
{
name
:
'put'
,
call
:
'put'
},
{
name
:
'get'
,
call
:
'get'
},
{
name
:
'putString'
,
call
:
'putString'
},
{
name
:
'getString'
,
call
:
'getString'
}
];
};
var
shhMethods
=
function
()
{
return
[
{
name
:
'post'
,
call
:
'post'
},
{
name
:
'newIdentity'
,
call
:
'newIdentity'
},
{
name
:
'haveIdentity'
,
call
:
'haveIdentity'
},
{
name
:
'newGroup'
,
call
:
'newGroup'
},
{
name
:
'addToGroup'
,
call
:
'addToGroup'
}
];
};
var
ethWatchMethods
=
function
()
{
var
newFilter
=
function
(
args
)
{
return
typeof
args
[
0
]
===
'string'
?
'newFilterString'
:
'newFilter'
;
};
return
[
{
name
:
'newFilter'
,
call
:
newFilter
},
{
name
:
'uninstallFilter'
,
call
:
'uninstallFilter'
},
{
name
:
'getMessages'
,
call
:
'getMessages'
}
];
};
var
shhWatchMethods
=
function
()
{
return
[
{
name
:
'newFilter'
,
call
:
'shhNewFilter'
},
{
name
:
'uninstallFilter'
,
call
:
'shhUninstallFilter'
},
{
name
:
'getMessage'
,
call
:
'shhGetMessages'
}
];
};
var
setupMethods
=
function
(
obj
,
methods
)
{
methods
.
forEach
(
function
(
method
)
{
obj
[
method
.
name
]
=
function
()
{
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
(
result
)
{
if
(
result
||
typeof
result
===
"boolean"
)
{
resolve
(
result
);
return
;
}
reject
(
result
);
});
});
}).
catch
(
function
(
err
)
{
console
.
error
(
err
);
});
};
};
});
};
var
uncleCall
=
function
(
args
)
{
return
typeof
args
[
0
]
===
"string"
?
'uncleByHash'
:
'uncleByNumber'
;
var
setupProperties
=
function
(
obj
,
properties
)
{
};
properties
.
forEach
(
function
(
property
)
{
var
proto
=
{};
var
methods
=
[
proto
.
get
=
function
()
{
{
name
:
'balanceAt'
,
call
:
'balanceAt'
},
return
new
Promise
(
function
(
resolve
,
reject
)
{
{
name
:
'stateAt'
,
call
:
'stateAt'
},
web3
.
provider
.
send
({
call
:
property
.
getter
},
function
(
result
)
{
{
name
:
'countAt'
,
call
:
'countAt'
},
resolve
(
result
);
{
name
:
'codeAt'
,
call
:
'codeAt'
},
});
{
name
:
'transact'
,
call
:
'transact'
},
});
{
name
:
'call'
,
call
:
'call'
},
{
name
:
'block'
,
call
:
blockCall
},
{
name
:
'transaction'
,
call
:
transactionCall
},
{
name
:
'uncle'
,
call
:
uncleCall
},
{
name
:
'compile'
,
call
:
'compile'
}
];
return
methods
;
};
var
ethProperties
=
function
()
{
return
[
{
name
:
'coinbase'
,
getter
:
'coinbase'
,
setter
:
'setCoinbase'
},
{
name
:
'listening'
,
getter
:
'listening'
,
setter
:
'setListening'
},
{
name
:
'mining'
,
getter
:
'mining'
,
setter
:
'setMining'
},
{
name
:
'gasPrice'
,
getter
:
'gasPrice'
},
{
name
:
'account'
,
getter
:
'account'
},
{
name
:
'accounts'
,
getter
:
'accounts'
},
{
name
:
'peerCount'
,
getter
:
'peerCount'
},
{
name
:
'defaultBlock'
,
getter
:
'defaultBlock'
,
setter
:
'setDefaultBlock'
},
{
name
:
'number'
,
getter
:
'number'
}
];
};
var
dbMethods
=
function
()
{
return
[
{
name
:
'put'
,
call
:
'put'
},
{
name
:
'get'
,
call
:
'get'
},
{
name
:
'putString'
,
call
:
'putString'
},
{
name
:
'getString'
,
call
:
'getString'
}
];
};
var
shhMethods
=
function
()
{
return
[
{
name
:
'post'
,
call
:
'post'
},
{
name
:
'newIdentity'
,
call
:
'newIdentity'
},
{
name
:
'haveIdentity'
,
call
:
'haveIdentity'
},
{
name
:
'newGroup'
,
call
:
'newGroup'
},
{
name
:
'addToGroup'
,
call
:
'addToGroup'
}
];
};
var
ethWatchMethods
=
function
()
{
var
newFilter
=
function
(
args
)
{
return
typeof
args
[
0
]
===
'string'
?
'newFilterString'
:
'newFilter'
;
};
};
if
(
property
.
setter
)
{
proto
.
set
=
function
(
val
)
{
return
[
return
flattenPromise
([
val
]).
then
(
function
(
args
)
{
{
name
:
'newFilter'
,
call
:
newFilter
},
return
new
Promise
(
function
(
resolve
)
{
{
name
:
'uninstallFilter'
,
call
:
'uninstallFilter'
},
web3
.
provider
.
send
({
call
:
property
.
setter
,
args
:
args
},
function
(
result
)
{
{
name
:
'getMessages'
,
call
:
'getMessages'
}
if
(
result
)
{
];
};
var
shhWatchMethods
=
function
()
{
return
[
{
name
:
'newFilter'
,
call
:
'shhNewFilter'
},
{
name
:
'uninstallFilter'
,
call
:
'shhUninstallFilter'
},
{
name
:
'getMessage'
,
call
:
'shhGetMessages'
}
];
};
var
setupMethods
=
function
(
obj
,
methods
)
{
methods
.
forEach
(
function
(
method
)
{
obj
[
method
.
name
]
=
function
()
{
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
(
result
)
{
if
(
result
||
typeof
result
===
"boolean"
)
{
resolve
(
result
);
resolve
(
result
);
}
else
{
return
;
reject
(
result
);
}
}
reject
(
result
);
});
});
});
});
}).
catch
(
function
(
err
)
{
}).
catch
(
function
(
err
)
{
console
.
error
(
err
);
console
.
error
(
err
);
});
});
};
};
}
});
Object
.
defineProperty
(
obj
,
property
.
name
,
proto
);
};
});
};
var
setupProperties
=
function
(
obj
,
properties
)
{
properties
.
forEach
(
function
(
property
)
{
var
web3
=
{
var
proto
=
{};
_callbacks
:
{},
proto
.
get
=
function
()
{
_events
:
{},
return
new
Promise
(
function
(
resolve
,
reject
)
{
providers
:
{},
web3
.
provider
.
send
({
call
:
property
.
getter
},
function
(
result
)
{
toHex
:
function
(
str
)
{
resolve
(
result
);
var
hex
=
""
;
});
for
(
var
i
=
0
;
i
<
str
.
length
;
i
++
)
{
});
var
n
=
str
.
charCodeAt
(
i
).
toString
(
16
);
};
hex
+=
n
.
length
<
2
?
'0'
+
n
:
n
;
if
(
property
.
setter
)
{
}
proto
.
set
=
function
(
val
)
{
return
flattenPromise
([
val
]).
then
(
function
(
args
)
{
return
new
Promise
(
function
(
resolve
)
{
web3
.
provider
.
send
({
call
:
property
.
setter
,
args
:
args
},
function
(
result
)
{
if
(
result
)
{
resolve
(
result
);
}
else
{
reject
(
result
);
}
});
});
}).
catch
(
function
(
err
)
{
console
.
error
(
err
);
});
};
}
Object
.
defineProperty
(
obj
,
property
.
name
,
proto
);
});
};
var
web3
=
{
_callbacks
:
{},
_events
:
{},
providers
:
{},
toHex
:
function
(
str
)
{
var
hex
=
""
;
for
(
var
i
=
0
;
i
<
str
.
length
;
i
++
)
{
var
n
=
str
.
charCodeAt
(
i
).
toString
(
16
);
hex
+=
n
.
length
<
2
?
'0'
+
n
:
n
;
}
return
hex
;
},
toAscii
:
function
(
hex
)
{
// Find termination
var
str
=
""
;
var
i
=
0
,
l
=
hex
.
length
;
for
(;
i
<
l
;
i
+=
2
)
{
var
code
=
hex
.
charCodeAt
(
i
);
if
(
code
===
0
)
{
break
;
}
str
+=
String
.
fromCharCode
(
parseInt
(
hex
.
substr
(
i
,
2
),
16
));
}
return
hex
;
return
str
;
},
},
toAscii
:
function
(
hex
)
{
toDecimal
:
function
(
val
)
{
// Find termination
return
parseInt
(
val
,
16
);
var
str
=
""
;
},
var
i
=
0
,
l
=
hex
.
length
;
for
(;
i
<
l
;
i
+=
2
)
{
fromAscii
:
function
(
str
,
pad
)
{
var
code
=
hex
.
charCodeAt
(
i
);
pad
=
pad
===
undefined
?
32
:
pad
;
if
(
code
===
0
)
{
var
hex
=
this
.
toHex
(
str
);
break
;
while
(
hex
.
length
<
pad
*
2
)
hex
+=
"00"
;
return
hex
;
},
eth
:
{
prototype
:
Object
(),
// jshint ignore:line
watch
:
function
(
params
)
{
return
new
Filter
(
params
,
ethWatch
);
}
}
},
str
+=
String
.
fromCharCode
(
parseInt
(
hex
.
substr
(
i
,
2
),
16
));
db
:
{
prototype
:
Object
()
// jshint ignore:line
},
shh
:
{
prototype
:
Object
(),
// jshint ignore:line
watch
:
function
(
params
)
{
return
new
Filter
(
params
,
shhWatch
);
}
},
on
:
function
(
event
,
id
,
cb
)
{
if
(
web3
.
_events
[
event
]
===
undefined
)
{
web3
.
_events
[
event
]
=
{};
}
web3
.
_events
[
event
][
id
]
=
cb
;
return
this
;
},
off
:
function
(
event
,
id
)
{
if
(
web3
.
_events
[
event
]
!==
undefined
)
{
delete
web3
.
_events
[
event
][
id
];
}
return
this
;
},
trigger
:
function
(
event
,
id
,
data
)
{
var
callbacks
=
web3
.
_events
[
event
];
if
(
!
callbacks
||
!
callbacks
[
id
])
{
return
;
}
var
cb
=
callbacks
[
id
];
cb
(
data
);
}
}
};
return
str
;
var
eth
=
web3
.
eth
;
},
setupMethods
(
eth
,
ethMethods
());
setupProperties
(
eth
,
ethProperties
());
toDecimal
:
function
(
val
)
{
setupMethods
(
web3
.
db
,
dbMethods
());
return
parseInt
(
val
,
16
);
setupMethods
(
web3
.
shh
,
shhMethods
());
},
var
ethWatch
=
{
fromAscii
:
function
(
str
,
pad
)
{
changed
:
'changed'
pad
=
pad
===
undefined
?
32
:
pad
;
};
var
hex
=
this
.
toHex
(
str
);
setupMethods
(
ethWatch
,
ethWatchMethods
());
while
(
hex
.
length
<
pad
*
2
)
var
shhWatch
=
{
hex
+=
"00"
;
changed
:
'shhChanged'
return
hex
;
};
},
setupMethods
(
shhWatch
,
shhWatchMethods
());
eth
:
{
var
ProviderManager
=
function
()
{
prototype
:
Object
(),
// jshint ignore:line
this
.
queued
=
[];
watch
:
function
(
params
)
{
this
.
polls
=
[];
return
new
Filter
(
params
,
ethWatch
);
this
.
ready
=
false
;
this
.
provider
=
undefined
;
this
.
id
=
1
;
var
self
=
this
;
var
poll
=
function
()
{
if
(
self
.
provider
&&
self
.
provider
.
poll
)
{
self
.
polls
.
forEach
(
function
(
data
)
{
data
.
data
.
_id
=
self
.
id
;
self
.
id
++
;
self
.
provider
.
poll
(
data
.
data
,
data
.
id
);
});
}
setTimeout
(
poll
,
12000
);
};
poll
();
};
ProviderManager
.
prototype
.
send
=
function
(
data
,
cb
)
{
data
.
_id
=
this
.
id
;
if
(
cb
)
{
web3
.
_callbacks
[
data
.
_id
]
=
cb
;
}
}
},
db
:
{
data
.
args
=
data
.
args
||
[];
prototype
:
Object
()
// jshint ignore:line
this
.
id
++
;
},
shh
:
{
if
(
this
.
provider
!==
undefined
)
{
prototype
:
Object
(),
// jshint ignore:line
this
.
provider
.
send
(
data
);
watch
:
function
(
params
)
{
}
else
{
return
new
Filter
(
params
,
shhWatch
);
console
.
warn
(
"provider is not set"
);
this
.
queued
.
push
(
data
);
}
}
}
,
}
;
on
:
function
(
event
,
id
,
cb
)
{
ProviderManager
.
prototype
.
set
=
function
(
provider
)
{
if
(
web3
.
_events
[
event
]
=
==
undefined
)
{
if
(
this
.
provider
!==
undefined
&&
this
.
provider
.
unload
!
==
undefined
)
{
web3
.
_events
[
event
]
=
{}
;
this
.
provider
.
unload
()
;
}
}
web3
.
_events
[
event
][
id
]
=
cb
;
this
.
provider
=
provider
;
return
this
;
this
.
ready
=
true
;
}
,
}
;
off
:
function
(
event
,
id
)
{
ProviderManager
.
prototype
.
sendQueued
=
function
()
{
if
(
web3
.
_events
[
event
]
!==
undefined
)
{
for
(
var
i
=
0
;
this
.
queued
.
length
;
i
++
)
{
delete
web3
.
_events
[
event
][
id
];
// Resend
this
.
send
(
this
.
queued
[
i
]);
}
}
};
return
this
;
ProviderManager
.
prototype
.
installed
=
function
()
{
},
return
this
.
provider
!==
undefined
;
};
trigger
:
function
(
event
,
id
,
data
)
{
ProviderManager
.
prototype
.
startPolling
=
function
(
data
,
pollId
)
{
var
callbacks
=
web3
.
_events
[
event
];
if
(
!
this
.
provider
||
!
this
.
provider
.
poll
)
{
if
(
!
callbacks
||
!
callbacks
[
id
])
{
return
;
return
;
}
}
var
cb
=
callbacks
[
id
];
this
.
polls
.
push
({
data
:
data
,
id
:
pollId
});
cb
(
data
);
}
};
var
eth
=
web3
.
eth
;
setupMethods
(
eth
,
ethMethods
());
setupProperties
(
eth
,
ethProperties
());
setupMethods
(
web3
.
db
,
dbMethods
());
setupMethods
(
web3
.
shh
,
shhMethods
());
var
ethWatch
=
{
changed
:
'changed'
};
setupMethods
(
ethWatch
,
ethWatchMethods
());
var
shhWatch
=
{
changed
:
'shhChanged'
};
setupMethods
(
shhWatch
,
shhWatchMethods
());
var
ProviderManager
=
function
()
{
this
.
queued
=
[];
this
.
polls
=
[];
this
.
ready
=
false
;
this
.
provider
=
undefined
;
this
.
id
=
1
;
var
self
=
this
;
var
poll
=
function
()
{
if
(
self
.
provider
&&
self
.
provider
.
poll
)
{
self
.
polls
.
forEach
(
function
(
data
)
{
data
.
data
.
_id
=
self
.
id
;
self
.
id
++
;
self
.
provider
.
poll
(
data
.
data
,
data
.
id
);
});
}
setTimeout
(
poll
,
12000
);
};
};
poll
();
};
ProviderManager
.
prototype
.
send
=
function
(
data
,
cb
)
{
ProviderManager
.
prototype
.
stopPolling
=
function
(
pollId
)
{
data
.
_id
=
this
.
id
;
for
(
var
i
=
this
.
polls
.
length
;
i
--
;)
{
if
(
cb
)
{
var
poll
=
this
.
polls
[
i
];
web3
.
_callbacks
[
data
.
_id
]
=
cb
;
if
(
poll
.
id
===
pollId
)
{
}
this
.
polls
.
splice
(
i
,
1
);
}
}
};
data
.
args
=
data
.
args
||
[];
web3
.
provider
=
new
ProviderManager
();
this
.
id
++
;
if
(
this
.
provider
!==
undefined
)
{
web3
.
setProvider
=
function
(
provider
)
{
this
.
provider
.
send
(
data
);
provider
.
onmessage
=
messageHandler
;
}
else
{
web3
.
provider
.
set
(
provider
);
console
.
warn
(
"provider is not set"
);
web3
.
provider
.
sendQueued
();
this
.
queued
.
push
(
data
);
};
}
};
ProviderManager
.
prototype
.
set
=
function
(
provider
)
{
var
Filter
=
function
(
options
,
impl
)
{
if
(
this
.
provider
!==
undefined
&&
this
.
provider
.
unload
!==
undefined
)
{
this
.
impl
=
impl
;
this
.
provider
.
unload
();
this
.
callbacks
=
[];
}
this
.
provider
=
provider
;
var
self
=
this
;
this
.
ready
=
true
;
this
.
promise
=
impl
.
newFilter
(
options
);
};
this
.
promise
.
then
(
function
(
id
)
{
self
.
id
=
id
;
web3
.
on
(
impl
.
changed
,
id
,
self
.
trigger
.
bind
(
self
));
web3
.
provider
.
startPolling
({
call
:
impl
.
changed
,
args
:
[
id
]},
id
);
});
};
ProviderManager
.
prototype
.
sendQueued
=
function
()
{
Filter
.
prototype
.
arrived
=
function
(
callback
)
{
for
(
var
i
=
0
;
this
.
queued
.
length
;
i
++
)
{
this
.
changed
(
callback
);
// Resend
};
this
.
send
(
this
.
queued
[
i
]);
}
};
ProviderManager
.
prototype
.
installed
=
function
()
{
Filter
.
prototype
.
changed
=
function
(
callback
)
{
return
this
.
provider
!==
undefined
;
var
self
=
this
;
};
this
.
promise
.
then
(
function
(
id
)
{
self
.
callbacks
.
push
(
callback
);
});
};
ProviderManager
.
prototype
.
startPolling
=
function
(
data
,
pollId
)
{
Filter
.
prototype
.
trigger
=
function
(
messages
)
{
if
(
!
this
.
provider
||
!
this
.
provider
.
poll
)
{
for
(
var
i
=
0
;
i
<
this
.
callbacks
.
length
;
i
++
)
{
return
;
this
.
callbacks
[
i
].
call
(
this
,
messages
);
}
this
.
polls
.
push
({
data
:
data
,
id
:
pollId
});
};
ProviderManager
.
prototype
.
stopPolling
=
function
(
pollId
)
{
for
(
var
i
=
this
.
polls
.
length
;
i
--
;)
{
var
poll
=
this
.
polls
[
i
];
if
(
poll
.
id
===
pollId
)
{
this
.
polls
.
splice
(
i
,
1
);
}
}
}
};
};
web3
.
provider
=
new
ProviderManager
();
web3
.
setProvider
=
function
(
provider
)
{
provider
.
onmessage
=
messageHandler
;
web3
.
provider
.
set
(
provider
);
web3
.
provider
.
sendQueued
();
};
var
Filter
=
function
(
options
,
impl
)
{
this
.
impl
=
impl
;
this
.
callbacks
=
[];
var
self
=
this
;
this
.
promise
=
impl
.
newFilter
(
options
);
this
.
promise
.
then
(
function
(
id
)
{
self
.
id
=
id
;
web3
.
on
(
impl
.
changed
,
id
,
self
.
trigger
.
bind
(
self
));
web3
.
provider
.
startPolling
({
call
:
impl
.
changed
,
args
:
[
id
]},
id
);
});
};
Filter
.
prototype
.
arrived
=
function
(
callback
)
{
this
.
changed
(
callback
);
};
Filter
.
prototype
.
changed
=
function
(
callback
)
{
var
self
=
this
;
this
.
promise
.
then
(
function
(
id
)
{
self
.
callbacks
.
push
(
callback
);
});
};
Filter
.
prototype
.
trigger
=
function
(
messages
)
{
Filter
.
prototype
.
uninstall
=
function
()
{
for
(
var
i
=
0
;
i
<
this
.
callbacks
.
length
;
i
++
)
{
var
self
=
this
;
this
.
callbacks
[
i
].
call
(
this
,
messages
);
this
.
promise
.
then
(
function
(
id
)
{
}
self
.
impl
.
uninstallFilter
(
id
);
};
web3
.
provider
.
stopPolling
(
id
);
web3
.
off
(
impl
.
changed
,
id
);
Filter
.
prototype
.
uninstall
=
function
()
{
});
var
self
=
this
;
};
this
.
promise
.
then
(
function
(
id
)
{
self
.
impl
.
uninstallFilter
(
id
);
web3
.
provider
.
stopPolling
(
id
);
web3
.
off
(
impl
.
changed
,
id
);
});
};
Filter
.
prototype
.
messages
=
function
()
{
Filter
.
prototype
.
messages
=
function
()
{
var
self
=
this
;
var
self
=
this
;
return
this
.
promise
.
then
(
function
(
id
)
{
return
this
.
promise
.
then
(
function
(
id
)
{
return
self
.
impl
.
getMessages
(
id
);
return
self
.
impl
.
getMessages
(
id
);
});
});
};
};
function
messageHandler
(
data
)
{
function
messageHandler
(
data
)
{
if
(
data
.
_event
!==
undefined
)
{
if
(
data
.
_event
!==
undefined
)
{
web3
.
trigger
(
data
.
_event
,
data
.
_id
,
data
.
data
);
web3
.
trigger
(
data
.
_event
,
data
.
_id
,
data
.
data
);
return
;
return
;
}
}
if
(
data
.
_id
)
{
if
(
data
.
_id
)
{
var
cb
=
web3
.
_callbacks
[
data
.
_id
];
var
cb
=
web3
.
_callbacks
[
data
.
_id
];
if
(
cb
)
{
if
(
cb
)
{
cb
.
call
(
this
,
data
.
data
);
cb
.
call
(
this
,
data
.
data
);
delete
web3
.
_callbacks
[
data
.
_id
];
delete
web3
.
_callbacks
[
data
.
_id
];
}
}
}
}
}
}
/*
// Install default provider
if(!web3.provider.installed()) {
var sock = new web3.providers.WebSocketProvider("ws://localhost:40404/eth");
web3.setProvider(sock);
}
*/
module
.
exports
=
web3
;
module
.
exports
=
web3
;
...
@@ -612,26 +604,26 @@ module.exports = web3;
...
@@ -612,26 +604,26 @@ module.exports = web3;
* @date 2014
* @date 2014
*/
*/
var
QtProvider
=
function
()
{
var
QtProvider
=
function
()
{
this
.
handlers
=
[];
this
.
handlers
=
[];
var
self
=
this
;
var
self
=
this
;
navigator
.
qt
.
onmessage
=
function
(
message
)
{
navigator
.
qt
.
onmessage
=
function
(
message
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
JSON
.
parse
(
message
.
data
));
handler
.
call
(
self
,
JSON
.
parse
(
message
.
data
));
});
});
};
};
};
};
QtProvider
.
prototype
.
send
=
function
(
payload
)
{
QtProvider
.
prototype
.
send
=
function
(
payload
)
{
navigator
.
qt
.
postMessage
(
JSON
.
stringify
(
payload
));
navigator
.
qt
.
postMessage
(
JSON
.
stringify
(
payload
));
};
};
Object
.
defineProperty
(
QtProvider
.
prototype
,
"onmessage"
,
{
Object
.
defineProperty
(
QtProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
handler
)
{
set
:
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
this
.
handlers
.
push
(
handler
);
}
}
});
});
module
.
exports
=
QtProvider
;
module
.
exports
=
QtProvider
;
...
@@ -662,51 +654,51 @@ module.exports = QtProvider;
...
@@ -662,51 +654,51 @@ module.exports = QtProvider;
var
WebSocket
=
require
(
'ws'
);
// jshint ignore:line
var
WebSocket
=
require
(
'ws'
);
// jshint ignore:line
var
WebSocketProvider
=
function
(
host
)
{
var
WebSocketProvider
=
function
(
host
)
{
// onmessage handlers
// onmessage handlers
this
.
handlers
=
[];
this
.
handlers
=
[];
// queue will be filled with messages if send is invoked before the ws is ready
// queue will be filled with messages if send is invoked before the ws is ready
this
.
queued
=
[];
this
.
queued
=
[];
this
.
ready
=
false
;
this
.
ready
=
false
;
this
.
ws
=
new
WebSocket
(
host
);
this
.
ws
=
new
WebSocket
(
host
);
var
self
=
this
;
var
self
=
this
;
this
.
ws
.
onmessage
=
function
(
event
)
{
this
.
ws
.
onmessage
=
function
(
event
)
{
for
(
var
i
=
0
;
i
<
self
.
handlers
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
self
.
handlers
.
length
;
i
++
)
{
self
.
handlers
[
i
].
call
(
self
,
JSON
.
parse
(
event
.
data
),
event
);
self
.
handlers
[
i
].
call
(
self
,
JSON
.
parse
(
event
.
data
),
event
);
}
}
};
};
this
.
ws
.
onopen
=
function
()
{
this
.
ws
.
onopen
=
function
()
{
self
.
ready
=
true
;
self
.
ready
=
true
;
for
(
var
i
=
0
;
i
<
self
.
queued
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
self
.
queued
.
length
;
i
++
)
{
// Resend
// Resend
self
.
send
(
self
.
queued
[
i
]);
self
.
send
(
self
.
queued
[
i
]);
}
};
};
WebSocketProvider
.
prototype
.
send
=
function
(
payload
)
{
if
(
this
.
ready
)
{
var
data
=
JSON
.
stringify
(
payload
);
this
.
ws
.
send
(
data
);
}
else
{
this
.
queued
.
push
(
payload
);
}
}
};
};
};
WebSocketProvider
.
prototype
.
send
=
function
(
payload
)
{
if
(
this
.
ready
)
{
var
data
=
JSON
.
stringify
(
payload
);
this
.
ws
.
send
(
data
);
WebSocketProvider
.
prototype
.
onMessage
=
function
(
handler
)
{
}
else
{
this
.
handlers
.
push
(
handler
);
this
.
queued
.
push
(
payload
);
};
}
};
WebSocketProvider
.
prototype
.
unload
=
function
()
{
this
.
ws
.
close
();
WebSocketProvider
.
prototype
.
onMessage
=
function
(
handler
)
{
};
this
.
handlers
.
push
(
handler
);
Object
.
defineProperty
(
WebSocketProvider
.
prototype
,
"onmessage"
,
{
};
set
:
function
(
provider
)
{
this
.
onMessage
(
provider
);
}
});
WebSocketProvider
.
prototype
.
unload
=
function
()
{
this
.
ws
.
close
();
};
Object
.
defineProperty
(
WebSocketProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
provider
)
{
this
.
onMessage
(
provider
);
}
});
module
.
exports
=
WebSocketProvider
;
module
.
exports
=
WebSocketProvider
;
...
...
lib/httprpc.js
View file @
15088d7e
...
@@ -25,68 +25,68 @@
...
@@ -25,68 +25,68 @@
var
XMLHttpRequest
=
require
(
'xmlhttprequest'
).
XMLHttpRequest
;
// jshint ignore:line
var
XMLHttpRequest
=
require
(
'xmlhttprequest'
).
XMLHttpRequest
;
// jshint ignore:line
var
HttpRpcProvider
=
function
(
host
)
{
var
HttpRpcProvider
=
function
(
host
)
{
this
.
handlers
=
[];
this
.
handlers
=
[];
this
.
host
=
host
;
this
.
host
=
host
;
};
function
formatJsonRpcObject
(
object
)
{
return
{
jsonrpc
:
'2.0'
,
method
:
object
.
call
,
params
:
object
.
args
,
id
:
object
.
_id
};
};
}
function
formatJsonRpcMessage
(
message
)
{
function
formatJsonRpcObject
(
object
)
{
var
object
=
JSON
.
parse
(
message
);
return
{
jsonrpc
:
'2.0'
,
method
:
object
.
call
,
params
:
object
.
args
,
id
:
object
.
_id
};
}
return
{
function
formatJsonRpcMessage
(
message
)
{
_id
:
object
.
id
,
var
object
=
JSON
.
parse
(
message
);
data
:
object
.
result
};
}
HttpRpcProvider
.
prototype
.
sendRequest
=
function
(
payload
,
cb
)
{
return
{
var
data
=
formatJsonRpcObject
(
payload
);
_id
:
object
.
id
,
data
:
object
.
result
};
}
var
request
=
new
XMLHttpRequest
();
HttpRpcProvider
.
prototype
.
sendRequest
=
function
(
payload
,
cb
)
{
request
.
open
(
"POST"
,
this
.
host
,
true
);
var
data
=
formatJsonRpcObject
(
payload
);
request
.
send
(
JSON
.
stringify
(
data
));
request
.
onreadystatechange
=
function
()
{
var
request
=
new
XMLHttpRequest
();
if
(
request
.
readyState
===
4
&&
cb
)
{
request
.
open
(
"POST"
,
this
.
host
,
true
);
cb
(
request
);
request
.
send
(
JSON
.
stringify
(
data
));
}
request
.
onreadystatechange
=
function
()
{
if
(
request
.
readyState
===
4
&&
cb
)
{
cb
(
request
);
}
};
};
};
};
HttpRpcProvider
.
prototype
.
send
=
function
(
payload
)
{
HttpRpcProvider
.
prototype
.
send
=
function
(
payload
)
{
var
self
=
this
;
var
self
=
this
;
this
.
sendRequest
(
payload
,
function
(
request
)
{
this
.
sendRequest
(
payload
,
function
(
request
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
formatJsonRpcMessage
(
request
.
responseText
));
handler
.
call
(
self
,
formatJsonRpcMessage
(
request
.
responseText
));
});
});
});
}
)
;
};
};
HttpRpcProvider
.
prototype
.
poll
=
function
(
payload
,
id
)
{
HttpRpcProvider
.
prototype
.
poll
=
function
(
payload
,
id
)
{
var
self
=
this
;
var
self
=
this
;
this
.
sendRequest
(
payload
,
function
(
request
)
{
this
.
sendRequest
(
payload
,
function
(
request
)
{
var
parsed
=
JSON
.
parse
(
request
.
responseText
);
var
parsed
=
JSON
.
parse
(
request
.
responseText
);
if
(
parsed
.
result
instanceof
Array
?
parsed
.
result
.
length
===
0
:
!
parsed
.
result
)
{
if
(
parsed
.
result
instanceof
Array
?
parsed
.
result
.
length
===
0
:
!
parsed
.
result
)
{
return
;
return
;
}
}
self
.
handlers
.
forEach
(
function
(
handler
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
{
_event
:
payload
.
call
,
_id
:
id
,
data
:
parsed
.
result
});
handler
.
call
(
self
,
{
_event
:
payload
.
call
,
_id
:
id
,
data
:
parsed
.
result
});
});
});
});
});
};
};
Object
.
defineProperty
(
HttpRpcProvider
.
prototype
,
"onmessage"
,
{
Object
.
defineProperty
(
HttpRpcProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
handler
)
{
set
:
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
this
.
handlers
.
push
(
handler
);
}
}
});
});
module
.
exports
=
HttpRpcProvider
;
module
.
exports
=
HttpRpcProvider
;
lib/main.js
View file @
15088d7e
...
@@ -23,436 +23,428 @@ along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
...
@@ -23,436 +23,428 @@ along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/
*/
function
isPromise
(
o
)
{
function
isPromise
(
o
)
{
return
o
instanceof
Promise
;
return
o
instanceof
Promise
;
}
function
flattenPromise
(
obj
)
{
if
(
obj
instanceof
Promise
)
{
return
Promise
.
resolve
(
obj
);
}
}
if
(
obj
instanceof
Array
)
{
function
flattenPromise
(
obj
)
{
return
new
Promise
(
function
(
resolve
)
{
if
(
obj
instanceof
Promise
)
{
var
promises
=
obj
.
map
(
function
(
o
)
{
return
Promise
.
resolve
(
obj
);
return
flattenPromise
(
o
);
}
});
return
Promise
.
all
(
promises
).
then
(
function
(
res
)
{
if
(
obj
instanceof
Array
)
{
for
(
var
i
=
0
;
i
<
obj
.
length
;
i
++
)
{
return
new
Promise
(
function
(
resolve
)
{
obj
[
i
]
=
res
[
i
];
var
promises
=
obj
.
map
(
function
(
o
)
{
}
return
flattenPromise
(
o
);
resolve
(
obj
);
});
});
});
}
if
(
obj
instanceof
Object
)
{
return
Promise
.
all
(
promises
).
then
(
function
(
res
)
{
return
new
Promise
(
function
(
resolve
)
{
for
(
var
i
=
0
;
i
<
obj
.
length
;
i
++
)
{
var
keys
=
Object
.
keys
(
obj
);
obj
[
i
]
=
res
[
i
];
var
promises
=
keys
.
map
(
function
(
key
)
{
}
return
flattenPromise
(
obj
[
key
]);
resolve
(
obj
);
});
});
});
}
return
Promise
.
all
(
promises
).
then
(
function
(
res
)
{
if
(
obj
instanceof
Object
)
{
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
return
new
Promise
(
function
(
resolve
)
{
obj
[
keys
[
i
]]
=
res
[
i
];
var
keys
=
Object
.
keys
(
obj
);
}
var
promises
=
keys
.
map
(
function
(
key
)
{
resolve
(
obj
);
return
flattenPromise
(
obj
[
key
]);
});
return
Promise
.
all
(
promises
).
then
(
function
(
res
)
{
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
obj
[
keys
[
i
]]
=
res
[
i
];
}
resolve
(
obj
);
});
});
});
});
}
return
Promise
.
resolve
(
obj
);
}
}
return
Promise
.
resolve
(
obj
);
var
ethMethods
=
function
()
{
}
var
blockCall
=
function
(
args
)
{
return
typeof
args
[
0
]
===
"string"
?
"blockByHash"
:
"blockByNumber"
;
};
var
transactionCall
=
function
(
args
)
{
return
typeof
args
[
0
]
===
"string"
?
'transactionByHash'
:
'transactionByNumber'
;
};
var
uncleCall
=
function
(
args
)
{
return
typeof
args
[
0
]
===
"string"
?
'uncleByHash'
:
'uncleByNumber'
;
};
var
ethMethods
=
function
()
{
var
methods
=
[
var
blockCall
=
function
(
args
)
{
{
name
:
'balanceAt'
,
call
:
'balanceAt'
},
return
typeof
args
[
0
]
===
"string"
?
"blockByHash"
:
"blockByNumber"
;
{
name
:
'stateAt'
,
call
:
'stateAt'
},
{
name
:
'countAt'
,
call
:
'countAt'
},
{
name
:
'codeAt'
,
call
:
'codeAt'
},
{
name
:
'transact'
,
call
:
'transact'
},
{
name
:
'call'
,
call
:
'call'
},
{
name
:
'block'
,
call
:
blockCall
},
{
name
:
'transaction'
,
call
:
transactionCall
},
{
name
:
'uncle'
,
call
:
uncleCall
},
{
name
:
'compile'
,
call
:
'compile'
}
];
return
methods
;
};
};
var
transactionCall
=
function
(
args
)
{
var
ethProperties
=
function
()
{
return
typeof
args
[
0
]
===
"string"
?
'transactionByHash'
:
'transactionByNumber'
;
return
[
{
name
:
'coinbase'
,
getter
:
'coinbase'
,
setter
:
'setCoinbase'
},
{
name
:
'listening'
,
getter
:
'listening'
,
setter
:
'setListening'
},
{
name
:
'mining'
,
getter
:
'mining'
,
setter
:
'setMining'
},
{
name
:
'gasPrice'
,
getter
:
'gasPrice'
},
{
name
:
'account'
,
getter
:
'account'
},
{
name
:
'accounts'
,
getter
:
'accounts'
},
{
name
:
'peerCount'
,
getter
:
'peerCount'
},
{
name
:
'defaultBlock'
,
getter
:
'defaultBlock'
,
setter
:
'setDefaultBlock'
},
{
name
:
'number'
,
getter
:
'number'
}
];
};
};
var
uncleCall
=
function
(
args
)
{
var
dbMethods
=
function
()
{
return
typeof
args
[
0
]
===
"string"
?
'uncleByHash'
:
'uncleByNumber'
;
return
[
{
name
:
'put'
,
call
:
'put'
},
{
name
:
'get'
,
call
:
'get'
},
{
name
:
'putString'
,
call
:
'putString'
},
{
name
:
'getString'
,
call
:
'getString'
}
];
};
};
var
methods
=
[
var
shhMethods
=
function
()
{
{
name
:
'balanceAt'
,
call
:
'balanceAt'
},
return
[
{
name
:
'stateAt'
,
call
:
'stateAt'
},
{
name
:
'post'
,
call
:
'post'
},
{
name
:
'countAt'
,
call
:
'countAt'
},
{
name
:
'newIdentity'
,
call
:
'newIdentity'
},
{
name
:
'codeAt'
,
call
:
'codeAt'
},
{
name
:
'haveIdentity'
,
call
:
'haveIdentity'
},
{
name
:
'transact'
,
call
:
'transact'
},
{
name
:
'newGroup'
,
call
:
'newGroup'
},
{
name
:
'call'
,
call
:
'call'
},
{
name
:
'addToGroup'
,
call
:
'addToGroup'
}
{
name
:
'block'
,
call
:
blockCall
},
];
{
name
:
'transaction'
,
call
:
transactionCall
},
{
name
:
'uncle'
,
call
:
uncleCall
},
{
name
:
'compile'
,
call
:
'compile'
}
];
return
methods
;
};
var
ethProperties
=
function
()
{
return
[
{
name
:
'coinbase'
,
getter
:
'coinbase'
,
setter
:
'setCoinbase'
},
{
name
:
'listening'
,
getter
:
'listening'
,
setter
:
'setListening'
},
{
name
:
'mining'
,
getter
:
'mining'
,
setter
:
'setMining'
},
{
name
:
'gasPrice'
,
getter
:
'gasPrice'
},
{
name
:
'account'
,
getter
:
'account'
},
{
name
:
'accounts'
,
getter
:
'accounts'
},
{
name
:
'peerCount'
,
getter
:
'peerCount'
},
{
name
:
'defaultBlock'
,
getter
:
'defaultBlock'
,
setter
:
'setDefaultBlock'
},
{
name
:
'number'
,
getter
:
'number'
}
];
};
var
dbMethods
=
function
()
{
return
[
{
name
:
'put'
,
call
:
'put'
},
{
name
:
'get'
,
call
:
'get'
},
{
name
:
'putString'
,
call
:
'putString'
},
{
name
:
'getString'
,
call
:
'getString'
}
];
};
var
shhMethods
=
function
()
{
return
[
{
name
:
'post'
,
call
:
'post'
},
{
name
:
'newIdentity'
,
call
:
'newIdentity'
},
{
name
:
'haveIdentity'
,
call
:
'haveIdentity'
},
{
name
:
'newGroup'
,
call
:
'newGroup'
},
{
name
:
'addToGroup'
,
call
:
'addToGroup'
}
];
};
var
ethWatchMethods
=
function
()
{
var
newFilter
=
function
(
args
)
{
return
typeof
args
[
0
]
===
'string'
?
'newFilterString'
:
'newFilter'
;
};
};
return
[
var
ethWatchMethods
=
function
()
{
{
name
:
'newFilter'
,
call
:
newFilter
},
var
newFilter
=
function
(
args
)
{
{
name
:
'uninstallFilter'
,
call
:
'uninstallFilter'
},
return
typeof
args
[
0
]
===
'string'
?
'newFilterString'
:
'newFilter'
;
{
name
:
'getMessages'
,
call
:
'getMessages'
}
];
};
var
shhWatchMethods
=
function
()
{
return
[
{
name
:
'newFilter'
,
call
:
'shhNewFilter'
},
{
name
:
'uninstallFilter'
,
call
:
'shhUninstallFilter'
},
{
name
:
'getMessage'
,
call
:
'shhGetMessages'
}
];
};
var
setupMethods
=
function
(
obj
,
methods
)
{
methods
.
forEach
(
function
(
method
)
{
obj
[
method
.
name
]
=
function
()
{
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
(
result
)
{
if
(
result
||
typeof
result
===
"boolean"
)
{
resolve
(
result
);
return
;
}
reject
(
result
);
});
});
}).
catch
(
function
(
err
)
{
console
.
error
(
err
);
});
};
});
};
var
setupProperties
=
function
(
obj
,
properties
)
{
properties
.
forEach
(
function
(
property
)
{
var
proto
=
{};
proto
.
get
=
function
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
web3
.
provider
.
send
({
call
:
property
.
getter
},
function
(
result
)
{
resolve
(
result
);
});
});
};
};
if
(
property
.
setter
)
{
proto
.
set
=
function
(
val
)
{
return
[
return
flattenPromise
([
val
]).
then
(
function
(
args
)
{
{
name
:
'newFilter'
,
call
:
newFilter
},
return
new
Promise
(
function
(
resolve
)
{
{
name
:
'uninstallFilter'
,
call
:
'uninstallFilter'
},
web3
.
provider
.
send
({
call
:
property
.
setter
,
args
:
args
},
function
(
result
)
{
{
name
:
'getMessages'
,
call
:
'getMessages'
}
if
(
result
)
{
];
};
var
shhWatchMethods
=
function
()
{
return
[
{
name
:
'newFilter'
,
call
:
'shhNewFilter'
},
{
name
:
'uninstallFilter'
,
call
:
'shhUninstallFilter'
},
{
name
:
'getMessage'
,
call
:
'shhGetMessages'
}
];
};
var
setupMethods
=
function
(
obj
,
methods
)
{
methods
.
forEach
(
function
(
method
)
{
obj
[
method
.
name
]
=
function
()
{
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
(
result
)
{
if
(
result
||
typeof
result
===
"boolean"
)
{
resolve
(
result
);
resolve
(
result
);
}
else
{
return
;
reject
(
result
);
}
}
reject
(
result
);
});
});
});
});
}).
catch
(
function
(
err
)
{
}).
catch
(
function
(
err
)
{
console
.
error
(
err
);
console
.
error
(
err
);
});
});
};
};
}
});
Object
.
defineProperty
(
obj
,
property
.
name
,
proto
);
};
});
};
var
setupProperties
=
function
(
obj
,
properties
)
{
properties
.
forEach
(
function
(
property
)
{
var
web3
=
{
var
proto
=
{};
_callbacks
:
{},
proto
.
get
=
function
()
{
_events
:
{},
return
new
Promise
(
function
(
resolve
,
reject
)
{
providers
:
{},
web3
.
provider
.
send
({
call
:
property
.
getter
},
function
(
result
)
{
toHex
:
function
(
str
)
{
resolve
(
result
);
var
hex
=
""
;
});
for
(
var
i
=
0
;
i
<
str
.
length
;
i
++
)
{
});
var
n
=
str
.
charCodeAt
(
i
).
toString
(
16
);
};
hex
+=
n
.
length
<
2
?
'0'
+
n
:
n
;
if
(
property
.
setter
)
{
}
proto
.
set
=
function
(
val
)
{
return
flattenPromise
([
val
]).
then
(
function
(
args
)
{
return
new
Promise
(
function
(
resolve
)
{
web3
.
provider
.
send
({
call
:
property
.
setter
,
args
:
args
},
function
(
result
)
{
if
(
result
)
{
resolve
(
result
);
}
else
{
reject
(
result
);
}
});
});
}).
catch
(
function
(
err
)
{
console
.
error
(
err
);
});
};
}
Object
.
defineProperty
(
obj
,
property
.
name
,
proto
);
});
};
var
web3
=
{
_callbacks
:
{},
_events
:
{},
providers
:
{},
toHex
:
function
(
str
)
{
var
hex
=
""
;
for
(
var
i
=
0
;
i
<
str
.
length
;
i
++
)
{
var
n
=
str
.
charCodeAt
(
i
).
toString
(
16
);
hex
+=
n
.
length
<
2
?
'0'
+
n
:
n
;
}
return
hex
;
},
toAscii
:
function
(
hex
)
{
// Find termination
var
str
=
""
;
var
i
=
0
,
l
=
hex
.
length
;
for
(;
i
<
l
;
i
+=
2
)
{
var
code
=
hex
.
charCodeAt
(
i
);
if
(
code
===
0
)
{
break
;
}
return
hex
;
str
+=
String
.
fromCharCode
(
parseInt
(
hex
.
substr
(
i
,
2
),
16
));
},
toAscii
:
function
(
hex
)
{
// Find termination
var
str
=
""
;
var
i
=
0
,
l
=
hex
.
length
;
for
(;
i
<
l
;
i
+=
2
)
{
var
code
=
hex
.
charCodeAt
(
i
);
if
(
code
===
0
)
{
break
;
}
}
str
+=
String
.
fromCharCode
(
parseInt
(
hex
.
substr
(
i
,
2
),
16
));
return
str
;
},
toDecimal
:
function
(
val
)
{
return
parseInt
(
val
,
16
);
},
fromAscii
:
function
(
str
,
pad
)
{
pad
=
pad
===
undefined
?
32
:
pad
;
var
hex
=
this
.
toHex
(
str
);
while
(
hex
.
length
<
pad
*
2
)
hex
+=
"00"
;
return
hex
;
},
eth
:
{
prototype
:
Object
(),
// jshint ignore:line
watch
:
function
(
params
)
{
return
new
Filter
(
params
,
ethWatch
);
}
},
db
:
{
prototype
:
Object
()
// jshint ignore:line
},
shh
:
{
prototype
:
Object
(),
// jshint ignore:line
watch
:
function
(
params
)
{
return
new
Filter
(
params
,
shhWatch
);
}
},
on
:
function
(
event
,
id
,
cb
)
{
if
(
web3
.
_events
[
event
]
===
undefined
)
{
web3
.
_events
[
event
]
=
{};
}
web3
.
_events
[
event
][
id
]
=
cb
;
return
this
;
},
off
:
function
(
event
,
id
)
{
if
(
web3
.
_events
[
event
]
!==
undefined
)
{
delete
web3
.
_events
[
event
][
id
];
}
return
this
;
},
trigger
:
function
(
event
,
id
,
data
)
{
var
callbacks
=
web3
.
_events
[
event
];
if
(
!
callbacks
||
!
callbacks
[
id
])
{
return
;
}
var
cb
=
callbacks
[
id
];
cb
(
data
);
}
}
};
var
eth
=
web3
.
eth
;
setupMethods
(
eth
,
ethMethods
());
setupProperties
(
eth
,
ethProperties
());
setupMethods
(
web3
.
db
,
dbMethods
());
setupMethods
(
web3
.
shh
,
shhMethods
());
var
ethWatch
=
{
changed
:
'changed'
};
setupMethods
(
ethWatch
,
ethWatchMethods
());
var
shhWatch
=
{
changed
:
'shhChanged'
};
setupMethods
(
shhWatch
,
shhWatchMethods
());
var
ProviderManager
=
function
()
{
this
.
queued
=
[];
this
.
polls
=
[];
this
.
ready
=
false
;
this
.
provider
=
undefined
;
this
.
id
=
1
;
var
self
=
this
;
var
poll
=
function
()
{
if
(
self
.
provider
&&
self
.
provider
.
poll
)
{
self
.
polls
.
forEach
(
function
(
data
)
{
data
.
data
.
_id
=
self
.
id
;
self
.
id
++
;
self
.
provider
.
poll
(
data
.
data
,
data
.
id
);
});
}
setTimeout
(
poll
,
12000
);
};
poll
();
};
return
str
;
ProviderManager
.
prototype
.
send
=
function
(
data
,
cb
)
{
},
data
.
_id
=
this
.
id
;
if
(
cb
)
{
toDecimal
:
function
(
val
)
{
web3
.
_callbacks
[
data
.
_id
]
=
cb
;
return
parseInt
(
val
,
16
);
},
fromAscii
:
function
(
str
,
pad
)
{
pad
=
pad
===
undefined
?
32
:
pad
;
var
hex
=
this
.
toHex
(
str
);
while
(
hex
.
length
<
pad
*
2
)
hex
+=
"00"
;
return
hex
;
},
eth
:
{
prototype
:
Object
(),
// jshint ignore:line
watch
:
function
(
params
)
{
return
new
Filter
(
params
,
ethWatch
);
}
}
},
db
:
{
data
.
args
=
data
.
args
||
[];
prototype
:
Object
()
// jshint ignore:line
this
.
id
++
;
},
shh
:
{
if
(
this
.
provider
!==
undefined
)
{
prototype
:
Object
(),
// jshint ignore:line
this
.
provider
.
send
(
data
);
watch
:
function
(
params
)
{
}
else
{
return
new
Filter
(
params
,
shhWatch
);
console
.
warn
(
"provider is not set"
);
this
.
queued
.
push
(
data
);
}
}
}
,
}
;
on
:
function
(
event
,
id
,
cb
)
{
ProviderManager
.
prototype
.
set
=
function
(
provider
)
{
if
(
web3
.
_events
[
event
]
=
==
undefined
)
{
if
(
this
.
provider
!==
undefined
&&
this
.
provider
.
unload
!
==
undefined
)
{
web3
.
_events
[
event
]
=
{}
;
this
.
provider
.
unload
()
;
}
}
web3
.
_events
[
event
][
id
]
=
cb
;
this
.
provider
=
provider
;
return
this
;
this
.
ready
=
true
;
}
,
}
;
off
:
function
(
event
,
id
)
{
ProviderManager
.
prototype
.
sendQueued
=
function
()
{
if
(
web3
.
_events
[
event
]
!==
undefined
)
{
for
(
var
i
=
0
;
this
.
queued
.
length
;
i
++
)
{
delete
web3
.
_events
[
event
][
id
];
// Resend
this
.
send
(
this
.
queued
[
i
]);
}
}
};
return
this
;
ProviderManager
.
prototype
.
installed
=
function
()
{
},
return
this
.
provider
!==
undefined
;
};
trigger
:
function
(
event
,
id
,
data
)
{
ProviderManager
.
prototype
.
startPolling
=
function
(
data
,
pollId
)
{
var
callbacks
=
web3
.
_events
[
event
];
if
(
!
this
.
provider
||
!
this
.
provider
.
poll
)
{
if
(
!
callbacks
||
!
callbacks
[
id
])
{
return
;
return
;
}
}
var
cb
=
callbacks
[
id
];
this
.
polls
.
push
({
data
:
data
,
id
:
pollId
});
cb
(
data
);
};
}
};
ProviderManager
.
prototype
.
stopPolling
=
function
(
pollId
)
{
for
(
var
i
=
this
.
polls
.
length
;
i
--
;)
{
var
eth
=
web3
.
eth
;
var
poll
=
this
.
polls
[
i
];
setupMethods
(
eth
,
ethMethods
());
if
(
poll
.
id
===
pollId
)
{
setupProperties
(
eth
,
ethProperties
());
this
.
polls
.
splice
(
i
,
1
);
setupMethods
(
web3
.
db
,
dbMethods
());
}
setupMethods
(
web3
.
shh
,
shhMethods
());
var
ethWatch
=
{
changed
:
'changed'
};
setupMethods
(
ethWatch
,
ethWatchMethods
());
var
shhWatch
=
{
changed
:
'shhChanged'
};
setupMethods
(
shhWatch
,
shhWatchMethods
());
var
ProviderManager
=
function
()
{
this
.
queued
=
[];
this
.
polls
=
[];
this
.
ready
=
false
;
this
.
provider
=
undefined
;
this
.
id
=
1
;
var
self
=
this
;
var
poll
=
function
()
{
if
(
self
.
provider
&&
self
.
provider
.
poll
)
{
self
.
polls
.
forEach
(
function
(
data
)
{
data
.
data
.
_id
=
self
.
id
;
self
.
id
++
;
self
.
provider
.
poll
(
data
.
data
,
data
.
id
);
});
}
}
setTimeout
(
poll
,
12000
);
};
};
poll
();
};
ProviderManager
.
prototype
.
send
=
function
(
data
,
cb
)
{
web3
.
provider
=
new
ProviderManager
();
data
.
_id
=
this
.
id
;
if
(
cb
)
{
web3
.
_callbacks
[
data
.
_id
]
=
cb
;
}
data
.
args
=
data
.
args
||
[];
web3
.
setProvider
=
function
(
provider
)
{
this
.
id
++
;
provider
.
onmessage
=
messageHandler
;
web3
.
provider
.
set
(
provider
);
web3
.
provider
.
sendQueued
();
};
if
(
this
.
provider
!==
undefined
)
{
var
Filter
=
function
(
options
,
impl
)
{
this
.
provider
.
send
(
data
);
this
.
impl
=
impl
;
}
else
{
this
.
callbacks
=
[];
console
.
warn
(
"provider is not set"
);
this
.
queued
.
push
(
data
);
}
};
ProviderManager
.
prototype
.
set
=
function
(
provider
)
{
var
self
=
this
;
if
(
this
.
provider
!==
undefined
&&
this
.
provider
.
unload
!==
undefined
)
{
this
.
promise
=
impl
.
newFilter
(
options
);
this
.
provider
.
unload
();
this
.
promise
.
then
(
function
(
id
)
{
}
self
.
id
=
id
;
web3
.
on
(
impl
.
changed
,
id
,
self
.
trigger
.
bind
(
self
));
web3
.
provider
.
startPolling
({
call
:
impl
.
changed
,
args
:
[
id
]},
id
);
});
};
this
.
provider
=
provider
;
Filter
.
prototype
.
arrived
=
function
(
callback
)
{
this
.
ready
=
true
;
this
.
changed
(
callback
)
;
};
};
ProviderManager
.
prototype
.
sendQueued
=
function
(
)
{
Filter
.
prototype
.
changed
=
function
(
callback
)
{
for
(
var
i
=
0
;
this
.
queued
.
length
;
i
++
)
{
var
self
=
this
;
// Resend
this
.
promise
.
then
(
function
(
id
)
{
this
.
send
(
this
.
queued
[
i
]
);
self
.
callbacks
.
push
(
callback
);
}
});
};
};
ProviderManager
.
prototype
.
installed
=
function
()
{
Filter
.
prototype
.
trigger
=
function
(
messages
)
{
return
this
.
provider
!==
undefined
;
for
(
var
i
=
0
;
i
<
this
.
callbacks
.
length
;
i
++
)
{
};
this
.
callbacks
[
i
].
call
(
this
,
messages
);
}
};
ProviderManager
.
prototype
.
startPolling
=
function
(
data
,
pollId
)
{
Filter
.
prototype
.
uninstall
=
function
()
{
if
(
!
this
.
provider
||
!
this
.
provider
.
poll
)
{
var
self
=
this
;
return
;
this
.
promise
.
then
(
function
(
id
)
{
}
self
.
impl
.
uninstallFilter
(
id
);
this
.
polls
.
push
({
data
:
data
,
id
:
pollId
});
web3
.
provider
.
stopPolling
(
id
);
};
web3
.
off
(
impl
.
changed
,
id
);
});
ProviderManager
.
prototype
.
stopPolling
=
function
(
pollId
)
{
};
for
(
var
i
=
this
.
polls
.
length
;
i
--
;)
{
var
poll
=
this
.
polls
[
i
];
Filter
.
prototype
.
messages
=
function
()
{
if
(
poll
.
id
===
pollId
)
{
var
self
=
this
;
this
.
polls
.
splice
(
i
,
1
);
return
this
.
promise
.
then
(
function
(
id
)
{
return
self
.
impl
.
getMessages
(
id
);
});
};
function
messageHandler
(
data
)
{
if
(
data
.
_event
!==
undefined
)
{
web3
.
trigger
(
data
.
_event
,
data
.
_id
,
data
.
data
);
return
;
}
}
}
};
web3
.
provider
=
new
ProviderManager
();
web3
.
setProvider
=
function
(
provider
)
{
provider
.
onmessage
=
messageHandler
;
web3
.
provider
.
set
(
provider
);
web3
.
provider
.
sendQueued
();
};
var
Filter
=
function
(
options
,
impl
)
{
this
.
impl
=
impl
;
this
.
callbacks
=
[];
var
self
=
this
;
this
.
promise
=
impl
.
newFilter
(
options
);
this
.
promise
.
then
(
function
(
id
)
{
self
.
id
=
id
;
web3
.
on
(
impl
.
changed
,
id
,
self
.
trigger
.
bind
(
self
));
web3
.
provider
.
startPolling
({
call
:
impl
.
changed
,
args
:
[
id
]},
id
);
});
};
Filter
.
prototype
.
arrived
=
function
(
callback
)
{
this
.
changed
(
callback
);
};
Filter
.
prototype
.
changed
=
function
(
callback
)
{
var
self
=
this
;
this
.
promise
.
then
(
function
(
id
)
{
self
.
callbacks
.
push
(
callback
);
});
};
Filter
.
prototype
.
trigger
=
function
(
messages
)
{
for
(
var
i
=
0
;
i
<
this
.
callbacks
.
length
;
i
++
)
{
this
.
callbacks
[
i
].
call
(
this
,
messages
);
}
};
Filter
.
prototype
.
uninstall
=
function
()
{
var
self
=
this
;
this
.
promise
.
then
(
function
(
id
)
{
self
.
impl
.
uninstallFilter
(
id
);
web3
.
provider
.
stopPolling
(
id
);
web3
.
off
(
impl
.
changed
,
id
);
});
};
Filter
.
prototype
.
messages
=
function
()
{
var
self
=
this
;
return
this
.
promise
.
then
(
function
(
id
)
{
return
self
.
impl
.
getMessages
(
id
);
});
};
function
messageHandler
(
data
)
{
if
(
data
.
_event
!==
undefined
)
{
web3
.
trigger
(
data
.
_event
,
data
.
_id
,
data
.
data
);
return
;
}
if
(
data
.
_id
)
{
if
(
data
.
_id
)
{
var
cb
=
web3
.
_callbacks
[
data
.
_id
];
var
cb
=
web3
.
_callbacks
[
data
.
_id
];
if
(
cb
)
{
if
(
cb
)
{
cb
.
call
(
this
,
data
.
data
);
cb
.
call
(
this
,
data
.
data
);
delete
web3
.
_callbacks
[
data
.
_id
];
delete
web3
.
_callbacks
[
data
.
_id
];
}
}
}
}
}
}
/*
// Install default provider
if(!web3.provider.installed()) {
var sock = new web3.providers.WebSocketProvider("ws://localhost:40404/eth");
web3.setProvider(sock);
}
*/
module
.
exports
=
web3
;
module
.
exports
=
web3
;
lib/qt.js
View file @
15088d7e
...
@@ -20,25 +20,25 @@
...
@@ -20,25 +20,25 @@
* @date 2014
* @date 2014
*/
*/
var
QtProvider
=
function
()
{
var
QtProvider
=
function
()
{
this
.
handlers
=
[];
this
.
handlers
=
[];
var
self
=
this
;
var
self
=
this
;
navigator
.
qt
.
onmessage
=
function
(
message
)
{
navigator
.
qt
.
onmessage
=
function
(
message
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
JSON
.
parse
(
message
.
data
));
handler
.
call
(
self
,
JSON
.
parse
(
message
.
data
));
});
});
};
};
};
};
QtProvider
.
prototype
.
send
=
function
(
payload
)
{
QtProvider
.
prototype
.
send
=
function
(
payload
)
{
navigator
.
qt
.
postMessage
(
JSON
.
stringify
(
payload
));
navigator
.
qt
.
postMessage
(
JSON
.
stringify
(
payload
));
};
};
Object
.
defineProperty
(
QtProvider
.
prototype
,
"onmessage"
,
{
Object
.
defineProperty
(
QtProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
handler
)
{
set
:
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
this
.
handlers
.
push
(
handler
);
}
}
});
});
module
.
exports
=
QtProvider
;
module
.
exports
=
QtProvider
;
lib/websocket.js
View file @
15088d7e
...
@@ -24,50 +24,50 @@
...
@@ -24,50 +24,50 @@
var
WebSocket
=
require
(
'ws'
);
// jshint ignore:line
var
WebSocket
=
require
(
'ws'
);
// jshint ignore:line
var
WebSocketProvider
=
function
(
host
)
{
var
WebSocketProvider
=
function
(
host
)
{
// onmessage handlers
// onmessage handlers
this
.
handlers
=
[];
this
.
handlers
=
[];
// queue will be filled with messages if send is invoked before the ws is ready
// queue will be filled with messages if send is invoked before the ws is ready
this
.
queued
=
[];
this
.
queued
=
[];
this
.
ready
=
false
;
this
.
ready
=
false
;
this
.
ws
=
new
WebSocket
(
host
);
this
.
ws
=
new
WebSocket
(
host
);
var
self
=
this
;
var
self
=
this
;
this
.
ws
.
onmessage
=
function
(
event
)
{
this
.
ws
.
onmessage
=
function
(
event
)
{
for
(
var
i
=
0
;
i
<
self
.
handlers
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
self
.
handlers
.
length
;
i
++
)
{
self
.
handlers
[
i
].
call
(
self
,
JSON
.
parse
(
event
.
data
),
event
);
self
.
handlers
[
i
].
call
(
self
,
JSON
.
parse
(
event
.
data
),
event
);
}
}
};
};
this
.
ws
.
onopen
=
function
()
{
this
.
ws
.
onopen
=
function
()
{
self
.
ready
=
true
;
self
.
ready
=
true
;
for
(
var
i
=
0
;
i
<
self
.
queued
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
self
.
queued
.
length
;
i
++
)
{
// Resend
// Resend
self
.
send
(
self
.
queued
[
i
]);
self
.
send
(
self
.
queued
[
i
]);
}
}
};
};
};
};
WebSocketProvider
.
prototype
.
send
=
function
(
payload
)
{
WebSocketProvider
.
prototype
.
send
=
function
(
payload
)
{
if
(
this
.
ready
)
{
if
(
this
.
ready
)
{
var
data
=
JSON
.
stringify
(
payload
);
var
data
=
JSON
.
stringify
(
payload
);
this
.
ws
.
send
(
data
);
this
.
ws
.
send
(
data
);
}
else
{
}
else
{
this
.
queued
.
push
(
payload
);
this
.
queued
.
push
(
payload
);
}
}
};
};
WebSocketProvider
.
prototype
.
onMessage
=
function
(
handler
)
{
WebSocketProvider
.
prototype
.
onMessage
=
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
this
.
handlers
.
push
(
handler
);
};
};
WebSocketProvider
.
prototype
.
unload
=
function
()
{
WebSocketProvider
.
prototype
.
unload
=
function
()
{
this
.
ws
.
close
();
this
.
ws
.
close
();
};
};
Object
.
defineProperty
(
WebSocketProvider
.
prototype
,
"onmessage"
,
{
Object
.
defineProperty
(
WebSocketProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
provider
)
{
this
.
onMessage
(
provider
);
}
set
:
function
(
provider
)
{
this
.
onMessage
(
provider
);
}
});
});
module
.
exports
=
WebSocketProvider
;
module
.
exports
=
WebSocketProvider
;
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