TronApi.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. <?php
  2. namespace TronTool;
  3. // use common\helpers\RedisHelper;
  4. class TronApi{
  5. protected $fullNode;
  6. protected $solidityNode;
  7. protected $eventNode;
  8. static function mainNet(){
  9. $time = time();
  10. $key = 'trc20_'.$time;
  11. // if(!RedisHelper::isAllow($key,1,5)){
  12. // sleep(1);
  13. // }
  14. return new self('https://api.trongrid.io');
  15. }
  16. static function testNet(){
  17. return new self('https://api.shasta.trongrid.io');
  18. }
  19. static function testNetNilo(){
  20. return new self('https://nile.trongrid.io');
  21. }
  22. function __construct($fullNodeUrl,$solidityNodeUrl=null,$eventNodeUrl=null){
  23. if(is_null($solidityNodeUrl)){
  24. $solidityNodeUrl = $fullNodeUrl;
  25. }
  26. if(is_null($eventNodeUrl)){
  27. $eventNodeUrl = $fullNodeUrl;
  28. }
  29. $this->fullNode = new NodeClient($fullNodeUrl);
  30. $this->solidityNode = new NodeClient($solidityNodeUrl);
  31. $this->eventNode = new NodeClient($eventNodeUrl);
  32. }
  33. function getNextMaintenanceTime(){
  34. return $this->fullNode->get('/wallet/getnextmaintenancetime');
  35. }
  36. function timeUntilNextVoteCycle(){
  37. $args = func_get_args();
  38. return $this->getNextMaintenanceTime(...$args);
  39. }
  40. function broadcastTransaction($tx){
  41. return $this->fullNode->post('/wallet/broadcasttransaction',$tx);
  42. }
  43. function sendRawTransaction(){
  44. $args = func_get_args();
  45. return $this->broadcastTransaction(...$args);
  46. }
  47. /*
  48. function createTransaction($to,$amount,$from){
  49. $payload = [
  50. 'to_address' => Address::decode($to),
  51. 'owner_address' => Address::decode($from),
  52. 'amount' => $amount
  53. ];
  54. return $this->fullNode->post('/wallet/createtransaction',$payload);
  55. }
  56. */
  57. function sendTrx(){
  58. $args = func_get_args();
  59. return $this->createTransaction(...$args);
  60. }
  61. function getContractEvents($contractAddress,$since){
  62. $api = '/event/contract/' . $contractAddress;
  63. $payload = [ 'since' => $since, 'sort' => 'block_timestamp' ];
  64. return $this->eventNode->get($api,$payload);
  65. }
  66. function getTransactionEvents($txid){
  67. $api = '/event/transaction/' . $txid;
  68. return $this->eventNode->get($api,[]);
  69. }
  70. /*
  71. function triggerSmartContract($contractAddress,$functionSelector,$parameter,$fromAddress,$feeLimit=1000000000,$callValue=0,$bandwidthLimit=0){
  72. $payload = [
  73. 'contract_address' => Address::decode($contractAddress),
  74. 'function_selector' => $functionSelector,
  75. 'parameter' => $parameter,
  76. 'owner_address' => Address::decode($fromAddress),
  77. 'fee_limit' => $feeLimit,
  78. 'call_value' => $callValue,
  79. 'consume_user_resource_percent' => $bandwidthLimit,
  80. ];
  81. return $this->fullNode->post('/wallet/triggersmartcontract', $payload);
  82. }
  83. */
  84. function getAccount($address,$confirmed=true){
  85. $payload = [
  86. 'address' => Address::decode($address)
  87. ];
  88. if($confirmed){
  89. $res = $this->fullNode->get('/wallet/getaccount',$payload);
  90. return $res;
  91. }else{
  92. return $this->solidityNode->get('/walletsolidity/getaccount',$payload);
  93. }
  94. }
  95. function getBalance($address,$confirmed=true){
  96. $accountInfo = $this->getAccount($address,$confirmed);
  97. if(!isset($accountInfo->balance)){
  98. throw new \Exception('Balance error. Maybe you should send 1.1 trx to this address to activate it.');
  99. }
  100. return $accountInfo->balance;
  101. }
  102. function getUncomfirmedBalance($address){
  103. return $this->getBalance($address,false);
  104. }
  105. function getAccountNet($address){
  106. $payload = [
  107. 'address' => Address::decode($address)
  108. ];
  109. return $this->fullNode->post('/wallet/getaccountnet',$payload);
  110. }
  111. function getBandwidth(){
  112. $args = func_get_args();
  113. return $this->getAccountNet(...$args);
  114. }
  115. function getAccountResource($address){
  116. $payload = [
  117. 'address' => Address::decode($address)
  118. ];
  119. return $this->fullNode->post('/wallet/getaccountresource',$payload);
  120. }
  121. function getContract($address){
  122. $payload = [
  123. 'value' => Address::decode($address)
  124. ];
  125. return $this->fullNode->get('/wallet/getcontract',$payload);
  126. }
  127. function getChainParameters(){
  128. return $this->fullNode->get('/wallet/getchainparameters',[]);
  129. }
  130. function getNodeInfo(){
  131. return $this->fullNode->get('/wallet/nodeinfo',[]);
  132. }
  133. function listNodes(){
  134. return $this->fullNode->get('/wallet/listnodes',[]);
  135. }
  136. //get|post?
  137. function getNowBlock($confirmed=true){
  138. if($confirmed){
  139. return $this->solidityNode->get('/walletsolidity/getnowblock',[]);
  140. }else{
  141. return $this->fullNode->get('/wallet/getnowblock',[]);
  142. }
  143. }
  144. function getCurrentBlock(){
  145. $args = func_get_args();
  146. return $this->getNowBlock(...$args);
  147. }
  148. function getBlockById($hash){
  149. $payload = [
  150. 'value' => $hash
  151. ];
  152. return $this->fullNode->post('/wallet/getblockbyid',$payload);
  153. }
  154. function getBlockByHash(){
  155. $args = func_get_args();
  156. return $this->getBlockById(...$args);
  157. }
  158. function getBlockByNum($num){
  159. $payload = [
  160. 'num' => $num
  161. ];
  162. return $this->fullNode->post('/wallet/getblockbynum',$payload);
  163. }
  164. function getBlockByNumber(){
  165. $args = func_get_args();
  166. return $this->getBlockByNum(...$args);
  167. }
  168. function getBlockByLimitNext($start,$end){
  169. $payload = [
  170. 'startNum' => $start,
  171. 'endNum' => $end
  172. ];
  173. return $this->fullNode->get('/wallet/getblockbylimitnext',$payload);
  174. }
  175. function getBlockRange(){
  176. $args = func_get_args();
  177. return $this->getBlockByLimitNext(...$args);
  178. }
  179. function getTransactionById($txid,$confirmed=true){
  180. $payload = [
  181. 'value' => $txid
  182. ];
  183. if($confirmed){
  184. return $this->solidityNode->post('/walletsolidity/gettransactionbyid',$payload);
  185. }else{
  186. return $this->fullNode->post('/wallet/gettransactionbyid',$payload);
  187. }
  188. }
  189. function getTransaction(){
  190. $args = func_get_args();
  191. return $this->gettransactionbyid(...$args);
  192. }
  193. function getConfirmedTransaction(){
  194. $args = func_get_args();
  195. return $this->getTransactionById(...$args);
  196. }
  197. function getTransactionInfoById($txid,$confirmed=true){
  198. $payload = [
  199. 'value' => $txid
  200. ];
  201. if($confirmed){
  202. return $this->solidityNode->post('/walletsolidity/gettransactioninfobyid',$payload);
  203. }else{
  204. return $this->fullNode->post('/wallet/gettransactioninfobyid',$payload);
  205. }
  206. }
  207. function getTransactionInfo(){
  208. $args = func_get_args();
  209. return $this->getTransactionInfoById(...$args);
  210. }
  211. function getUnconfirmedTransactionInfo($txid){
  212. return $this->getTransactionInfoById($txid,false);
  213. }
  214. //all|from|to
  215. function getTransactionsByAddress($address,$direction='from',$offset=0,$limit=30){
  216. $payload = [
  217. 'account' => [
  218. 'address' => Address::decode($address)
  219. ],
  220. 'offset' => $offset,
  221. 'limit' => $limit
  222. ];
  223. $api = '/walletextension/gettransactions' . $direction . 'this';
  224. return $this->solidityNode->post($api,$payload);
  225. }
  226. function getReward($address,$confirmed=true){
  227. $payload = [
  228. 'address' => Address::decode($address)
  229. ];
  230. if($confirmed){
  231. return $this->solidityNode->post('/walletsolidity/getreward',$payload);
  232. }else{
  233. return $this->fullNode->post('/wallet/getreward',$payload);
  234. }
  235. }
  236. function getUnconfirmedReward($address){
  237. return $this->getReward($address,false);
  238. }
  239. function getApprovedList($tx){
  240. return $this->fullNode->post('/wallet/getapprovedlist',$tx);
  241. }
  242. function getSignWeight($tx){
  243. return $this->fullNode->post('/wallet/getsignweight',$tx);
  244. }
  245. function listWitnesses($confirmed=true){
  246. if($confirmed){
  247. return $this->solidityNode->get('/walletsolidity/listwitnesses',[]);
  248. }else{
  249. return $this->fullNode->get('/walletsolidity/listwitnesses',[]);
  250. }
  251. }
  252. function listSuperRepresentatives(){
  253. $args = func_get_args();
  254. return $this->listWitnesses(...$args);
  255. }
  256. /*txbuilder*/
  257. function createTransaction($to,$amount,$from){
  258. $payload = [
  259. 'to_address' => Address::decode($to),
  260. 'owner_address' => Address::decode($from),
  261. 'amount' => $amount
  262. ];
  263. $ret = $this->fullNode->post('/wallet/createtransaction',$payload);
  264. return $ret;
  265. }
  266. function transferAsset($to,$asset,$amount,$from){
  267. $payload = [
  268. 'to_address' => Address::decode($to),
  269. 'asset_name' => bin2hex($asset),
  270. 'amount' => $amount,
  271. 'owner_address' => Address::decode($from)
  272. ];
  273. return $this->fullNode->post('/wallet/transferasset',$payload);
  274. }
  275. function sendAsset(){
  276. $args = func_get_args();
  277. return $this->transferAsset(...$args);
  278. }
  279. function sendToken(){
  280. $args = func_get_args();
  281. return $this->transferAsset(...$args);
  282. }
  283. function createAssetIssue($name,$abbr,$desc,$url,$supply,$trxRatio,$tokenRatio,$start,$end,$limit,$publicLimit,$frozenAmount,$frozenDays,$precision,$from){
  284. $payload = [
  285. 'name' => bin2hex($name),
  286. 'addr' => bin2hex($abbr),
  287. 'total_supply' => $supply,
  288. 'precision' => $precision,
  289. 'trx_num' => $trxRatio,
  290. 'num' => $tokenRatio,
  291. 'start_time' => $start,
  292. 'end_time' => $end,
  293. 'description' => bin2hex($desc),
  294. 'url' => bin2hex($url),
  295. 'free_asset_net_limit' => $limit,
  296. 'public_free_asset_net_limit' => $publicLimit,
  297. 'frozen_supply' => [
  298. 'frozen_amount' => $frozenAmount,
  299. 'frozen_days' => $frozenDays
  300. ],
  301. 'owner_address' => Address::decode($from)
  302. ];
  303. return $this->fullNode->post('/wallet/createassetissue',$payload);
  304. }
  305. function createToken(){
  306. $args = func_get_args();
  307. return $this->createAssetIssue(...$args);
  308. }
  309. function createAsset(){
  310. $args = func_get_args();
  311. return $this->createAssetIssue(...$args);
  312. }
  313. function updateAsset($url,$desc,$limit,$publicLimit,$from){
  314. $payload = [
  315. 'url' => bin2hex($url),
  316. 'description' => bin2hex($desc),
  317. 'new_limit' => $limit,
  318. 'new_public_limit' => $publicLimit,
  319. 'owner_address' => Address::decode($from)
  320. ];
  321. return $this->fullNode->post('/wallet/updateasset',$payload);
  322. }
  323. function updateToken(){
  324. $args = func_get_args();
  325. return $this->updateAsset(...$args);
  326. }
  327. function participateAssetIssue($to,$asset,$amount,$from){
  328. $payload = [
  329. 'to_address' => Address::decode($to),
  330. 'asset_name' => bin2hex($asset),
  331. 'amount' => $amount,
  332. 'owner_address' => Address::decode($from)
  333. ];
  334. return $this->fullNode->post('/wallet/participateassetissue',$payload);
  335. }
  336. function purchaseAsset(){
  337. $args = func_get_args();
  338. return $this->participateAssetIssue(...$args);
  339. }
  340. function purchaseToken(){
  341. $args = func_get_args();
  342. return $this->participateAssetIssue(...$args);
  343. }
  344. function getAssetIssueById($token,$confirmed=true){
  345. $payload = [
  346. 'value' => $token
  347. ];
  348. if($confirmed){
  349. return $this->solidityNode->post('/walletsolidity/getassetissuebyid',$payload);
  350. }else{
  351. return $this->fullNode->post('/wallet/getassetissuebyid',$payload);
  352. }
  353. }
  354. function getTokenById(){
  355. $args = func_get_args();
  356. return $this->getAssetIssueById(...$args);
  357. }
  358. function getAssetIssueByName($token){
  359. $payload = [
  360. 'value' => bin2hex($token)
  361. ];
  362. return $this->fullNode->post('/wallet/getassetissuebyname',$payload);
  363. }
  364. function getTokenFromId(){
  365. $args = func_get_args();
  366. return $this->getAssetIssueByName(...$args);
  367. }
  368. function getAssetIssueList(){
  369. return $this->fullNode->get('/wallet/getassetissuelist',[]);
  370. }
  371. function listTokens(){
  372. $args = func_get_args();
  373. return $this->getAssetIssueList(...$args);
  374. }
  375. function getAssetIssueListByName($token){
  376. $payload = [
  377. 'value' => bin2hex($token)
  378. ];
  379. return $this->fullNode->post('/wallet/getassetissuelistbyname',$payload);
  380. }
  381. function getTokenListByName(){
  382. $args = func_get_args();
  383. return $this->getAssetIssueListByName(...$args);
  384. }
  385. function getAssetIssueByAccount($address){
  386. $payload = [
  387. 'address' => Address::decode($address)
  388. ];
  389. return $this->fullNode->post('/wallet/getassetissuebyaccount',$payload);
  390. }
  391. function getTokenIssuedByAddress(){
  392. $args = func_get_args();
  393. return $this->getAssetIssueByAccount(...$args);
  394. }
  395. function freezeBalance($balance,$duration,$type,$from,$receiver=null){
  396. $payload = [
  397. 'freeze_balance' => $balance,
  398. 'freeze_duration' => $duration,
  399. 'resource' => $type,
  400. 'owner_address' => Address::decode($from),
  401. 'receiver_address' => Address::decode($receiver)
  402. ];
  403. return $this->fullNode->post('/wallet/freezebalance',$payload);
  404. }
  405. function unfreezeBalance($type,$from,$receiver=null){
  406. $payload = [
  407. 'resource' => $type,
  408. 'owner_address' => Address::decode($from),
  409. 'receiver' => Address::decode($receiver)
  410. ];
  411. return $this->fullNode->post('/wallet/unfreezebalance',$payload);
  412. }
  413. function withdrawBalance($address){
  414. $payload = [
  415. 'owner_address' => Address::decode($address)
  416. ];
  417. return $this->fullNode->post('/wallet/withdrawbalance',$payload);
  418. }
  419. function withdrawBlockRewards(){
  420. $args = func_get_args();
  421. return $this->withdrawBalance(...$args);
  422. }
  423. function createWitness($address,$url){
  424. $payload = [
  425. 'owner_address' => Address::decode($address),
  426. 'url' => bin2hex($url)
  427. ];
  428. return $this->fullNode->post('/wallet/createwitness',$payload);
  429. }
  430. function applyForSR(){
  431. $args = func_get_args();
  432. return $this->createWitness(...$args);
  433. }
  434. function getBrokerage($address,$confirmed=true){
  435. $payload = [
  436. 'address' => Address::decode($address)
  437. ];
  438. if($confirmed){
  439. return $this->solidityNode->post('/walletsolidity/getbrokerage',$payload);
  440. }else{
  441. return $this->fullNode->post('/wallet/getbrokerage',$payload);
  442. }
  443. }
  444. function getUncomfirmedBrokerage($address){
  445. return $this->getBrokerage($address,false);
  446. }
  447. function voteWitnessAccount($address,$votes){
  448. $payload = [
  449. 'owner_address' => Address::decode($address),
  450. 'votes' => $votes
  451. ];
  452. return $this->fullNode->post('/wallet/votewitnessaccount',$payload);
  453. }
  454. function vote(){
  455. $args = func_get_args();
  456. return $this->voteWitnessAccount(...$args);
  457. }
  458. //trc20
  459. function deployContract($abi,$bytecode,$parameter,$name,$value,$from){
  460. $payload = [
  461. 'abi' => $abi,
  462. 'bytecode' => $bytecode,
  463. 'parameter' => $parameter,
  464. 'name' => $name,
  465. 'call_value' => $value,
  466. 'owner_address' => Address::decode($from),
  467. 'fee_limit' => 1000000000,
  468. 'origin_energy_limit' => 10000000,
  469. 'consume_user_resource_percent' => 100
  470. ];
  471. return $this->fullNode->post('/wallet/deploycontract',$payload);
  472. }
  473. function createSmartContract(){
  474. $args = func_get_args();
  475. return $this->deployContract(...$args);
  476. }
  477. function triggerSmartContract($contract,$function,$parameter,$value,$from){
  478. $payload = [
  479. 'contract_address' => Address::decode($contract),
  480. 'function_selector' => $function,
  481. 'parameter' => $parameter,
  482. 'call_value' => $value,
  483. 'owner_address' => Address::decode($from),
  484. 'fee_limit' => 1000000000
  485. ];
  486. return $this->fullNode->post('/wallet/triggersmartcontract',$payload);
  487. }
  488. function triggerConstantSmartContract($contract,$function,$parameter,$value,$from,$confirmed=true){
  489. $payload = [
  490. 'contract_address' => Address::decode($contract),
  491. 'function_selector' => $function,
  492. 'parameter' => $parameter,
  493. 'call_value' => $value,
  494. 'owner_address' => Address::decode($from),
  495. 'fee_limit' => 1000000000
  496. ];
  497. if($confirmed){
  498. return $this->solidityNode->post('/walletsolidity/triggerconstantsmartcontract',$payload);
  499. }else{
  500. return $this->fullNode->post('/wallet/triggerconstantsmartcontract',$payload);
  501. }
  502. }
  503. function clearAbi($contract,$from){
  504. $payload = [
  505. 'contract_address' => Address::decode($contract),
  506. 'owner_address' => Address::decode($from)
  507. ];
  508. return $this->fullNode->post('/wallet/clearabi',$payload);
  509. }
  510. function updateSetting($contract,$userPercent,$from){
  511. $payload = [
  512. 'contract_address' => Address::decode($contract),
  513. 'consume_user_resource_percent' => $userPercent,
  514. 'owner_address' => Address::decode($from)
  515. ];
  516. return $this->fullNode->post('/wallet/updatesetting',$payload);
  517. }
  518. function updateEnergyLimit($contract,$limit,$from){
  519. $payload = [
  520. 'contract_address' => Address::decode($contract),
  521. 'origin_energy_limit' => $limit,
  522. 'owner_address' => Address::decode($from)
  523. ];
  524. return $this->fullNode->post('/wallet/updateenergylimit',$payload);
  525. }
  526. function updateBrokerage($brokerage,$from){
  527. $payload = [
  528. 'brokerage' => $brokerage,
  529. 'owner_address' => Address::decode($from)
  530. ];
  531. return $this->fullNode->post('/wallet/updatebrokerage',$payload);
  532. }
  533. function updateAccount($name,$from){
  534. $payload = [
  535. 'account_name' => bin2hex($name),
  536. 'owner_address' => Address::decode($from)
  537. ];
  538. return $this->fullNode->post('/wallet/updateaccount',$payload);
  539. }
  540. function accountPermissionUpdate($ownerPermits,$witnessPermits,$activePermits,$from){
  541. $payload = [
  542. 'owner' => $ownerPermits,
  543. 'witness' => $witnessPermits,
  544. 'active' => $activePermits,
  545. 'owner_address' => Address::decode($from)
  546. ];
  547. return $this->fullNode->post('/wallet/accountpermissionupdate',$payload);
  548. }
  549. function setAccountId($id,$from){
  550. $payload = [
  551. 'account_id' => $id,
  552. 'owner_address' => Address::decode($from)
  553. ];
  554. return $this->fullNode->post('/wallet/setaccountid',$payload);
  555. }
  556. //dex
  557. function proposalCreate($parameters,$from){
  558. $payload = [
  559. 'parameters' => $parameters,
  560. 'owner_address' => Address::decode($from)
  561. ];
  562. return $this->fullNode->post('/wallet/proposalcreate',$payload);
  563. }
  564. function createProposal(){
  565. $args = func_get_args();
  566. return $this->proposalCreate(...$args);
  567. }
  568. function listProposals(){
  569. return $this->fullNode->post('/wallet/listproposals',[]);
  570. }
  571. function proposalDelete($id,$from){
  572. $payload = [
  573. 'proposal_id' => $id,
  574. 'owner_address' => Address::decode($from)
  575. ];
  576. return $this->fullNode->post('/wallet/proposaldelete',$payload);
  577. }
  578. function deleteProposal(){
  579. $args = func_get_args();
  580. return $this->proposalDelete(...$args);
  581. }
  582. function proposalApprove($id,$from){
  583. $payload = [
  584. 'proposal_id' => $id,
  585. 'owner_address' => Address::decode($from)
  586. ];
  587. return $this->fullNode->post('/wallet/proposalapprove',$payload);
  588. }
  589. function voteProposal(){
  590. $args = func_get_args();
  591. return $this->proposalApprove(...$args);
  592. }
  593. function exchangeCreate($token1,$balance1,$token2,$balance2,$from){
  594. $payload = [
  595. 'first_token_id' => bin2hex($token1),
  596. 'first_token_balance' => $balance1,
  597. 'second_token_id' => bin2hex($token2),
  598. 'second_token_balance' => $balance2,
  599. 'owner_address' => Address::decode($from)
  600. ];
  601. return $this->fullNode->post('/wallet/exchangecreate',$payload);
  602. }
  603. function listExchanges(){
  604. return $this->fullNode->post('/wallet/listexchanges',[]);
  605. }
  606. function getPaginatedExchangeList($offset=0,$limit=30){
  607. $payload = [
  608. 'offset' => $offset,
  609. 'limit' => $limit
  610. ];
  611. return $this->fullNode->post('/wallet/getpaginatedexchangelist',$payload);
  612. }
  613. function listExchangePaginated(){
  614. $args = func_get_args();
  615. return $this->getPaginatedExchangeList(...$args);
  616. }
  617. function exchangeInject($exchange,$token,$quant,$from){
  618. $payload = [
  619. 'exchange_id' => $exchange,
  620. 'token_id' => bin2hex($token),
  621. 'quant' => $quant,
  622. 'owner_address' => Address::decode($from)
  623. ];
  624. return $this->fullNode->post('/wallet/exchangeinject',$payload);
  625. }
  626. function injectExchangeToken(){
  627. $args = func_get_args();
  628. return $this->exchangeInject(...$args);
  629. }
  630. function exchangeWithdraw($exchange,$token,$quant,$from){
  631. $payload = [
  632. 'exchange_id' => $exchange,
  633. 'token_id' => bin2hex($token),
  634. 'quant' => $quant,
  635. 'owner_address' => Address::decode($from)
  636. ];
  637. return $this->fullNode->post('/wallet/exchangewithdraw',$payload);
  638. }
  639. function withdrawExchangeTokens(){
  640. $args = func_get_args();
  641. return $this->exchangeWithdraw(...$args);
  642. }
  643. function exchangeTransaction($exchange,$token,$quant,$expected,$from){
  644. $payload = [
  645. 'exchange_id' => $exchange,
  646. 'token_id' => bin2hex($token),
  647. 'quant' => $quant,
  648. 'expected' => $expected,
  649. 'owner_address' => Address::decode($from)
  650. ];
  651. return $this->fullNode->post('/wallet/exchangetransaction',$payload);
  652. }
  653. function getExchangeById($id){
  654. $payload = [
  655. 'id' => $id
  656. ];
  657. return $this->fullNode->post('/wallet/getexchangebyid',$payload);
  658. }
  659. function tradeExchangeTokens(){
  660. $args = func_get_args();
  661. return $this->exchangeTransaction(...$args);
  662. }
  663. }