BlockchainServiceInterface.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Module\Blockchain\Contracts;
  3. use App\Module\Blockchain\Dto\TransactionStatus;
  4. use App\Module\Transaction\Enums\ACCOUNT_TYPE;
  5. interface BlockchainServiceInterface
  6. {
  7. /**
  8. * 获取代币余额
  9. *
  10. * @param string $address 钱包地址
  11. * @param ACCOUNT_TYPE $tokenType 代币类型
  12. * @return float 余额
  13. */
  14. public function getBalance(string $address, ACCOUNT_TYPE $tokenType): float;
  15. /**
  16. * 验证地址是否有效
  17. *
  18. * @param string $address 钱包地址
  19. * @return bool
  20. */
  21. public function isValidAddress(string $address): bool;
  22. /**
  23. * 获取交易状态
  24. *
  25. * @param string $txHash 交易哈希
  26. * @return array{
  27. * status: int,
  28. * blockNumber: ?int,
  29. * gasUsed: ?string,
  30. * effectiveGasPrice: ?string
  31. * }
  32. */
  33. public function getTransactionStatus(string $txHash): TransactionStatus;
  34. /**
  35. * 获取交易收据
  36. *
  37. * @param string $txHash 交易哈希
  38. * @return array 交易收据详情
  39. */
  40. public function getTransactionReceipt(string $txHash): array;
  41. /**
  42. * 估算Gas费用
  43. *
  44. * @param string $from 发送地址
  45. * @param string $to 接收地址
  46. * @param ACCOUNT_TYPE $tokenType 代币类型
  47. * @param float $amount 金额
  48. * @return float Gas费用(BNB)
  49. */
  50. public function estimateGasFee(string $from, string $to, ACCOUNT_TYPE $tokenType, float $amount): float;
  51. /**
  52. * 获取交易历史
  53. *
  54. * @param string $address 钱包地址
  55. * @param ACCOUNT_TYPE $tokenType 代币类型
  56. * @param int $page 页码
  57. * @param int $limit 每页数量
  58. * @return array 交易历史列表
  59. */
  60. public function getTransactionHistory(string $address, ACCOUNT_TYPE $tokenType, int $page = 1, int $limit = 10): array;
  61. }