-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new method CNet::queryTransactionTree (#27)
- Loading branch information
Showing
9 changed files
with
562 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Extraton\TonClient\Entity; | ||
|
||
use Extraton\TonClient\Exception\DataException; | ||
|
||
class AbstractData | ||
{ | ||
/** @var array<mixed> */ | ||
private array $data; | ||
|
||
/** | ||
* @param array<mixed> $data | ||
*/ | ||
public function __construct(array $data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
/** | ||
* @param string ...$keys | ||
* @return array|mixed|null | ||
*/ | ||
protected function getOriginData(string ...$keys) | ||
{ | ||
$result = $this->data; | ||
while ($key = array_shift($keys)) { | ||
if (!is_array($result) || !isset($result[$key])) { | ||
return null; | ||
} | ||
|
||
$result = $result[$key]; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param string ...$keys | ||
* @return array<mixed>|null | ||
*/ | ||
protected function getArray(string ...$keys): ?array | ||
{ | ||
$result = $this->getOriginData(...$keys); | ||
|
||
if (!is_array($result)) { | ||
return null; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param string ...$keys | ||
* @return string|null | ||
*/ | ||
protected function getString(string ...$keys): ?string | ||
{ | ||
$result = $this->getOriginData(...$keys); | ||
|
||
if (!is_string($result)) { | ||
return null; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param string ...$keys | ||
* @return int|null | ||
*/ | ||
protected function getInt(string ...$keys): ?int | ||
{ | ||
$result = $this->getOriginData(...$keys); | ||
|
||
if (!is_int($result)) { | ||
return null; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param string ...$keys | ||
* @return mixed | ||
* @throws DataException | ||
*/ | ||
protected function requireData(string ...$keys) | ||
{ | ||
$result = $this->getOriginData(...$keys); | ||
|
||
if ($result === null) { | ||
$path = implode('.', $keys); | ||
|
||
throw new DataException(sprintf('Data not found by key %s.', $path)); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param string ...$keys | ||
* @return array<mixed> | ||
* @throws DataException | ||
*/ | ||
protected function requireArray(string ...$keys): array | ||
{ | ||
$result = $this->requireData(...$keys); | ||
|
||
if (!is_array($result)) { | ||
$path = implode('.', $keys); | ||
|
||
throw new DataException(sprintf('Data is corrupted by key %s.', $path)); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param string ...$keys | ||
* @return string | ||
* @throws DataException | ||
*/ | ||
protected function requireString(string ...$keys): string | ||
{ | ||
$result = $this->requireData(...$keys); | ||
|
||
if (!is_string($result)) { | ||
$path = implode('.', $keys); | ||
|
||
throw new DataException(sprintf('Data is corrupted by key %s.', $path)); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param string ...$keys | ||
* @return int | ||
* @throws DataException | ||
*/ | ||
protected function requireInt(string ...$keys): int | ||
{ | ||
$result = $this->requireData(...$keys); | ||
|
||
if (!is_int($result)) { | ||
$path = implode('.', $keys); | ||
|
||
throw new DataException(sprintf('Data is corrupted by key %s.', $path)); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param string ...$keys | ||
* @return bool | ||
* @throws DataException | ||
*/ | ||
protected function requireBool(string ...$keys): bool | ||
{ | ||
$result = $this->requireData(...$keys); | ||
|
||
if (!is_bool($result)) { | ||
$path = implode('.', $keys); | ||
|
||
throw new DataException(sprintf('Data is corrupted by key %s.', $path)); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Extraton\TonClient\Entity\Net; | ||
|
||
use Extraton\TonClient\Entity\Abi\DecodedMessageBody; | ||
use Extraton\TonClient\Entity\AbstractData; | ||
use Extraton\TonClient\Handler\Response; | ||
|
||
/** | ||
* Type MessageNode | ||
*/ | ||
class MessageNode extends AbstractData | ||
{ | ||
/** | ||
* Create collection of MessageNode | ||
* | ||
* @param array<array<mixed>> $list | ||
* @return array<MessageNode> | ||
*/ | ||
public static function createCollection(array $list): array | ||
{ | ||
return array_map( | ||
fn ($data): self => new self($data), | ||
$list | ||
); | ||
} | ||
|
||
/** | ||
* Get message id | ||
* | ||
* @return string | ||
*/ | ||
public function getId(): string | ||
{ | ||
return $this->requireString('id'); | ||
} | ||
|
||
/** | ||
* Source transaction id. This field is missing for an external inbound messages. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getSrcTransactionId(): ?string | ||
{ | ||
return $this->getString('src_transaction_id'); | ||
} | ||
|
||
/** | ||
* Destination transaction id. This field is missing for an external outbound messages. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getDstTransactionId(): ?string | ||
{ | ||
return $this->getString('dst_transaction_id'); | ||
} | ||
|
||
/** | ||
* Get source address | ||
* | ||
* @return string|null | ||
*/ | ||
public function getSrcAddress(): ?string | ||
{ | ||
return $this->getString('src'); | ||
} | ||
|
||
/** | ||
* Destination address | ||
* | ||
* @return string|null | ||
*/ | ||
public function getDstAddress(): ?string | ||
{ | ||
return $this->getString('dst'); | ||
} | ||
|
||
/** | ||
* Get transferred tokens value | ||
* | ||
* @return string|null | ||
*/ | ||
public function getValue(): ?string | ||
{ | ||
return $this->getString('value'); | ||
} | ||
|
||
/** | ||
* Get bounce flag | ||
* | ||
* @return bool|null | ||
*/ | ||
public function getBounce(): ?bool | ||
{ | ||
return $this->requireBool('bounce'); | ||
} | ||
|
||
/** | ||
* Get decoded body. | ||
* Library tries to decode message body using provided params.abi_registry. | ||
* This field will be missing if none of the provided abi can be used to decode. | ||
* | ||
* @return DecodedMessageBody|null | ||
*/ | ||
public function getDecodedBody(): ?DecodedMessageBody | ||
{ | ||
$data = $this->getArray('decoded_body'); | ||
if ($data === null) { | ||
return null; | ||
} | ||
|
||
return new DecodedMessageBody(new Response($data)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Extraton\TonClient\Entity\Net; | ||
|
||
use Extraton\TonClient\Entity\AbstractResult; | ||
|
||
/** | ||
* Type ResultOfQueryTransactionTree | ||
*/ | ||
class ResultOfQueryTransactionTree extends AbstractResult | ||
{ | ||
/** | ||
* Get Messages | ||
* | ||
* @return array<MessageNode> | ||
*/ | ||
public function getMessages(): array | ||
{ | ||
return MessageNode::createCollection($this->requireArray('messages')); | ||
} | ||
|
||
/** | ||
* Get transactions | ||
* | ||
* @return array<TransactionNode> | ||
*/ | ||
public function getTransactions(): array | ||
{ | ||
return TransactionNode::createCollection($this->requireArray('transactions')); | ||
} | ||
} |
Oops, something went wrong.