Skip to content

Commit

Permalink
Merge pull request #69 from MinterTeam/dev
Browse files Browse the repository at this point in the history
make relative api paths
  • Loading branch information
grkamil authored Nov 4, 2019
2 parents e0e993d + e781ffc commit 6a7d21e
Showing 1 changed file with 43 additions and 32 deletions.
75 changes: 43 additions & 32 deletions src/Minter/MinterAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Minter;

use Exception;
use Minter\Library\Http;

/**
Expand All @@ -28,11 +29,11 @@ public function __construct($nodeUrl)
* Get status of node
*
* @return \stdClass
* @throws \Exception
* @throws Exception
*/
public function getStatus(): \stdClass
{
return $this->get('/status');
return $this->get('status');
}

/**
Expand All @@ -42,7 +43,7 @@ public function getStatus(): \stdClass
* @param string $publicKey
* @param null|int $height
* @return \stdClass
* @throws \Exception
* @throws Exception
*/
public function getCandidate(string $publicKey, ?int $height = null): \stdClass
{
Expand All @@ -52,19 +53,19 @@ public function getCandidate(string $publicKey, ?int $height = null): \stdClass
$params['height'] = $height;
}

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

/**
* Returns list of active validators
*
* @param null|int $height
* @return \stdClass
* @throws \Exception
* @throws Exception
*/
public function getValidators(?int $height = null): \stdClass
{
return $this->get('/validators', ($height ? ['height' => $height] : null));
return $this->get('validators', ($height ? ['height' => $height] : null));
}

/**
Expand All @@ -73,7 +74,7 @@ public function getValidators(?int $height = null): \stdClass
* @param string $address
* @param null|int $height
* @return \stdClass
* @throws \Exception
* @throws Exception
*/
public function getBalance(string $address, ?int $height = null): \stdClass
{
Expand All @@ -83,14 +84,15 @@ public function getBalance(string $address, ?int $height = null): \stdClass
$params['height'] = $height;
}

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

/**
* Returns nonce.
*
* @param string $address
* @return int
* @throws Exception
*/
public function getNonce(string $address): int
{
Expand All @@ -102,54 +104,56 @@ public function getNonce(string $address): int
*
* @param string $tx
* @return \stdClass
* @throws \Exception
* @throws Exception
*/
public function send(string $tx): \stdClass
{
return $this->get('/send_transaction', ['tx' => $tx]);
return $this->get('send_transaction', ['tx' => $tx]);
}

/**
* Returns transaction info.
*
* @param string $hash
* @return \stdClass
* @throws \Exception
* @throws Exception
*/
public function getTransaction(string $hash): \stdClass
{
return $this->get('/transaction', ['hash' => $hash]);
return $this->get('transaction', ['hash' => $hash]);
}

/**
* Returns block data at given height.
*
* @param int $height
* @return \stdClass
* @throws \Exception
* @throws Exception
*/
public function getBlock(int $height): \stdClass
{
return $this->get('/block', ['height' => $height]);
return $this->get('block', ['height' => $height]);
}

/**
* Returns events at given height.
*
* @param int $height
* @return \stdClass
* @throws Exception
*/
public function getEvents(int $height): \stdClass
{
return $this->get('/events', ['height' => $height]);
return $this->get('events', ['height' => $height]);
}

/**
* Returns list of candidates.
*
* @param null|int $height
* @param null|int $height
* @param bool|null $includeStakes
* @return \stdClass
* @throws \Exception
* @throws Exception
*/
public function getCandidates(?int $height = null, ?bool $includeStakes = false): \stdClass
{
Expand All @@ -163,16 +167,17 @@ public function getCandidates(?int $height = null, ?bool $includeStakes = false)
$params['height'] = $height;
}

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

/**
* Returns information about coin.
* Note: this method does not return information about base coins (MNT and BIP).
*
* @param null|int $height
* @param string $symbol
* @param string $symbol
* @return \stdClass
* @throws Exception
*/
public function getCoinInfo(string $symbol, ?int $height = null): \stdClass
{
Expand All @@ -182,7 +187,7 @@ public function getCoinInfo(string $symbol, ?int $height = null): \stdClass
$params['height'] = $height;
}

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

/**
Expand All @@ -193,7 +198,7 @@ public function getCoinInfo(string $symbol, ?int $height = null): \stdClass
* @param string $coinToBuy
* @param null|int $height
* @return \stdClass
* @throws \Exception
* @throws Exception
*/
public function estimateCoinSell(string $coinToSell, string $valueToSell, string $coinToBuy, ?int $height = null): \stdClass
{
Expand All @@ -207,7 +212,7 @@ public function estimateCoinSell(string $coinToSell, string $valueToSell, string
$params['height'] = $height;
}

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

/**
Expand All @@ -218,7 +223,7 @@ public function estimateCoinSell(string $coinToSell, string $valueToSell, string
* @param string $coinToBuy
* @param null|int $height
* @return \stdClass
* @throws \Exception
* @throws Exception
*/
public function estimateCoinBuy(string $coinToSell, string $valueToBuy, string $coinToBuy, ?int $height = null): \stdClass
{
Expand All @@ -232,27 +237,29 @@ public function estimateCoinBuy(string $coinToSell, string $valueToBuy, string $
$params['height'] = $height;
}

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

/**
* Return estimate of transaction.
*
* @param string $tx
* @return \stdClass
* @throws Exception
*/
public function estimateTxCommission(string $tx): \stdClass
{
return $this->get('/estimate_tx_commission', ['tx' => $tx]);
return $this->get('estimate_tx_commission', ['tx' => $tx]);
}

/**
* Get transactions by query.
*
* @param string $query
* @param string $query
* @param int|null $page
* @param int|null $perPage
* @return \stdClass
* @throws Exception
*/
public function getTransactions(string $query, ?int $page = null, ?int $perPage = null): \stdClass
{
Expand All @@ -267,47 +274,51 @@ public function getTransactions(string $query, ?int $page = null, ?int $perPage
}


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

/**
* Returns unconfirmed transactions.
*
* @param int|null $limit
* @return \stdClass
* @throws Exception
*/
public function getUnconfirmedTxs(?int $limit = null): \stdClass
{
return $this->get('/unconfirmed_txs', ($limit ? ['limit' => $limit] : null));
return $this->get('unconfirmed_txs', ($limit ? ['limit' => $limit] : null));
}

/**
* Returns current max gas price.
*
* @param int|null $height
* @return \stdClass
* @throws Exception
*/
public function getMaxGasPrice(?int $height = null): \stdClass
{
return $this->get('/max_gas', ($height ? ['height' => $height] : null));
return $this->get('max_gas', ($height ? ['height' => $height] : null));
}

/**
* Returns current min gas price.
*
* @return \stdClass
* @throws Exception
*/
public function getMinGasPrice(): \stdClass
{
return $this->get('/min_gas_price');
return $this->get('min_gas_price');
}

/**
* Returns missed blocks by validator public key.
*
* @param string $pubKey
* @param string $pubKey
* @param int|null $height
* @return \stdClass
* @throws Exception
*/
public function getMissedBlocks(string $pubKey, ?int $height = null): \stdClass
{
Expand All @@ -316,6 +327,6 @@ public function getMissedBlocks(string $pubKey, ?int $height = null): \stdClass
$params['height'] = $height;
}

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

0 comments on commit 6a7d21e

Please sign in to comment.