Skip to content

Commit

Permalink
add transaction log events
Browse files Browse the repository at this point in the history
  • Loading branch information
michavie committed Aug 10, 2022
1 parent 0dc8f66 commit a33c8db
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 105 deletions.
2 changes: 2 additions & 0 deletions src/Api/Entities/TransactionDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(
public ?string $tokenIdentifier = null,
public ?string $tokenValue = null,
public Collection $results = new Collection,
public ?TransactionLog $logs = null,
) {
}

Expand All @@ -41,6 +42,7 @@ protected static function transformResponse(array $res): array
'data' => isset($res['data']) ? base64_decode($res['data']) : null,
'timestamp' => isset($res['timestamp']) ? Carbon::createFromTimestampUTC($res['timestamp']) : null,
'results' => isset($res['results']) ? SmartContractResult::fromApiResponseMany($res['results']) : collect(),
'logs' => isset($res['logs']) ? TransactionLog::fromApiResponse($res['logs']) : null,
]);
}
}
28 changes: 28 additions & 0 deletions src/Api/Entities/TransactionLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Superciety\ElrondSdk\Api\Entities;

use Illuminate\Support\Collection;
use Superciety\ElrondSdk\Api\ApiTransformable;
use Superciety\ElrondSdk\Api\Entities\TransactionLogEvent;
use Superciety\ElrondSdk\Domain\Address;

final class TransactionLog
{
use ApiTransformable;

public function __construct(
public string $id,
public Address $address,
public Collection $events,
) {
}

protected static function transformResponse(array $res): array
{
return array_merge($res, [
'address' => isset($res['address']) ? Address::fromBech32($res['address']) : null,
'events' => isset($res['events']) ? TransactionLogEvent::fromApiResponseMany($res['events']) : collect(),
]);
}
}
29 changes: 29 additions & 0 deletions src/Api/Entities/TransactionLogEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Superciety\ElrondSdk\Api\Entities;

use Illuminate\Support\Collection;
use Superciety\ElrondSdk\Api\ApiTransformable;
use Superciety\ElrondSdk\Domain\Address;
use Superciety\ElrondSdk\Utils\Decoder;

final class TransactionLogEvent
{
use ApiTransformable;

public function __construct(
public Address $address,
public string $identifier,
public Collection $topics,
public ?string $data = null,
) {
}

protected static function transformResponse(array $res): array
{
return array_merge($res, [
'address' => isset($res['address']) ? Address::fromBech32($res['address']) : null,
'topics' => isset($res['topics']) ? collect($res['topics']) : [],
]);
}
}
4 changes: 2 additions & 2 deletions tests/Api/TransactionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
use Superciety\ElrondSdk\Elrond;

it('gets a transaction by transaction hash', function () {
fakeApiRequestWithResponse('/transactions/7a25e0f453a3cfe5e05b97f6c8e160028b98bb41fa0f932cff837d9f1fcad500', 'transactions/transaction.json');
fakeApiRequestWithResponse('/transactions/01b94cb36f027bab9391414971c7feb348755c53f8ea27f19c18fb82db35ea7d', 'transactions/transaction.json');

$actual = Elrond::api()
->transactions()
->getByHash('7a25e0f453a3cfe5e05b97f6c8e160028b98bb41fa0f932cff837d9f1fcad500');
->getByHash('01b94cb36f027bab9391414971c7feb348755c53f8ea27f19c18fb82db35ea7d');

assertMatchesResponseSnapshot($actual);
});
Loading

0 comments on commit a33c8db

Please sign in to comment.