fork download
  1. <?php
  2. ini_set('display_errors',1);
  3. ini_set('display_startup_errors',1);
  4. require_once('ethereum-php/ethereum.php');
  5.  
  6. // Create a new object
  7. $ethereum = new Ethereum('127.0.0.1', 8545);
  8.  
  9. echo "Starting functions.";
  10. // This function will convert our data into hex for the transaction
  11. function hexCon($data) {
  12. $prefix = '0x';
  13. $suffix = bin2hex($data);
  14. return $prefix . $suffix;
  15. }
  16.  
  17. // Use these to ABI encode variables to pass into ethereum network--hex + pad
  18. function encString($string) {
  19. $encString = bin2hex($string);
  20. $padTo = (strlen($encString) + (32 - (strlen($encString) % 32)))
  21. $fullString = str_pad($encString, $padTo, "0");
  22. return $fullString;
  23. }
  24. function encStatic($static) {
  25. $encStatic = bin2hex((string)$static);
  26. $padTo = (strlen($encStatic) + (32 - (strlen($encStatic) % 32)))
  27. $fullStatic = str_pad($encStatic, $padTo, "0", STR_PAD_LEFT);
  28. return $fullStatic;
  29. }
  30.  
  31. echo "Declaring variables.";
  32. // We grab any and all passed variables for edit/new of listing/vendor
  33. // if (isset($_POST['create'])) { $create = $_POST['create']; }
  34. // else { echo "No input was received."; die; }
  35. // if (isset($_POST['action'])) { $action = $_POST['action']; }
  36. // else { echo "No input was received."; die; }
  37. if (isset($_POST['title'])) $title = $_POST['title'];
  38. else $title = "";
  39. if (isset($_POST['description'])) $description = $_POST['description'];
  40. else $description = "";
  41. if (isset($_POST['images'])) $images = $_POST['images'];
  42. else $images = "";
  43. if (isset($_POST['keywords'])) $keywords = $_POST['keywords'];
  44. else $keywords = "";
  45. if (isset($_POST['price'])) $price = $_POST['price'];
  46. else $price = "";
  47. if (isset($_POST['commission'])) $commission = $_POST['commission'];
  48. else $commission = "";
  49. if (isset($_POST['payAddress'])) $payAddress = $_POST['payAddress'];
  50. else $payAddress = "";
  51. if (isset($_POST['vendorAddress'])) $vendorAddress = $_POST['vendorAddress'];
  52. else $vendorAddress = "";
  53. if (isset($_POST['name'])) $name = $_POST['name'];
  54. else $name = "";
  55. if (isset($_POST['profile'])) $profile = $_POST['profile'];
  56. else $profile = "";
  57. if (isset($_POST['vendorPage'])) $vendorPage = $_POST['vendorPage'];
  58. else $vendorPage = "";
  59. if (isset($_POST['listingPage'])) $listingPage = $_POST['listingPage'];
  60. else $listingPage = "";
  61.  
  62. $listingCreator = "0xec8ae771d2e99e7a700af32acb14908031873e5a";
  63. $vendorCreator = "0x88b2f9e698ddaad14cc52b0bdb4c82fb880aa3c8";
  64.  
  65. echo "Made it this far.";
  66. $header = "";
  67. $data = "";
  68. // Decide which action user is taking. Takes in variables, converts to ABI, creates tx, and sends to creator contract
  69. if ($create == "listing" && $action == "edit") {
  70. //$data = "($title,$description,$images,$price,$commission)";
  71. // ABI-encoding sucks. 5 lines of header, 1 to describe each dynamic, at least 1 for each dynamic, 1 for each static
  72. $header = encStatic(5*32) . encStatic(6*32+strlen(encString($title))) . encStatic(7*32+strlen(encString($title))+strlen(encString($description))) . encStatic($price) . encStatic($commission);
  73. // Body just adds the dynamic information
  74. $body = encStatic(strlen($title)) . encString($title) . encStatic(strlen($description)) . encString($description) . encStatic(strlen($images)) . encString($images);
  75. $data = $header . $body;
  76. echo $data;
  77. $transaction = new Ethereum_Message("0xf63dfaee6fc634ec46cf8f776e525a6a400189ak", $listingPage, "0x61ce825d" . $data);
  78. $ethereum->eth_sendFunction($transaction);
  79. echo "yep, done";
  80. } elseif ($create == "listing" && $action == "new") {
  81. $data = "($title,$description,$keywords,$images,$price,$payAddress,$commission,$vendorAddress,$vendorName)";
  82. $transaction = new Ethereum_Message("0xf63dfaee6fc634ec46cf8f776e525a6a400189ak", $listingCreator, "0x522e117700000000000000000000000000000000");
  83. $ethereum->eth_sendFunction($transaction);
  84. } elseif ($create == "vendor" && $action == "edit") {
  85. $data = "($vendorAddress,$name,$profile,$images,$payAddress)";
  86. $transaction = new Ethereum_Message("0xf63dfaee6fc634ec46cf8f776e525a6a400189ak", $vendorPage, "0x522e117700000000000000000000000000000000");
  87. $ethereum->eth_sendFunction($transaction);
  88. } elseif ($create == "vendor" && $action == "new") {
  89. $data = "($name,$profile,$images,$payAddress,$vendorAddress)";
  90. $transaction = new Ethereum_Message("0xf63dfaee6fc634ec46cf8f776e525a6a400189ak", $vendorCreator, "0x522e117700000000000000000000000000000000");
  91. $ethereum->eth_sendFunction($transaction);
  92. }
  93.  
  94. echo "Creation/edit complete!";
  95. ?>
Runtime error #stdin #stdout #stderr 0.01s 83264KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Parse error:  syntax error, unexpected '$fullString' (T_VARIABLE) in /home/ehhWLv/prog.php on line 22