-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
enum ActionType: string | ||
{ | ||
case Contract = 'contract'; | ||
case Query = 'query'; | ||
case Link = 'link'; | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Vleap\Actions; | ||
|
||
use MultiversX\Address; | ||
use Illuminate\Support\Collection; | ||
|
||
final class QueryAction implements IWarpAction | ||
{ | ||
public function __construct( | ||
public readonly string $label, | ||
public readonly ?string $description, | ||
public readonly Address $address, | ||
public readonly string $func, | ||
public readonly array $args, | ||
public readonly ?string $abi, | ||
/** @var Collection<WarpActionInput> */ | ||
public readonly Collection $inputs = new Collection, | ||
) { | ||
} | ||
|
||
public function getType(): ActionType | ||
{ | ||
return ActionType::Query; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Vleap\Transformers\Actions; | ||
|
||
use Brick\Math\BigInteger; | ||
use MultiversX\Address; | ||
use Vleap\Actions\QueryAction; | ||
|
||
final class QueryActionTransformer | ||
{ | ||
public static function toArray(QueryAction $action): array | ||
{ | ||
return [ | ||
'type' => $action->getType()->value, | ||
'label' => $action->label, | ||
'description' => $action->description, | ||
'address' => $action->address->bech32(), | ||
'func' => $action->func, | ||
'args' => $action->args, | ||
'abi' => $action->abi, | ||
]; | ||
} | ||
|
||
public static function fromArray(array $data): QueryAction | ||
{ | ||
return new QueryAction( | ||
label: $data['label'], | ||
description: $data['description'] ?? null, | ||
address: Address::newFromBech32($data['address']), | ||
func: $data['func'], | ||
args: $data['args'], | ||
abi: $data['abi'], | ||
); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
tests/Transformers/Actions/ContractQueryTransformerTest.php
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,24 @@ | ||
<?php | ||
|
||
use Brick\Math\BigInteger; | ||
use Vleap\WarpAction; | ||
use MultiversX\Address; | ||
use Vleap\Actions\ActionType; | ||
use Vleap\Transformers\Actions\QueryActionTransformer; | ||
|
||
it('transforms a contract query', function () { | ||
$address = Address::zero(); | ||
$action = WarpAction::create('test action')->query($address, 'test endpoint', ['test arg'], 'https://vleap.io/abi.json'); | ||
|
||
$actual = QueryActionTransformer::toArray($action); | ||
|
||
expect($actual)->toBe([ | ||
'type' => ActionType::Query->value, | ||
'label' => 'test action', | ||
'description' => null, | ||
'address' => 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu', | ||
'func' => 'test endpoint', | ||
'args' => ['test arg'], | ||
'abi' => 'https://vleap.io/abi.json', | ||
]); | ||
}); |