Created
February 1, 2013 18:03
-
-
Save xqus/4692966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require '../vendor/autoload.php'; | |
require '../TwigView.php'; | |
$app = new \Slim\Slim( | |
array('view' => 'TwigView') | |
); | |
/** | |
* Configuration options. | |
*/ | |
$app->rpc = 'http://rpc:rpc-password-1337@localhost:8332'; | |
$app->dataDir = dirname(__DIR__).'/data'; | |
$psl = new phpSec\Core(); | |
$psl->dataDir = $app->dataDir; | |
$psl['store'] = $psl->share(function($psl) { | |
return new phpSec\Store\File($psl->dataDir, $psl); | |
}); | |
$sessionStarted = $psl['session']; | |
/** | |
* Hook to read profile data. | |
*/ | |
$app->hook('slim.before.router', function () use ($app) { | |
$app->user['store'] = json_decode(file_get_contents($app->dataDir.'/profile.json'), true); | |
$app->user['store']['lastSeen'] = time(); | |
}); | |
/** | |
* Hook to write profile data. | |
*/ | |
$app->hook('slim.after', function () use ($app) { | |
$jsonData = json_encode($app->user['store'], JSON_PRETTY_PRINT); | |
$fp = fopen($app->dataDir.'/profile.json', 'w'); | |
fwrite($fp, $jsonData); | |
fclose($fp); | |
}); | |
/** | |
* Hook to display common data in template. | |
*/ | |
$app->hook('slim.before.dispatch', function () use ($app) { | |
$view = $app->view(); | |
$bitcoind = new \Nbobtc\Bitcoind\Bitcoind(new \Nbobtc\Bitcoind\Client($app->rpc)); | |
$getInfo = $bitcoind->getinfo(); | |
$view->setData('balance', $getInfo->balance); | |
$view->setData('walletStatus', $getInfo->unlocked_until); | |
}); | |
/** | |
* Route: / | |
*/ | |
$app->get('/', function() use($app) { | |
$app->render('index.html', array()); | |
}); | |
/** | |
* Route: /unlock (GET) | |
*/ | |
$app->get('/unlock', function() use($app) { | |
$app->render('unlock.html', array()); | |
}); | |
/** | |
* Route: /unlock (POST) | |
*/ | |
$app->post('/unlock', function() use($app) { | |
$bitcoind = new \Nbobtc\Bitcoind\Bitcoind(new \Nbobtc\Bitcoind\Client($app->rpc)); | |
try { | |
$bitcoind->walletpassphrase($_POST['password'], 120); | |
$app->response()->redirect('/', 302); | |
} catch(Exception $e) { | |
$app->flash('error', $e->getMessage()); | |
$app->redirect('/unlock'); | |
} | |
}); | |
/** | |
* Route: /lock | |
*/ | |
$app->get('/lock', function() use($app) { | |
$bitcoind = new \Nbobtc\Bitcoind\Bitcoind(new \Nbobtc\Bitcoind\Client($app->rpc)); | |
$bitcoind->walletlock(); | |
$app->response()->redirect('/', 302); | |
}); | |
/** | |
* Route: /addresses (GET) | |
*/ | |
$app->get('/addresses', function() use($app) { | |
$app->render('addresses.html', array('addresses' => $app->user['store']['addr'])); | |
}); | |
/** | |
* Route: /addresses (POST) | |
*/ | |
$app->post('/addresses', function() use($app) { | |
$bitcoind = new \Nbobtc\Bitcoind\Bitcoind(new \Nbobtc\Bitcoind\Client($app->rpc)); | |
$addr = $bitcoind->validateaddress($_POST['address']); | |
if($addr->result->isvalid) { | |
$app->user['store']['addr'][$_POST['address']] = $_POST['label']; | |
$app->flash('success', 'Address saved.'); | |
$app->redirect('/addresses'); | |
} else { | |
$app->flash('error', 'Invalid Bitcoin address.'); | |
$app->redirect('/addresses'); | |
} | |
}); | |
/** | |
* Route: /send (GET) | |
*/ | |
$app->get('/send', function() use($app) { | |
$app->render('send.html', array()); | |
}); | |
/** | |
* Run application. UP UP AND AWAAAAY! | |
*/ | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment