-
Notifications
You must be signed in to change notification settings - Fork 277
/
Tron.php
1367 lines (1196 loc) · 37.2 KB
/
Tron.php
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* TronAPI
*
* @author Shamsudin Serderov <steein.shamsudin@gmail.com>
* @license https://github.com/iexbase/tron-api/blob/master/LICENSE (MIT License)
* @version 1.3.4
* @link https://github.com/iexbase/tron-api
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace IEXBase\TronAPI;
use BN\BN;
use Elliptic\EC;
use IEXBase\TronAPI\Support\Base58;
use IEXBase\TronAPI\Support\Base58Check;
use IEXBase\TronAPI\Support\Crypto;
use IEXBase\TronAPI\Support\Hash;
use IEXBase\TronAPI\Support\Keccak;
use IEXBase\TronAPI\Support\Utils;
use IEXBase\TronAPI\Provider\HttpProviderInterface;
use IEXBase\TronAPI\Exception\TronException;
use kornrunner\Secp256k1;
/**
* A PHP API for interacting with the Tron (TRX)
*
* @package TronAPI
* @author Shamsudin Serderov <steein.shamsudin@gmail.com>
* @since 1.0.0
*/
class Tron implements TronInterface
{
use TronAwareTrait,
Concerns\ManagesUniversal,
Concerns\ManagesTronscan;
const ADDRESS_SIZE = 34;
const ADDRESS_PREFIX = "41";
const ADDRESS_PREFIX_BYTE = 0x41;
/**
* Default Address
*
* @var array
*/
public $address = [
'base58' => null,
'hex' => null
];
/**
* Private key
*
* @var string
*/
protected $privateKey;
/**
* Default block
*
* @var string|integer|bool
*/
protected $defaultBlock = 'latest';
/**
* Transaction Builder
*
* @var TransactionBuilder
*/
protected $transactionBuilder;
/**
* Provider manager
*
* @var TronManager
*/
protected $manager;
/**
* Object Result
*
* @var bool
*/
protected $isObject = false;
/**
* Create a new Tron object
*
* @param HttpProviderInterface $fullNode
* @param HttpProviderInterface $solidityNode
* @param HttpProviderInterface|null $eventServer
* @param HttpProviderInterface|null $signServer
* @param HttpProviderInterface|null $explorer
* @param string $privateKey
* @throws TronException
*/
public function __construct(?HttpProviderInterface $fullNode = null,
?HttpProviderInterface $solidityNode = null,
?HttpProviderInterface $eventServer = null,
?HttpProviderInterface $signServer = null,
?HttpProviderInterface $explorer = null,
?string $privateKey = null)
{
if(!is_null($privateKey)) {
$this->setPrivateKey($privateKey);
}
$this->setManager(new TronManager($this, [
'fullNode' => $fullNode,
'solidityNode' => $solidityNode,
'eventServer' => $eventServer,
'signServer' => $signServer,
]));
$this->transactionBuilder = new TransactionBuilder($this);
}
/**
* Create a new tron instance if the value isn't one already.
*
* @param HttpProviderInterface|null $fullNode
* @param HttpProviderInterface|null $solidityNode
* @param HttpProviderInterface|null $eventServer
* @param HttpProviderInterface|null $signServer
* @param string|null $privateKey
* @return static
* @throws TronException
*/
public static function make(?HttpProviderInterface $fullNode = null,
?HttpProviderInterface $solidityNode = null,
?HttpProviderInterface $eventServer = null,
?HttpProviderInterface $signServer = null,
string $privateKey = null) {
return new static($fullNode, $solidityNode, $eventServer, $signServer, $privateKey);
}
/**
* Фасад для Laravel
*
* @return Tron
*/
public function getFacade(): Tron {
return $this;
}
/**
* Enter the link to the manager nodes
*
* @param $providers
*/
public function setManager($providers) {
$this->manager = $providers;
}
/**
* Get provider manager
*
* @return TronManager
*/
public function getManager(): TronManager {
return $this->manager;
}
/**
* Set is object
*
* @param bool $value
* @return Tron
*/
public function setIsObject(bool $value)
{
$this->isObject = boolval($value);
return $this;
}
/**
* Get Transaction Builder
*
* @return TransactionBuilder
*/
public function getTransactionBuilder(): TransactionBuilder
{
return $this->transactionBuilder;
}
/**
* Check connected provider
*
* @param $provider
* @return bool
*/
public function isValidProvider($provider): bool
{
return ($provider instanceof HttpProviderInterface);
}
/**
* Enter the default block
*
* @param bool $blockID
* @return void
* @throws TronException
*/
public function setDefaultBlock($blockID = false): void
{
if($blockID === false || $blockID == 'latest' || $blockID == 'earliest' || $blockID === 0) {
$this->defaultBlock = $blockID;
return;
}
if(!is_integer($blockID)) {
throw new TronException('Invalid block ID provided');
}
$this->defaultBlock = abs($blockID);
}
/**
* Get default block
*
* @return string|integer|bool
*/
public function getDefaultBlock()
{
return $this->defaultBlock;
}
/**
* Enter your private account key
*
* @param string $privateKey
*/
public function setPrivateKey(string $privateKey): void
{
$this->privateKey = $privateKey;
}
/**
* Enter your account address
*
* @param string $address
*/
public function setAddress(string $address): void
{
$_toHex = $this->address2HexString($address);
$_fromHex = $this->hexString2Address($address);
$this->address = [
'hex' => $_toHex,
'base58' => $_fromHex
];
}
/**
* Get account address
*
* @return array
*/
public function getAddress(): array
{
return $this->address;
}
/**
* Get customized provider data
*
* @return array
*/
public function providers(): array
{
return $this->manager->getProviders();
}
/**
* Check Connection Providers
*
* @return array
*/
public function isConnected(): array
{
return $this->manager->isConnected();
}
/**
* Last block number
*
* @return array
* @throws TronException
*/
public function getCurrentBlock(): array
{
return $this->manager->request('wallet/getnowblock');
}
/**
* Will return all events matching the filters.
*
* @param $contractAddress
* @param int $sinceTimestamp
* @param string|null $eventName
* @param int $blockNumber
* @return array
* @throws TronException
*/
public function getEventResult($contractAddress, int $sinceTimestamp = 0, string $eventName = null, int $blockNumber = 0)
{
if (!$this->isValidProvider($this->manager->eventServer())) {
throw new TronException('No event server configured');
}
$routeParams = [];
if($eventName && !$contractAddress) {
throw new TronException('Usage of event name filtering requires a contract address');
}
if($blockNumber && !$eventName)
throw new TronException('Usage of block number filtering requires an event name');
if($contractAddress) {
array_push($routeParams, $contractAddress);
}
if($eventName) {
array_push($routeParams, $eventName);
}
if($blockNumber) {
array_push($routeParams, $blockNumber);
}
$routeParams = implode('/', $routeParams);
return $this->manager->request("event/contract/{$routeParams}?since={$sinceTimestamp}");
}
/**
* Will return all events within a transactionID.
*
* @param string $transactionID
* @return array
* @throws TronException
*/
public function getEventByTransactionID(string $transactionID)
{
if (!$this->isValidProvider($this->manager->eventServer())) {
throw new TronException('No event server configured');
}
return $this->manager->request("event/transaction/{$transactionID}");
}
/**
* Get block details using HashString or blockNumber
*
* @param null $block
* @return array
* @throws TronException
*/
public function getBlock($block = null): array
{
$block = (is_null($block) ? $this->defaultBlock : $block);
if($block === false) {
throw new TronException('No block identifier provided');
}
if($block == 'earliest') {
$block = 0;
}
if($block == 'latest') {
return $this->getCurrentBlock();
}
if(Utils::isHex($block)) {
return $this->getBlockByHash($block);
}
return $this->getBlockByNumber($block);
}
/**
* Query block by ID
*
* @param $hashBlock
* @return array
* @throws TronException
*/
public function getBlockByHash(string $hashBlock): array
{
return $this->manager->request('wallet/getblockbyid', [
'value' => $hashBlock
]);
}
/**
* Query block by height
*
* @param $blockID
* @return array
* @throws TronException
*/
public function getBlockByNumber(int $blockID): array
{
if(!is_integer($blockID) || $blockID < 0) {
throw new TronException('Invalid block number provided');
}
$response = $this->manager->request('wallet/getblockbynum', [
'num' => intval($blockID)
]);
if (empty($response)) {
throw new TronException('Block not found');
}
return $response;
}
/**
* Total number of transactions in a block
*
* @param $block
* @return int
* @throws TronException
*/
public function getBlockTransactionCount($block): int
{
$transaction = $this->getBlock($block)['transactions'];
if(!$transaction) {
return 0;
}
return count($transaction);
}
/**
* Get transaction details from Block
*
* @param null $block
* @param int $index
* @return array | string
* @throws TronException
*/
public function getTransactionFromBlock($block = null, $index = 0)
{
if(!is_integer($index) || $index < 0) {
throw new TronException('Invalid transaction index provided');
}
$transactions = $this->getBlock($block)['transactions'];
if(!$transactions || count($transactions) < $index) {
throw new TronException('Transaction not found in block');
}
return $transactions[$index];
}
/**
* Query transaction based on id
*
* @param $transactionID
* @return array
* @throws TronException
*/
public function getTransaction(string $transactionID): array
{
$response = $this->manager->request('wallet/gettransactionbyid', [
'value' => $transactionID
]);
if(!$response) {
throw new TronException('Transaction not found');
}
return $response;
}
/**
* Query transaction fee based on id
*
* @param $transactionID
* @return array
* @throws TronException
*/
public function getTransactionInfo(string $transactionID): array
{
return $this->manager->request('walletsolidity/gettransactioninfobyid', [
'value' => $transactionID
]);
}
/**
* Query the list of transactions received by an address
*
* @param string $address
* @param int $limit
* @param int $offset
* @return array
* @throws TronException
*/
public function getTransactionsToAddress(string $address, int $limit = 30, int $offset = 0)
{
return $this->getTransactionsRelated($address,'to', $limit, $offset);
}
/**
* Query the list of transactions sent by an address
*
* @param string $address
* @param int $limit
* @param int $offset
* @return array
* @throws TronException
*/
public function getTransactionsFromAddress(string $address, int $limit = 30, int $offset = 0)
{
return $this->getTransactionsRelated($address,'from', $limit, $offset);
}
/**
* Query information about an account
*
* @param $address
* @return array
* @throws TronException
*/
public function getAccount(string $address = null): array
{
$address = (!is_null($address) ? $this->toHex($address) : $this->address['hex']);
return $this->manager->request('walletsolidity/getaccount', [
'address' => $address
]);
}
/**
* Getting a balance
*
* @param string $address
* @param bool $fromTron
* @return float
* @throws TronException
*/
public function getBalance(string $address = null, bool $fromTron = false): float
{
$account = $this->getAccount($address);
if(!array_key_exists('balance', $account)) {
return 0;
}
return ($fromTron == true ?
$this->fromTron($account['balance']) :
$account['balance']);
}
/**
* Get token balance
*
* @param string $address
* @param int $tokenId
* @param bool $fromTron
* @return array|int
* @throws TronException
*/
public function getTokenBalance(int $tokenId, string $address, bool $fromTron = false)
{
$account = $this->getAccount($address);
if(isset($account['assetV2']) and !empty($account['assetV2']) )
{
$value = array_filter($account['assetV2'], function($item) use ($tokenId) {
return $item['key'] == $tokenId;
});
if(empty($value)) {
throw new TronException('Token id not found');
}
$first = array_shift($value);
return ($fromTron == true ? $this->fromTron($first['value']) : $first['value']);
}
return 0;
}
/**
* Query bandwidth information.
*
* @param $address
* @return array
* @throws TronException
*/
public function getBandwidth(string $address = null)
{
$address = (!is_null($address) ? $this->toHex($address) : $this->address['hex']);
return $this->manager->request('wallet/getaccountnet', [
'address' => $address
]);
}
/**
* Getting data in the "from","to" directions
*
* @param string $address
* @param string $direction
* @param int $limit
* @param int $offset
* @return array
* @throws TronException
*/
public function getTransactionsRelated(string $address, string $direction = 'to', int $limit = 30, int $offset = 0)
{
if(!in_array($direction, ['to', 'from'])) {
throw new TronException('Invalid direction provided: Expected "to", "from"');
}
if(!is_integer($limit) || $limit < 0 || ($offset && $limit < 1)) {
throw new TronException('Invalid limit provided');
}
if(!is_integer($offset) || $offset < 0) {
throw new TronException('Invalid offset provided');
}
$response = $this->manager->request(sprintf('walletextension/gettransactions%sthis', $direction), [
'account' => ['address' => $this->toHex($address)],
'limit' => $limit,
'offset' => $offset
]);
return array_merge($response, ['direction' => $direction]);
}
/**
* Count all transactions on the network
*
* @return integer
* @throws TronException
*/
public function getTransactionCount(): int
{
$response = $this->manager->request('wallet/totaltransaction');
return $response['num'];
}
/**
* Send transaction to Blockchain
*
* @param string $to
* @param float $amount
* @param string|null $message
* @param string $from
*
* @return array
* @throws TronException
*/
public function sendTransaction(string $to, float $amount, string $message= null, string $from = null): array
{
if (is_null($from)) {
$from = $this->address['hex'];
}
$transaction = $this->transactionBuilder->sendTrx($to, $amount, $from);
$signedTransaction = $this->signTransaction($transaction, $message);
$response = $this->sendRawTransaction($signedTransaction);
return array_merge($response, $signedTransaction);
}
/**
* Send token transaction to Blockchain
*
* @param string $to
* @param float $amount
* @param int $tokenID
* @param string $from
*
* @return array
* @throws TronException
*/
public function sendTokenTransaction(string $to, float $amount, int $tokenID = null, string $from = null): array
{
if (is_null($from)) {
$from = $this->address['hex'];
}
$transaction = $this->transactionBuilder->sendToken($to, $this->toTron($amount), (string)$tokenID, $from);
$signedTransaction = $this->signTransaction($transaction);
$response = $this->sendRawTransaction($signedTransaction);
return array_merge($response, $signedTransaction);
}
/**
* Sign the transaction, the api has the risk of leaking the private key,
* please make sure to call the api in a secure environment
*
* @param $transaction
* @param string|null $message
* @return array
* @throws TronException
*/
public function signTransaction($transaction, string $message = null): array
{
if(!$this->privateKey) {
throw new TronException('Missing private key');
}
if(!is_array($transaction)) {
throw new TronException('Invalid transaction provided');
}
if(isset($transaction['Error']))
throw new TronException($transaction['Error']);
if(isset($transaction['signature'])) {
throw new TronException('Transaction is already signed');
}
if(!is_null($message)) {
$transaction['raw_data']['data'] = $this->stringUtf8toHex($message);
}
$signature = Support\Secp::sign($transaction['txID'], $this->privateKey);
$transaction['signature'] = [$signature];
return $transaction;
}
/**
* Broadcast the signed transaction
*
* @param $signedTransaction
* @return array
* @throws TronException
*/
public function sendRawTransaction($signedTransaction): array
{
if(!is_array($signedTransaction)) {
throw new TronException('Invalid transaction provided');
}
if(!array_key_exists('signature', $signedTransaction) || !is_array($signedTransaction['signature'])) {
throw new TronException('Transaction is not signed');
}
return $this->manager->request('wallet/broadcasttransaction',
$signedTransaction);
}
/**
* Modify account name
* Note: Username is allowed to edit only once.
*
* @param $address
* @param $account_name
* @return array
* @throws TronException
*/
public function changeAccountName(string $address = null, string $account_name)
{
$address = (!is_null($address) ? $address : $this->address['hex']);
$transaction = $this->manager->request('wallet/updateaccount', [
'account_name' => $this->stringUtf8toHex($account_name),
'owner_address' => $this->toHex($address)
]);
$signedTransaction = $this->signTransaction($transaction);
$response = $this->sendRawTransaction($signedTransaction);
return $response;
}
/**
* Send funds to the Tron account (option 2)
*
* @param array $args
* @return array
* @throws TronException
*/
public function send(...$args): array {
return $this->sendTransaction(...$args);
}
/**
* Send funds to the Tron account (option 3)
*
* @param array $args
* @return array
* @throws TronException
*/
public function sendTrx(...$args): array {
return $this->sendTransaction(...$args);
}
/**
* Creating a new token based on Tron
*
* @param array token {
* "owner_address": "41e552f6487585c2b58bc2c9bb4492bc1f17132cd0",
* "name": "0x6173736574497373756531353330383934333132313538",
* "abbr": "0x6162627231353330383934333132313538",
* "total_supply": 4321,
* "trx_num": 1,
* "num": 1,
* "start_time": 1530894315158,
* "end_time": 1533894312158,
* "description": "007570646174654e616d6531353330363038383733343633",
* "url": "007570646174654e616d6531353330363038383733343633",
* "free_asset_net_limit": 10000,
* "public_free_asset_net_limit": 10000,
* "frozen_supply": { "frozen_amount": 1, "frozen_days": 2 }
*
* @return array
* @throws TronException
*/
public function createToken($token = [])
{
return $this->manager->request('wallet/createassetissue', [
'owner_address' => $this->toHex($token['owner_address']),
'name' => $this->stringUtf8toHex($token['name']),
'abbr' => $this->stringUtf8toHex($token['abbr']),
'description' => $this->stringUtf8toHex($token['description']),
'url' => $this->stringUtf8toHex($token['url']),
'total_supply' => $token['total_supply'],
'trx_num' => $token['trx_num'],
'num' => $token['num'],
'start_time' => $token['start_time'],
'end_time' => $token['end_time'],
'free_asset_net_limit' => $token['free_asset_net_limit'],
'public_free_asset_net_limit' => $token['public_free_asset_net_limit'],
'frozen_supply' => $token['frozen_supply']
]);
}
/**
* Create an account.
* Uses an already activated account to create a new account
*
* @param $address
* @param $newAccountAddress
* @return array
* @throws TronException
*/
public function registerAccount(string $address, string $newAccountAddress): array
{
return $this->manager->request('wallet/createaccount', [
'owner_address' => $this->toHex($address),
'account_address' => $this->toHex($newAccountAddress)
]);
}
/**
* Apply to become a super representative
*
* @param $address
* @param $url
* @return array
* @throws TronException
*/
public function applyForSuperRepresentative(string $address, string $url)
{
return $this->manager->request('wallet/createwitness', [
'owner_address' => $this->toHex($address),
'url' => $this->stringUtf8toHex($url)
]);
}
/**
* Transfer Token
*
* @param $to
* @param $amount
* @param $tokenID
* @param $from
* @return array
* @throws TronException
*/
public function sendToken(string $to, int $amount, string $tokenID, string $from = null)
{
if($from == null) {
$from = $this->address['hex'];
}
$transfer = $this->transactionBuilder->sendToken($to, $amount, $tokenID, $from);
$signedTransaction = $this->signTransaction($transfer);
$response = $this->sendRawTransaction($signedTransaction);
return array_merge($response, $signedTransaction);
}
/**
* Purchase a Token
* @param $issuerAddress
* @param $tokenID
* @param $amount
* @param null $buyer
* @return array
* @throws TronException
*/
public function purchaseToken($issuerAddress, $tokenID, $amount, $buyer = null)
{
if($buyer == null) {
$buyer = $this->address['hex'];
}
$purchase = $this->transactionBuilder->purchaseToken($issuerAddress, $tokenID, $amount, $buyer);
$signedTransaction = $this->signTransaction($purchase);
$response = $this->sendRawTransaction($signedTransaction);
return array_merge($response, $signedTransaction);
}
/**
* Freezes an amount of TRX.
* Will give bandwidth OR Energy and TRON Power(voting rights) to the owner of the frozen tokens.
*
* @param float $amount
* @param int $duration
* @param string $resource
* @param string $owner_address
* @return array
* @throws TronException
*/
public function freezeBalance(float $amount = 0, int $duration = 3, string $resource = 'BANDWIDTH', string $owner_address = null)
{
if($owner_address == null) {
$owner_address = $this->address['hex'];
}
$freeze = $this->transactionBuilder->freezeBalance($amount, $duration, $resource, $owner_address);
$signedTransaction = $this->signTransaction($freeze);
$response = $this->sendRawTransaction($signedTransaction);
return array_merge($response, $signedTransaction);
}
/**
* Unfreeze TRX that has passed the minimum freeze duration.
* Unfreezing will remove bandwidth and TRON Power.
*
* @param string $resource
* @param string $owner_address
* @return array
* @throws TronException
*/
public function unfreezeBalance(string $resource = 'BANDWIDTH', string $owner_address = null)
{
if($owner_address == null) {
$owner_address = $this->address['hex'];
}
$unfreeze = $this->transactionBuilder->unfreezeBalance($resource, $owner_address);
$signedTransaction = $this->signTransaction($unfreeze);
$response = $this->sendRawTransaction($signedTransaction);
return array_merge($response, $signedTransaction);
}
/**
* Withdraw Super Representative rewards, useable every 24 hours.
*
* @param string $owner_address
* @return array
* @throws TronException
*/
public function withdrawBlockRewards(string $owner_address = null)
{
if($owner_address == null) {
$owner_address = $this->address['hex'];
}
$withdraw = $this->transactionBuilder->withdrawBlockRewards($owner_address);
$signedTransaction = $this->signTransaction($withdraw);
$response = $this->sendRawTransaction($signedTransaction);
return array_merge($response, $signedTransaction);
}
/**
* Update a Token's information
*
* @param string $description
* @param string $url
* @param int $freeBandwidth
* @param int $freeBandwidthLimit
* @param $owner_address
* @return array
* @throws TronException