Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 1 addition & 77 deletions src/Modules/IexecPoco.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-License-Identifier: Apache-2.0

import { Address, BigInt, dataSource } from '@graphprotocol/graph-ts';
Expand All @@ -8,7 +8,6 @@ import {
AccurateContribution as AccurateContributionEvent,
FaultyContribution as FaultyContributionEvent,
IexecInterfaceToken as IexecInterfaceTokenContract,
MatchOrdersCall,
OrdersMatched as OrdersMatchedEvent,
SchedulerNotice as SchedulerNoticeEvent,
TaskClaimed as TaskClaimedEvent,
Expand All @@ -35,7 +34,6 @@ import {
} from '../../generated/schema';

import {
ADDRESS_ZERO,
createContributionID,
createEventID,
fetchAccount,
Expand All @@ -47,84 +45,10 @@ import {
fetchRequestorder,
fetchTask,
fetchWorkerpoolorder,
hashApporder,
hashDatasetorder,
hashRequestorder,
hashWorkerpoolorder,
logTransaction,
toRLC,
} from '../utils';

export function handleMatchOrders(call: MatchOrdersCall): void {
const contract = IexecInterfaceTokenContract.bind(call.to);
const domain = contract.domain();

const apporderInput = call.inputs.value0;
const apporder = fetchApporder(hashApporder(domain, apporderInput).toHex());
apporder.app = apporderInput.app.toHex();
apporder.appprice = toRLC(apporderInput.appprice);
apporder.volume = apporderInput.volume;
apporder.tag = apporderInput.tag;
apporder.datasetrestrict = apporderInput.datasetrestrict;
apporder.workerpoolrestrict = apporderInput.workerpoolrestrict;
apporder.requesterrestrict = apporderInput.requesterrestrict;
apporder.salt = apporderInput.salt;
apporder.sign = apporderInput.sign;
apporder.save();

const datasetorderInput = call.inputs.value1;
if (datasetorderInput.dataset.toString() != ADDRESS_ZERO) {
const datasetorder = fetchDatasetorder(hashDatasetorder(domain, datasetorderInput).toHex());
datasetorder.dataset = datasetorderInput.dataset.toHex();
datasetorder.datasetprice = toRLC(datasetorderInput.datasetprice);
datasetorder.volume = datasetorderInput.volume;
datasetorder.tag = datasetorderInput.tag;
datasetorder.apprestrict = datasetorderInput.apprestrict;
datasetorder.workerpoolrestrict = datasetorderInput.workerpoolrestrict;
datasetorder.requesterrestrict = datasetorderInput.requesterrestrict;
datasetorder.salt = datasetorderInput.salt;
datasetorder.sign = datasetorderInput.sign;
datasetorder.save();
}

const workerpoolorderInput = call.inputs.value2;
const workerpoolorder = fetchWorkerpoolorder(
hashWorkerpoolorder(domain, workerpoolorderInput).toHex(),
);
workerpoolorder.workerpool = workerpoolorderInput.workerpool.toHex();
workerpoolorder.workerpoolprice = toRLC(workerpoolorderInput.workerpoolprice);
workerpoolorder.volume = workerpoolorderInput.volume;
workerpoolorder.tag = workerpoolorderInput.tag;
workerpoolorder.category = workerpoolorderInput.category.toString();
workerpoolorder.trust = workerpoolorderInput.trust;
workerpoolorder.apprestrict = workerpoolorderInput.apprestrict;
workerpoolorder.datasetrestrict = workerpoolorderInput.datasetrestrict;
workerpoolorder.requesterrestrict = workerpoolorderInput.requesterrestrict;
workerpoolorder.salt = workerpoolorderInput.salt;
workerpoolorder.sign = workerpoolorderInput.sign;
workerpoolorder.save();

const requestorderInput = call.inputs.value3;
const requestorder = fetchRequestorder(hashRequestorder(domain, requestorderInput).toHex());
requestorder.app = requestorderInput.app.toHex();
requestorder.appmaxprice = toRLC(requestorderInput.appmaxprice);
requestorder.dataset = requestorderInput.dataset.toHex();
requestorder.datasetmaxprice = toRLC(requestorderInput.datasetmaxprice);
requestorder.workerpool = requestorderInput.workerpool.toHex();
requestorder.workerpoolmaxprice = toRLC(requestorderInput.workerpoolmaxprice);
requestorder.requester = requestorderInput.requester.toHex();
requestorder.volume = requestorderInput.volume;
requestorder.tag = requestorderInput.tag;
requestorder.category = requestorderInput.category.toString();
requestorder.trust = requestorderInput.trust;
requestorder.beneficiary = requestorderInput.beneficiary.toHex();
requestorder.callback = requestorderInput.callback.toHex();
requestorder.params = requestorderInput.params;
requestorder.salt = requestorderInput.salt;
requestorder.sign = requestorderInput.sign;
requestorder.save();
}

export function handleOrdersMatched(event: OrdersMatchedEvent): void {
let contract = IexecInterfaceTokenContract.bind(event.address);
let viewedDeal = contract.viewDeal(event.params.dealid);
Expand Down
3 changes: 1 addition & 2 deletions src/Modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2020-2024 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-License-Identifier: Apache-2.0

export { handleCreateCategory } from './IexecCategoryManager';
Expand All @@ -8,7 +8,6 @@ export { handleLock, handleReward, handleSeize, handleTransfer, handleUnlock } f
export {
handleAccurateContribution,
handleFaultyContribution,
handleMatchOrders,
handleOrdersMatched,
handleSchedulerNotice,
handleTaskClaimed,
Expand Down
134 changes: 2 additions & 132 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/******************************************************************************
* Copyright 2020 IEXEC BLOCKCHAIN TECH *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/
// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH <contact@iex.ec>
// SPDX-License-Identifier: Apache-2.0

import {
Address,
Expand All @@ -39,10 +26,6 @@ import {

import {
IexecInterfaceToken__domainResultValue0Struct as IEIP712Domain,
MatchOrdersCallValue0Struct as IAppOrder,
MatchOrdersCallValue1Struct as IDatasetOrder,
MatchOrdersCallValue2Struct as IWorkerpoolOrder,
MatchOrdersCallValue3Struct as IRequestOrder,
} from "../generated/Core/IexecInterfaceToken";

export function createEventID(event: ethereum.Event): string {
Expand Down Expand Up @@ -229,117 +212,4 @@ function hashDomain(domain: IEIP712Domain): ByteArray {
);
}

export function hashApporder(
domain: IEIP712Domain,
apporder: IAppOrder
): ByteArray {
const structHash = crypto.keccak256(
ethereum.encode(
ethereum.Value.fromTuple(
changetype<ethereum.Tuple>([
encodeStringValue(
"AppOrder(address app,uint256 appprice,uint256 volume,bytes32 tag,address datasetrestrict,address workerpoolrestrict,address requesterrestrict,bytes32 salt)"
),
ethereum.Value.fromAddress(apporder.app),
ethereum.Value.fromUnsignedBigInt(apporder.appprice),
ethereum.Value.fromUnsignedBigInt(apporder.volume),
ethereum.Value.fromFixedBytes(apporder.tag),
ethereum.Value.fromAddress(apporder.datasetrestrict),
ethereum.Value.fromAddress(apporder.workerpoolrestrict),
ethereum.Value.fromAddress(apporder.requesterrestrict),
ethereum.Value.fromFixedBytes(apporder.salt),
]) // Change from 'as T' to 'changetype<T>'
)
)!
);
return hashEIP712(hashDomain(domain), structHash);
}

export function hashDatasetorder(
domain: IEIP712Domain,
datasetorder: IDatasetOrder
): ByteArray {
const structHash = crypto.keccak256(
ethereum.encode(
ethereum.Value.fromTuple(
changetype<ethereum.Tuple>([
encodeStringValue(
"DatasetOrder(address dataset,uint256 datasetprice,uint256 volume,bytes32 tag,address apprestrict,address workerpoolrestrict,address requesterrestrict,bytes32 salt)"
),
ethereum.Value.fromAddress(datasetorder.dataset),
ethereum.Value.fromUnsignedBigInt(datasetorder.datasetprice),
ethereum.Value.fromUnsignedBigInt(datasetorder.volume),
ethereum.Value.fromFixedBytes(datasetorder.tag),
ethereum.Value.fromAddress(datasetorder.apprestrict),
ethereum.Value.fromAddress(datasetorder.workerpoolrestrict),
ethereum.Value.fromAddress(datasetorder.requesterrestrict),
ethereum.Value.fromFixedBytes(datasetorder.salt),
]) // Change from 'as T' to 'changetype<T>'
)
)!
);
return hashEIP712(hashDomain(domain), structHash);
}

export function hashWorkerpoolorder(
domain: IEIP712Domain,
workerpoolorder: IWorkerpoolOrder
): ByteArray {
const structHash = crypto.keccak256(
ethereum.encode(
ethereum.Value.fromTuple(
changetype<ethereum.Tuple>([
encodeStringValue(
"WorkerpoolOrder(address workerpool,uint256 workerpoolprice,uint256 volume,bytes32 tag,uint256 category,uint256 trust,address apprestrict,address datasetrestrict,address requesterrestrict,bytes32 salt)"
),
ethereum.Value.fromAddress(workerpoolorder.workerpool),
ethereum.Value.fromUnsignedBigInt(workerpoolorder.workerpoolprice),
ethereum.Value.fromUnsignedBigInt(workerpoolorder.volume),
ethereum.Value.fromFixedBytes(workerpoolorder.tag),
ethereum.Value.fromUnsignedBigInt(workerpoolorder.category),
ethereum.Value.fromUnsignedBigInt(workerpoolorder.trust),
ethereum.Value.fromAddress(workerpoolorder.apprestrict),
ethereum.Value.fromAddress(workerpoolorder.datasetrestrict),
ethereum.Value.fromAddress(workerpoolorder.requesterrestrict),
ethereum.Value.fromFixedBytes(workerpoolorder.salt),
]) // Change from 'as T' to 'changetype<T>'
)
)!
);
return hashEIP712(hashDomain(domain), structHash);
}

export function hashRequestorder(
domain: IEIP712Domain,
requestorder: IRequestOrder
): ByteArray {
const structHash = crypto.keccak256(
ethereum.encode(
ethereum.Value.fromTuple(
changetype<ethereum.Tuple>([
encodeStringValue(
"RequestOrder(address app,uint256 appmaxprice,address dataset,uint256 datasetmaxprice,address workerpool,uint256 workerpoolmaxprice,address requester,uint256 volume,bytes32 tag,uint256 category,uint256 trust,address beneficiary,address callback,string params,bytes32 salt)"
),
ethereum.Value.fromAddress(requestorder.app),
ethereum.Value.fromUnsignedBigInt(requestorder.appmaxprice),
ethereum.Value.fromAddress(requestorder.dataset),
ethereum.Value.fromUnsignedBigInt(requestorder.datasetmaxprice),
ethereum.Value.fromAddress(requestorder.workerpool),
ethereum.Value.fromUnsignedBigInt(requestorder.workerpoolmaxprice),
ethereum.Value.fromAddress(requestorder.requester),
ethereum.Value.fromUnsignedBigInt(requestorder.volume),
ethereum.Value.fromFixedBytes(requestorder.tag),
ethereum.Value.fromUnsignedBigInt(requestorder.category),
ethereum.Value.fromUnsignedBigInt(requestorder.trust),
ethereum.Value.fromAddress(requestorder.beneficiary),
ethereum.Value.fromAddress(requestorder.callback),
encodeStringValue(requestorder.params),
ethereum.Value.fromFixedBytes(requestorder.salt),
]) // Change from 'as T' to 'changetype<T>'
)
)!
);
return hashEIP712(hashDomain(domain), structHash);
}

export const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";