Skip to content

Commit

Permalink
Added DaemonRpcClient::getTransactionPool()
Browse files Browse the repository at this point in the history
  • Loading branch information
refring committed Oct 11, 2023
1 parent 6e72090 commit 8c7bc18
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 35 deletions.
19 changes: 6 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Please review these guidelines before submitting any pull requests.

## Guidelines

* Please ensure the coding style running `composer lint`.
* Please ensure the coding style running `composer lint` and running phpstan `composer test:phpstan`.
* Send a coherent commit history, making sure each individual commit in your pull request is meaningful.
* You may need to [rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) to avoid merge conflicts.
* Please remember that we follow [SemVer](http://semver.org/).
Expand All @@ -24,13 +24,6 @@ Clone your fork, then install the dev dependencies:
composer install
```

## Refactor

Refactor your code:
```bash
composer refactor
```

## Lint

Lint your code:
Expand All @@ -47,15 +40,15 @@ composer test

Check code quality:
```bash
composer test:refactor
composer test:phpstan
```

Check types:
Unit tests:
```bash
composer test:types
composer test:unit
```

Unit tests:
Integration tests:
```bash
composer test:unit
composer test:integration
```
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ After that, run `composer test:integration` to run the integration tests.
## Roadmap
- [ ] More integration tests
- [ ] Improve documentation and add examples
- [ ] Implement remaining 'Other Daemon RPC Calls'
- [ ] /get_transaction_pool

## Contributing

Expand Down
3 changes: 0 additions & 3 deletions src/DaemonOther/GetOutsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
use RefRing\MoneroRpcPhp\Model\GetOutputsOut;
use RefRing\MoneroRpcPhp\Request\OtherRpcRequest;
use Square\Pjson\Json;
use Square\Pjson\JsonSerialize;

/**
* Get outputs.
*/
class GetOutsRequest extends OtherRpcRequest
{
use JsonSerialize;

/** @var GetOutputsOut[] */
#[Json]
public array $outputs;
Expand Down
16 changes: 16 additions & 0 deletions src/DaemonOther/GetTransactionPoolRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace RefRing\MoneroRpcPhp\DaemonOther;

use RefRing\MoneroRpcPhp\Request\OtherRpcRequest;
use RefRing\MoneroRpcPhp\Trait\EmptyOtherRpcRequest;

/**
* Show information about valid transactions seen by the node but not yet mined into a block, as well as spent key image information for the txpool in the node's memory.
*/
class GetTransactionPoolRequest extends OtherRpcRequest
{
use EmptyOtherRpcRequest;
}
29 changes: 29 additions & 0 deletions src/DaemonOther/GetTransactionPoolResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace RefRing\MoneroRpcPhp\DaemonOther;

use RefRing\MoneroRpcPhp\DaemonRpc\DaemonRpcAccessResponseFields;
use RefRing\MoneroRpcPhp\Model\MemPoolTransaction;
use RefRing\MoneroRpcPhp\Model\SpentOutputKeyImages;
use RefRing\MoneroRpcPhp\Trait\JsonSerializeBigInt;
use Square\Pjson\Json;
use Square\Pjson\JsonDataSerializable;

/**
* Show information about valid transactions seen by the node but not yet mined into a block, as well as spent key image information for the txpool in the node's memory.
*/
class GetTransactionPoolResponse implements JsonDataSerializable
{
use JsonSerializeBigInt;
use DaemonRpcAccessResponseFields;

/** @var SpentOutputKeyImages[] */
#[Json('spent_key_images', type: SpentOutputKeyImages::class)]
public array $spentKeyImages;

/** @var MemPoolTransaction[] */
#[Json(type: MemPoolTransaction::class)]
public array $transactions;
}
3 changes: 0 additions & 3 deletions src/DaemonOther/GetTransactionsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

use RefRing\MoneroRpcPhp\Request\OtherRpcRequest;
use Square\Pjson\Json;
use Square\Pjson\JsonSerialize;

/**
* Look up one or more transactions by hash.
*/
class GetTransactionsRequest extends OtherRpcRequest
{
use JsonSerialize;

/**
* @var string[] List of transaction hashes to look up.
*/
Expand Down
15 changes: 15 additions & 0 deletions src/DaemonRpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use RefRing\MoneroRpcPhp\DaemonOther\GetOutsResponse;
use RefRing\MoneroRpcPhp\DaemonOther\GetPeerListRequest;
use RefRing\MoneroRpcPhp\DaemonOther\GetPeerListResponse;
use RefRing\MoneroRpcPhp\DaemonOther\GetTransactionPoolRequest;
use RefRing\MoneroRpcPhp\DaemonOther\GetTransactionPoolResponse;
use RefRing\MoneroRpcPhp\DaemonOther\GetTransactionPoolStatsRequest;
use RefRing\MoneroRpcPhp\DaemonOther\GetTransactionPoolStatsResponse;
use RefRing\MoneroRpcPhp\DaemonOther\GetTransactionsRequest;
Expand Down Expand Up @@ -809,6 +811,19 @@ public function getTransactions(
*/
public function stopDaemon(): StopDaemonResponse
{
$this->endPointPath = '/stop_daemon';
return $this->handleRequest(StopDaemonRequest::create(), StopDaemonResponse::class);
}

/**
* Show information about valid transactions seen by the node but not yet mined into a block,
* as well as spent key image information for the txpool in the node's memory.
*
* @throws MoneroRpcException
*/
public function getTransactionPool(): GetTransactionPoolResponse
{
$this->endPointPath = '/get_transaction_pool';
return $this->handleRequest(GetTransactionPoolRequest::create(), GetTransactionPoolResponse::class);
}
}
4 changes: 2 additions & 2 deletions src/Model/GetOutputsOut.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace RefRing\MoneroRpcPhp\Model;

use RefRing\MoneroRpcPhp\Trait\JsonSerializeBigInt;
use Square\Pjson\Json;
use Square\Pjson\JsonDataSerializable;
use Square\Pjson\JsonSerialize;

class GetOutputsOut implements JsonDataSerializable
{
use JsonSerialize;
use JsonSerializeBigInt;

#[Json]
public int $amount;
Expand Down
6 changes: 3 additions & 3 deletions src/Model/GetTransactionsEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class GetTransactionsEntry
public string $asJson;

/**
* @var Transaction The transaction information as an object
* @var TransactionData The transaction information as an object
*/
public Transaction $transaction;
public TransactionData $transaction;

/**
* block height including the transaction
Expand Down Expand Up @@ -128,7 +128,7 @@ public static function fromJsonData($jd, array|string $path = []): static
{
$data = self::fromJsonDataOriginal($jd, $path);

$transaction = Transaction::fromJsonString($jd['as_json']);
$transaction = TransactionData::fromJsonString($jd['as_json']);
$data->transaction = $transaction;

return $data;
Expand Down
160 changes: 160 additions & 0 deletions src/Model/MemPoolTransaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php

declare(strict_types=1);

namespace RefRing\MoneroRpcPhp\Model;

use RefRing\MoneroRpcPhp\Monero\Amount;
use RefRing\MoneroRpcPhp\Trait\JsonSerializeBigInt;
use Square\Pjson\Json;
use Square\Pjson\JsonDataSerializable;

class MemPoolTransaction implements JsonDataSerializable
{
use JsonSerializeBigInt{
fromJsonData as fromJsonDataOriginal;
}

/**
* The size of the full transaction blob.
*/
#[Json('blob_size')]
public int $blobSize;

#[Json('do_not_relay')]
public bool $doNotRelay;

/**
* States if this transaction has been seen as double spend.
*/
#[Json('double_spend_seen')]
public bool $doubleSpendSeen;

/**
* The amount of the mining fee included in the transaction, in piconero.
*/
#[Json]
public Amount $fee;

/**
* The transaction ID hash.
*/
#[Json('id_hash')]
public string $idHash;

/**
* States if the tx was included in a block at least once (`true`) or not (`false`).
*/
#[Json('kept_by_block')]
public bool $keptByBlock;

/**
* If the transaction validation has previously failed, this tells at what height that occured.
*/
#[Json('last_failed_height')]
public int $lastFailedHeight;

/**
* Like the previous, this tells the previous transaction ID hash.
*/
#[Json('last_failed_id_hash')]
public string $lastFailedIdHash;

/**
* Last unix time at which the transaction has been relayed.
*/
#[Json('last_relayed_time')]
public int $lastRelayedTime;

/**
* Tells the height of the most recent block with an output used in this transaction.
*/
#[Json('max_used_block_height')]
public int $maxUsedBlockHeight;

/**
* Tells the hash of the most recent block with an output used in this transaction.
*/
#[Json('max_used_block_id_hash')]
public string $maxUsedBlockIdHash;

/**
* The Unix time that the transaction was first seen on the network by the node.
*/
#[Json('receive_time')]
public int $receiveTime;

/**
* States if this transaction has been relayed
*/
#[Json]
public bool $relayed;

/**
* Hexadecimal blob represnting the transaction.
*/
#[Json('tx_blob')]
public string $txBlob;

/**
* JSON structure of all information in the transaction:
*/
#[Json('tx_json')]
public string $txJson;

/**
* Structure of all information in the transaction
*/
public ?TransactionData $transaction = null;

#[Json]
public int $weight;

public function __construct(
int $blobSize,
bool $doubleSpendSeen,
Amount $fee,
string $idHash,
bool $keptByBlock,
int $lastFailedHeight,
string $lastFailedIdHash,
int $lastRelayedTime,
int $maxUsedBlockHeight,
string $maxUsedBlockIdHash,
int $receiveTime,
bool $relayed,
string $txBlob,
string $txJson,
int $weight,
) {
$this->blobSize = $blobSize;
$this->doubleSpendSeen = $doubleSpendSeen;
$this->fee = $fee;
$this->idHash = $idHash;
$this->keptByBlock = $keptByBlock;
$this->lastFailedHeight = $lastFailedHeight;
$this->lastFailedIdHash = $lastFailedIdHash;
$this->lastRelayedTime = $lastRelayedTime;
$this->maxUsedBlockHeight = $maxUsedBlockHeight;
$this->maxUsedBlockIdHash = $maxUsedBlockIdHash;
$this->receiveTime = $receiveTime;
$this->relayed = $relayed;
$this->txBlob = $txBlob;
$this->txJson = $txJson;
$this->weight = $weight;
}

/**
* @param string[] $jd
* @param mixed[]|string $path
*/
public static function fromJsonData($jd, array|string $path = []): static
{
$data = self::fromJsonDataOriginal($jd, $path);

$transaction = TransactionData::fromJsonString($jd['tx_json']);
$data->transaction = $transaction;

return $data;
}
}
4 changes: 2 additions & 2 deletions src/Model/OutputKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace RefRing\MoneroRpcPhp\Model;

use RefRing\MoneroRpcPhp\Trait\JsonSerializeBigInt;
use Square\Pjson\Json;
use Square\Pjson\JsonDataSerializable;
use Square\Pjson\JsonSerialize;

class OutputKey implements JsonDataSerializable
{
use JsonSerialize;
use JsonSerializeBigInt;

/**
* block height of the output
Expand Down

0 comments on commit 8c7bc18

Please sign in to comment.