diff --git a/composer.json b/composer.json index c18a2d4..fe53776 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "ext-openssl": "*", "ext-gmp": "*", "enjin/platform-core": "*", - "rebing/graphql-laravel": "^9.0.0-rc1", + "rebing/graphql-laravel": "^9.0", "spatie/laravel-package-tools": "^1.0", "spatie/laravel-ray": "^1.0", "phrity/websocket": "^1.0" diff --git a/src/Enums/DispatchRule.php b/src/Enums/DispatchRule.php index 2d6583b..3459fdd 100644 --- a/src/Enums/DispatchRule.php +++ b/src/Enums/DispatchRule.php @@ -4,6 +4,7 @@ use Enjin\Platform\FuelTanks\Models\Substrate\FuelTankRules; use Enjin\Platform\FuelTanks\Models\Substrate\MaxFuelBurnPerTransactionParams; +use Enjin\Platform\FuelTanks\Models\Substrate\PermittedCallsParams; use Enjin\Platform\FuelTanks\Models\Substrate\PermittedExtrinsicsParams; use Enjin\Platform\FuelTanks\Models\Substrate\RequireTokenParams; use Enjin\Platform\FuelTanks\Models\Substrate\TankFuelBudgetParams; @@ -24,6 +25,7 @@ enum DispatchRule: string case TANK_FUEL_BUDGET = 'TankFuelBudget'; case REQUIRE_TOKEN = 'RequireToken'; case PERMITTED_EXTRINSICS = 'PermittedExtrinsics'; + case PERMITTED_CALLS = 'PermittedCalls'; case WHITELISTED_PALLETS = 'WhitelistedPallets'; /** @@ -39,6 +41,7 @@ public function toKind(): FuelTankRules self::TANK_FUEL_BUDGET => new TankFuelBudgetParams('', ''), self::REQUIRE_TOKEN => new RequireTokenParams('', ''), self::PERMITTED_EXTRINSICS => new PermittedExtrinsicsParams(), + self::PERMITTED_CALLS => new PermittedCallsParams(), self::WHITELISTED_PALLETS => new WhitelistedPalletsParams(), }; } diff --git a/src/Events/Substrate/FuelTanks/AccountRemoved.php b/src/Events/Substrate/FuelTanks/AccountRemoved.php index ec9dc87..215a98c 100644 --- a/src/Events/Substrate/FuelTanks/AccountRemoved.php +++ b/src/Events/Substrate/FuelTanks/AccountRemoved.php @@ -12,7 +12,7 @@ class AccountRemoved extends PlatformBroadcastEvent /** * Create a new event instance. */ - public function __construct(Model $fuelTankAccount) + public function __construct(Model $fuelTankAccount, ?Model $transaction = null) { parent::__construct(); diff --git a/src/Events/Substrate/FuelTanks/CallDispatched.php b/src/Events/Substrate/FuelTanks/CallDispatched.php index e33e9e5..50f6fe4 100644 --- a/src/Events/Substrate/FuelTanks/CallDispatched.php +++ b/src/Events/Substrate/FuelTanks/CallDispatched.php @@ -12,7 +12,7 @@ class CallDispatched extends PlatformBroadcastEvent /** * Create a new event instance. */ - public function __construct(Model $fuelTank, Model $caller) + public function __construct(Model $fuelTank, Model $caller, ?Model $transaction = null) { parent::__construct(); diff --git a/src/Events/Substrate/FuelTanks/FreezeStateMutated.php b/src/Events/Substrate/FuelTanks/FreezeStateMutated.php index 3fea569..db4e4b0 100644 --- a/src/Events/Substrate/FuelTanks/FreezeStateMutated.php +++ b/src/Events/Substrate/FuelTanks/FreezeStateMutated.php @@ -12,7 +12,7 @@ class FreezeStateMutated extends PlatformBroadcastEvent /** * Create a new event instance. */ - public function __construct(Model $fuelTank) + public function __construct(Model $fuelTank, ?Model $transaction = null) { parent::__construct(); diff --git a/src/Events/Substrate/FuelTanks/FuelTankDestroyed.php b/src/Events/Substrate/FuelTanks/FuelTankDestroyed.php index 154c577..9dfe839 100644 --- a/src/Events/Substrate/FuelTanks/FuelTankDestroyed.php +++ b/src/Events/Substrate/FuelTanks/FuelTankDestroyed.php @@ -12,7 +12,7 @@ class FuelTankDestroyed extends PlatformBroadcastEvent /** * Create a new event instance. */ - public function __construct(Model $fuelTank) + public function __construct(Model $fuelTank, ?Model $transaction = null) { parent::__construct(); diff --git a/src/Events/Substrate/FuelTanks/FuelTankMutated.php b/src/Events/Substrate/FuelTanks/FuelTankMutated.php index e11fcc3..09be63e 100644 --- a/src/Events/Substrate/FuelTanks/FuelTankMutated.php +++ b/src/Events/Substrate/FuelTanks/FuelTankMutated.php @@ -12,7 +12,7 @@ class FuelTankMutated extends PlatformBroadcastEvent /** * Create a new event instance. */ - public function __construct(Model $fuelTank) + public function __construct(Model $fuelTank, ?Model $transaction = null) { parent::__construct(); diff --git a/src/Events/Substrate/FuelTanks/MutateFreezeStateScheduled.php b/src/Events/Substrate/FuelTanks/MutateFreezeStateScheduled.php index a511a5e..6628355 100644 --- a/src/Events/Substrate/FuelTanks/MutateFreezeStateScheduled.php +++ b/src/Events/Substrate/FuelTanks/MutateFreezeStateScheduled.php @@ -12,7 +12,7 @@ class MutateFreezeStateScheduled extends PlatformBroadcastEvent /** * Create a new event instance. */ - public function __construct(Model $fuelTank) + public function __construct(Model $fuelTank, ?Model $transaction = null) { parent::__construct(); diff --git a/src/Events/Substrate/FuelTanks/RuleSetRemoved.php b/src/Events/Substrate/FuelTanks/RuleSetRemoved.php index a190394..c17336a 100644 --- a/src/Events/Substrate/FuelTanks/RuleSetRemoved.php +++ b/src/Events/Substrate/FuelTanks/RuleSetRemoved.php @@ -12,7 +12,7 @@ class RuleSetRemoved extends PlatformBroadcastEvent /** * Create a new event instance. */ - public function __construct(Model $fuelTank, int $ruleSetId) + public function __construct(Model $fuelTank, int $ruleSetId, ?Model $transaction = null) { parent::__construct(); diff --git a/src/GraphQL/Mutations/InsertRuleSetMutation.php b/src/GraphQL/Mutations/InsertRuleSetMutation.php index e70451e..f65117a 100644 --- a/src/GraphQL/Mutations/InsertRuleSetMutation.php +++ b/src/GraphQL/Mutations/InsertRuleSetMutation.php @@ -94,7 +94,6 @@ public function resolve( Substrate $blockchainService ) { $dispatchRules = $blockchainService->getDispatchRulesParams($args['dispatchRules']); - $encodedData = $serializationService->encode( $this->getMutationName(), static::getEncodableParams( diff --git a/src/Models/Substrate/AccountRulesParams.php b/src/Models/Substrate/AccountRulesParams.php index 37e1456..5e5b639 100644 --- a/src/Models/Substrate/AccountRulesParams.php +++ b/src/Models/Substrate/AccountRulesParams.php @@ -20,6 +20,7 @@ public function __construct( */ public function fromEncodable(mixed $params): self { + if (!empty($whitelist = Arr::get($params, 'WhitelistedCallers'))) { $this->whitelistedCallers = WhitelistedCallersParams::fromEncodable($whitelist); } @@ -48,4 +49,12 @@ public function toEncodable(): array return $params; } + + public function toArray(): array + { + return [ + 'WhitelistedCallers' => $this->whitelistedCallers?->toArray(), + 'RequireToken' => $this->requireToken?->toArray(), + ]; + } } diff --git a/src/Models/Substrate/DispatchRulesParams.php b/src/Models/Substrate/DispatchRulesParams.php index 8a0d544..05015df 100644 --- a/src/Models/Substrate/DispatchRulesParams.php +++ b/src/Models/Substrate/DispatchRulesParams.php @@ -30,7 +30,7 @@ public function __construct( public function fromEncodable(int $setId, mixed $params): self { $this->ruleSetId = $setId; - $this->isFrozen = $params['isFrozen']; + $this->isFrozen = $params['isFrozen'] ?? false; foreach ($params['rules'] as $rule) { $ruleParam = '\Enjin\Platform\FuelTanks\Models\Substrate\\' . ($ruleName = array_key_first($rule)) . 'Params'; @@ -76,13 +76,54 @@ public function toEncodable(): array $params[] = $this->whitelistedPallets->toEncodable(); } - // We have to set an empty array for the permitted extrinsics here and encode manually later - // due to what appears to be a bug in the Scale Codec library where it cannot encode a Call - // type due to missing metadata when creating the Call ScaleInstance class. if ($this->permittedExtrinsics) { $params[] = ['PermittedExtrinsics' => ['extrinsics' => []]]; } + + return $params; + } + + public function toArray(): array + { + $params = []; + + if ($this->whitelistedCallers) { + $params[] = $this->whitelistedCallers->toArray(); + } + + if ($this->requireToken) { + $params[] = $this->requireToken->toArray(); + } + + if ($this->whitelistedCollections) { + $params[] = $this->whitelistedCollections->toArray(); + } + + if ($this->maxFuelBurnPerTransaction) { + $params[] = $this->maxFuelBurnPerTransaction->toArray(); + } + + if ($this->userFuelBudget) { + $params[] = $this->userFuelBudget->toArray(); + } + + if ($this->tankFuelBudget) { + $params[] = $this->tankFuelBudget->toArray(); + } + + if ($this->whitelistedPallets) { + $params[] = $this->whitelistedPallets->toArray(); + } + + if ($this->permittedCalls) { + $params[] = $this->permittedCalls->toArray(); + } + + if ($this->permittedExtrinsics) { + $params[] = $this->permittedExtrinsics->toArray(); + } + return $params; } } diff --git a/src/Models/Substrate/MaxFuelBurnPerTransactionParams.php b/src/Models/Substrate/MaxFuelBurnPerTransactionParams.php index 7975210..9be0c74 100644 --- a/src/Models/Substrate/MaxFuelBurnPerTransactionParams.php +++ b/src/Models/Substrate/MaxFuelBurnPerTransactionParams.php @@ -32,4 +32,11 @@ public function toEncodable(): array 'MaxFuelBurnPerTransaction' => $this->max, ]; } + + public function toArray(): array + { + return [ + 'MaxFuelBurnPerTransaction' => $this->max, + ]; + } } diff --git a/src/Models/Substrate/PermittedCallsParams.php b/src/Models/Substrate/PermittedCallsParams.php index ef8d1e7..aaaadea 100644 --- a/src/Models/Substrate/PermittedCallsParams.php +++ b/src/Models/Substrate/PermittedCallsParams.php @@ -2,16 +2,22 @@ namespace Enjin\Platform\FuelTanks\Models\Substrate; +use Enjin\BlockchainTools\HexConverter; use Illuminate\Support\Arr; class PermittedCallsParams extends FuelTankRules { + protected ?array $calls; + /** * Creates a new instance. */ - public function __construct( - public ?array $calls = [], - ) { + public function __construct(?array $calls = []) + { + $this->calls = array_map( + fn ($call) => HexConverter::prefix(is_string($call) ? $call : HexConverter::bytesToHex($call)), + $calls + ); } /** @@ -20,7 +26,7 @@ public function __construct( public static function fromEncodable(array $params): self { return new self( - calls: Arr::get($params, 'PermittedCalls.calls') + calls: Arr::get($params, 'PermittedCalls.calls') ?? Arr::get($params, 'PermittedCalls') ?? [] ); } @@ -33,4 +39,11 @@ public function toEncodable(): array 'PermittedCalls' => $this->calls, ]; } + + public function toArray(): array + { + return [ + 'PermittedCalls' => $this->calls, + ]; + } } diff --git a/src/Models/Substrate/PermittedExtrinsicsParams.php b/src/Models/Substrate/PermittedExtrinsicsParams.php index 667f89a..18889f1 100644 --- a/src/Models/Substrate/PermittedExtrinsicsParams.php +++ b/src/Models/Substrate/PermittedExtrinsicsParams.php @@ -4,20 +4,64 @@ use Enjin\BlockchainTools\HexConverter; use Enjin\Platform\Facades\TransactionSerializer; +use Enjin\Platform\GraphQL\Schemas\Primary\Substrate\Mutations\BatchTransferBalanceMutation; +use Enjin\Platform\Services\Processor\Substrate\Codec\Encoder as BaseEncoder; use Enjin\Platform\Interfaces\PlatformBlockchainTransaction; use Enjin\Platform\Package; -use Enjin\Platform\Services\Processor\Substrate\Codec\Encoder as BaseEncoder; use Illuminate\Support\Arr; use Illuminate\Support\Str; class PermittedExtrinsicsParams extends FuelTankRules { + protected ?array $extrinsics; + /** * Creates a new instance. */ - public function __construct( - public ?array $extrinsics = [], - ) { + public function __construct(?array $extrinsics = []) + { + $this->extrinsics = array_map( + function ($extrinsic) { + if (($palletName = Arr::get($extrinsic, 'palletName')) && ($methodName = Arr::get($extrinsic, 'extrinsicName'))) { + return HexConverter::hexToString($palletName) . '.' . HexConverter::hexToString($methodName); + } + + $palletName = array_key_first($extrinsic); + $methodName = array_key_first($extrinsic[$palletName]); + + return $palletName . '.' . $methodName; + }, + $extrinsics + ); + } + + public function fromMethods(array $methods): self + { + $mutations = Package::getClassesThatImplementInterface(PlatformBlockchainTransaction::class); + + return new self( + extrinsics: array_map( + function ($method) use ($mutations) { + $transactionMutation = $mutations->filter(fn ($class) => Str::contains(class_basename($class), $method))->first(); + $methodName = (new $transactionMutation())->getMethodName(); + + return [ + explode('.', Arr::get(BaseEncoder::getCallIndexKeys(), $methodName))[0] => [ + explode('.', Arr::get(BaseEncoder::getCallIndexKeys(), $methodName))[1] => null, + ], + ]; + }, + $methods + ) + ); + } + + public function toMethods(): array + { + return array_map( + fn ($extrinsic) => collect(BaseEncoder::getCallIndexKeys())->filter(fn ($item) => $item == $extrinsic)->keys()->first(), + $this->extrinsics + ); } /** @@ -26,31 +70,26 @@ public function __construct( public static function fromEncodable(array $params): self { return new self( - extrinsics: array_map( - fn ($extrinsic) => is_string($extrinsic) ? $extrinsic : - collect(BaseEncoder::getCallIndexKeys()) - ->filter( - fn ($item) => $item - == - sprintf( - '%s.%s', - HexConverter::hexToString(Arr::get($extrinsic, 'palletName')), - HexConverter::hexToString(Arr::get($extrinsic, 'extrinsicName')), - ), - )->keys()->first(), - Arr::get($params, 'PermittedExtrinsics.extrinsics', []) - ), + extrinsics: Arr::get($params, 'PermittedExtrinsics.extrinsics') ?? Arr::get($params, 'PermittedExtrinsics') ); } + public function toArray(): array + { + return [ + 'PermittedExtrinsics' => $this->extrinsics, + ]; + } + /** * Returns the encodable representation of this instance. */ public function toEncodable(): array { + $methods = array_unique($this->toMethods()); $encodedData = '07'; // TODO: This should come from the metadata and not hardcode it. - $encodedData .= HexConverter::intToHex(count($this->extrinsics) * 4); - $encodedData .= collect($this->extrinsics)->reduce(fn ($data, $mutation) => Str::of($data)->append($this->getEncodedData($mutation))->toString(), ''); + $encodedData .= HexConverter::intToHex(count($methods) * 4); + $encodedData .= collect($methods)->reduce(fn ($data, $mutation) => Str::of($data)->append($this->getEncodedData($mutation))->toString(), ''); return [ 'PermittedExtrinsics' => ['extrinsics' => $encodedData], @@ -60,6 +99,7 @@ public function toEncodable(): array protected function getEncodedData(string $mutationName): string { $transactionMutation = Package::getClassesThatImplementInterface(PlatformBlockchainTransaction::class) + ->filter(fn ($class) => $class !== BatchTransferBalanceMutation::class) ->filter(fn ($class) => Str::contains(class_basename($class), $mutationName))->first(); return HexConverter::unPrefix(TransactionSerializer::encode((new $transactionMutation())->getMethodName(), $transactionMutation::getEncodableParams())); diff --git a/src/Models/Substrate/RequireTokenParams.php b/src/Models/Substrate/RequireTokenParams.php index 6a082ef..cd00f75 100644 --- a/src/Models/Substrate/RequireTokenParams.php +++ b/src/Models/Substrate/RequireTokenParams.php @@ -20,9 +20,12 @@ public function __construct( */ public static function fromEncodable(array $params): self { + $collectionId = Arr::get($params, 'RequireToken.collectionId') ?? Arr::get($params, 'RequireToken.collection_id'); + $tokenId = Arr::get($params, 'RequireToken.tokenId') ?? Arr::get($params, 'RequireToken.token_id'); + return new self( - collectionId: gmp_strval(Arr::get($params, 'RequireToken.collectionId')), - tokenId: gmp_strval(Arr::get($params, 'RequireToken.tokenId')), + collectionId: gmp_strval($collectionId), + tokenId: gmp_strval($tokenId), ); } @@ -36,4 +39,12 @@ public function toEncodable(): array 'tokenId' => $this->tokenId, ]]; } + + public function toArray(): array + { + return ['RequireToken' => [ + 'collectionId' => $this->collectionId, + 'tokenId' => $this->tokenId, + ]]; + } } diff --git a/src/Models/Substrate/TankFuelBudgetParams.php b/src/Models/Substrate/TankFuelBudgetParams.php index 4ea4d49..7d87a92 100644 --- a/src/Models/Substrate/TankFuelBudgetParams.php +++ b/src/Models/Substrate/TankFuelBudgetParams.php @@ -44,4 +44,16 @@ public function toEncodable(): array ], ]; } + + public function toArray(): array + { + return [ + 'TankFuelBudget' => [ + 'amount' => $this->amount, + 'resetPeriod' => $this->resetPeriod, + 'totalConsumed' => $this->totalConsumed, + 'lastResetBlock' => $this->lastResetBlock, + ], + ]; + } } diff --git a/src/Models/Substrate/UserFuelBudgetParams.php b/src/Models/Substrate/UserFuelBudgetParams.php index cf999c3..61a87f8 100644 --- a/src/Models/Substrate/UserFuelBudgetParams.php +++ b/src/Models/Substrate/UserFuelBudgetParams.php @@ -40,4 +40,17 @@ public function toEncodable(): array ], ]; } + + /** + * Returns the encodable representation of this instance. + */ + public function toArray(): array + { + return [ + 'UserFuelBudget' => [ + 'amount' => $this->amount, + 'resetPeriod' => $this->resetPeriod, + ], + ]; + } } diff --git a/src/Models/Substrate/WhitelistedCallersParams.php b/src/Models/Substrate/WhitelistedCallersParams.php index 68bcbb4..0f11c35 100644 --- a/src/Models/Substrate/WhitelistedCallersParams.php +++ b/src/Models/Substrate/WhitelistedCallersParams.php @@ -27,7 +27,7 @@ public function __construct(?array $callers = []) public static function fromEncodable(array $params): self { return new self( - callers: Arr::get($params, 'WhitelistedCallers'), + callers: Arr::get($params, 'WhitelistedCallers') ?? $params, ); } @@ -40,4 +40,11 @@ public function toEncodable(): array 'WhitelistedCallers' => $this->callers, ]; } + + public function toArray(): array + { + return [ + 'WhitelistedCallers' => $this->callers, + ]; + } } diff --git a/src/Models/Substrate/WhitelistedCollectionsParams.php b/src/Models/Substrate/WhitelistedCollectionsParams.php index 98db4a9..523c123 100644 --- a/src/Models/Substrate/WhitelistedCollectionsParams.php +++ b/src/Models/Substrate/WhitelistedCollectionsParams.php @@ -36,4 +36,11 @@ public function toEncodable(): array 'WhitelistedCollections' => $this->collections, ]; } + + public function toArray(): array + { + return [ + 'WhitelistedCollections' => $this->collections, + ]; + } } diff --git a/src/Models/Substrate/WhitelistedPalletsParams.php b/src/Models/Substrate/WhitelistedPalletsParams.php index 23caeaf..f39eb92 100644 --- a/src/Models/Substrate/WhitelistedPalletsParams.php +++ b/src/Models/Substrate/WhitelistedPalletsParams.php @@ -40,4 +40,11 @@ public function toEncodable(): array ), ]; } + + public function toArray(): array + { + return [ + 'WhitelistedPallets' => $this->pallets, + ]; + } } diff --git a/src/Services/Blockchain/Implemetations/Substrate.php b/src/Services/Blockchain/Implemetations/Substrate.php index cf10098..0364613 100644 --- a/src/Services/Blockchain/Implemetations/Substrate.php +++ b/src/Services/Blockchain/Implemetations/Substrate.php @@ -73,7 +73,7 @@ public function getDispatchRulesParams(array $args): DispatchRulesParams ? new PermittedCallsParams(Arr::get($permittedCalls, 'calls')) : null, ($permittedExtrinsics = Arr::get($args, 'permittedExtrinsics')) - ? new PermittedExtrinsicsParams($permittedExtrinsics) + ? (new PermittedExtrinsicsParams())->fromMethods($permittedExtrinsics) : null, ($pallets = Arr::get($args, 'whitelistedPallets')) ? new WhitelistedPalletsParams($pallets) diff --git a/src/Services/Processor/Substrate/Events/Implementations/Traits/QueryDataOrFail.php b/src/Services/Processor/Substrate/Events/FuelTankSubstrateEvent.php similarity index 77% rename from src/Services/Processor/Substrate/Events/Implementations/Traits/QueryDataOrFail.php rename to src/Services/Processor/Substrate/Events/FuelTankSubstrateEvent.php index 3c3d871..15a6d7b 100644 --- a/src/Services/Processor/Substrate/Events/Implementations/Traits/QueryDataOrFail.php +++ b/src/Services/Processor/Substrate/Events/FuelTankSubstrateEvent.php @@ -1,19 +1,19 @@ Account::parseAccount($event->userId)]); + // Fails if it doesn't find the fuel tank $fuelTank = $this->getFuelTank($event->tankId); + $account = $this->firstOrStoreAccount($event->userId); + $fuelTankAccount = FuelTankAccount::create([ 'fuel_tank_id' => $fuelTank->id, 'wallet_id' => $account->id, @@ -38,36 +37,23 @@ public function run(PolkadartEvent $event, Block $block, Codec $codec): void 'total_received' => $event->totalReceived, ]); - $extrinsic = $block->extrinsics[$event->extrinsicIndex]; - $daemonTransaction = Transaction::firstWhere(['transaction_chain_hash' => $extrinsic->hash]); - - if ($daemonTransaction) { - Log::info( - sprintf( - 'FuelTankAccount %s (id: %s) of FuelTank %s (id: %s) was created from transaction %s (id: %s).', - $account->public_key, - $fuelTankAccount->id, - $fuelTank->public_key, - $fuelTank->id, - $daemonTransaction->transaction_chain_hash, - $daemonTransaction->id - ) - ); - } else { - Log::info( - sprintf( - 'FuelTankAccount %s (id: %s) of FuelTank %s (id: %s) was created from unknown transaction.', - $account->public_key, - $fuelTankAccount->id, - $fuelTank->public_key, - $fuelTank->id, - ) - ); - } + $transaction = $this->getTransaction($block, $event->extrinsicIndex); + + Log::info( + sprintf( + 'FuelTankAccount %s (id: %s) of FuelTank %s (id: %s) was created from transaction %s (id: %s).', + $account->public_key, + $fuelTankAccount->id, + $fuelTank->public_key, + $fuelTank->id, + $transaction?->transaction_chain_hash ?? 'unknown', + $transaction?->id ?? 'unknown' + ) + ); AccountAddedEvent::safeBroadcast( $fuelTankAccount, - $daemonTransaction + $transaction ); } } diff --git a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/AccountRemoved.php b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/AccountRemoved.php index af1fd8e..3dc0b63 100644 --- a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/AccountRemoved.php +++ b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/AccountRemoved.php @@ -2,49 +2,50 @@ namespace Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\FuelTanks; +use Enjin\Platform\Exceptions\PlatformException; use Enjin\Platform\FuelTanks\Events\Substrate\FuelTanks\AccountRemoved as AccountRemovedEvent; use Enjin\Platform\FuelTanks\Models\FuelTankAccount; -use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\Traits\QueryDataOrFail; +use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\FuelTankSubstrateEvent; use Enjin\Platform\Models\Laravel\Block; use Enjin\Platform\Services\Processor\Substrate\Codec\Codec; use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\FuelTanks\AccountRemoved as AccountRemovedPolkadart; -use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent; -use Enjin\Platform\Services\Processor\Substrate\Events\SubstrateEvent; -use Enjin\Platform\Support\Account; -use Facades\Enjin\Platform\Services\Database\WalletService; +use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Event; use Illuminate\Support\Facades\Log; -class AccountRemoved implements SubstrateEvent +class AccountRemoved extends FuelTankSubstrateEvent { - use QueryDataOrFail; - /** * Handle the account removed event. + * + * @throws PlatformException */ - public function run(PolkadartEvent $event, Block $block, Codec $codec): void + public function run(Event $event, Block $block, Codec $codec): void { if (!$event instanceof AccountRemovedPolkadart) { return; } - $account = WalletService::firstOrStore(['account' => Account::parseAccount($event->userId)]); + // Fails if it doesn't find the fuel tank $fuelTank = $this->getFuelTank($event->tankId); - $fuelTankAccount = FuelTankAccount::firstWhere([ + $account = $this->firstOrStoreAccount($event->userId); + + $fuelTankAccount = FuelTankAccount::where([ 'fuel_tank_id' => $fuelTank->id, 'wallet_id' => $account->id, - ]); - $fuelTankAccount->delete(); + ])?->delete(); Log::info( sprintf( - 'FuelTankAccount %s (id: %s) of FuelTank %s (id: %s) was removed.', + 'FuelTankAccount %s of FuelTank %s (id: %s) was removed.', $account->public_key, - $fuelTankAccount->id, $fuelTank->public_key, $fuelTank->id, ) ); - AccountRemovedEvent::safeBroadcast($fuelTankAccount); + AccountRemovedEvent::safeBroadcast( + $fuelTankAccount, + $this->getTransaction($block, $event->extrinsicIndex), + ); } } diff --git a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/AccountRuleDataRemoved.php b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/AccountRuleDataRemoved.php index 8cddb7b..ee926d7 100644 --- a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/AccountRuleDataRemoved.php +++ b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/AccountRuleDataRemoved.php @@ -2,18 +2,18 @@ namespace Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\FuelTanks; +use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\FuelTankSubstrateEvent; use Enjin\Platform\Models\Laravel\Block; use Enjin\Platform\Services\Processor\Substrate\Codec\Codec; use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\FuelTanks\AccountRuleDataRemoved as AccountRuleDataPolkadart; -use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent; -use Enjin\Platform\Services\Processor\Substrate\Events\SubstrateEvent; +use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Event; -class AccountRuleDataRemoved implements SubstrateEvent +class AccountRuleDataRemoved extends FuelTankSubstrateEvent { /** * Handle the account rule data removed event. */ - public function run(PolkadartEvent $event, Block $block, Codec $codec): void + public function run(Event $event, Block $block, Codec $codec): void { if (!$event instanceof AccountRuleDataPolkadart) { return; diff --git a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/CallDispatched.php b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/CallDispatched.php index 041d19a..de78c30 100644 --- a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/CallDispatched.php +++ b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/CallDispatched.php @@ -2,31 +2,31 @@ namespace Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\FuelTanks; +use Enjin\Platform\Exceptions\PlatformException; use Enjin\Platform\FuelTanks\Events\Substrate\FuelTanks\CallDispatched as CallDispatchedEvent; -use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\Traits\QueryDataOrFail; +use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\FuelTankSubstrateEvent; use Enjin\Platform\Models\Laravel\Block; use Enjin\Platform\Services\Processor\Substrate\Codec\Codec; use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\FuelTanks\CallDispatched as CallDispatchedPolkadart; -use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent; -use Enjin\Platform\Services\Processor\Substrate\Events\SubstrateEvent; -use Facades\Enjin\Platform\Services\Database\WalletService; +use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Event; use Illuminate\Support\Facades\Log; -class CallDispatched implements SubstrateEvent +class CallDispatched extends FuelTankSubstrateEvent { - use QueryDataOrFail; - /** * Handle the call dispatched event. + * + * @throws PlatformException */ - public function run(PolkadartEvent $event, Block $block, Codec $codec): void + public function run(Event $event, Block $block, Codec $codec): void { if (!$event instanceof CallDispatchedPolkadart) { return; } - $account = WalletService::firstOrStore(['account' => $event->caller]); + // Fail if it doesn't find the fuel tank $fuelTank = $this->getFuelTank($event->tankId); + $account = $this->firstOrStoreAccount($event->caller); Log::info( sprintf( @@ -38,6 +38,10 @@ public function run(PolkadartEvent $event, Block $block, Codec $codec): void ) ); - CallDispatchedEvent::safeBroadcast($fuelTank, $account); + CallDispatchedEvent::safeBroadcast( + $fuelTank, + $account, + $this->getTransaction($block, $event->extrinsicIndex), + ); } } diff --git a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FreezeStateMutated.php b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FreezeStateMutated.php index 0767bcb..804e7be 100644 --- a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FreezeStateMutated.php +++ b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FreezeStateMutated.php @@ -2,29 +2,30 @@ namespace Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\FuelTanks; +use Enjin\Platform\Exceptions\PlatformException; use Enjin\Platform\FuelTanks\Events\Substrate\FuelTanks\FreezeStateMutated as FreezeStateMutatedEvent; use Enjin\Platform\FuelTanks\Models\DispatchRule; -use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\Traits\QueryDataOrFail; +use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\FuelTankSubstrateEvent; use Enjin\Platform\Models\Laravel\Block; use Enjin\Platform\Services\Processor\Substrate\Codec\Codec; use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\FuelTanks\FreezeStateMutated as FreezeStateMutatedPolkadart; -use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent; -use Enjin\Platform\Services\Processor\Substrate\Events\SubstrateEvent; +use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Event; use Illuminate\Support\Facades\Log; -class FreezeStateMutated implements SubstrateEvent +class FreezeStateMutated extends FuelTankSubstrateEvent { - use QueryDataOrFail; - /** * Handle the freeze state mutated event. + * + * @throws PlatformException */ - public function run(PolkadartEvent $event, Block $block, Codec $codec): void + public function run(Event $event, Block $block, Codec $codec): void { if (!$event instanceof FreezeStateMutatedPolkadart) { return; } + // Fail if it doesn't find the fuel tank $fuelTank = $this->getFuelTank($event->tankId); if (!$event->ruleSetId) { @@ -56,6 +57,9 @@ public function run(PolkadartEvent $event, Block $block, Codec $codec): void ); } - FreezeStateMutatedEvent::safeBroadcast($fuelTank); + FreezeStateMutatedEvent::safeBroadcast( + $fuelTank, + $this->getTransaction($block, $event->extrinsicIndex), + ); } } diff --git a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankCreated.php b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankCreated.php index 37e187e..50ea28e 100644 --- a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankCreated.php +++ b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankCreated.php @@ -2,26 +2,25 @@ namespace Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\FuelTanks; -use Enjin\BlockchainTools\HexConverter; use Enjin\Platform\FuelTanks\Events\Substrate\FuelTanks\FuelTankCreated as FuelTankCreatedEvent; use Enjin\Platform\FuelTanks\Models\FuelTank; +use Enjin\Platform\FuelTanks\Models\Substrate\AccountRulesParams; +use Enjin\Platform\FuelTanks\Models\Substrate\DispatchRulesParams; +use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\FuelTankSubstrateEvent; use Enjin\Platform\Models\Laravel\Block; -use Enjin\Platform\Models\Transaction; use Enjin\Platform\Services\Processor\Substrate\Codec\Codec; use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\FuelTanks\FuelTankCreated as FuelTankCreatedPolkadart; -use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent; -use Enjin\Platform\Services\Processor\Substrate\Events\SubstrateEvent; +use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Event; use Enjin\Platform\Support\Account; -use Facades\Enjin\Platform\Services\Database\WalletService; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; -class FuelTankCreated implements SubstrateEvent +class FuelTankCreated extends FuelTankSubstrateEvent { /** * Handle the fuel tank created event. */ - public function run(PolkadartEvent $event, Block $block, Codec $codec): void + public function run(Event $event, Block $block, Codec $codec): void { if (!$event instanceof FuelTankCreatedPolkadart) { return; @@ -31,74 +30,89 @@ public function run(PolkadartEvent $event, Block $block, Codec $codec): void $params = $extrinsic->params; $providesDeposit = Arr::get($params, 'descriptor.provides_deposit'); - $reservesExistentialDeposit = Arr::get($params, 'descriptor.user_account_management.Some.tank_reserves_existential_deposit'); - $reservesAccountCreationDeposit = Arr::get($params, 'descriptor.user_account_management.Some.tank_reserves_account_creation_deposit'); - - $owner = WalletService::firstOrStore(['account' => Account::parseAccount($event->owner)]); - $fuelTank = FuelTank::create([ - 'public_key' => Account::parseAccount($event->tankId), - 'name' => HexConverter::hexToString($event->tankName), - 'owner_wallet_id' => $owner->id, - 'reserves_existential_deposit' => $reservesExistentialDeposit, - 'reserves_account_creation_deposit' => $reservesAccountCreationDeposit, - 'provides_deposit' => $providesDeposit, - 'is_frozen' => false, + $reservesExistentialDeposit = $this->getValue($params, [ + 'descriptor.user_account_management.Some.tank_reserves_existential_deposit', + 'descriptor.user_account_management.tank_reserves_existential_deposit', ]); - $accountRules = Arr::get($params, 'descriptor.account_rules', []); + $reservesAccountCreationDeposit = $this->getValue($params, [ + 'descriptor.user_account_management.Some.tank_reserves_account_creation_deposit', + 'descriptor.user_account_management.tank_reserves_account_creation_deposit', + ]); + + $owner = $this->firstOrStoreAccount($event->owner); + $fuelTank = FuelTank::updateOrCreate( + [ + 'public_key' => Account::parseAccount($event->tankId), + ], + [ + 'name' => $event->tankName, + 'owner_wallet_id' => $owner->id, + 'reserves_existential_deposit' => $reservesExistentialDeposit, + 'reserves_account_creation_deposit' => $reservesAccountCreationDeposit, + 'provides_deposit' => $providesDeposit, + 'is_frozen' => false, + ] + ); + $insertAccountRules = []; - foreach ($accountRules as $rule) { - $ruleName = array_key_first($rule); - $ruleData = $rule[$ruleName]; - $insertAccountRules[] = [ - 'rule' => $ruleName, - 'value' => $ruleData, - ]; + $accountRules = Arr::get($params, 'descriptor.account_rules', []); + $rules = collect($accountRules)->collapse(); + + if ($rules->isNotEmpty()) { + $accountRules = (new AccountRulesParams())->fromEncodable($rules->toArray())->toArray(); + + if (!empty($accountRules['WhitelistedCallers'])) { + $insertAccountRules[] = [ + 'rule' => 'WhitelistedCallers', + 'value' => $accountRules['WhitelistedCallers'], + ]; + } + + if (!empty($accountRules['RequireToken'])) { + $insertAccountRules[] = [ + 'rule' => 'RequireToken', + 'value' => $accountRules['RequireToken'], + ]; + } } + $fuelTank->accountRules()->createMany($insertAccountRules); $dispatchRules = Arr::get($params, 'descriptor.rule_sets', []); $insertDispatchRules = []; + foreach ($dispatchRules as $ruleSet) { $ruleSetId = $ruleSet[0]; - foreach ($ruleSet[1] as $rule) { - $ruleName = array_key_first($rule); - $ruleData = $rule[$ruleName]; + $rules = collect($ruleSet[1])->toArray(); + + $dispatchRule = (new DispatchRulesParams())->fromEncodable($ruleSetId, ['rules' => $rules])->toArray(); + foreach ($dispatchRule as $rule) { $insertDispatchRules[] = [ 'rule_set_id' => $ruleSetId, - 'rule' => $ruleName, - 'value' => $ruleData, + 'rule' => array_key_first($rule), + 'value' => $rule[array_key_first($rule)], 'is_frozen' => false, ]; } } + $fuelTank->dispatchRules()->createMany($insertDispatchRules); + $transaction = $this->getTransaction($block, $event->extrinsicIndex); - $daemonTransaction = Transaction::firstWhere(['transaction_chain_hash' => $extrinsic->hash]); - - if ($daemonTransaction) { - Log::info( - sprintf( - 'FuelTank %s (id: %s) was created from transaction %s (id: %s)', - $fuelTank->public_key, - $fuelTank->id, - $daemonTransaction->transaction_chain_hash, - $daemonTransaction->id - ) - ); - } else { - Log::info( - sprintf( - 'FuelTank %s (id: %s) was created from unknown transaction', - $fuelTank->public_key, - $fuelTank->id, - ) - ); - } + Log::info( + sprintf( + 'FuelTank %s (id: %s) was created from transaction %s (id: %s)', + $fuelTank->public_key, + $fuelTank->id, + $transaction?->transaction_chain_hash ?? 'unknown', + $transaction?->id ?? 'unknown' + ) + ); FuelTankCreatedEvent::safeBroadcast( $fuelTank, - $daemonTransaction + $transaction ); } } diff --git a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankDestroyed.php b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankDestroyed.php index e1d4e4d..3aace4e 100644 --- a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankDestroyed.php +++ b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankDestroyed.php @@ -2,23 +2,23 @@ namespace Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\FuelTanks; +use Enjin\Platform\Exceptions\PlatformException; use Enjin\Platform\FuelTanks\Events\Substrate\FuelTanks\FuelTankDestroyed as FuelTankDestroyedEvent; -use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\Traits\QueryDataOrFail; +use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\FuelTankSubstrateEvent; use Enjin\Platform\Models\Laravel\Block; use Enjin\Platform\Services\Processor\Substrate\Codec\Codec; use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\FuelTanks\FuelTankDestroyed as FuelTankDestroyedPolkadart; -use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent; -use Enjin\Platform\Services\Processor\Substrate\Events\SubstrateEvent; +use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Event; use Illuminate\Support\Facades\Log; -class FuelTankDestroyed implements SubstrateEvent +class FuelTankDestroyed extends FuelTankSubstrateEvent { - use QueryDataOrFail; - /** * Handle the fuel tank destroyed event. + * + * @throws PlatformException */ - public function run(PolkadartEvent $event, Block $block, Codec $codec): void + public function run(Event $event, Block $block, Codec $codec): void { if (!$event instanceof FuelTankDestroyedPolkadart) { return; @@ -31,12 +31,14 @@ public function run(PolkadartEvent $event, Block $block, Codec $codec): void Log::info( sprintf( - 'FuelTank %s (id: %s) was destroyed.', - $fuelTank->public_key, - $fuelTank->id, + 'FuelTank %s was destroyed.', + $event->tankId, ) ); - FuelTankDestroyedEvent::safeBroadcast($fuelTank); + FuelTankDestroyedEvent::safeBroadcast( + $fuelTank, + $this->getTransaction($block, $event->extrinsicIndex), + ); } } diff --git a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankMutated.php b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankMutated.php index 987735b..2d58c6e 100644 --- a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankMutated.php +++ b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/FuelTankMutated.php @@ -2,34 +2,35 @@ namespace Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\FuelTanks; +use Enjin\Platform\Exceptions\PlatformException; use Enjin\Platform\FuelTanks\Events\Substrate\FuelTanks\FuelTankMutated as FuelTankMutatedEvent; use Enjin\Platform\FuelTanks\Models\AccountRule; -use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\Traits\QueryDataOrFail; +use Enjin\Platform\FuelTanks\Models\Substrate\AccountRulesParams; +use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\FuelTankSubstrateEvent; use Enjin\Platform\Models\Laravel\Block; use Enjin\Platform\Services\Processor\Substrate\Codec\Codec; use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\FuelTanks\FuelTankMutated as FuelTankMutatedPolkadart; -use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent; -use Enjin\Platform\Services\Processor\Substrate\Events\SubstrateEvent; -use Illuminate\Support\Arr; +use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Event; -class FuelTankMutated implements SubstrateEvent +class FuelTankMutated extends FuelTankSubstrateEvent { - use QueryDataOrFail; - /** * Handle the fuel tank mutated event. + * + * @throws PlatformException */ - public function run(PolkadartEvent $event, Block $block, Codec $codec): void + public function run(Event $event, Block $block, Codec $codec): void { if (!$event instanceof FuelTankMutatedPolkadart) { return; } + // Fail if it doesn't find the fuel tank $fuelTank = $this->getFuelTank($event->tankId); if (!is_null($uac = $event->userAccountManagement)) { - $fuelTank->reserves_existential_deposit = Arr::get($uac, 'Some.tank_reserves_existential_deposit'); - $fuelTank->reserves_account_creation_deposit = Arr::get($uac, 'Some.tank_reserves_account_creation_deposit'); + $fuelTank->reserves_existential_deposit = $this->getValue($uac, ['Some.tank_reserves_existential_deposit', 'tank_reserves_existential_deposit']); + $fuelTank->reserves_account_creation_deposit = $this->getValue($uac, ['Some.tank_reserves_account_creation_deposit', 'tank_reserves_account_creation_deposit']); } if (!is_null($providesDeposit = $event->providesDeposit)) { @@ -40,18 +41,31 @@ public function run(PolkadartEvent $event, Block $block, Codec $codec): void AccountRule::where('fuel_tank_id', $fuelTank->id)?->delete(); $insertAccountRules = []; - foreach ($accountRules as $rule) { - $ruleName = array_key_first($rule); - $ruleData = $rule[$ruleName]; + $rules = collect($accountRules)->collapse(); + $accountRules = (new AccountRulesParams())->fromEncodable($rules->toArray())->toArray(); + + if (!empty($accountRules['WhitelistedCallers'])) { + $insertAccountRules[] = [ + 'rule' => 'WhitelistedCallers', + 'value' => $accountRules['WhitelistedCallers'], + ]; + } + + if (!empty($accountRules['RequireToken'])) { $insertAccountRules[] = [ - 'rule' => $ruleName, - 'value' => $ruleData, + 'rule' => 'RequireToken', + 'value' => $accountRules['RequireToken'], ]; } + $fuelTank->accountRules()->createMany($insertAccountRules); } $fuelTank->save(); - FuelTankMutatedEvent::safeBroadcast($fuelTank); + + FuelTankMutatedEvent::safeBroadcast( + $fuelTank, + $this->getTransaction($block, $event->extrinsicIndex), + ); } } diff --git a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/RuleSetInserted.php b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/RuleSetInserted.php index a87186f..9ff29f4 100644 --- a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/RuleSetInserted.php +++ b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/RuleSetInserted.php @@ -2,27 +2,26 @@ namespace Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\FuelTanks; -use Carbon\Carbon; +use Enjin\Platform\Exceptions\PlatformException; use Enjin\Platform\FuelTanks\Events\Substrate\FuelTanks\RuleSetInserted as RuleSetInsertedEvent; use Enjin\Platform\FuelTanks\Models\DispatchRule; -use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\Traits\QueryDataOrFail; +use Enjin\Platform\FuelTanks\Models\Substrate\DispatchRulesParams; +use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\FuelTankSubstrateEvent; use Enjin\Platform\Models\Laravel\Block; -use Enjin\Platform\Models\Transaction; use Enjin\Platform\Services\Processor\Substrate\Codec\Codec; use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\FuelTanks\RuleSetInserted as RuleSetInsertedPolkadart; -use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent; -use Enjin\Platform\Services\Processor\Substrate\Events\SubstrateEvent; +use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Event; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; -class RuleSetInserted implements SubstrateEvent +class RuleSetInserted extends FuelTankSubstrateEvent { - use QueryDataOrFail; - /** * Handle the rule set inserted event. + * + * @throws PlatformException */ - public function run(PolkadartEvent $event, Block $block, Codec $codec): void + public function run(Event $event, Block $block, Codec $codec): void { if (!$event instanceof RuleSetInsertedPolkadart) { return; @@ -31,50 +30,46 @@ public function run(PolkadartEvent $event, Block $block, Codec $codec): void $extrinsic = $block->extrinsics[$event->extrinsicIndex]; $params = $extrinsic->params; $rules = Arr::get($params, 'rules', []); + + // Fail if it doesn't find the fuel tank $fuelTank = $this->getFuelTank($event->tankId); - $insertRules = []; - foreach ($rules as $rule) { - $ruleName = array_key_first($rule); - $ruleData = $rule[$ruleName]; - $insertRules[] = [ + // Removes rules from that rule set id + DispatchRule::where([ + 'fuel_tank_id' => $fuelTank->id, + 'rule_set_id' => $event->ruleSetId, + ])?->delete(); + + $insertDispatchRules = []; + $dispatchRule = (new DispatchRulesParams())->fromEncodable($event->ruleSetId, ['rules' => $rules])->toArray(); + + foreach ($dispatchRule as $rule) { + $insertDispatchRules[] = [ 'fuel_tank_id' => $fuelTank->id, 'rule_set_id' => $event->ruleSetId, - 'rule' => $ruleName, - 'value' => is_string($ruleData) ? $ruleData : json_encode($ruleData), + 'rule' => array_key_first($rule), + 'value' => $rule[array_key_first($rule)], 'is_frozen' => false, - 'created_at' => $now = Carbon::now(), - 'updated_at' => $now, ]; } - DispatchRule::insert($insertRules); - $daemonTransaction = Transaction::firstWhere(['transaction_chain_hash' => $extrinsic->hash]); + $fuelTank->dispatchRules()->createMany($insertDispatchRules); + $transaction = $this->getTransaction($block, $event->extrinsicIndex); - if ($daemonTransaction) { - Log::info( - sprintf( - 'RuleSetInserted at FuelTank %s (id: %s) from transaction %s (id: %s).', - $fuelTank->public_key, - $fuelTank->id, - $daemonTransaction->transaction_chain_hash, - $daemonTransaction->id - ) - ); - } else { - Log::info( - sprintf( - 'RuleSetInserted at FuelTank %s (id: %s) from unknown transaction.', - $fuelTank->public_key, - $fuelTank->id, - ) - ); - } + Log::info( + sprintf( + 'RuleSetInserted at FuelTank %s (id: %s) from transaction %s (id: %s).', + $fuelTank->public_key, + $fuelTank->id, + $transaction?->transaction_chain_hash ?? 'unknown', + $transaction?->id ?? 'unknown', + ) + ); RuleSetInsertedEvent::safeBroadcast( $fuelTank, - $insertRules, - $daemonTransaction + $insertDispatchRules, + $transaction ); } } diff --git a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/RuleSetRemoved.php b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/RuleSetRemoved.php index 25cc14b..943e117 100644 --- a/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/RuleSetRemoved.php +++ b/src/Services/Processor/Substrate/Events/Implementations/FuelTanks/RuleSetRemoved.php @@ -2,29 +2,30 @@ namespace Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\FuelTanks; +use Enjin\Platform\Exceptions\PlatformException; use Enjin\Platform\FuelTanks\Events\Substrate\FuelTanks\RuleSetRemoved as RuleSetRemovedEvent; use Enjin\Platform\FuelTanks\Models\DispatchRule; -use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\Implementations\Traits\QueryDataOrFail; +use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Events\FuelTankSubstrateEvent; use Enjin\Platform\Models\Laravel\Block; use Enjin\Platform\Services\Processor\Substrate\Codec\Codec; use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\FuelTanks\RuleSetRemoved as RuleSetRemovedPolkadart; -use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\PolkadartEvent; -use Enjin\Platform\Services\Processor\Substrate\Events\SubstrateEvent; +use Enjin\Platform\Services\Processor\Substrate\Codec\Polkadart\Events\Event; use Illuminate\Support\Facades\Log; -class RuleSetRemoved implements SubstrateEvent +class RuleSetRemoved extends FuelTankSubstrateEvent { - use QueryDataOrFail; - /** * Handle the rule set removed event. + * + * @throws PlatformException */ - public function run(PolkadartEvent $event, Block $block, Codec $codec): void + public function run(Event $event, Block $block, Codec $codec): void { if (!$event instanceof RuleSetRemovedPolkadart) { return; } + // Fail if it doesn't find the fuel tank $fuelTank = $this->getFuelTank($event->tankId); $rules = DispatchRule::where([ 'fuel_tank_id' => $fuelTank->id, @@ -41,6 +42,10 @@ public function run(PolkadartEvent $event, Block $block, Codec $codec): void ) ); - RuleSetRemovedEvent::safeBroadcast($fuelTank, $event->ruleSetId); + RuleSetRemovedEvent::safeBroadcast( + $fuelTank, + $event->ruleSetId, + $this->getTransaction($block, $event->extrinsicIndex), + ); } } diff --git a/src/Services/Processor/Substrate/Parser.php b/src/Services/Processor/Substrate/Parser.php index dce9f8d..500d479 100644 --- a/src/Services/Processor/Substrate/Parser.php +++ b/src/Services/Processor/Substrate/Parser.php @@ -137,7 +137,7 @@ protected function fuelTankRules(array $data): void 'fuel_tank_id' => $tank->id, 'rule_set_id' => $ruleSet->ruleSetId, 'rule' => $rule, - 'value' => json_encode(Arr::get($ruleParam->toEncodable(), $rule)), + 'value' => json_encode(Arr::get($ruleParam->toArray(), $rule)), 'is_frozen' => $ruleSet->isFrozen, 'created_at' => $now = Carbon::now(), 'updated_at' => $now, @@ -156,7 +156,7 @@ protected function fuelTankRules(array $data): void $insertAccountRules[] = [ 'fuel_tank_id' => $tank->id, 'rule' => $rule, - 'value' => json_encode(Arr::get($ruleParam->toEncodable(), $rule)), + 'value' => json_encode(Arr::get($ruleParam->toArray(), $rule)), 'created_at' => $now = Carbon::now(), 'updated_at' => $now, ]; diff --git a/tests/Feature/GraphQL/Mutations/CreateFuelTankTest.php b/tests/Feature/GraphQL/Mutations/CreateFuelTankTest.php index 093bd24..e094a7d 100644 --- a/tests/Feature/GraphQL/Mutations/CreateFuelTankTest.php +++ b/tests/Feature/GraphQL/Mutations/CreateFuelTankTest.php @@ -6,6 +6,7 @@ use Enjin\Platform\FuelTanks\GraphQL\Mutations\CreateFuelTankMutation; use Enjin\Platform\FuelTanks\Models\FuelTank; use Enjin\Platform\FuelTanks\Services\Blockchain\Implemetations\Substrate; +use Enjin\Platform\Services\Serialization\Implementations\Substrate as SubstrateEncoder; use Enjin\Platform\FuelTanks\Tests\Feature\GraphQL\TestCaseGraphQL; use Enjin\Platform\Support\Hex; use Illuminate\Support\Str; @@ -19,6 +20,7 @@ class CreateFuelTankTest extends TestCaseGraphQL public function test_it_can_create_fuel_tank(): void { + $substrate = new SubstrateEncoder(); $response = $this->graphql($this->method, $data = $this->generateData()); $blockchainService = resolve(Substrate::class); @@ -28,7 +30,7 @@ public function test_it_can_create_fuel_tank(): void $this->assertEquals( $response['encodedData'], - TransactionSerializer::encode($this->method, CreateFuelTankMutation::getEncodableParams(...$data)) + $substrate->encode($this->method, CreateFuelTankMutation::getEncodableParams(...$data)) ); } diff --git a/tests/Unit/EncodingTest.php b/tests/Unit/EncodingTest.php index d91fe56..337c2ea 100644 --- a/tests/Unit/EncodingTest.php +++ b/tests/Unit/EncodingTest.php @@ -2,7 +2,6 @@ namespace Enjin\Platform\FuelTanks\Tests\Unit; -use Enjin\Platform\Facades\TransactionSerializer; use Enjin\Platform\FuelTanks\GraphQL\Mutations\AddAccountMutation; use Enjin\Platform\FuelTanks\GraphQL\Mutations\BatchAddAccountMutation; use Enjin\Platform\FuelTanks\GraphQL\Mutations\BatchRemoveAccountMutation; @@ -29,28 +28,31 @@ use Enjin\Platform\FuelTanks\Models\Substrate\WhitelistedCollectionsParams; use Enjin\Platform\FuelTanks\Services\Processor\Substrate\Codec\Codec; use Enjin\Platform\FuelTanks\Tests\TestCase; +use Enjin\Platform\Services\Serialization\Implementations\Substrate; use Illuminate\Support\Arr; use Illuminate\Support\Str; class EncodingTest extends TestCase { + protected Substrate $substrate; protected Codec $codec; protected function setUp(): void { parent::setUp(); + $this->substrate = new Substrate(); $this->codec = new Codec(); } public function test_it_can_encode_add_account() { - $data = TransactionSerializer::encode('AddAccount', AddAccountMutation::getEncodableParams( + $data = $this->substrate->encode('AddAccount', AddAccountMutation::getEncodableParams( tankId: '0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f', userId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d' )); - $callIndex = $this->codec->encoder()->getCallIndex('FuelTanks.add_account', true, true); + $callIndex = $this->codec->encoder()->getCallIndex('FuelTanks.add_account', true); $this->assertEquals( "0x{$callIndex}00be5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f00d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d", $data @@ -59,7 +61,7 @@ public function test_it_can_encode_add_account() public function test_it_can_encode_remove_account() { - $data = TransactionSerializer::encode('RemoveAccount', RemoveAccountMutation::getEncodableParams( + $data = $this->substrate->encode('RemoveAccount', RemoveAccountMutation::getEncodableParams( tankId: '0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f', userId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d' )); @@ -73,7 +75,7 @@ public function test_it_can_encode_remove_account() public function test_it_can_encode_destroy_fuel_tank() { - $data = TransactionSerializer::encode('DestroyFuelTank', DestroyFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('DestroyFuelTank', DestroyFuelTankMutation::getEncodableParams( tankId: '0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f' )); @@ -86,7 +88,7 @@ public function test_it_can_encode_destroy_fuel_tank() public function test_it_can_encode_batch_add_account() { - $data = TransactionSerializer::encode('BatchAddAccount', BatchAddAccountMutation::getEncodableParams( + $data = $this->substrate->encode('BatchAddAccount', BatchAddAccountMutation::getEncodableParams( tankId: '0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f', userIds: [ '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', @@ -103,7 +105,7 @@ public function test_it_can_encode_batch_add_account() public function test_it_can_encode_batch_remove_account() { - $data = TransactionSerializer::encode('BatchRemoveAccount', BatchRemoveAccountMutation::getEncodableParams( + $data = $this->substrate->encode('BatchRemoveAccount', BatchRemoveAccountMutation::getEncodableParams( tankId: '0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f', userIds: [ '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', @@ -122,7 +124,7 @@ public function test_it_can_encode_create_fuel_tank_with_min_params() { $accountRules = new AccountRulesParams(); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Fuel Tank', providesDeposit: false, accountRules: $accountRules, @@ -139,7 +141,7 @@ public function test_it_can_encode_create_fuel_tank_with_provide_deposit_true() { $accountRules = new AccountRulesParams(); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Fuel Tank', providesDeposit: true, accountRules: $accountRules, @@ -160,7 +162,7 @@ public function test_it_can_encode_create_fuel_tank_with_user_account_management tankReservesAccountCreationDeposit: true, ); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Fuel Tank', providesDeposit: false, accountRules: $accountRules, @@ -184,7 +186,7 @@ public function test_it_can_encode_create_fuel_tank_with_require_token() ) ); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Fuel Tank', providesDeposit: false, accountRules: $accountRules, @@ -208,7 +210,7 @@ public function test_it_can_encode_create_fuel_tank_with_whitelisted_callers() ) ); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Fuel Tank', providesDeposit: false, accountRules: $accountRules, @@ -236,7 +238,7 @@ public function test_it_can_encode_create_fuel_tank_with_both_account_rule_set() ), ); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Fuel Tank', providesDeposit: false, accountRules: $accountRules, @@ -259,7 +261,7 @@ public function test_it_can_encode_create_fuel_tank_with_whitelisted_callers_dis ) ); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Tank', providesDeposit: false, userAccountManagement: null, @@ -281,7 +283,7 @@ public function test_it_can_encode_create_fuel_tank_with_whitelisted_collections ), ); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Tank', providesDeposit: false, userAccountManagement: null, @@ -303,7 +305,7 @@ public function test_it_can_encode_create_fuel_tank_with_max_fuel_burn_per_trans ), ); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Tank', providesDeposit: false, userAccountManagement: null, @@ -326,7 +328,7 @@ public function test_it_can_encode_create_fuel_tank_with_user_fuel_budget() ), ); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Tank', providesDeposit: false, userAccountManagement: null, @@ -349,7 +351,7 @@ public function test_it_can_encode_create_fuel_tank_with_tank_fuel_budget() ), ); - $data = TransactionSerializer::encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('CreateFuelTank', CreateFuelTankMutation::getEncodableParams( name: 'Enjin Tank', providesDeposit: false, userAccountManagement: null, @@ -365,7 +367,7 @@ public function test_it_can_encode_create_fuel_tank_with_tank_fuel_budget() public function test_it_can_encode_schedule_mutate_freeze_state_without_rule_set_id() { - $data = TransactionSerializer::encode('MutateFreezeState', ScheduleMutateFreezeStateMutation::getEncodableParams( + $data = $this->substrate->encode('MutateFreezeState', ScheduleMutateFreezeStateMutation::getEncodableParams( tankId: '0x18353dcf7a6eb053b6f0c01774d1f8cfe0c15963780f6935c49a9fd4f50b893c', isFrozen: true, )); @@ -379,7 +381,7 @@ public function test_it_can_encode_schedule_mutate_freeze_state_without_rule_set public function test_it_can_encode_schedule_mutate_freeze_state_with_rule_set_id() { - $data = TransactionSerializer::encode('MutateFreezeState', ScheduleMutateFreezeStateMutation::getEncodableParams( + $data = $this->substrate->encode('MutateFreezeState', ScheduleMutateFreezeStateMutation::getEncodableParams( tankId: '0x18353dcf7a6eb053b6f0c01774d1f8cfe0c15963780f6935c49a9fd4f50b893c', isFrozen: true, ruleSetId: '255', @@ -400,7 +402,7 @@ public function test_it_can_encode_insert_or_update_rule_set() ), ); - $data = TransactionSerializer::encode('InsertRuleSet', InsertRuleSetMutation::getEncodableParams( + $data = $this->substrate->encode('InsertRuleSet', InsertRuleSetMutation::getEncodableParams( tankId: '0x18353dcf7a6eb053b6f0c01774d1f8cfe0c15963780f6935c49a9fd4f50b893c', ruleSetId: '10', dispatchRules: $dispatchRules, @@ -416,12 +418,10 @@ public function test_it_can_encode_insert_or_update_rule_set() public function test_it_can_encode_insert_or_update_rule_with_permitted_extrinsics() { $dispatchRules = new DispatchRulesParams( - permittedExtrinsics: new PermittedExtrinsicsParams( - extrinsics: ['CreateCollection', 'ApproveCollection', 'SimpleTransferToken', 'OperatorTransferToken'], - ), + permittedExtrinsics: (new PermittedExtrinsicsParams())->fromMethods(['CreateCollection', 'ApproveCollection', 'SimpleTransferToken', 'OperatorTransferToken']), ); - $data = TransactionSerializer::encode('InsertRuleSet', InsertRuleSetMutation::getEncodableParams( + $data = $this->substrate->encode('InsertRuleSet', InsertRuleSetMutation::getEncodableParams( tankId: '0x18353dcf7a6eb053b6f0c01774d1f8cfe0c15963780f6935c49a9fd4f50b893c', ruleSetId: '10', dispatchRules: $dispatchRules, @@ -432,14 +432,14 @@ public function test_it_can_encode_insert_or_update_rule_with_permitted_extrinsi $callIndex = $this->codec->encoder()->getCallIndex('FuelTanks.insert_rule_set', true); $this->assertEquals( - "0x{$callIndex}0018353dcf7a6eb053b6f0c01774d1f8cfe0c15963780f6935c49a9fd4f50b893c0a0000000407102800000000000000280f006a03b1a3d40d7e344dfb27157931b14b59fe2ff11d7352353321fe400e956802002806006a03b1a3d40d7e344dfb27157931b14b59fe2ff11d7352353321fe400e95680200000000002806006a03b1a3d40d7e344dfb27157931b14b59fe2ff11d7352353321fe400e9568020001006a03b1a3d40d7e344dfb27157931b14b59fe2ff11d7352353321fe400e9568020000", + "0x{$callIndex}0018353dcf7a6eb053b6f0c01774d1f8cfe0c15963780f6935c49a9fd4f50b893c0a00000004070c2800000000000000280f006a03b1a3d40d7e344dfb27157931b14b59fe2ff11d7352353321fe400e95680200280c0000", $data ); } public function test_it_can_encode_remove_rule_set() { - $data = TransactionSerializer::encode('RemoveRuleSet', RemoveRuleSetMutation::getEncodableParams( + $data = $this->substrate->encode('RemoveRuleSet', RemoveRuleSetMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', ruleSetId: '10' )); @@ -453,7 +453,7 @@ public function test_it_can_encode_remove_rule_set() public function test_it_can_encode_remove_account_rule_data() { - $data = TransactionSerializer::encode('RemoveAccountRuleData', RemoveAccountRuleDataMutation::getEncodableParams( + $data = $this->substrate->encode('RemoveAccountRuleData', RemoveAccountRuleDataMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', userId: '0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48', ruleSetId: '20', @@ -469,7 +469,7 @@ public function test_it_can_encode_remove_account_rule_data() public function test_it_can_encode_mutate_fuel_tank_with_some_mutation_null() { - $data = TransactionSerializer::encode('MutateFuelTank', MutateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('MutateFuelTank', MutateFuelTankMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', )); @@ -482,7 +482,7 @@ public function test_it_can_encode_mutate_fuel_tank_with_some_mutation_null() public function test_it_can_encode_mutate_fuel_tank_with_some_mutation_filled() { - $data = TransactionSerializer::encode('MutateFuelTank', MutateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('MutateFuelTank', MutateFuelTankMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', userAccount: new UserAccountManagementParams( tankReservesExistentialDeposit: true, @@ -499,7 +499,7 @@ public function test_it_can_encode_mutate_fuel_tank_with_some_mutation_filled() public function test_it_can_encode_mutate_fuel_tank_with_provides_deposit() { - $data = TransactionSerializer::encode('MutateFuelTank', MutateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('MutateFuelTank', MutateFuelTankMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', userAccount: [], providesDeposit: true, @@ -514,7 +514,7 @@ public function test_it_can_encode_mutate_fuel_tank_with_provides_deposit() public function test_it_can_encode_mutate_fuel_tank_with_account_rules() { - $data = TransactionSerializer::encode('MutateFuelTank', MutateFuelTankMutation::getEncodableParams( + $data = $this->substrate->encode('MutateFuelTank', MutateFuelTankMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', userAccount: [], providesDeposit: null, @@ -536,7 +536,7 @@ public function test_it_can_encode_mutate_fuel_tank_with_account_rules() public function test_it_can_encode_dispatch() { $createCollection = '2800000000000000'; - $data = TransactionSerializer::encode('Dispatch', DispatchMutation::getEncodableParams( + $data = $this->substrate->encode('Dispatch', DispatchMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', ruleSetId: 255, )) . $createCollection . '00'; @@ -551,7 +551,7 @@ public function test_it_can_encode_dispatch() public function test_it_can_encode_dispatch_and_touch() { $createCollection = '2800000000000000'; - $data = TransactionSerializer::encode('DispatchAndTouch', DispatchAndTouchMutation::getEncodableParams( + $data = $this->substrate->encode('DispatchAndTouch', DispatchAndTouchMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', ruleSetId: 255, )) . $createCollection . '00'; @@ -565,7 +565,7 @@ public function test_it_can_encode_dispatch_and_touch() public function test_it_can_encode_set_consumption_with_no_options() { - $data = TransactionSerializer::encode('ForceSetConsumption', ForceSetConsumptionMutation::getEncodableParams( + $data = $this->substrate->encode('ForceSetConsumption', ForceSetConsumptionMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', ruleSetId: 255, totalConsumed: '100000000' @@ -580,7 +580,7 @@ public function test_it_can_encode_set_consumption_with_no_options() public function test_it_can_encode_set_consumption_with_user_id() { - $data = TransactionSerializer::encode('ForceSetConsumption', ForceSetConsumptionMutation::getEncodableParams( + $data = $this->substrate->encode('ForceSetConsumption', ForceSetConsumptionMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', ruleSetId: 255, totalConsumed: '100000000', @@ -596,7 +596,7 @@ public function test_it_can_encode_set_consumption_with_user_id() public function test_it_can_encode_set_consumption_with_last_reset_block() { - $data = TransactionSerializer::encode('ForceSetConsumption', ForceSetConsumptionMutation::getEncodableParams( + $data = $this->substrate->encode('ForceSetConsumption', ForceSetConsumptionMutation::getEncodableParams( tankId: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d', ruleSetId: 255, totalConsumed: '100000000',