Skip to content

Commit

Permalink
Merge pull request #82 from MinterTeam/dev
Browse files Browse the repository at this point in the history
update api
  • Loading branch information
grkamil authored Mar 16, 2020
2 parents 3d5c577 + 9c0ca69 commit 4b83175
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 9 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ This is a pure PHP SDK for working with <b>Minter</b> blockchain
- [getBalance](#getbalance)
- [getNonce](#getnonce)
- [send](#send)
- [getAddresses](#getaddresses)
- [getStatus](#getstatus)
- [getValidators](#getvalidators)
- [estimateCoinBuy](#estimatecoinbuy)
- [estimateCoinSell](#estimatecoinsell)
- [estimateCoinSellAll](#estimatecoinsellall)
- [getCoinInfo](#getcoininfo)
- [getBlock](#getblock)
- [getEvents](#getevents)
Expand Down Expand Up @@ -118,6 +120,14 @@ send(string $tx): \stdClass
$api->send('f873010101aae98a4d4e540000000000000094fe60014a6e9ac91618f5d1cab3fd58cded61ee99880de0b6b3a764000080801ca0ae0ee912484b9bf3bee785f4cbac118793799450e0de754667e2c18faa510301a04f1e4ed5fad4b489a1065dc1f5255b356ab9a2ce4b24dde35bcb9dc43aba019c')
```

### getAddresses

Returns addresses balances.

``
getAddresses(array $addresses, ?int $height = null): \stdClass
``

### getStatus

Returns node status info.
Expand All @@ -131,7 +141,7 @@ getStatus(): \stdClass
Returns list of active validators.

``
getValidators(?int $height = null): \stdClass
getValidators(?int $height = null, ?int $page = 1, ?int $perPage = null): \stdClass
``

### estimateCoinBuy
Expand All @@ -150,6 +160,14 @@ Return estimate of sell coin transaction.
estimateCoinSell(string $coinToSell, string $valueToSell, string $coinToBuy, ?int $height = null): \stdClass
``

### estimateCoinSellAll

Return estimate of sell coin all transaction.

``
estimateCoinSellAll(string $coinToSell, string $valueToSell, string $coinToBuy, ?int $height = null): \stdClass
``

### getCoinInfo

Returns information about coin.
Expand Down Expand Up @@ -206,7 +224,7 @@ getCandidates(?int $height = null, ?bool $includeStakes = false): \stdClass
Return estimate of transaction.

``
estimateTxCommission(string $tx): \stdClass
estimateTxCommission(string $tx, ?int $height = null): \stdClass
``

### getTransactions
Expand Down Expand Up @@ -249,6 +267,22 @@ Returns missed blocks by validator public key.
getMissedBlocks(string $pubKey, ?int $height = null): \stdClass
``

### getGenesis

Return network genesis.

``
getGenesis(): \stdClass
``

### getNetworkInfo

Return node network information.

``
getNetworkInfo(): \stdClass
``

### Error handling

Example of how you can handle errors and get the response body.
Expand Down
101 changes: 94 additions & 7 deletions src/Minter/MinterAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,24 @@ public function getCandidate(string $publicKey, ?int $height = null): \stdClass
* Returns list of active validators
*
* @param null|int $height
* @param int|null $page
* @param int|null $perPage
* @return \stdClass
* @throws Exception
* @throws GuzzleException
*/
public function getValidators(?int $height = null): \stdClass
public function getValidators(?int $height = null, ?int $page = 1, ?int $perPage = null): \stdClass
{
return $this->get('validators', ($height ? ['height' => $height] : null));
$params = ['page' => $page];

if($height) {
$params['height'] = $height;
}

if($perPage) {
$params['perPage'] = $perPage;
}

return $this->get('validators', $params);
}

/**
Expand All @@ -117,6 +128,25 @@ public function getBalance(string $address, ?int $height = null): \stdClass
return $this->get('address', $params);
}

/**
* Returns addresses balances.
*
* @param array $addresses
* @param int|null $height
* @return \stdClass
* @throws GuzzleException
*/
public function getAddresses(array $addresses, ?int $height = null): \stdClass
{
$params = ['addresses' => json_encode($addresses)];

if ($height) {
$params['height'] = $height;
}

return $this->get('addresses', $params);
}

/**
* Returns nonce.
*
Expand Down Expand Up @@ -257,6 +287,35 @@ public function estimateCoinSell(
return $this->get('estimate_coin_sell', $params);
}

/**
* Return estimate of sell all coin transaction.
*
* @param string $coinToSell
* @param string $valueToSell
* @param string $coinToBuy
* @param int|null $height
* @return \stdClass
* @throws GuzzleException
*/
public function estimateCoinSellAll(
string $coinToSell,
string $valueToSell,
string $coinToBuy,
?int $height = null
): \stdClass {
$params = [
'coin_to_sell' => $coinToSell,
'value_to_sell' => $valueToSell,
'coin_to_buy' => $coinToBuy
];

if ($height) {
$params['height'] = $height;
}

return $this->get('estimate_coin_sell_all', $params);
}

/**
* Return estimate of buy coin transaction.
*
Expand Down Expand Up @@ -290,14 +349,20 @@ public function estimateCoinBuy(
/**
* Return estimate of transaction.
*
* @param string $tx
* @param string $tx
* @param int|null $height
* @return \stdClass
* @throws Exception
* @throws GuzzleException
*/
public function estimateTxCommission(string $tx): \stdClass
public function estimateTxCommission(string $tx, ?int $height = null): \stdClass
{
return $this->get('estimate_tx_commission', ['tx' => $tx]);
$params = ['tx' => $tx];

if($height) {
$params['height'] = $height;
}

return $this->get('estimate_tx_commission', $params);
}

/**
Expand Down Expand Up @@ -382,4 +447,26 @@ public function getMissedBlocks(string $pubKey, ?int $height = null): \stdClass

return $this->get('missed_blocks', $params);
}

/**
* Return network genesis.
*
* @return \stdClass
* @throws GuzzleException
*/
public function getGenesis(): \stdClass
{
return $this->get('genesis');
}

/**
* Return node network information.
*
* @return \stdClass
* @throws GuzzleException
*/
public function getNetworkInfo(): \stdClass
{
return $this->get('net_info');
}
}
1 change: 1 addition & 0 deletions src/Minter/SDK/MinterTx.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @property string serviceData
* @property int signatureType
* @property array signatureData
* @property string from
*/
class MinterTx
{
Expand Down

0 comments on commit 4b83175

Please sign in to comment.