Skip to content

Commit

Permalink
Fixed: bitcoin amounts over 1 btc were not being stored correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mythril committed Jun 3, 2014
1 parent 15bbb9d commit 088ec14
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion database/purchases.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS `purchases` (
`bitcoin_price` DECIMAL(16, 4) NOT NULL,

-- The amount of Bitcoin that can be purchased in relation to the amount of currency entered
`bitcoin_amount` DECIMAL(8, 8) NOT NULL DEFAULT 0.0000,
`bitcoin_amount` DECIMAL(16, 8) NOT NULL DEFAULT 0.0000,

-- The Bitcoin network TXID that establishes the transaction has happened
`txid` VARCHAR(64) NULL DEFAULT NULL,
Expand Down
2 changes: 1 addition & 1 deletion includes/Purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function getCurrencyAmount() {

private $bitcoinAmount;

public function setBitcoinAmount(Amount $amt) {
private function setBitcoinAmount(Amount $amt) {
$this->bitcoinAmount = $amt;
return $this;
}
Expand Down
16 changes: 15 additions & 1 deletion update.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

$addEmailToNotify = true;
$addNTXID = true;
$fixPrecision = true;

foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
echo $row['Field'] . "\n";
if ($row['Field'] === 'email_to_notify') {
$addEmailToNotify = false;
}
if ($row['Field'] === 'bitcoin_amount') {
if (strpos($row['Type'], '16') !== false) {
$fixPrecision = false;
}
}
if ($row['Field'] === 'ntxid') {
$addNTXID = false;
}
Expand All @@ -37,6 +42,15 @@
echo "Column 'ntxid' added.\n";
}

if ($fixPrecision) {
$db->query('
ALTER TABLE `purchases`
MODIFY COLUMN
bitcoin_amount DECIMAL(16, 8) NOT NULL DEFAULT 0.0000
');
echo "Column 'bitcoin_amount' fixed.\n";
}

$stmt = $db->query(file_get_contents(__DIR__ . '/database/jobs.sql'));

echo "update finished\n";

0 comments on commit 088ec14

Please sign in to comment.