FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
web3.php/src/Web3.php at master · superpositionedpixel/web3.php · GitHub
superpositionedpixel
/
web3.php
Public
forked from
web3p/web3.php
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
web3.php
/
src
/
Web3.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
290 lines (260 loc) · 6.04 KB
Breadcrumbs
web3.php
/
src
/
Web3.php
Copy path
File metadata and controls
290 lines (260 loc) · 6.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/**
* This file is part of web3.php package.
*
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
*
* @author Peter Lai <alk03073135@gmail.com>
* @license MIT
*/
namespace
Web3
;
use
Web3
\
Eth
;
use
Web3
\
Net
;
use
Web3
\
Personal
;
use
Web3
\
Shh
;
use
Web3
\
Utils
;
use
Web3
\
Providers
\
Provider
;
use
Web3
\
Providers
\
HttpProvider
;
use
Web3
\
Providers
\
WsProvider
;
class
Web3
{
/**
* provider
*
* @var \Web3\Providers\Provider
*/
protected
$
provider
;
/**
* eth
*
* @var \Web3\Eth
*/
protected
$
eth
;
/**
* net
*
* @var \Web3\Net
*/
protected
$
net
;
/**
* personal
*
* @var \Web3\Personal
*/
protected
$
personal
;
/**
* shh
*
* @var \Web3\Shh
*/
protected
$
shh
;
/**
* utils
*
* @var \Web3\Utils
*/
protected
$
utils
;
/**
* methods
*
* @var array
*/
private
$
methods
= [];
/**
* allowedMethods
*
* @var array
*/
private
$
allowedMethods
= [
'
web3_clientVersion
'
,
'
web3_sha3
'
];
/**
* construct
*
* @param string|\Web3\Providers\Provider $provider
* @param float $timeout
* @return void
*/
public
function
__construct
(
$
provider
,
$
timeout
=
1
)
{
if
(
is_string
(
$
provider
) && (
filter_var
(
$
provider
,
FILTER_VALIDATE_URL
) !==
false
)) {
// check the uri schema
if
(
preg_match
(
'
/^https?:\/\//
'
,
$
provider
) ===
1
) {
$
this
->
provider
=
new
HttpProvider
(
$
provider
,
$
timeout
);
}
else
if
(
preg_match
(
'
/^wss?:\/\//
'
,
$
provider
) ===
1
) {
$
this
->
provider
=
new
WsProvider
(
$
provider
,
$
timeout
);
}
}
else
if
(
$
provider
instanceof
Provider) {
$
this
->
provider
=
$
provider
;
}
}
/**
* call
*
* @param string $name
* @param array $arguments
* @return void
*/
public
function
__call
(
$
name
,
$
arguments
)
{
if
(
empty
(
$
this
->
provider
)) {
throw
new
\
RuntimeException
(
'
Please set provider first.
'
);
}
$
class
=
explode
(
'\\'
,
get_class
(
$
this
));
if
(
preg_match
(
'
/^[a-zA-Z0-9]+$/
'
,
$
name
) ===
1
) {
$
method
=
strtolower
(
$
class
[
1
]) .
'
_
'
.
$
name
;
if
(!
in_array
(
$
method
,
$
this
->
allowedMethods
)) {
throw
new
\
RuntimeException
(
'
Unallowed rpc method:
'
.
$
method
);
}
if
(
$
this
->
provider
->
isBatch
) {
$
callback
=
null
;
}
else
{
$
callback
=
array_pop
(
$
arguments
);
if
(
is_callable
(
$
callback
) !==
true
) {
throw
new
\
InvalidArgumentException
(
'
The last param must be callback function.
'
);
}
}
if
(!
array_key_exists
(
$
method
,
$
this
->
methods
)) {
// new the method
$
methodClass
=
sprintf
(
"
\Web3\Methods\%s\%s
"
,
ucfirst
(
$
class
[
1
]),
ucfirst
(
$
name
));
$
methodObject
=
new
$
methodClass
(
$
method
,
$
arguments
);
$
this
->
methods
[
$
method
] =
$
methodObject
;
}
else
{
$
methodObject
=
$
this
->
methods
[
$
method
];
}
if
(
$
methodObject
->
validate
(
$
arguments
)) {
$
inputs
=
$
methodObject
->
transform
(
$
arguments
,
$
methodObject
->
inputFormatters
);
$
methodObject
->
arguments
=
$
inputs
;
return
$
this
->
provider
->
send
(
$
methodObject
,
$
callback
);
}
}
}
/**
* get
*
* @param string $name
* @return mixed
*/
public
function
__get
(
$
name
)
{
$
method
=
'
get
'
.
ucfirst
(
$
name
);
if
(
method_exists
(
$
this
,
$
method
)) {
return
call_user_func_array
([
$
this
,
$
method
], []);
}
return
false
;
}
/**
* set
*
* @param string $name
* @param mixed $value
* @return mixed
*/
public
function
__set
(
$
name
,
$
value
)
{
$
method
=
'
set
'
.
ucfirst
(
$
name
);
if
(
method_exists
(
$
this
,
$
method
)) {
return
call_user_func_array
([
$
this
,
$
method
], [
$
value
]);
}
return
false
;
}
/**
* getProvider
*
* @return \Web3\Providers\Provider
*/
public
function
getProvider
()
{
return
$
this
->
provider
;
}
/**
* setProvider
*
* @param \Web3\Providers\Provider $provider
* @return bool
*/
public
function
setProvider
(
$
provider
)
{
if
(
$
provider
instanceof
Provider) {
$
this
->
provider
=
$
provider
;
return
true
;
}
return
false
;
}
/**
* getEth
*
* @return \Web3\Eth
*/
public
function
getEth
()
{
if
(!
isset
(
$
this
->
eth
)) {
$
eth
=
new
Eth
(
$
this
->
provider
);
$
this
->
eth
=
$
eth
;
}
return
$
this
->
eth
;
}
/**
* getNet
*
* @return \Web3\Net
*/
public
function
getNet
()
{
if
(!
isset
(
$
this
->
net
)) {
$
net
=
new
Net
(
$
this
->
provider
);
$
this
->
net
=
$
net
;
}
return
$
this
->
net
;
}
/**
* getPersonal
*
* @return \Web3\Personal
*/
public
function
getPersonal
()
{
if
(!
isset
(
$
this
->
personal
)) {
$
personal
=
new
Personal
(
$
this
->
provider
);
$
this
->
personal
=
$
personal
;
}
return
$
this
->
personal
;
}
/**
* getShh
*
* @return \Web3\Shh
*/
public
function
getShh
()
{
if
(!
isset
(
$
this
->
shh
)) {
$
shh
=
new
Shh
(
$
this
->
provider
);
$
this
->
shh
=
$
shh
;
}
return
$
this
->
shh
;
}
/**
* getUtils
*
* @return \Web3\Utils
*/
public
function
getUtils
()
{
if
(!
isset
(
$
this
->
utils
)) {
$
utils
=
new
Utils
;
$
this
->
utils
=
$
utils
;
}
return
$
this
->
utils
;
}
/**
* batch
*
* @param bool $status
* @return void
*/
public
function
batch
(
$
status
)
{
$
status
=
is_bool
(
$
status
);
$
this
->
provider
->
batch
(
$
status
);
}
}
Back
|
FazBrowse Home
|
New Git URL