Skip to content

Commit

Permalink
Users can generate and remove ɃTC wallet addresses.
Browse files Browse the repository at this point in the history
# v 0.0.2

-----

- Users can generate and remove ɃTC wallet addresses.

- Minor changes to DB schema

- Unbound wallet_address and wallet. Addresses are independent of a
wallet (Until  Multi-sig support implemented).

- Removed BTC Wallets.
  • Loading branch information
montraydavis committed May 14, 2017
1 parent 2cfc231 commit e6d594a
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 113 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,11 @@
# v 0.0.2

-----

- Users can generate and remove ɃTC wallet addresses.

- Minor changes to DB schema

- Unbound wallet_address and wallet. Addresses are independent of a wallet (Until Multi-sig support implemented).

- Removed BTC Wallets.
75 changes: 0 additions & 75 deletions master-dev/exchange/app/Bitcoind/BitcoinWallet.php

This file was deleted.

9 changes: 2 additions & 7 deletions master-dev/exchange/app/Bitcoind/BitcoinWalletAddress.php
Expand Up @@ -25,7 +25,7 @@ public function validator(array $data)

//Validate required Address fields
return Validator::make($data, [
'wallet_id' => 'required',
'uid' => 'required',
'wallet_address' => 'required',
'confirmations' => 'required|min:0',
'total_received' => 'required',
Expand All @@ -42,7 +42,7 @@ public function validator(array $data)
]);
}

protected $fillable = ['wallet_id', 'wallet_address', 'confirmations',
protected $fillable = ['uid', 'wallet_address', 'confirmations',
'total_received', 'total_sent', 'balance',
'unconfirmed_balance', 'final_balance', 'n_tx',
'unconfirmed_n_tx', 'final_n_tx', 'tx_url',
Expand All @@ -57,11 +57,6 @@ public function validator(array $data)

protected $hidden = [];

public function wallet()
{
return $this->hasOne('App\Bitcoind\BitcoinWallet', 'id', 'wallet_id');
}

public static function GetAddrInfo($addr)
{
return $addr_info = App\Bitcoind\BitcoindWalletAddr::where('wallet_address', $addr)->first();
Expand Down
30 changes: 9 additions & 21 deletions master-dev/exchange/app/Http/Controllers/BitcoindController.php
Expand Up @@ -31,7 +31,7 @@ public function __construct()
//Authentication Required
$this->middleware('auth');

header("Content-type: application/json");
header("Content-type: application/json");
}

/**
Expand All @@ -42,7 +42,6 @@ public function __construct()
public function GenBitcoinWalletAddress(Request $request)
{
//First require that user is authenticated
$this->middleware('auth');

$apiContext = \BlockCypher\Rest\ApiContext::create(
'test3', 'btc', 'v1', new \BlockCypher\Auth\SimpleTokenCredential(''),
Expand All @@ -61,7 +60,7 @@ public function GenBitcoinWalletAddress(Request $request)


$bwa = new \App\Bitcoind\BitcoinWalletAddress(); // Create new Ƀitcoin Wallet->Address Endpoint object
$bwa->wallet_id = 0;
$bwa->uid = \Auth::user()->id;
$bwa->wallet_address = $address->address; // Wallet->Address identifier. Not to be confused with Wallet Address.

if(sizeof($address->txrefs) > 0 ){
Expand Down Expand Up @@ -92,32 +91,21 @@ public function GenBitcoinWalletAddress_v2(){
return view('gen-address', ['address'=>$btcblock['address'], 'privatekey' => $btcblock['private'], 'publickey' => $btcblock['public'], 'privatekey_wif' => $btcblock['wif']]);
}

public function DeleteWalletAddress ($wallet_address)
public function GrabMyAddresses()
{
return \Auth::user()->BTCAddresses()->get();
}

$h = \App\Bitcoind\BitcoinWallet::find(3)->addys;

var_dump($h);



die();
public function DeleteWalletAddress ($wallet_address)
{
// Find the wallet->address bound to
$wallet_addr = \App\Bitcoind\BitcoinWalletAddress::where('wallet_address', $wallet_address)->first()->wallet;
$wallet_addr = \App\Bitcoind\BitcoinWalletAddress::where(array('uid' => \Auth::user()->id, 'wallet_address' => $wallet_address))->first();

if($wallet_addr==null){
return json_encode(array('action'=>'delete:wallet_'.$wallet_address, 'action_status'=>'fail', 'reason'=>'Wallet->Address does not exist!')); // Wallet->Address cannot be found
}

// Get the owner of the wallet
$owner = $wallet_addr->owner;

// Compare owner to logged in user
if($owner->id!=Auth::user()->id){
return json_encode(array('action'=>'delete:wallet_'.$wallet_address, 'action_status'=>'fail', 'reason'=>'Permission denied!')); // Probably does not own the wallet->address
}else{
$wallet_addr->forceDelete(); // Delete the record
}
$wallet_addr->forceDelete(); // Delete the record

return json_encode(array('action'=>'delete:wallet_'.$wallet_address, 'action_status'=>'success'));
}
Expand Down
2 changes: 1 addition & 1 deletion master-dev/exchange/app/Http/routes.php
Expand Up @@ -21,7 +21,7 @@

Route::get("/GenerateAddress", 'BitcoindController@GenBitcoinWalletAddress');

Route::get("/CreateAddress", 'BitcoindController@GenBitcoinWalletAddress_v2');
Route::get("/MyAddresses", 'BitcoindController@GrabMyAddresses');

Route::get("/{wallet_address}/Delete", 'BitcoindController@DeleteWalletAddress');
});
Expand Down
5 changes: 5 additions & 0 deletions master-dev/exchange/app/User.php
Expand Up @@ -31,4 +31,9 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*/
protected $hidden = ['password', 'remember_token'];

public function BTCAddresses() // Owner of currency
{
return $this->hasMany('App\Bitcoind\BitcoinWalletAddress', 'uid', 'id');
}

}
54 changes: 54 additions & 0 deletions master-dev/exchange/public/js/btc-apps.js
@@ -0,0 +1,54 @@
var app = angular.module("btcApps", []).config(function($interpolateProvider){$interpolateProvider.startSymbol('{[{').endSymbol('}]}');});
app.controller("btcappsController", function($scope) {

$scope.walletAddresses = [];

$scope.lock = false;


$scope.disableInput = (function(){
$(".generate-waddress-button").prop('disabled', true);
$(".delete-waddress-button").prop('disabled', true);
$(".generate-waddress-button").stop(1);
$(".generate-waddress-button").fadeOut(1000, function(){
$(".generate-waddress-button").prop('disabled', false);
$(".delete-waddress-button").prop('disabled', false);
});
})

$scope.enableInput = (function(){
$(".generate-waddress-button").prop('disabled', false);
$(".delete-waddress-button").prop('disabled', false);
$(".generate-waddress-button").fadeIn(1000);
})


generateWalletAddress = (function(){
$scope.disableInput();
$.get("/exchange/public/index.php/Bitcoind/Wallet/GenerateAddress", function(data){
grabMyAddresses();
$scope.enableInput();
});
});

$scope.deleteWalletAddress = (function(address){
$scope.disableInput();
$.get("/exchange/public/index.php/Bitcoind/Wallet/"+address+"/Delete", function(data){
grabMyAddresses();
$scope.enableInput();
});
});

grabMyAddresses = (function(){
$scope.disableInput();
$.get("/exchange/public/index.php/Bitcoind/Wallet/MyAddresses", function(data){

$scope.walletAddresses = data;
$scope.enableInput();
$scope.$apply();
});
});

grabMyAddresses();

});
@@ -0,0 +1,15 @@
<button class="generate-waddress-button button button-primary" onclick="generateWalletAddress()">Generate address</button><br /><br />
<table class="table table-bordered" ng-controller="btcappsController">
<thead>
<tr>
<th>Address</th>
<th>Balance</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="walletAddress in walletAddresses">
<td>{[{ walletAddress.wallet_address }]} <button class="button button-danger delete-waddress-button" ng-click="deleteWalletAddress(walletAddress.wallet_address)">Delete</button></td>
<td><small>Ƀ</small>{[{ walletAddress.final_balance }]}<small></small> </td>
</tr>
</tbody>
</table>
5 changes: 3 additions & 2 deletions master-dev/exchange/resources/views/app.blade.php
Expand Up @@ -20,13 +20,14 @@
<!-- JQUERY / BOOTSTRAP CDN -->
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js"></script>


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css" />


<!-- Private Key Mini-App -->
<script src="{{ asset('/js/hide-passphrase.js') }}"></script>

<script src="{{ asset('/js/btc-apps.js') }}"></script>
<![endif]-->
</head>
<body>
Expand Down
8 changes: 4 additions & 4 deletions master-dev/exchange/resources/views/home.blade.php
Expand Up @@ -30,7 +30,7 @@
<li class="active"><a data-toggle="tab" href="#home">Overview</a></li>
<li><a data-toggle="tab" href="#menu1">Trade</a></li>
<li><a data-toggle="tab" href="#menu2">Funding</a></li>
<li><a data-toggle="tab" href="#menu3">Security</a></li>
<li><a data-toggle="tab" href="#menu3">Bitcoin</a></li>
</ul>
</div>
<div class="panel-body">
Expand All @@ -53,9 +53,9 @@
<div id="menu2" class="tab-pane fade">
@include('account.linked-payments')
</div>
<div id="menu3" class="tab-pane fade">
<h3>Menu 3</h3>
<p>Some content in menu 3.</p>
<div id="menu3" class="tab-pane fade" ng-app="btcApps">
<h3>Ƀitcoin Addresses</h3>
@include('account.btc-addresses')
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions master-dev/exchange/resources/views/welcome.blade.php
@@ -1,6 +1,6 @@
<html>
<head>
<title>Laravel</title>
<title>ZenX Exchange</title>

<link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>

Expand Down Expand Up @@ -40,8 +40,8 @@
<body>
<div class="container">
<div class="content">
<div class="title">Laravel 5</div>
<div class="quote">{{ Inspiring::quote() }}</div>
<div class="title">ZenX</div>
<div class="quote"><a href="index.php/home">View Exchange</a></div>
</div>
</div>
</body>
Expand Down

0 comments on commit e6d594a

Please sign in to comment.