mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
sql: add bookmarks table and link to wallet
This commit is contained in:
parent
3e0c13a2bd
commit
ad89a55256
7 changed files with 232 additions and 4 deletions
18
sql/2016-05-23-bookmarks.sql
Normal file
18
sql/2016-05-23-bookmarks.sql
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
-- Recent additions to add after db init (.gz)
|
||||||
|
-- mysql yaamp -p < file.sql
|
||||||
|
|
||||||
|
CREATE TABLE `bookmarks` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`idcoin` int(11) NOT NULL,
|
||||||
|
`label` varchar(32) NULL,
|
||||||
|
`address` varchar(128) NOT NULL,
|
||||||
|
`lastused` int(10) UNSIGNED NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
-- KEYS
|
||||||
|
|
||||||
|
ALTER TABLE `bookmarks`
|
||||||
|
ADD KEY `bookmarks_coin` (`idcoin`);
|
||||||
|
|
||||||
|
ALTER TABLE `bookmarks` ADD CONSTRAINT fk_bookmarks_coin FOREIGN KEY (`idcoin`)
|
||||||
|
REFERENCES coins (`id`) ON DELETE CASCADE;
|
33
web/yaamp/models/db_bookmarksModel.php
Normal file
33
web/yaamp/models/db_bookmarksModel.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class db_bookmarks extends CActiveRecord
|
||||||
|
{
|
||||||
|
public static function model($className=__CLASS__)
|
||||||
|
{
|
||||||
|
return parent::model($className);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tableName()
|
||||||
|
{
|
||||||
|
return 'bookmarks';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relations()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attributeLabels()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,11 @@ class MarketController extends CommonController
|
||||||
if(!$this->admin) return;
|
if(!$this->admin) return;
|
||||||
|
|
||||||
$market = getdbo('db_markets', getiparam('id'));
|
$market = getdbo('db_markets', getiparam('id'));
|
||||||
|
if(!$market) {
|
||||||
|
user()->setFlash('error', "invalid market");
|
||||||
|
$this->goback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
$coin = getdbo('db_coins', $market->coinid);
|
$coin = getdbo('db_coins', $market->coinid);
|
||||||
|
|
||||||
if(isset($_POST['db_markets']))
|
if(isset($_POST['db_markets']))
|
||||||
|
@ -46,6 +51,11 @@ class MarketController extends CommonController
|
||||||
if(!$this->admin) return;
|
if(!$this->admin) return;
|
||||||
|
|
||||||
$market = getdbo('db_markets', getiparam('id'));
|
$market = getdbo('db_markets', getiparam('id'));
|
||||||
|
if(!$market) {
|
||||||
|
user()->setFlash('error', "invalid market");
|
||||||
|
$this->goback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
$coin = getdbo('db_coins', $market->coinid);
|
$coin = getdbo('db_coins', $market->coinid);
|
||||||
$amount = getparam('amount');
|
$amount = getparam('amount');
|
||||||
|
|
||||||
|
@ -72,6 +82,9 @@ class MarketController extends CommonController
|
||||||
{
|
{
|
||||||
user()->setFlash('error', $remote->error);
|
user()->setFlash('error', $remote->error);
|
||||||
$this->redirect(array('site/coin', 'id'=>$coin->id));
|
$this->redirect(array('site/coin', 'id'=>$coin->id));
|
||||||
|
} else {
|
||||||
|
$market->lastsent = time();
|
||||||
|
$market->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$exchange = new db_exchange;
|
$exchange = new db_exchange;
|
||||||
|
|
|
@ -172,6 +172,94 @@ class SiteController extends CommonController
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public function actionBookmarkAdd()
|
||||||
|
{
|
||||||
|
if(!$this->admin) return;
|
||||||
|
$coin = getdbo('db_coins', getiparam('id'));
|
||||||
|
if ($coin) {
|
||||||
|
$bookmark = new db_bookmarks;
|
||||||
|
$bookmark->isNewRecord = true;
|
||||||
|
$bookmark->idcoin = $coin->id;
|
||||||
|
if (isset($_POST['db_bookmarks'])) {
|
||||||
|
$bookmark->setAttributes($_POST['db_bookmarks'], false);
|
||||||
|
if($bookmark->save())
|
||||||
|
$this->redirect(array('/site/coin', 'id'=>$coin->id));
|
||||||
|
}
|
||||||
|
$this->render('bookmark', array('bookmark'=>$bookmark, 'coin'=>$coin));
|
||||||
|
} else {
|
||||||
|
$this->goback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionBookmarkDel()
|
||||||
|
{
|
||||||
|
if(!$this->admin) return;
|
||||||
|
$bookmark = getdbo('db_bookmarks', getiparam('id'));
|
||||||
|
if ($bookmark) {
|
||||||
|
$bookmark->delete();
|
||||||
|
}
|
||||||
|
$this->goback();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionBookmarkEdit()
|
||||||
|
{
|
||||||
|
if(!$this->admin) return;
|
||||||
|
$bookmark = getdbo('db_bookmarks', getiparam('id'));
|
||||||
|
if($bookmark) {
|
||||||
|
$coin = getdbo('db_coins', $bookmark->idcoin);
|
||||||
|
if ($coin && isset($_POST['db_bookmarks'])) {
|
||||||
|
$bookmark->setAttributes($_POST['db_bookmarks'], false);
|
||||||
|
if($bookmark->save())
|
||||||
|
$this->redirect(array('/site/coin', 'id'=>$coin->id));
|
||||||
|
}
|
||||||
|
$this->render('bookmark', array('bookmark'=>$bookmark, 'coin'=>$coin));
|
||||||
|
} else {
|
||||||
|
user()->setFlash('error', "invalid bookmark");
|
||||||
|
$this->goback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionBookmarkSend()
|
||||||
|
{
|
||||||
|
if(!$this->admin) return;
|
||||||
|
|
||||||
|
$bookmark = getdbo('db_bookmarks', getiparam('id'));
|
||||||
|
if($bookmark) {
|
||||||
|
$coin = getdbo('db_coins', $bookmark->idcoin);
|
||||||
|
$amount = getparam('amount');
|
||||||
|
|
||||||
|
$remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
|
||||||
|
|
||||||
|
$info = $remote->getinfo();
|
||||||
|
if(!$info || !$info['balance']) return false;
|
||||||
|
|
||||||
|
$deposit_info = $remote->validateaddress($bookmark->address);
|
||||||
|
if(!$deposit_info || !isset($deposit_info['isvalid']) || !$deposit_info['isvalid']) {
|
||||||
|
user()->setFlash('error', "invalid address for {$coin->name}, {$bookmark->address}");
|
||||||
|
$this->redirect(array('site/coin', 'id'=>$coin->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
$amount = min($amount, $info['balance'] - $info['paytxfee']);
|
||||||
|
$amount = round($amount, 8);
|
||||||
|
|
||||||
|
$tx = $remote->sendtoaddress($bookmark->address, $amount);
|
||||||
|
if(!$tx) {
|
||||||
|
debuglog("unable to send $amount {$coin->symbol} to bookmark {$bookmark->address}");
|
||||||
|
debuglog($remote->error);
|
||||||
|
user()->setFlash('error', $remote->error);
|
||||||
|
$this->redirect(array('site/coin', 'id'=>$coin->id));
|
||||||
|
} else {
|
||||||
|
debuglog("sent $amount {$coin->symbol} to bookmark {$bookmark->address}");
|
||||||
|
$bookmark->lastused = time();
|
||||||
|
$bookmark->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->redirect(array('site/coin', 'id'=>$coin->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
|
||||||
public function actionConsole()
|
public function actionConsole()
|
||||||
{
|
{
|
||||||
if(!$this->admin) return;
|
if(!$this->admin) return;
|
||||||
|
|
28
web/yaamp/modules/site/bookmark.php
Normal file
28
web/yaamp/modules/site/bookmark.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Edit bookmark address
|
||||||
|
|
||||||
|
echo "<a href='/site/coin?id={$coin->id}'>{$coin->name}</a> ";
|
||||||
|
echo "Bookmark: $bookmark->label<br>";
|
||||||
|
|
||||||
|
$this->widget('UniForm');
|
||||||
|
|
||||||
|
echo CUFHtml::beginForm();
|
||||||
|
echo CUFHtml::errorSummary($bookmark);
|
||||||
|
echo CUFHtml::openTag('fieldset', array('class'=>'inlineLabels'));
|
||||||
|
|
||||||
|
echo CUFHtml::openActiveCtrlHolder($bookmark, 'label');
|
||||||
|
echo CUFHtml::activeLabelEx($bookmark, 'label');
|
||||||
|
echo CUFHtml::activeTextField($bookmark, 'label', array('maxlength'=>32));
|
||||||
|
echo "<p class='formHint2'>.</p>";
|
||||||
|
echo CUFHtml::closeCtrlHolder();
|
||||||
|
|
||||||
|
echo CUFHtml::openActiveCtrlHolder($bookmark, 'address');
|
||||||
|
echo CUFHtml::activeLabelEx($bookmark, 'address');
|
||||||
|
echo CUFHtml::activeTextField($bookmark, 'address', array('maxlength'=>128));
|
||||||
|
echo "<p class='formHint2'>.</p>";
|
||||||
|
echo CUFHtml::closeCtrlHolder();
|
||||||
|
|
||||||
|
echo CUFHtml::closeTag('fieldset');
|
||||||
|
showSubmitButton('Save');
|
||||||
|
echo CUFHtml::endForm();
|
|
@ -114,7 +114,7 @@ function main_error()
|
||||||
main_timeout = setTimeout(main_refresh, main_delay*2);
|
main_timeout = setTimeout(main_refresh, main_delay*2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showSellAmountDialog(marketid, marketname, address)
|
function showSellAmountDialog(marketname, address, marketid, bookmarkid)
|
||||||
{
|
{
|
||||||
$("#dlgaddr").html(address);
|
$("#dlgaddr").html(address);
|
||||||
$("#sell-amount-dialog").dialog(
|
$("#sell-amount-dialog").dialog(
|
||||||
|
@ -130,7 +130,10 @@ function showSellAmountDialog(marketid, marketname, address)
|
||||||
"Send / Sell": function()
|
"Send / Sell": function()
|
||||||
{
|
{
|
||||||
amount = $('#input_sell_amount').val();
|
amount = $('#input_sell_amount').val();
|
||||||
window.location.href = '/market/sellto?id='+marketid+'&amount='+amount;
|
if (marketid > 0)
|
||||||
|
window.location.href = '/market/sellto?id='+marketid+'&amount='+amount;
|
||||||
|
else
|
||||||
|
window.location.href = '/site/bookmarkSend?id='+bookmarkid+'&amount='+amount;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,6 +34,8 @@ echo ", ".CHtml::link($reserved1, "/site/payments?id=".$coin->id)." $symbol clea
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
$bookmarkAdd = CHtml::link('+', "/site/bookmarkAdd?id=".$coin->id, array('title'=>'Add a bookmark'));
|
||||||
|
|
||||||
echo <<<end
|
echo <<<end
|
||||||
<div id="markets">
|
<div id="markets">
|
||||||
<table class="dataGrid">
|
<table class="dataGrid">
|
||||||
|
@ -48,7 +50,7 @@ echo <<<end
|
||||||
<th width="100">Traded</th>
|
<th width="100">Traded</th>
|
||||||
<th width="40">Late</th>
|
<th width="40">Late</th>
|
||||||
<th align="center" width="500">Message</th>
|
<th align="center" width="500">Message</th>
|
||||||
<th align="right" width="100">Actions</th>
|
<th align="right" width="100">{$bookmarkAdd} Actions</th>
|
||||||
</tr></thead><tbody>
|
</tr></thead><tbody>
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -84,7 +86,7 @@ foreach($list as $market)
|
||||||
echo CHtml::link(
|
echo CHtml::link(
|
||||||
YAAMP_ALLOW_EXCHANGE ? "sell" : "send",
|
YAAMP_ALLOW_EXCHANGE ? "sell" : "send",
|
||||||
"javascript:;", array(
|
"javascript:;", array(
|
||||||
'onclick'=>"return showSellAmountDialog({$market->id}, $name, $addr);"
|
'onclick'=>"return showSellAmountDialog($name, $addr, {$market->id});"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
echo ' '.$market->deposit_address;
|
echo ' '.$market->deposit_address;
|
||||||
|
@ -120,6 +122,49 @@ foreach($list as $market)
|
||||||
echo "</tr>";
|
echo "</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// in the list after the markets, made for quick send between wallets
|
||||||
|
$list = getdbolist('db_bookmarks', "idcoin={$coin->id} ORDER BY lastused DESC");
|
||||||
|
|
||||||
|
foreach($list as $bookmark)
|
||||||
|
{
|
||||||
|
echo '<tr class="ssrow bookmark">';
|
||||||
|
|
||||||
|
echo '<td><b>'.$bookmark->label.'<b></td>';
|
||||||
|
echo '<td></td>';
|
||||||
|
echo '<td></td>';
|
||||||
|
|
||||||
|
echo '<td>';
|
||||||
|
if (!empty($bookmark->address)) {
|
||||||
|
$name = CJavaScript::encode($bookmark->label);
|
||||||
|
$addr = CJavaScript::encode($bookmark->address);
|
||||||
|
echo CHtml::link(
|
||||||
|
"send",
|
||||||
|
"javascript:;", array(
|
||||||
|
'onclick'=>"return showSellAmountDialog($name, $addr, 0, {$bookmark->id});"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
echo ' '.$bookmark->address;
|
||||||
|
}
|
||||||
|
echo ' <a href="/site/bookmarkEdit?id='.$bookmark->id.'">edit</a>';
|
||||||
|
echo '</td>';
|
||||||
|
|
||||||
|
echo '<td></td>';
|
||||||
|
echo '<td></td>';
|
||||||
|
|
||||||
|
$sent = datetoa2($bookmark->lastused);
|
||||||
|
echo '<td>'.(empty($sent) ? "" : "$sent ago").'</td>';
|
||||||
|
echo '<td></td>';
|
||||||
|
echo '<td></td>';
|
||||||
|
|
||||||
|
echo '<td align="center"></td>';
|
||||||
|
|
||||||
|
echo '<td align="right">';
|
||||||
|
echo '<a class="red" href="/site/bookmarkDel?id='.$bookmark->id.'">delete</a>';
|
||||||
|
echo '</td>';
|
||||||
|
|
||||||
|
echo "</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
echo "</tbody></table></div>";
|
echo "</tbody></table></div>";
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Reference in a new issue