From 92ba4ad4436652fb5514383f6b61b5f0ff39a312 Mon Sep 17 00:00:00 2001 From: Kamil Mukhametzyanov Date: Mon, 16 Mar 2020 11:59:30 +0300 Subject: [PATCH 1/2] update api --- README.md | 38 +++++++++++++- src/Minter/MinterAPI.php | 101 +++++++++++++++++++++++++++++++++--- src/Minter/SDK/MinterTx.php | 3 +- 3 files changed, 132 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5b9de29..7a62174 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,12 @@ This is a pure PHP SDK for working with Minter 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) @@ -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. @@ -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 @@ -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. @@ -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 @@ -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. diff --git a/src/Minter/MinterAPI.php b/src/Minter/MinterAPI.php index c9dbc51..06308ad 100644 --- a/src/Minter/MinterAPI.php +++ b/src/Minter/MinterAPI.php @@ -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); } /** @@ -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. * @@ -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. * @@ -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); } /** @@ -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'); + } } diff --git a/src/Minter/SDK/MinterTx.php b/src/Minter/SDK/MinterTx.php index 90b21e8..10e82e6 100644 --- a/src/Minter/SDK/MinterTx.php +++ b/src/Minter/SDK/MinterTx.php @@ -38,6 +38,7 @@ * @property string serviceData * @property int signatureType * @property array signatureData + * @property string from */ class MinterTx { @@ -341,7 +342,7 @@ private function decode(string $tx): array * @return array * @throws InvalidArgumentException */ - private function encode(array $tx, bool $isHexFormat = false): array + private function encode(array $tx, bool $isHexFormat = false): array { // fill with default values if not present $tx['payload'] = $tx['payload'] ?? ''; From 9c0ca69372a3d47a9a373b4fa8c6fd761647a6dd Mon Sep 17 00:00:00 2001 From: Kamil Mukhametzyanov Date: Mon, 16 Mar 2020 12:01:35 +0300 Subject: [PATCH 2/2] fix --- src/Minter/SDK/MinterTx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Minter/SDK/MinterTx.php b/src/Minter/SDK/MinterTx.php index 10e82e6..88ce1e3 100644 --- a/src/Minter/SDK/MinterTx.php +++ b/src/Minter/SDK/MinterTx.php @@ -342,7 +342,7 @@ private function decode(string $tx): array * @return array * @throws InvalidArgumentException */ - private function encode(array $tx, bool $isHexFormat = false): array + private function encode(array $tx, bool $isHexFormat = false): array { // fill with default values if not present $tx['payload'] = $tx['payload'] ?? '';