diff --git a/src/Minter/SDK/MinterCoins/MinterCoinTx.php b/src/Minter/SDK/MinterCoins/MinterCoinTx.php index e8b6575..8884a75 100644 --- a/src/Minter/SDK/MinterCoins/MinterCoinTx.php +++ b/src/Minter/SDK/MinterCoins/MinterCoinTx.php @@ -49,6 +49,7 @@ abstract class MinterCoinTx implements MinterTxInterface MinterMoveStakeTx::TYPE => MinterMoveStakeTx::class, MinterLockStakeTx::TYPE => MinterLockStakeTx::class, MinterLockTx::TYPE => MinterLockTx::class, + MinterVoteUpdateTx::TYPE => MinterVoteUpdateTx::class, ]; /** diff --git a/src/Minter/SDK/MinterCoins/MinterVoteUpdateTx.php b/src/Minter/SDK/MinterCoins/MinterVoteUpdateTx.php new file mode 100644 index 0000000..0709ea2 --- /dev/null +++ b/src/Minter/SDK/MinterCoins/MinterVoteUpdateTx.php @@ -0,0 +1,53 @@ +publicKey = $publicKey; + $this->version = $version; + $this->height = $height; + } + + /** + * Prepare data for signing + * + * @return array + */ + public function encodeData(): array + { + return [ + $this->version, + hex2bin(Helper::removePrefix($this->publicKey, MinterPrefix::PUBLIC_KEY)), + $this->height + ]; + } + + public function decodeData() + { + $this->publicKey = MinterPrefix::PUBLIC_KEY . $this->publicKey; + $this->height = hexdec($this->height); + $this->version = Helper::hex2str($this->version); + } +} \ No newline at end of file diff --git a/src/Minter/SDK/MinterTx.php b/src/Minter/SDK/MinterTx.php index 67f8619..bba0776 100644 --- a/src/Minter/SDK/MinterTx.php +++ b/src/Minter/SDK/MinterTx.php @@ -37,6 +37,7 @@ use Minter\SDK\MinterCoins\MinterSetCandidateOnTx; use Minter\SDK\MinterCoins\MinterSetHaltBlockTx; use Minter\SDK\MinterCoins\MinterUnbondTx; +use Minter\SDK\MinterCoins\MinterVoteUpdateTx; use Web3p\RLP\RLP;; use Minter\Library\Helper; use Minter\SDK\MinterCoins\MinterCoinTx; @@ -375,7 +376,7 @@ public function getSignatureData(): MinterSignature } /** - * @return MinterSendCoinTx|MinterBuyCoinTx|MinterSellCoinTx|MinterSellAllCoinTx|MinterDelegateTx|MinterUnbondTx|MinterMultiSendTx|MinterCreateMultisigTx|MinterCreateCoinTx|MinterRecreateCoinTx|MinterEditCoinOwnerTx|MinterDeclareCandidacyTx|MinterSetCandidateOnTx|MinterSetCandidateOffTx|MinterEditCandidateTx|MinterRedeemCheckTx|MinterSetHaltBlockTx|MinterSellSwapPoolTx|MinterSellAllSwapPoolTx|MinterBuySwapPoolTx|MinterPriceCommissionTx|MinterCreateTokenTx|MinterRecreateTokenTx|MinterCreateSwapPoolTx|MinterBurnTokenTx|MinterMintTokenTx|MinterAddLiquidityTx|MinterRemoveLiquidityTx|MinterAddLimitOrderTx|MinterRemoveLimitOrderTx|MinterLockTx|MinterLockStakeTx|MinterMoveStakeTx + * @return MinterSendCoinTx|MinterBuyCoinTx|MinterSellCoinTx|MinterSellAllCoinTx|MinterDelegateTx|MinterUnbondTx|MinterMultiSendTx|MinterCreateMultisigTx|MinterCreateCoinTx|MinterRecreateCoinTx|MinterEditCoinOwnerTx|MinterDeclareCandidacyTx|MinterSetCandidateOnTx|MinterSetCandidateOffTx|MinterEditCandidateTx|MinterRedeemCheckTx|MinterSetHaltBlockTx|MinterSellSwapPoolTx|MinterSellAllSwapPoolTx|MinterBuySwapPoolTx|MinterPriceCommissionTx|MinterCreateTokenTx|MinterRecreateTokenTx|MinterCreateSwapPoolTx|MinterBurnTokenTx|MinterMintTokenTx|MinterAddLiquidityTx|MinterRemoveLiquidityTx|MinterAddLimitOrderTx|MinterRemoveLimitOrderTx|MinterLockTx|MinterLockStakeTx|MinterMoveStakeTx|MinterVoteUpdateTx */ public function getData(): MinterTxInterface { diff --git a/tests/MinterVoteUpdateTxTest.php b/tests/MinterVoteUpdateTxTest.php new file mode 100644 index 0000000..b2b169a --- /dev/null +++ b/tests/MinterVoteUpdateTxTest.php @@ -0,0 +1,68 @@ +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()->publicKey, $tx->getData()->publicKey); + $this->assertSame($validTx->getData()->version, $tx->getData()->version); + $this->assertSame($validTx->getData()->height, $tx->getData()->height); + $this->assertSame(self::MINTER_ADDRESS, $tx->getSenderAddress()); + } + + /** + * Test signing MinterUnbondTx + */ + public function testSign(): void + { + $signature = $this->makeTransaction()->sign(self::PRIVATE_KEY); + $this->assertSame($signature, self::VALID_SIGNATURE); + } + + /** + * @return MinterTx + */ + private function makeTransaction(): MinterTx + { + $data = new MinterVoteUpdateTx( + 'test', + 'Mpd83e627510eea6aefa46d9914b0715dabf4a561ced78d34267b31d41d5f700b5', + 99999999, '100' + ); + + return (new MinterTx(1, $data))->setTestnetChainId(); + } +}