TransactionResult.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Module\Blockchain\Dto;
  3. /**
  4. * 区块链交易结果数据传输对象
  5. */
  6. class TransactionResult
  7. {
  8. /**
  9. * @var int 交易状态 1=已确认 0=未确认
  10. */
  11. public $status;
  12. /**
  13. * @var int|null 区块高度(十进制)
  14. */
  15. public $blockNumber;
  16. /**
  17. * @var string|null 消耗的Gas数量
  18. */
  19. public $gasUsed;
  20. /**
  21. * @var string|null 实际Gas价格
  22. */
  23. public $effectiveGasPrice;
  24. /**
  25. * 构造函数
  26. * @param int $status 交易状态
  27. * @param int|null $blockNumber 区块高度
  28. * @param string|null $gasUsed 消耗的Gas数量
  29. * @param string|null $effectiveGasPrice 实际Gas价格
  30. */
  31. public function __construct(
  32. int $status,
  33. ?int $blockNumber = null,
  34. ?string $gasUsed = null,
  35. ?string $effectiveGasPrice = null
  36. ) {
  37. $this->status = $status;
  38. $this->blockNumber = $blockNumber;
  39. $this->gasUsed = $gasUsed;
  40. $this->effectiveGasPrice = $effectiveGasPrice;
  41. }
  42. /**
  43. * 转换为数组
  44. * @return array
  45. */
  46. public function toArray(): array
  47. {
  48. return [
  49. 'status' => $this->status,
  50. 'blockNumber' => $this->blockNumber,
  51. 'gasUsed' => $this->gasUsed,
  52. 'effectiveGasPrice' => $this->effectiveGasPrice
  53. ];
  54. }
  55. }