Skip to content

Commit

Permalink
Added forgetCurrentAddress() method to Wallet model.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tate Peñaranda committed Jul 15, 2018
1 parent 9dea990 commit 0c9756f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
20 changes: 0 additions & 20 deletions .gitignore

This file was deleted.

20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# BCoin (bcoin.io) Laravel
A Laravel 5 package to connect with BCoin full node API
A Laravel 5 package to connect with BCoin full node API.

## About package
This packages integrates a BCoin (bcoin.io) Bitcoin node to a Laravel App by using BCoin API.
Expand All @@ -21,11 +21,19 @@ Set BCoin server configuration (config/bcoin.php):
```
return [
'accept_self_signed_certificates' => env('BCOIN_ACCEPT_SELF_SIGNED_CERTIFICATES', true),
'api_key' => env('BCOIN_API_KEY', false),
'number_of_confirmations_to_consider_transaction_done' => env('NUMBER_OF_CONFIRMATIONS_TO_CONSIDER_TRANSACTION_DONE', 3),
'api_key' => env('BCOIN_API_KEY', null),
'number_of_confirmations_to_consider_transaction_done' => env('BCOIN_NUMBER_OF_CONFIRMATIONS_TO_CONSIDER_TRANSACTION_DONE', 3),
'server_ip' => env('BCOIN_SERVER_IP', '127.0.0.1'),
'server_port' => env('BCOIN_SERVER_PORT', 18333),
'server_port' => env('BCOIN_SERVER_PORT', 8332),
'server_ssl' => env('BCOIN_SERVER_SSL', false),
'server_timeout_seconds' => env('BCOIN_SERVER_TIMEOUT_SECONDS', 20),
'service_key' => env('BCOIN_SERVICE_KEY', null),
'wallet_admin_token' => env('BCOIN_WALLET_ADMIN_TOKEN', null),
'wallet_api_key' => env('BCOIN_WALLET_API_KEY', null),
'wallet_server_ip' => env('BCOIN_WALLET_SERVER_IP', '127.0.0.1'),
'wallet_server_port' => env('BCOIN_WALLET_SERVER_PORT', 8334),
'wallet_server_ssl' => env('BCOIN_WALLET_SERVER_SSL', false),
'wallet_service_key' => env('BCOIN_WALLET_SERVICE_KEY', null),
];
```

Expand All @@ -37,7 +45,7 @@ return [
use BCoinNode; // Package Facade
$serverModel = BCoinNode::getServer() // Server Model
$serverModel->version // 'v1.0.0-beta.14' string
$serverModel->version // 'v1.0.2' string
$transaction = BCoinNode::getTransaction('a42785c8351d896329dfeab4b95bbc1185e7ffb284f5f80275bd0df3632fccbb') // Transaction Model
Expand All @@ -53,7 +61,7 @@ $transaction = $wallet->sendTransaction(<destination_address>, <amount_in_satosh
$boolean = BCoinNode::addressBelongsToWallet(<address>, <wallet_id>) // Check if a BTC address belongs to a Node Wallet
*Have a look to TPenaranda\BCoin\BCoin class for (many) undocumented methods.*
*Have a look to TPenaranda\BCoin\BCoin class (and Models) for (many) undocumented methods.*
```

Donations => bitcoin:38NYkcaqSCxijvsfvgGexPsNkVZLfaTw54
14 changes: 11 additions & 3 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ public function getDataFromAPI(): string

public function getCacheKey(): string
{
if (empty($this->id)) {
throw new BCoinException("Can't get cache key without a valid id.");
}

return self::BASE_CACHE_KEY_NAME . $this->id;
}

public function deriveNestedAddress(): string
public function getNestedAddress(): string
{
return BCoin::postToWalletAPI("/wallet/{$this->id}/nested", ['account' => 'default']);
}
Expand Down Expand Up @@ -51,15 +55,19 @@ public function sendTransaction(string $destination_address, int $amount_in_sato
return new Transaction(BCoin::postToWalletAPI("/wallet/{$this->id}/send", array_merge($payload, array_merge($default_opts, $opts))));
}

public function forgetCurrentAddress() {
return Cache::forget("{$this->getCacheKey()}_address");
}

protected function addCoinsAttribute(): Collection
{
return BCoin::getWalletCoins($this->id);
}

protected function addAddressAttribute(): string
{
return Cache::remember("{$this->getCacheKey()}_address", $minutes = 60, function () {
return json_decode($this->deriveNestedAddress())->address;
return Cache::rememberForever("{$this->getCacheKey()}_address", function () {
return json_decode($this->getNestedAddress())->address;
});
}

Expand Down

0 comments on commit 0c9756f

Please sign in to comment.