Skip to content

Commit

Permalink
Merge pull request #87 from MinterTeam/taconet
Browse files Browse the repository at this point in the history
Upgrade sdk to taconet
  • Loading branch information
grkamil authored Apr 12, 2021
2 parents cc8f682 + 0560f06 commit 3f28e9b
Show file tree
Hide file tree
Showing 48 changed files with 2,073 additions and 171 deletions.
317 changes: 280 additions & 37 deletions README.md

Large diffs are not rendered by default.

76 changes: 65 additions & 11 deletions src/Minter/MinterAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,14 @@ public function getTransaction(string $hash): \stdClass
}

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

/**
Expand Down Expand Up @@ -260,6 +258,7 @@ public function getCoinInfo(string $symbol, ?int $height = null): \stdClass
* @param string $valueToSell
* @param string $coinToBuy
* @param null|int $height
* @param string $swapFrom
* @return \stdClass
* @throws Exception
* @throws GuzzleException
Expand All @@ -268,12 +267,14 @@ public function estimateCoinSell(
string $coinToSell,
string $valueToSell,
string $coinToBuy,
?int $height = null
?int $height = null,
string $swapFrom = 'optimal'
): \stdClass {
$params = [
'coin_to_sell' => $coinToSell,
'value_to_sell' => $valueToSell,
'coin_to_buy' => $coinToBuy
'coin_to_buy' => $coinToBuy,
'swap_from' => $swapFrom
];

if ($height) {
Expand All @@ -290,19 +291,22 @@ public function estimateCoinSell(
* @param string $valueToSell
* @param string $coinToBuy
* @param int|null $height
* @param string $swapFrom
* @return \stdClass
* @throws GuzzleException
*/
public function estimateCoinSellAll(
string $coinToSell,
string $valueToSell,
string $coinToBuy,
?int $height = null
?int $height = null,
string $swapFrom = 'optimal'
): \stdClass {
$params = [
'coin_to_sell' => $coinToSell,
'value_to_sell' => $valueToSell,
'coin_to_buy' => $coinToBuy
'coin_to_buy' => $coinToBuy,
'swap_from' => $swapFrom
];

if ($height) {
Expand All @@ -319,6 +323,7 @@ public function estimateCoinSellAll(
* @param string $valueToBuy
* @param string $coinToBuy
* @param null|int $height
* @param string $swapFrom
* @return \stdClass
* @throws Exception
* @throws GuzzleException
Expand All @@ -327,12 +332,15 @@ public function estimateCoinBuy(
string $coinToSell,
string $valueToBuy,
string $coinToBuy,
?int $height = null
?int $height = null,
string $swapFrom = 'optimal'
): \stdClass {
$params = [
'coin_to_sell' => $coinToSell,
'value_to_buy' => $valueToBuy,
'coin_to_buy' => $coinToBuy
'coin_to_buy' => $coinToBuy,
'swap_from' => $swapFrom

];

if ($height) {
Expand Down Expand Up @@ -517,4 +525,50 @@ public function getWaitlist(string $address, ?string $publicKey = null, ?int $he

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

/**
* @param int|null $height
* @return \stdClass
* @throws GuzzleException
*/
public function getPriceCommissions(?int $height = null): \stdClass
{
return $this->get('price_commissions', ($height ? ['height' => $height] : null));
}

/**
* @param int $height
* @return \stdClass
* @throws GuzzleException
*/
public function getPriceVotes(int $height): \stdClass
{
return $this->get('price_votes/' . $height);
}

/**
* @param string $coin0
* @param string $coin1
* @param int|null $height
* @return \stdClass
* @throws GuzzleException
*/
public function getSwapPool(string $coin0, string $coin1, ?int $height = null): \stdClass
{
return $this->get('swap_pool/' . $coin0 . '/' . $coin1, ($height ? ['height' => $height] : null));
}

/**
* @param string $coin0
* @param string $coin1
* @param string $provider
* @param int|null $height
* @return \stdClass
* @throws GuzzleException
*/
public function getSwapPoolProvider(string $coin0, string $coin1, string $provider, ?int $height = null): \stdClass
{
return $this->get('swap_pool/' . $coin0 . '/' . $coin1 . '/' . $provider, ($height ? ['height' => $height] : null));
}

}
60 changes: 60 additions & 0 deletions src/Minter/SDK/MinterCoins/MinterAddLiquidityTx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php


namespace Minter\SDK\MinterCoins;

use Minter\Contracts\MinterTxInterface;
use Minter\Library\Helper;
use Minter\SDK\MinterConverter;

/**
* Class MinterAddLiquidityTx
* @package Minter\SDK\MinterCoins
*/
class MinterAddLiquidityTx extends MinterCoinTx implements MinterTxInterface
{
public $coin0;
public $coin1;
public $volume0;
public $maximumVolume1;

const TYPE = 21;

/**
* MinterAddLiquidityTx constructor.
* @param $coin0
* @param $coin1
* @param $volume0
* @param $maximumVolume1
*/
public function __construct($coin0, $coin1, $volume0, $maximumVolume1)
{
$this->coin0 = $coin0;
$this->coin1 = $coin1;
$this->volume0 = $volume0;
$this->maximumVolume1 = $maximumVolume1;
}

/**
* Prepare data for signing
*
* @return array
*/
function encodeData(): array
{
return [
$this->coin0,
$this->coin1,
MinterConverter::convertToPip($this->volume0),
MinterConverter::convertToPip($this->maximumVolume1)
];
}

function decodeData()
{
$this->coin0 = hexdec($this->coin0);
$this->coin1 = hexdec($this->coin1);
$this->volume0 = MinterConverter::convertToBase(Helper::hexDecode($this->volume0));
$this->maximumVolume1 = MinterConverter::convertToBase(Helper::hexDecode($this->maximumVolume1));
}
}
49 changes: 49 additions & 0 deletions src/Minter/SDK/MinterCoins/MinterBurnTokenTx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Minter\SDK\MinterCoins;

use Minter\Contracts\MinterTxInterface;
use Minter\Library\Helper;
use Minter\SDK\MinterConverter;

/**
* Class MinterBurnTokenTx
* @package Minter\SDK\MinterCoins
*/
class MinterBurnTokenTx extends MinterCoinTx implements MinterTxInterface
{
public $coin;
public $value;

const TYPE = 29;

/**
* MinterBurnTokenTx constructor.
* @param $coin
* @param $value
*/
public function __construct($coin, $value)
{
$this->coin = $coin;
$this->value = $value;
}

/**
* Prepare data for signing
*
* @return array
*/
public function encodeData(): array
{
return [
$this->coin,
MinterConverter::convertToPip($this->value)
];
}

public function decodeData()
{
$this->coin = hexdec($this->coin);
$this->value = MinterConverter::convertToBase(Helper::hexDecode($this->value));
}
}
3 changes: 1 addition & 2 deletions src/Minter/SDK/MinterCoins/MinterBuyCoinTx.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class MinterBuyCoinTx extends MinterCoinTx implements MinterTxInterface
public $valueToBuy;
public $maximumValueToSell;

const TYPE = 4;
const COMMISSION = 100;
const TYPE = 4;

/**
* MinterBuyCoinTx constructor.
Expand Down
52 changes: 52 additions & 0 deletions src/Minter/SDK/MinterCoins/MinterBuySwapPoolTx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php


namespace Minter\SDK\MinterCoins;

use Minter\Contracts\MinterTxInterface;
use Minter\Library\Helper;
use Minter\SDK\MinterConverter;

/**
* Class MinterBuySwapPoolTx
* @package Minter\SDK\MinterCoins
*/
class MinterBuySwapPoolTx extends MinterCoinTx implements MinterTxInterface
{
public $coins;
public $valueToBuy;
public $maximumValueToSell;

const TYPE = 24;

/**
* MinterBuySwapPoolTx constructor.
* @param $coins
* @param $valueToBuy
* @param $maximumValueToSell
*/
public function __construct($coins, $valueToBuy, $maximumValueToSell)
{
$this->coins = $coins;
$this->valueToBuy = $valueToBuy;
$this->maximumValueToSell = $maximumValueToSell;
}

public function encodeData(): array
{
return [
$this->coins,
MinterConverter::convertToPip($this->valueToBuy),
MinterConverter::convertToPip($this->maximumValueToSell)
];
}

public function decodeData()
{
$this->valueToBuy = MinterConverter::convertToBase(Helper::hexDecode($this->valueToBuy));
$this->maximumValueToSell = MinterConverter::convertToBase(Helper::hexDecode($this->maximumValueToSell));
$this->coins = array_map(function ($value) {
return hexdec($value);
}, $this->coins);
}
}
61 changes: 31 additions & 30 deletions src/Minter/SDK/MinterCoins/MinterCoinTx.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,39 @@
abstract class MinterCoinTx implements MinterTxInterface
{
public const TYPE_TO_DATA = [
MinterSendCoinTx::TYPE => MinterSendCoinTx::class,
MinterSellCoinTx::TYPE => MinterSellCoinTx::class,
MinterSellAllCoinTx::TYPE => MinterSellAllCoinTx::class,
MinterBuyCoinTx::TYPE => MinterBuyCoinTx::class,
MinterCreateCoinTx::TYPE => MinterCreateCoinTx::class,
MinterDeclareCandidacyTx::TYPE => MinterDeclareCandidacyTx::class,
MinterDelegateTx::TYPE => MinterDelegateTx::class,
MinterUnbondTx::TYPE => MinterUnbondTx::class,
MinterRedeemCheckTx::TYPE => MinterRedeemCheckTx::class,
MinterSetCandidateOnTx::TYPE => MinterSetCandidateOnTx::class,
MinterSetCandidateOffTx::TYPE => MinterSetCandidateOffTx::class,
MinterCreateMultisigTx::TYPE => MinterCreateMultisigTx::class,
MinterMultiSendTx::TYPE => MinterMultiSendTx::class,
MinterEditCandidateTx::TYPE => MinterEditCandidateTx::class,
MinterRecreateCoinTx::TYPE => MinterRecreateCoinTx::class,
MinterEditCoinOwnerTx::TYPE => MinterEditCoinOwnerTx::class,
MinterSetHaltBlockTx::TYPE => MinterSetHaltBlockTx::class,
MinterEditMultisigTx::TYPE => MinterEditMultisigTx::class,
MinterPriceVoteTx::TYPE => MinterPriceVoteTx::class,
MinterEditCandidatePublicKeyTx::TYPE => MinterEditCandidatePublicKeyTx::class
MinterSendCoinTx::TYPE => MinterSendCoinTx::class,
MinterSellCoinTx::TYPE => MinterSellCoinTx::class,
MinterSellAllCoinTx::TYPE => MinterSellAllCoinTx::class,
MinterBuyCoinTx::TYPE => MinterBuyCoinTx::class,
MinterCreateCoinTx::TYPE => MinterCreateCoinTx::class,
MinterDeclareCandidacyTx::TYPE => MinterDeclareCandidacyTx::class,
MinterDelegateTx::TYPE => MinterDelegateTx::class,
MinterUnbondTx::TYPE => MinterUnbondTx::class,
MinterRedeemCheckTx::TYPE => MinterRedeemCheckTx::class,
MinterSetCandidateOnTx::TYPE => MinterSetCandidateOnTx::class,
MinterSetCandidateOffTx::TYPE => MinterSetCandidateOffTx::class,
MinterCreateMultisigTx::TYPE => MinterCreateMultisigTx::class,
MinterMultiSendTx::TYPE => MinterMultiSendTx::class,
MinterEditCandidateTx::TYPE => MinterEditCandidateTx::class,
MinterRecreateCoinTx::TYPE => MinterRecreateCoinTx::class,
MinterEditCoinOwnerTx::TYPE => MinterEditCoinOwnerTx::class,
MinterSetHaltBlockTx::TYPE => MinterSetHaltBlockTx::class,
MinterEditMultisigTx::TYPE => MinterEditMultisigTx::class,
MinterEditCandidatePublicKeyTx::TYPE => MinterEditCandidatePublicKeyTx::class,
MinterAddLiquidityTx::TYPE => MinterAddLiquidityTx::class,
MinterRemoveLiquidityTx::TYPE => MinterRemoveLiquidityTx::class,
MinterSellSwapPoolTx::TYPE => MinterSellSwapPoolTx::class,
MinterBuySwapPoolTx::TYPE => MinterBuySwapPoolTx::class,
MinterSellAllSwapPoolTx::TYPE => MinterSellAllSwapPoolTx::class,
MinterEditCandidateCommissionTx::TYPE => MinterEditCandidateCommissionTx::class,
MinterMintTokenTx::TYPE => MinterMintTokenTx::class,
MinterBurnTokenTx::TYPE => MinterBurnTokenTx::class,
MinterCreateTokenTx::TYPE => MinterCreateTokenTx::class,
MinterRecreateTokenTx::TYPE => MinterRecreateTokenTx::class,
MinterPriceCommissionTx::TYPE => MinterPriceCommissionTx::class,
MinterCreateSwapPoolTx::TYPE => MinterCreateSwapPoolTx::class
];

/**
* Get transaction data fee
*
* @return int
*/
public function getFee()
{
return static::COMMISSION;
}

/**
* @return int
*/
Expand Down
Loading

0 comments on commit 3f28e9b

Please sign in to comment.