Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added Ethereum support - Removed some unnecessary code
- Loading branch information
1 parent
767b984
commit 8608d9a
Showing
12 changed files
with
281 additions
and
16 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
master-dev/exchange/app/Ethereumd/EthereumWalletAddress.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php namespace App\Ethereumd; | ||
|
||
use Illuminate\Auth\Authenticatable; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; | ||
|
||
class EthereumWalletAddress extends Model { | ||
|
||
use Authenticatable; | ||
|
||
/** | ||
* The database table used by the model. | ||
* | ||
* @var string | ||
*/ | ||
public $table = 'eth-wallet_addresses'; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
public function validator(array $data) | ||
{ | ||
|
||
//Validate required Address fields | ||
return Validator::make($data, [ | ||
'uid' => 'required', | ||
'wallet_address' => 'required', | ||
'confirmations' => 'required|min:0', | ||
'total_received' => 'required', | ||
'total_sent' => 'required', | ||
'balance' => 'required', | ||
'unconfirmed_balance' => 'required', | ||
'final_balance' => 'required', | ||
'n_tx' => 'required', | ||
'unconfirmed_n_tx' => 'required', | ||
'final_n_tx' => 'required', | ||
'tx_url' => 'required', | ||
'tx_hash' => 'required', | ||
'updated_at' => 'required' | ||
]); | ||
} | ||
|
||
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', | ||
'tx_hash', 'updated_at', 'used']; | ||
|
||
/** | ||
* The attributes excluded from the model's JSON form. | ||
* | ||
* @var array | ||
*/ | ||
|
||
|
||
protected $hidden = []; | ||
|
||
public static function GetAddrInfo($addr) | ||
{ | ||
return $addr_info = App\Bitcoind\EthereumWalletAddr::where('wallet_address', $addr)->first(); | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php namespace App\Exchange\Currencies; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
// Ƀitcoin to USD | ||
class BTC_USD extends \App\Exchange\BaseCurrency { | ||
|
||
/** | ||
* The database table used by the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'eth-usd_orders'; | ||
|
||
} |
This file contains 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
109 changes: 109 additions & 0 deletions
109
master-dev/exchange/app/Http/Controllers/EthereumdController.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
|
||
//use BlockCypher\Api\Wallet; | ||
use BlockCypher\Client\AddressClient; | ||
use BlockCypher\Auth\SimpleTokenCredential; | ||
use BlockCypher\Rest\ApiContext; | ||
use Illuminate\Http\Request; | ||
use App\Ethereumd; | ||
//use BlockCypher\Client\WalletClient; | ||
|
||
class EthereumdController extends \App\Http\Controllers\Controller { | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Ethereumd Controller | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This controller contains most of the Ethereum(wallet) functionality. | ||
| | ||
*/ | ||
|
||
/** | ||
* Initialize Wallet. | ||
* | ||
*/ | ||
public function __construct() | ||
{ | ||
//Authentication Required | ||
$this->middleware('auth'); | ||
|
||
header("Content-type: application/json"); | ||
} | ||
|
||
/** | ||
* Wallet Funds Management | ||
* | ||
* These set of functions handle tasks such as Wallet Creation, Balance Inqueries, and other useful tasks specific to the Ethereum Wallet. | ||
*/ | ||
public function GenEthereumWalletAddress(Request $request) | ||
{ | ||
//First require that user is authenticated | ||
|
||
$apiContext = \BlockCypher\Rest\ApiContext::create( | ||
'test', 'beth', 'v1', new \BlockCypher\Auth\SimpleTokenCredential(''), | ||
array('log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG') | ||
); | ||
|
||
$addressClient = new \BlockCypher\Client\AddressClient($apiContext); | ||
$data = $addressClient->generateAddress(); | ||
|
||
$ethblock = (array) json_decode($data, true); // Convert JSON to array | ||
$ethblock = (object) $ethblock; //Convert array to object | ||
|
||
$address = $addressClient->get($ethblock->address); | ||
|
||
$address->txrefs = $address->txrefs != null ? (object) $address->txrefs : null ; | ||
|
||
|
||
$bwa = new \App\Ethereumd\EthereumWalletAddress(); // Create new Ƀitcoin Wallet->Address Endpoint object | ||
$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 ){ | ||
$bwa->confirmations = $address->txrefs[sizeof($address->txrefs)-1]->confirmations ; // Confirmations will not be available immediately | ||
$bwa->tx_hash = $address->txrefs[sizeof($address->txrefs)-1]->tx_hash; // A tx_hash won't be available immediately | ||
}else{ | ||
$bwa->confirmations = 0 ; // Confirmations will not be available immediately | ||
$bwa->tx_hash = ""; // A tx_hash won't be available immediately | ||
} | ||
|
||
$bwa->total_received = $address->total_received; // Total Ƀitcoin received | ||
$bwa->total_sent = $address->total_sent; // Total Ƀitcoin sent | ||
$bwa->balance = $address->balance; // Total current balance | ||
$bwa->unconfirmed_balance = $address->unconfirmed_balance; // Unconfirmed balance | ||
$bwa->final_balance = $address->final_balance; // Total available balance | ||
$bwa->n_tx = $address->n_tx; | ||
$bwa->unconfirmed_n_tx = $address->unconfirmed_n_tx; | ||
|
||
$bwa->used = $bwa->total_sent + $bwa->total_received + $bwa->unconfirmed_balance + $bwa->balance != 0; // Has address received or sent any Ƀitcoin? | ||
$bwa->save(); | ||
|
||
$bwa->privatekey = $data->privatekey; // Is not saved to DB, only returned to user | ||
return json_encode(json_decode($bwa,1)); | ||
} | ||
|
||
public function GrabMyAddresses() | ||
{ | ||
return \Auth::user()->ETHAddresses()->get(); | ||
} | ||
|
||
public function DeleteWalletAddress ($wallet_address) | ||
{ | ||
// Find the wallet->address bound to | ||
$wallet_addr = \App\Ethereumd\EthereumWalletAddress::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 | ||
} | ||
|
||
$wallet_addr->forceDelete(); // Delete the record | ||
|
||
return json_encode(array('action'=>'delete:wallet_'.$wallet_address, 'action_status'=>'success')); | ||
} | ||
|
||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
15 changes: 15 additions & 0 deletions
15
master-dev/exchange/resources/views/account/eth-addresses.blade.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<button class="generate-waddress-button button button-primary" onclick="eth_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="eth_walletAddress in eth_walletAddresses"> | ||
<td>{[{ eth_walletAddress.wallet_address }]} <button class="button button-danger delete-waddress-button" ng-click="eth_deleteWalletAddress(eth_walletAddress.wallet_address)">Delete</button></td> | ||
<td><small>ETH</small> {[{ eth_walletAddress.final_balance }]}<small></small> </td> | ||
</tr> | ||
</tbody> | ||
</table> |
This file contains 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
This file contains 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
Oops, something went wrong.