Skip to content

Commit

Permalink
add transaction-detailed operations
Browse files Browse the repository at this point in the history
  • Loading branch information
michavie committed Sep 4, 2022
1 parent c13d841 commit 2d3d7c5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Api/Entities/TransactionDetailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
public ?string $tokenValue = null,
public Collection $results = new Collection,
public ?TransactionLog $logs = null,
public Collection $operations = new Collection,
) {
}

Expand All @@ -44,6 +45,7 @@ protected static function transformResponse(array $res): array
'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,
'operations' => isset($res['operations']) ? TransactionOperation::fromApiResponseMany($res['operations']) : collect(),
]);
}
}
36 changes: 36 additions & 0 deletions src/Api/Entities/TransactionOperation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Superciety\ElrondSdk\Api\Entities;

use Brick\Math\BigInteger;
use Superciety\ElrondSdk\Api\ApiTransformable;
use Superciety\ElrondSdk\Domain\Address;

final class TransactionOperation
{
use ApiTransformable;

public function __construct(
public string $id,
public string $action,
public string $type,
public BigInteger $value,
public Address $sender,
public Address $receiver,
public ?string $name = null,
public ?string $collection = null,
public ?string $identifier = null,
public ?string $esdtType = null,
public ?string $data = null,
) {
}

protected static function transformResponse(array $res): array
{
return array_merge($res, [
'value' => isset($res['value']) ? BigInteger::of($res['value']) : BigInteger::zero(),
'sender' => isset($res['sender']) ? Address::fromBech32($res['sender']) : null,
'receiver' => isset($res['receiver']) ? Address::fromBech32($res['receiver']) : null,
]);
}
}
Binary file not shown.

0 comments on commit 2d3d7c5

Please sign in to comment.