@@ -181,9 +181,7 @@ public function getTransactionsRelated(string $address = null,bool $confirmed =
181
181
$ data ['only_to ' ] = $ to ;
182
182
$ data ['only_from ' ] = $ from ;
183
183
$ data ['search_internal ' ] = $ searchinternal ;
184
- if ($ limit >= 1 and $ limit <= 200 ):
185
- $ data ['limit ' ] = $ limit ;
186
- endif ;
184
+ $ data ['limit ' ] = max (min ($ limit ,200 ),20 );
187
185
$ data ['order_by ' ] = $ order ;
188
186
if (is_null ($ mintimestamp ) === false ):
189
187
$ data ['min_timestamp ' ] = date ('Y-m-d\TH:i:s.v\Z ' ,$ mintimestamp );
@@ -197,6 +195,7 @@ public function getTransactionsRelated(string $address = null,bool $confirmed =
197
195
if (isset ($ transactions ->success ) and $ transactions ->success === true ):
198
196
$ transactions ->iterator = new Transactions ($ this ->sender ,array ($ transactions ));
199
197
endif ;
198
+ $ this ->sender = clone $ this ->sender ;
200
199
return $ transactions ;
201
200
}
202
201
public function getTransactionsFromAddress (string $ address = null ,int $ limit = 20 ) : object {
@@ -210,6 +209,7 @@ public function getTransactionsNext(string $url) : object {
210
209
if (isset ($ transactions ->success ) and $ transactions ->success === true ):
211
210
$ transactions ->iterator = new Transactions ($ this ->sender ,array ($ transactions ));
212
211
endif ;
212
+ $ this ->sender = clone $ this ->sender ;
213
213
return $ transactions ;
214
214
}
215
215
public function createAccount (string $ newaddress ,string $ address = null ) : object {
@@ -257,6 +257,30 @@ public function getBalance(string $address = null,bool $sun = false) : float {
257
257
$ balance = isset ($ account ->balance ) ? $ account ->balance : 0 ;
258
258
return ($ sun ? $ balance : $ balance / 1e6 );
259
259
}
260
+ public function getAccurateBalance (string $ address = null ,bool $ sun = false ) : float {
261
+ $ account = $ this ->getAccount ($ address );
262
+ $ owner = isset ($ account ->address ) ? $ account ->address : $ this ->address2hex (is_null ($ address ) ? $ this ->wallet : $ address );
263
+ $ balance = isset ($ account ->balance ) ? $ account ->balance : 0 ;
264
+ $ unconfirmed = $ this ->getTransactionsRelated (address : $ address ,confirmed : false ,limit : 200 );
265
+ foreach ($ unconfirmed ->iterator as $ transactions ):
266
+ foreach ($ transactions ->data as $ transaction ):
267
+ $ contract = current ($ transaction ->raw_data ->contract )->parameter ->value ;
268
+ $ amount = $ contract ->amount ;
269
+ $ from = $ contract ->owner_address ;
270
+ $ ret = current ($ transaction ->ret );
271
+ $ status = $ ret ->contractRet ;
272
+ $ fee = $ ret ->fee ;
273
+ if ($ status === 'SUCCESS ' ):
274
+ if ($ from === $ owner ):
275
+ $ balance -= $ amount + $ fee ;
276
+ else :
277
+ $ balance += $ amount ;
278
+ endif ;
279
+ endif ;
280
+ endforeach ;
281
+ endforeach ;
282
+ return ($ sun ? $ balance : $ balance / 1e6 );
283
+ }
260
284
public function getAccountName (string $ address = null ,bool $ hex = false ) : mixed {
261
285
$ account = $ this ->getAccount ($ address );
262
286
$ accountname = isset ($ account ->account_name ) ? $ account ->account_name : null ;
0 commit comments