Bep20.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace qiniu\services\blockchain\bsc;
  3. define('ABI_BEP20', file_get_contents(QINIU_PATH . 'services/blockchain/bsc/json/bep20.json'));
  4. //define('EVENTSIG_TRANSFER', '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef');
  5. class Bep20 extends SmartContract
  6. {
  7. function __construct($client, $credential, $address)
  8. {
  9. parent::__construct($client, $credential, ABI_BEP20);
  10. $this->at($address);
  11. }
  12. function getTransferEvents($from = [], $to = [], $fromBlock = 'latest', $toBlock = 'latest')
  13. {
  14. $toTopic = function ($addr) {
  15. $addr = preg_replace('/^0x/', '', $addr);
  16. return '0x' . str_pad($addr, 64, '0', STR_PAD_LEFT);
  17. };
  18. $from = array_map($toTopic, $from);
  19. $to = array_map($toTopic, $to);
  20. return $this->queryEvents([EVENTSIG_TRANSFER, $from, $to], $fromBlock, $toBlock);
  21. }
  22. function getBlockNumber()
  23. {
  24. $cb = new Callback();
  25. $this->eth->blockNumber($cb);
  26. return $cb->result->toString();
  27. }
  28. function getTransactionReceipt($tx_hash)
  29. {
  30. $cb = new Callback();
  31. $this->eth->getTransactionReceipt($tx_hash, $cb);
  32. return $cb->result;
  33. }
  34. }