public function info() { $paycoin = new PaycoinRPC(); $rpcInfo = $paycoin->getInfo(); $info = array('blocks' => $rpcInfo['blocks'], 'moneysupply' => $rpcInfo['moneysupply']); $this->outputJsonResponse($info); }
public function buildDatabase() { if (!$this->tryLock(self::LOCK_FILE)) { die("Already running.\n"); } register_shutdown_function('unlink', self::LOCK_FILE); echo 'Building Database' . PHP_EOL; $paycoinRPC = new PaycoinRPC(); $paycoinDb = new PaycoinDb(); $startBlockHeight = $paycoinDb->getLastBlockInDb(); $startBlockHeight = (int) $startBlockHeight; $endBlockHeight = $paycoinRPC->getBlockCount(); if ($startBlockHeight == $endBlockHeight) { echo "Caught up. Last block was {$endBlockHeight}" . PHP_EOL; return; } else { echo "Catching up with blockchain {$startBlockHeight} => {$endBlockHeight}" . PHP_EOL; } //@todo move this... $startBlockHeight++; $paycoinDb->buildDb($startBlockHeight, $endBlockHeight); echo "Complete" . PHP_EOL; }
public function tagging() { $this->addJs('/js/tagging.js'); $message = 'Paycoin Blockchain'; $this->setData('messageToSign', $message); $this->setData('pageTitle', 'Tag a Paycoin address'); $this->setData('success', false); if ($this->bootstrap->httpRequest->getRealMethod() == 'POST') { $address = $this->bootstrap->httpRequest->request->getAlnum('address'); $tag = $this->bootstrap->httpRequest->get('tag'); $signature = $this->bootstrap->httpRequest->request->get('signature'); $url = $this->bootstrap->httpRequest->request->get('url'); $message = 'Paycoin Blockchain'; $this->setData('messageToSign', $message); $this->setData('address', $address); $this->setData('tag', $tag); $this->setData('url', $url); $paycoinRpc = new PaycoinRPC(); $error = false; if (!empty($url)) { $pu = parse_url($url); if (empty($pu['scheme']) || empty($pu['host'])) { $error = 'Invalid URL'; } } if (empty($address)) { $error = 'Invalid Address'; } if (empty($signature)) { $error = 'Invalid Signature'; } if (empty($tag)) { $error = 'Invalid Tag'; } if (empty($error)) { $isVerified = $paycoinRpc->verifySignedMessage($address, $signature, $message); if ($isVerified === true) { $this->setData('success', true); $paycoinDb = new PaycoinDb(); $paycoinDb->addTagToAddress($address, $tag, $url, 1); } elseif ($isVerified === false) { $this->setData('error', 'Failed to Verify Message'); } elseif ($isVerified !== true) { $this->setData('error', $isVerified); } else { $this->setData('error', 'Unknown error'); } } else { $this->setData('error', $error); } } $this->setData('pageName', 'Address Tagging'); $this->render('header'); $this->render('tagging'); $this->render('footer'); }