Skip to content

Commit 0f65315

Browse files
author
Sandro Keil
committed
added satoshi view helper to convert satoshi to other unit e.g. bitcoin, updated docs
1 parent 2481ab4 commit 0f65315

File tree

11 files changed

+492
-15
lines changed

11 files changed

+492
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Version 1.0.0 - TBA
44

5+
* Satoshi view helper which converts satoshi to other unit e.g. bitcoin
56
* Validator support via input filter
67
* Service plugin manager for responses, requests and input filter
78
* Hydrator strategies for address list and addresses

CONTRIBUTING.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# CONTRIBUTING
2+
3+
## RESOURCES
4+
5+
If you wish to contribute to Zend Framework, please be sure to read to the following resources:
6+
7+
- Coding Standards: [PSR-0/1/2/4](https://github.com/php-fig/fig-standards/tree/master/accepted)
8+
- Git Guide: [README-GIT.md](README-GIT.md)
9+
10+
If you are working on new features, or refactoring an existing
11+
component, please create a proposal. You can do this in on the RFC's
12+
page, https://github.com/sandrokeil/BlockchainWalletApi/wiki/RFCs.
13+
14+
## RUNNING TESTS
15+
16+
To run tests:
17+
18+
- Make sure you have a recent version of PHPUnit installed; 3.7.0
19+
minimally.
20+
- Be sure you are in the root directory
21+
- Execute PHPUnit
22+
23+
```sh
24+
% phpunit
25+
```
26+
27+
You can turn on conditional tests with the TestConfig.php file.
28+
To do so:
29+
30+
- Enter the `test/` subdirectory.
31+
- Copy `TestConfig.php.dist` file to `TestConfig.php`
32+
- Edit `TestConfig.php` to enable any specific functionality you want to test, as well as to provide test values to
33+
utilize.

README-GIT.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# USING THE GIT REPOSITORY
2+
3+
## Setup your own public github repository
4+
5+
Your first step is to establish a public repository from which i can pull your work into the master repository.
6+
7+
1. Setup a GitHub account (http://github.com/), if you haven't yet
8+
2. Fork the BlockchainWalletApi repository (http://github.com/sandrokeil/BlockchainWalletApi)
9+
3. Clone your fork locally and enter it (use your own GitHub username in the statement below)
10+
11+
```sh
12+
% git clone git@github.com:<username>/BlockchainWalletApi.git
13+
% cd BlockchainWalletApi
14+
```
15+
16+
4. Add a remote to the canonical BlockchainWalletApi repository, so you can keep your fork
17+
up-to-date:
18+
19+
```sh
20+
% git remote add upstream https://github.com/sandrokeil/BlockchainWalletApi.git
21+
% git fetch upstream
22+
```
23+
24+
## Keeping Up-to-Date
25+
26+
Periodically, you should update your fork to match the canonical BlockchainWalletApi repository. we have
27+
added a remote to the BlockchainWalletApi repository, which allows you to do the following:
28+
29+
```sh
30+
% git checkout master
31+
% git pull upstream master
32+
- OPTIONALLY, to keep your remote up-to-date -
33+
% git push origin
34+
```
35+
36+
If you're tracking other branches -- for example, the "develop" branch, where new feature development occurs --
37+
you'll want to do the same operations for that branch; simply substitute "develop" for "master".
38+
39+
## Working on BlockchainWalletApi
40+
41+
When working on BlockchainWalletApi, we recommend you do each new feature or bugfix in a new branch. This simplifies the
42+
task of code review as well as of merging your changes into the canonical repository.
43+
44+
A typical work flow will then consist of the following:
45+
46+
1. Create a new local branch based off your master branch.
47+
2. Switch to your new local branch. (This step can be combined with the previous step with the use of `git checkout -b`.)
48+
3. Do some work, commit, repeat as necessary.
49+
4. Push the local branch to your remote repository.
50+
5. Send a pull request.
51+
52+
The mechanics of this process are actually quite trivial. Below, we will create a branch for fixing an issue in the tracker.
53+
54+
```sh
55+
% git checkout -b 3452
56+
Switched to a new branch '3452'
57+
```
58+
... do some work ...
59+
60+
```sh
61+
% git commit
62+
```
63+
... write your log message ...
64+
65+
```sh
66+
% git push origin HEAD:3452
67+
Counting objects: 38, done.
68+
Delta compression using up to 2 threads.
69+
Compression objects: 100% (18/18), done.
70+
Writing objects: 100% (20/20), 8.19KiB, done.
71+
Total 20 (delta 12), reused 0 (delta 0)
72+
To ssh://git@github.com/sandrokeil/BlockchainWalletApi.git
73+
g5342..9k3532 HEAD -> master
74+
```
75+
76+
You can do the pull request from github. Navigate to your repository, select the branch you just created, and then
77+
select the "Pull Request" button in the upper right. Select the user "sandrokeil" as the recipient.
78+
79+
### What branch to issue the pull request against?
80+
81+
Which branch should you issue a pull request against?
82+
83+
- For fixes against the stable release, issue the pull request against the "master" branch.
84+
- For new features, or fixes that introduce new elements to the public API
85+
(such as new public methods or properties), issue the pull request against the "develop" branch.
86+
87+
## Branch Cleanup
88+
89+
As you might imagine, if you are a frequent contributor, you'll start to get a ton of branches both locally and on
90+
your remote.
91+
92+
Once you know that your changes have been accepted to the master repository, we suggest doing some cleanup of these
93+
branches.
94+
95+
- Local branch cleanup
96+
97+
```sh
98+
% git branch -d <branchname>
99+
```
100+
101+
- Remote branch removal
102+
103+
```sh
104+
% git push origin :<branchname>
105+
```
106+
107+
108+
## FEEDS AND EMAILS
109+
110+
RSS feeds may be found at:
111+
112+
`https://github.com/sandrokeil/BlockchainWalletApi/commits/<branch>.atom`
113+
114+
where &lt;branch&gt; is a branch in the repository.
115+
116+
To subscribe to git email notifications, simply watch or fork the BlockchainWalletApi repository on GitHub.

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Zend Framework 2 client library for [blockchain wallet api](https://blockchain.i
1414
* **Adapts To Your Needs.** There are several possibilities to configure this module.
1515
* **Well tested.** Besides unit test and continuous integration/inspection this solution is also ready for production use.
1616
* **Great foundations.** Based on [Zend Framework 2](https://github.com/zendframework/zf2) and [Easy Config](https://github.com/sandrokeil/EasyConfig)
17-
* **Every change is tracked**. Want to know whats new? Take a look at [CHANGELOG.md](https://github.com/sandrokeil/BlockchainWalletApi/blob/master/CHANGELOG.md)
18-
* **Listen to your ideas.** Have a great idea? Bring your tested pull request or open a new issue.
17+
* **Every change is tracked**. Want to know whats new? Take a look at [CHANGELOG.md](CHANGELOG.md)
18+
* **Listen to your ideas.** Have a great idea? Bring your tested pull request or open a new issue. See [CONTRIBUTING.md](CONTRIBUTING.md)
1919

2020
## Installation
2121

@@ -50,11 +50,10 @@ These request classes matches to api methods
5050
* AddressUnarchive => unarchive_address
5151
* AutoConsolidateAddresses => auto_consolidate
5252

53-
Here is an example how to send bitcoins to an bitcoin address:
53+
Here is an example how to send bitcoins to a bitcoin address:
5454

5555
```php
5656
<?php
57-
5857
use Sake\BlockchainWalletApi;
5958

6059
// $sl is the service locator
@@ -84,7 +83,6 @@ Here is an example how to retrieve wallet balance:
8483

8584
```php
8685
<?php
87-
8886
use Sake\BlockchainWalletApi;
8987

9088
// $sl is the service locator
@@ -107,6 +105,19 @@ try {
107105
// error handling
108106
}
109107
```
108+
Here is an example how to use satoshi view helper to convert satoshi to other unit:
109+
110+
```php
111+
<?php
112+
// assume we are in a template
113+
114+
/* @var $response BlockchainWalletApi\Response\WalletBalance */
115+
echo $this->satoshi($response->getBalanace(), 'BTC'); // Bitcoin
116+
// or
117+
echo $this->satoshi($response->getBalanace(), 'mBTC'); // Milli Bits
118+
// or
119+
echo $this->satoshi($response->getBalanace(), 'uBTC'); // Micro Bitcoin
120+
```
110121

111122
## Configuration
112123
Connection parameters can be defined in the application configuration:
@@ -139,7 +150,5 @@ return array(
139150
* `sake_bwa.service.input_filter`: a \Sake\BlockchainWalletApi\Service\InputFilterPluginManager Service plugin manager to create input filter via api method name
140151
* `sake_bwa.service.hydrator`: a \Zend\Stdlib\Hydrator\ClassMethods instance with strategies and filters for requests/responses
141152

142-
## Todo's
143-
* More unit tests
144-
* Satoshi converter/filter
145-
* View Helper to display data
153+
## Registered view helper
154+
* `satoshi`: a \Zend\View\Helper\AbstractHelper instance which converts satoshi to other unit e.g. bitcoin

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"license": "BSD-3-Clause",
66
"type": "library",
77
"keywords": [
8+
"blockhain",
9+
"bitcoin",
810
"zf2",
911
"blockhain wallet api",
10-
"bitcoin",
11-
"blockhain",
1212
"wallet",
1313
"api",
1414
"webservice",
@@ -39,9 +39,11 @@
3939
"zendframework/zend-serializer": "~2.2",
4040
"zendframework/zend-log": "~2.2",
4141
"zendframework/zend-modulemanager": "~2.2",
42+
"zendframework/zend-view": "~2.2",
4243
"sandrokeil/citools": "~1.0"
4344
},
4445
"suggest": {
46+
"zendframework/zend-view": "Zend\\View to use satoshi view helper",
4547
"zendframework/zend-modulemanager": "Zend\\ModuleManager to use default module configuration e.g. services"
4648
}
4749
}

config/blockchainwalletapi.local.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ return array(
1313
'connection' => array(
1414
'default' => array(
1515
'options' => array(
16-
// see \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions for all configurations
16+
// see \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions for all options
1717
'url' => 'https://blockchain.info/de/merchant/', // note on your country
1818
'guid' => 'your My Wallet identifier (found on the login page)',
1919
'main_password' => 'Your Main My wallet password',

config/view_helper.config.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Sake
4+
*
5+
* @link http://github.com/sandrokeil/BlockchainWalletApi for the canonical source repository
6+
* @copyright Copyright (c) 2014 Sandro Keil
7+
* @license http://github.com/sandrokeil/BlockchainWalletApi/blob/master/LICENSE.txt New BSD License
8+
*/
9+
10+
return array(
11+
'invokables' => array(
12+
'satoshi' => '\Sake\BlockchainWalletApi\View\Helper\Satoshi',
13+
),
14+
);

src/Module.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
namespace Sake\BlockchainWalletApi;
1111

1212
use Zend\ModuleManager\Feature\ServiceProviderInterface;
13+
use Zend\ModuleManager\Feature\ViewHelperProviderInterface;
1314

1415
/**
1516
* This class initializes the BlockchainWalletApi module.
1617
*/
17-
class Module implements ServiceProviderInterface
18+
class Module implements ServiceProviderInterface, ViewHelperProviderInterface
1819
{
1920
/**
2021
* Return service config
@@ -26,4 +27,15 @@ public function getServiceConfig()
2627
{
2728
return require dirname(__DIR__) . '/config/service_manager.config.php';
2829
}
30+
31+
/**
32+
* Expected to return \Zend\ServiceManager\Config object or array to
33+
* seed such an object.
34+
*
35+
* @return array
36+
*/
37+
public function getViewHelperConfig()
38+
{
39+
return require dirname(__DIR__) . '/config/view_helper.config.php';
40+
}
2941
}

src/Service/BlockchainWallet.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Zend\Http\Request;
1717
use Zend\Http\Response as HttpResponse;
1818
use Sake\BlockchainWalletApi\Exception;
19-
use Zend\InputFilter\InputFilter;
2019

2120
/**
2221
* Blockchain wallet api service
@@ -82,7 +81,7 @@ public function send(RequestInterface $request)
8281
*/
8382
public function isValid(RequestInterface $request)
8483
{
85-
/* @var $inputFilter InputFilter */
84+
/* @var $inputFilter \Zend\InputFilter\InputFilter */
8685
$inputFilter = $this->getOptions()->getInputFilterPluginManager()->get($request->getMethod());
8786
$inputFilter->setData($this->getOptions()->getHydrator()->extract($request));
8887
return $inputFilter->isValid();

0 commit comments

Comments
 (0)