Skip to content

Commit

Permalink
feat: fix service instance design
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone committed Nov 5, 2024
1 parent 5ed68d5 commit 76bb328
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
pragma solidity ^0.8.19;

import "tnt-core/BlueprintServiceManagerBase.sol";
import "./IncredibleSquaringInstance.sol";
import "incredible-squaring/IncredibleSquaringInstance.sol";

/**
* @title IncredibleSquaringBlueprint
* @dev This contract is an example of a service blueprint that provides a single
* service to square a number. It demonstrates the lifecycle hooks that can be
* implemented in a service blueprint.
*/

contract IncredibleSquaringBlueprint is BlueprintServiceManagerBase {
/**
* @dev A mapping of all service operators registered with the blueprint.
Expand All @@ -27,25 +26,20 @@ contract IncredibleSquaringBlueprint is BlueprintServiceManagerBase {
* @dev Hook for service instance requests. Called when a user requests a service
* instance from the blueprint.
* @param serviceId The ID of the requested service.
* @param operators The operators involved in the service in bytes array format.
* @param operatorsOfService The operators involved in the service in bytes array format.
* @param requestInputs Inputs required for the service request in bytes format.
*/
function onRequest(
uint64 serviceId,
bytes[] calldata operators,
bytes calldata requestInputs
)
function onRequest(uint64 serviceId, bytes[] calldata operatorsOfService, bytes calldata requestInputs)
public
payable
virtual
override
onlyFromRootChain
{
address deployed = new IncredibleSquaringInstance(serviceId);
serviceInstances[serviceId] = deployed;
IncredibleSquaringInstance deployed = new IncredibleSquaringInstance(serviceId);
serviceInstances[serviceId] = address(deployed);
}


/**
* @dev Verifies the result of a job call. This function is used to validate the
* outputs of a job execution against the expected results.
Expand All @@ -55,8 +49,6 @@ contract IncredibleSquaringBlueprint is BlueprintServiceManagerBase {
* @param participant The participant (operator) whose result is being verified.
* @param inputs Inputs used for the job execution.
* @param outputs Outputs resulting from the job execution.
* @return bool Returns true if the job call result is verified successfully,
* otherwise false.
*/
function onJobResult(
uint64 serviceId,
Expand All @@ -65,7 +57,7 @@ contract IncredibleSquaringBlueprint is BlueprintServiceManagerBase {
bytes calldata participant,
bytes calldata inputs,
bytes calldata outputs
) override public pure {
) public payable override {
// Decode the inputs and outputs
uint256 input = abi.decode(inputs, (uint256));
uint256 output = abi.decode(outputs, (uint256));
Expand All @@ -74,4 +66,3 @@ contract IncredibleSquaringBlueprint is BlueprintServiceManagerBase {
require(isValid, "Invalid result");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pragma solidity ^0.8.20;
/**
* @title IncredibleSquaringInstance
* @dev This contract represents an instance of the IncredibleSquaring service.
* It is deployed when a user requests a new service instance and handles the
* It is deployed when a user requests a new service instance and handles the
* actual squaring computation.
*/
contract IncredibleSquaringInstance {
// Address of the blueprint that created this instance
address public immutable blueprint;

// Service ID assigned by the root chain
uint64 public immutable serviceId;

Expand Down

0 comments on commit 76bb328

Please sign in to comment.