TransactionFormatter.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * This file is part of web3.php package.
  4. *
  5. * (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
  6. *
  7. * @author Peter Lai <alk03073135@gmail.com>
  8. * @license MIT
  9. */
  10. namespace blockchain\web3\src\Formatters;
  11. use InvalidArgumentException;
  12. use blockchain\web3\src\Utils;
  13. use blockchain\web3\src\Formatters\IFormatter;
  14. use blockchain\web3\src\Formatters\HexFormatter;
  15. use blockchain\web3\src\Formatters\QuantityFormatter;
  16. class TransactionFormatter implements IFormatter
  17. {
  18. /**
  19. * format
  20. *
  21. * @param mixed $value
  22. * @return string
  23. */
  24. public static function format($value)
  25. {
  26. if (isset($value['gas'])) {
  27. $value['gas'] = QuantityFormatter::format($value['gas']);
  28. }
  29. if (isset($value['gasPrice'])) {
  30. $value['gasPrice'] = QuantityFormatter::format($value['gasPrice']);
  31. }
  32. if (isset($value['value'])) {
  33. $value['value'] = QuantityFormatter::format($value['value']);
  34. }
  35. if (isset($value['data'])) {
  36. $value['data'] = HexFormatter::format($value['data']);
  37. }
  38. if (isset($value['nonce'])) {
  39. $value['nonce'] = QuantityFormatter::format($value['nonce']);
  40. }
  41. return $value;
  42. }
  43. }