Skip to content

Commit

Permalink
add asset to balance()
Browse files Browse the repository at this point in the history
  • Loading branch information
deemru committed Dec 14, 2020
1 parent 214e000 commit c044615
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docs/WavesKit.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Creates WavesKit instance
**Description**

```php
public balance (string|null $address)
public balance (string|null $address, string|null $asset)
```

Gets an address full balance
Expand All @@ -132,12 +132,14 @@ Gets an address full balance

* `(string|null) $address`
: Address to get balance (default: null)
* `(string|null) $asset`
: Asset to get balance (default: null)

**Return Values**

`array|false`

> Balance of all assets as an array or FALSE on failure
> Balance of all assets as an array or balance of specific asset or FALSE on failure

<hr />
Expand Down
21 changes: 19 additions & 2 deletions src/WavesKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -1367,14 +1367,31 @@ public function ensure( $tx, $confirmations = 0, $sleep = 1, $timeout = 30, $har
* Gets an address full balance
*
* @param string|null $address Address to get balance (default: null)
* @param string|null $asset Asset to get balance (default: null)
*
* @return array|false Balance of all assets as an array or FALSE on failure
* @return array|false Balance of all assets as an array or balance of specific asset or FALSE on failure
*/
public function balance( $address = null )
public function balance( $address = null, $asset = null )
{
if( false === ( $address = isset( $address ) ? $address : $this->getAddress() ) )
return false;

if( isset( $asset ) )
{
if( $asset === 'WAVES' )
$query = '/addresses/balance/' . $address;
else
$query = '/assets/balance/' . $address . '/' . $asset;

if( false === ( $json = $this->fetch( $query ) ) )
return false;

if( null === ( $json = $this->json_decode( $json ) ) )
return false;

return $json['balance'];
}

if( false === ( $json = $this->fetch( "/addresses/balance/$address" ) ) )
return false;

Expand Down

0 comments on commit c044615

Please sign in to comment.