From eedda35694ed0b0bec00cf119e6ac389d7a777b2 Mon Sep 17 00:00:00 2001 From: Kamil Mukhametzyanov Date: Tue, 23 Feb 2021 11:04:22 +0300 Subject: [PATCH] fix swap transactions --- .../SDK/MinterCoins/MinterBuySwapPoolTx.php | 19 +++++++-------- .../MinterCoins/MinterSellAllSwapPoolTx.php | 21 ++++++++--------- .../SDK/MinterCoins/MinterSellSwapPoolTx.php | 23 ++++++++----------- src/Minter/SDK/MinterTx.php | 15 +++++++++++- tests/MinterBuySwapPoolTxTest.php | 7 +++--- tests/MinterSellAllSwapPoolTxTest.php | 9 ++++---- tests/MinterSellSwapPoolTxTest.php | 7 +++--- 7 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/Minter/SDK/MinterCoins/MinterBuySwapPoolTx.php b/src/Minter/SDK/MinterCoins/MinterBuySwapPoolTx.php index eed0c6e..270ceba 100644 --- a/src/Minter/SDK/MinterCoins/MinterBuySwapPoolTx.php +++ b/src/Minter/SDK/MinterCoins/MinterBuySwapPoolTx.php @@ -13,8 +13,7 @@ */ class MinterBuySwapPoolTx extends MinterCoinTx implements MinterTxInterface { - public $coinToBuy; - public $coinToSell; + public $coins; public $valueToBuy; public $maximumValueToSell; @@ -22,15 +21,13 @@ class MinterBuySwapPoolTx extends MinterCoinTx implements MinterTxInterface /** * MinterBuySwapPoolTx constructor. - * @param $coinToBuy + * @param $coins * @param $valueToBuy - * @param $coinToSell * @param $maximumValueToSell */ - public function __construct($coinToBuy, $valueToBuy, $coinToSell, $maximumValueToSell) + public function __construct($coins, $valueToBuy, $maximumValueToSell) { - $this->coinToBuy = $coinToBuy; - $this->coinToSell = $coinToSell; + $this->coins = $coins; $this->valueToBuy = $valueToBuy; $this->maximumValueToSell = $maximumValueToSell; } @@ -38,18 +35,18 @@ public function __construct($coinToBuy, $valueToBuy, $coinToSell, $maximumValueT public function encodeData(): array { return [ - $this->coinToBuy, + $this->coins, MinterConverter::convertToPip($this->valueToBuy), - $this->coinToSell, MinterConverter::convertToPip($this->maximumValueToSell) ]; } public function decodeData() { - $this->coinToBuy = hexdec($this->coinToBuy); $this->valueToBuy = MinterConverter::convertToBase(Helper::hexDecode($this->valueToBuy)); - $this->coinToSell = hexdec($this->coinToSell); $this->maximumValueToSell = MinterConverter::convertToBase(Helper::hexDecode($this->maximumValueToSell)); + $this->coins = array_map(function ($value) { + return hexdec($value); + }, $this->coins); } } \ No newline at end of file diff --git a/src/Minter/SDK/MinterCoins/MinterSellAllSwapPoolTx.php b/src/Minter/SDK/MinterCoins/MinterSellAllSwapPoolTx.php index 9c625b3..f55072e 100644 --- a/src/Minter/SDK/MinterCoins/MinterSellAllSwapPoolTx.php +++ b/src/Minter/SDK/MinterCoins/MinterSellAllSwapPoolTx.php @@ -13,22 +13,19 @@ */ class MinterSellAllSwapPoolTx extends MinterCoinTx implements MinterTxInterface { - public $coinToBuy; - public $coinToSell; + public $coins; public $minimumValueToBuy; const TYPE = 25; /** * MinterSellAllSwapPoolTx constructor. - * @param $coinToSell - * @param $coinToBuy - * @param $minimumValueToBuy + * @param array $coins + * @param $minimumValueToBuy */ - public function __construct($coinToSell, $coinToBuy, $minimumValueToBuy) + public function __construct(array $coins, $minimumValueToBuy) { - $this->coinToBuy = $coinToBuy; - $this->coinToSell = $coinToSell; + $this->coins = $coins; $this->minimumValueToBuy = $minimumValueToBuy; } @@ -40,16 +37,16 @@ public function __construct($coinToSell, $coinToBuy, $minimumValueToBuy) public function encodeData(): array { return [ - $this->coinToSell, - $this->coinToBuy, + $this->coins, MinterConverter::convertToPip($this->minimumValueToBuy) ]; } public function decodeData() { - $this->coinToSell = hexdec($this->coinToSell); - $this->coinToBuy = hexdec($this->coinToBuy); $this->minimumValueToBuy = MinterConverter::convertToBase(Helper::hexDecode($this->minimumValueToBuy)); + $this->coins = array_map(function ($value) { + return hexdec($value); + }, $this->coins); } } \ No newline at end of file diff --git a/src/Minter/SDK/MinterCoins/MinterSellSwapPoolTx.php b/src/Minter/SDK/MinterCoins/MinterSellSwapPoolTx.php index aca4cd2..f3c294e 100644 --- a/src/Minter/SDK/MinterCoins/MinterSellSwapPoolTx.php +++ b/src/Minter/SDK/MinterCoins/MinterSellSwapPoolTx.php @@ -13,8 +13,7 @@ */ class MinterSellSwapPoolTx extends MinterCoinTx implements MinterTxInterface { - public $coinToBuy; - public $coinToSell; + public $coins; public $valueToSell; public $minimumValueToBuy; @@ -22,15 +21,13 @@ class MinterSellSwapPoolTx extends MinterCoinTx implements MinterTxInterface /** * MinterSellSwapPoolTx constructor. - * @param $coinToSell - * @param $valueToSell - * @param $coinToBuy - * @param $minimumValueToBuy + * @param array $coins + * @param $valueToSell + * @param $minimumValueToBuy */ - public function __construct($coinToSell, $valueToSell, $coinToBuy, $minimumValueToBuy) + public function __construct(array $coins, $valueToSell, $minimumValueToBuy) { - $this->coinToBuy = $coinToBuy; - $this->coinToSell = $coinToSell; + $this->coins = $coins; $this->valueToSell = $valueToSell; $this->minimumValueToBuy = $minimumValueToBuy; } @@ -43,18 +40,18 @@ public function __construct($coinToSell, $valueToSell, $coinToBuy, $minimumValue public function encodeData(): array { return [ - $this->coinToSell, + $this->coins, MinterConverter::convertToPip($this->valueToSell), - $this->coinToBuy, MinterConverter::convertToPip($this->minimumValueToBuy) ]; } public function decodeData() { - $this->coinToSell = hexdec($this->coinToSell); $this->valueToSell = MinterConverter::convertToBase(Helper::hexDecode($this->valueToSell)); - $this->coinToBuy = hexdec($this->coinToBuy); $this->minimumValueToBuy = MinterConverter::convertToBase(Helper::hexDecode($this->minimumValueToBuy)); + $this->coins = array_map(function ($value) { + return hexdec($value); + }, $this->coins); } } \ No newline at end of file diff --git a/src/Minter/SDK/MinterTx.php b/src/Minter/SDK/MinterTx.php index a365435..16427ef 100644 --- a/src/Minter/SDK/MinterTx.php +++ b/src/Minter/SDK/MinterTx.php @@ -4,18 +4,31 @@ use InvalidArgumentException; use Minter\Contracts\MinterTxInterface; +use Minter\SDK\MinterCoins\MinterAddLiquidityTx; +use Minter\SDK\MinterCoins\MinterBurnTokenTx; use Minter\SDK\MinterCoins\MinterBuyCoinTx; +use Minter\SDK\MinterCoins\MinterBuySwapPoolTx; +use Minter\SDK\MinterCoins\MinterCreateSwapPoolTx; +use Minter\SDK\MinterCoins\MinterCreateTokenTx; use Minter\SDK\MinterCoins\MinterEditCoinOwnerTx; use Minter\SDK\MinterCoins\MinterCreateCoinTx; use Minter\SDK\MinterCoins\MinterCreateMultisigTx; use Minter\SDK\MinterCoins\MinterDeclareCandidacyTx; use Minter\SDK\MinterCoins\MinterDelegateTx; use Minter\SDK\MinterCoins\MinterEditCandidateTx; +use Minter\SDK\MinterCoins\MinterMintTokenTx; +use Minter\SDK\MinterCoins\MinterMoveStakeTx; use Minter\SDK\MinterCoins\MinterMultiSendTx; +use Minter\SDK\MinterCoins\MinterPriceCommissionTx; +use Minter\SDK\MinterCoins\MinterPriceVoteTx; use Minter\SDK\MinterCoins\MinterRecreateCoinTx; +use Minter\SDK\MinterCoins\MinterRecreateTokenTx; use Minter\SDK\MinterCoins\MinterRedeemCheckTx; +use Minter\SDK\MinterCoins\MinterRemoveLiquidityTx; use Minter\SDK\MinterCoins\MinterSellAllCoinTx; +use Minter\SDK\MinterCoins\MinterSellAllSwapPoolTx; use Minter\SDK\MinterCoins\MinterSellCoinTx; +use Minter\SDK\MinterCoins\MinterSellSwapPoolTx; use Minter\SDK\MinterCoins\MinterSendCoinTx; use Minter\SDK\MinterCoins\MinterSetCandidateOffTx; use Minter\SDK\MinterCoins\MinterSetCandidateOnTx; @@ -350,7 +363,7 @@ public function getSignatureData(): MinterSignature } /** - * @return MinterSendCoinTx|MinterBuyCoinTx|MinterSellCoinTx|MinterSellAllCoinTx|MinterDelegateTx|MinterUnbondTx|MinterMultiSendTx|MinterCreateMultisigTx|MinterCreateCoinTx|MinterRecreateCoinTx|MinterEditCoinOwnerTx|MinterDeclareCandidacyTx|MinterSetCandidateOnTx|MinterSetCandidateOffTx|MinterEditCandidateTx|MinterRedeemCheckTx|MinterSetHaltBlockTx + * @return MinterSendCoinTx|MinterBuyCoinTx|MinterSellCoinTx|MinterSellAllCoinTx|MinterDelegateTx|MinterUnbondTx|MinterMultiSendTx|MinterCreateMultisigTx|MinterCreateCoinTx|MinterRecreateCoinTx|MinterEditCoinOwnerTx|MinterDeclareCandidacyTx|MinterSetCandidateOnTx|MinterSetCandidateOffTx|MinterEditCandidateTx|MinterRedeemCheckTx|MinterSetHaltBlockTx|MinterSellSwapPoolTx|MinterSellAllSwapPoolTx|MinterBuySwapPoolTx|MinterPriceVoteTx|MinterPriceCommissionTx|MinterCreateTokenTx|MinterRecreateTokenTx|MinterCreateSwapPoolTx|MinterBurnTokenTx|MinterMintTokenTx|MinterAddLiquidityTx|MinterMoveStakeTx|MinterRemoveLiquidityTx */ public function getData(): MinterTxInterface { diff --git a/tests/MinterBuySwapPoolTxTest.php b/tests/MinterBuySwapPoolTxTest.php index ddd5306..7840efa 100644 --- a/tests/MinterBuySwapPoolTxTest.php +++ b/tests/MinterBuySwapPoolTxTest.php @@ -20,7 +20,7 @@ final class MinterBuySwapPoolTxTest extends TestCase /** * Predefined valid signature */ - const VALID_SIGNATURE = '0xf8670e0201801897d6018829a2241af62c0000808a010f0cf064dd59200000808001b845f8431ba06f309b5ebb47042147c0e6481e186bdd06d6e883b680c7f282495efb75e83423a076aa9b5da356f9075604c0f6e20ac64832b1df885fdbe28010cc006b38c48d8d'; + const VALID_SIGNATURE = '0xf8680e0201801898d7c202038829a2241af62c00008a010f0cf064dd59200000808001b845f8431ca0d77c1c580754c5143abb5a3ad3f5e892ebd36e7f9f44b7da2734ffff6c2e9611a022034256303ee750a9b32b148e60c6fff34665b5854f1a9770f7ab4a8a26cc00'; /** * Test to decode data for MinterBuySwapPoolTx @@ -34,9 +34,8 @@ public function testDecode(): void $this->assertSame($validTx->getGasCoin(), $tx->getGasCoin()); $this->assertSame($validTx->getGasPrice(), $tx->getGasPrice()); $this->assertSame($validTx->getChainID(), $tx->getChainID()); - $this->assertSame($validTx->getData()->coinToBuy, $tx->getData()->coinToBuy); + $this->assertSame($validTx->getData()->coins, $tx->getData()->coins); $this->assertSame($validTx->getData()->valueToBuy, $tx->getData()->valueToBuy); - $this->assertSame($validTx->getData()->coinToSell, $tx->getData()->coinToSell); $this->assertSame($validTx->getData()->maximumValueToSell, $tx->getData()->maximumValueToSell); $this->assertSame(self::MINTER_ADDRESS, $tx->getSenderAddress()); } @@ -55,7 +54,7 @@ public function testSign(): void */ private function makeTransaction(): MinterTx { - $data = new MinterBuySwapPoolTx(1, '3', 0, '5000'); + $data = new MinterBuySwapPoolTx([2, 3], '3', '5000'); return (new MinterTx(14, $data))->setChainID(MinterTx::TESTNET_CHAIN_ID); } } \ No newline at end of file diff --git a/tests/MinterSellAllSwapPoolTxTest.php b/tests/MinterSellAllSwapPoolTxTest.php index 3a4aa47..383393e 100644 --- a/tests/MinterSellAllSwapPoolTxTest.php +++ b/tests/MinterSellAllSwapPoolTxTest.php @@ -20,22 +20,21 @@ class MinterSellAllSwapPoolTxTest extends TestCase /** * Predefined valid signature */ - const VALID_SIGNATURE = '0xf85d10020180198dcc018089056bc75e2d63100000808001b845f8431ca0e50537db70ed7263094cfaee22c69545c0c41e9efedef521c0ecce3a4f33ade6a03e71cde08a52561136584bc14707b3c01e618513b01a96b9865b44ff0395fc7a'; + const VALID_SIGNATURE = '0xf85f10020180198fcec301040589056bc75e2d63100000808001b845f8431ca095651bdd2afa8964213f7bc064898b0edeb67fa39f3a0c71b52934f6463412afa0604ced9ff973bf1de6b252c9582982780cf1de4fd2b2e3814bfa8185d10bd6f5'; /** * Test to decode data for MinterSellAllSwapPoolTx */ public function testDecode(): void { - $tx = MinterTx::decode(self::VALID_SIGNATURE); + $tx = MinterTx::decode(self::VALID_SIGNATURE); $validTx = $this->makeTransaction(); $this->assertSame($validTx->getNonce(), $tx->getNonce()); $this->assertSame($validTx->getGasCoin(), $tx->getGasCoin()); $this->assertSame($validTx->getGasPrice(), $tx->getGasPrice()); $this->assertSame($validTx->getChainID(), $tx->getChainID()); - $this->assertSame($validTx->getData()->coinToBuy, $tx->getData()->coinToBuy); - $this->assertSame($validTx->getData()->coinToSell, $tx->getData()->coinToSell); + $this->assertSame($validTx->getData()->coins, $tx->getData()->coins); $this->assertSame($validTx->getData()->minimumValueToBuy, $tx->getData()->minimumValueToBuy); $this->assertSame(self::MINTER_ADDRESS, $tx->getSenderAddress()); } @@ -54,7 +53,7 @@ public function testSign(): void */ private function makeTransaction(): MinterTx { - $data = new MinterSellAllSwapPoolTx(1, 0, '100'); + $data = new MinterSellAllSwapPoolTx([1, 4, 5], '100'); return (new MinterTx(16, $data))->setChainID(MinterTx::TESTNET_CHAIN_ID); } } \ No newline at end of file diff --git a/tests/MinterSellSwapPoolTxTest.php b/tests/MinterSellSwapPoolTxTest.php index 7b59113..128151b 100644 --- a/tests/MinterSellSwapPoolTxTest.php +++ b/tests/MinterSellSwapPoolTxTest.php @@ -20,7 +20,7 @@ final class MinterSellSwapPoolTxTest extends TestCase /** * Predefined valid signature */ - const VALID_SIGNATURE = '0xf866050201801796d5018901158e460913d0000080881bc16d674ec80000808001b845f8431ba09e7c9adca770f8bdb6822d447c656dd0203ae97d0284153be7d6bfc8e07c4456a03cbe6a6db71cecacd5ee149c6c518b0d61b763a9265b5f2847fd150124571ccc'; + const VALID_SIGNATURE = '0xf867050201801797d6c201028901158e460913d00000881bc16d674ec80000808001b845f8431ba01ba1d7c9c05993e6d92d4db8cb24b32c9a28f61286464e41ffcaf86551f97a79a042dcd34363bd981676541b8e8f88b8bbbfcbf0746db2017be73f378afbf045c2'; /** * Test to decode data for MinterSellSwapPoolTx @@ -34,9 +34,8 @@ public function testDecode(): void $this->assertSame($validTx->getGasCoin(), $tx->getGasCoin()); $this->assertSame($validTx->getGasPrice(), $tx->getGasPrice()); $this->assertSame($validTx->getChainID(), $tx->getChainID()); - $this->assertSame($validTx->getData()->coinToSell, $tx->getData()->coinToSell); + $this->assertSame($validTx->getData()->coins, $tx->getData()->coins); $this->assertSame($validTx->getData()->valueToSell, $tx->getData()->valueToSell); - $this->assertSame($validTx->getData()->coinToBuy, $tx->getData()->coinToBuy); $this->assertSame($validTx->getData()->minimumValueToBuy, $tx->getData()->minimumValueToBuy); $this->assertSame(self::MINTER_ADDRESS, $tx->getSenderAddress()); } @@ -55,7 +54,7 @@ public function testSign(): void */ private function makeTransaction(): MinterTx { - $data = new MinterSellSwapPoolTx(1, '20', 0, '2'); + $data = new MinterSellSwapPoolTx([1, 2], '20', '2'); return (new MinterTx(5, $data))->setChainID(MinterTx::TESTNET_CHAIN_ID); } } \ No newline at end of file