Bep721.php 1.1 KB

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