Skip to content

Commit 45a3083

Browse files
refactor: cleanup code
1 parent 1e222b0 commit 45a3083

File tree

3 files changed

+7
-109
lines changed

3 files changed

+7
-109
lines changed

src/Modules/Bulk.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
CONTEXT_BOT_SIZE,
1616
CONTEXT_BULK,
1717
CONTEXT_DEAL,
18-
CONTEXT_DOMAIN_SEPARATOR_HASH,
1918
CONTEXT_INDEX,
2019
createBulkOrderID,
2120
createBulkSliceID,
@@ -30,13 +29,11 @@ import {
3029
export function handleBulk(content: Bytes): void {
3130
const hash = dataSource.stringParam();
3231
const context = dataSource.context();
33-
const domainSeparator = context.getBytes(CONTEXT_DOMAIN_SEPARATOR_HASH);
3432
const dealId = context.getString(CONTEXT_DEAL);
3533
const botFirst = context.getBigInt(CONTEXT_BOT_FIRST);
3634
const botSize = context.getBigInt(CONTEXT_BOT_SIZE);
3735

3836
const bulkId = dealId;
39-
4037
let bulk = Bulk.load(bulkId);
4138
if (bulk != null) {
4239
// immutable bulk already exists nothing to do
@@ -64,7 +61,6 @@ export function handleBulk(content: Bytes): void {
6461
sliceContext.setString(CONTEXT_BULK, bulkId);
6562
sliceContext.setString(CONTEXT_DEAL, dealId);
6663
sliceContext.setBigInt(CONTEXT_INDEX, index);
67-
sliceContext.setBytes(CONTEXT_DOMAIN_SEPARATOR_HASH, domainSeparator);
6864
DataSourceTemplate.createWithContext('BulkSlice', [sliceCid], sliceContext);
6965
}
7066
}
@@ -168,22 +164,6 @@ export function handleBulkSlice(content: Bytes): void {
168164
);
169165
datasetOrder.salt = Bytes.fromHexString(saltEntry.value.toString());
170166
datasetOrder.sign = Bytes.fromHexString(signEntry.value.toString());
171-
172-
// todo: it may be useful to keep on order entity?
173-
// compute order hash with domain separator from contract
174-
// const domainSeparator = context.getBytes(CONTEXT_DOMAIN_SEPARATOR_HASH);
175-
// const orderHash = hashDatasetOrder(
176-
// Address.fromString(datasetEntry.value.toString()),
177-
// BigInt.fromString(datasetPriceEntry.value.toString()),
178-
// BigInt.fromString(volumeEntry.value.toString()),
179-
// Bytes.fromHexString(tagEntry.value.toString()),
180-
// Address.fromString(apprestrictEntry.value.toString()),
181-
// Address.fromString(workerpoolrestrictEntry.value.toString()),
182-
// Address.fromString(requesterrestrictEntry.value.toString()),
183-
// Bytes.fromHexString(saltEntry.value.toString()),
184-
// domainSeparator,
185-
// );
186-
// order.hash = orderHash;
187167
datasetOrder.save();
188168

189169
let datasetOrders = bulkSlice.datasetOrders;

src/Modules/IexecPoco.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828

2929
import {
3030
AccurateContribution,
31-
Bulk,
3231
FaultyContribution,
3332
OrdersMatched,
3433
SchedulerNotice,
@@ -45,7 +44,6 @@ import {
4544
CONTEXT_BOT_FIRST,
4645
CONTEXT_BOT_SIZE,
4746
CONTEXT_DEAL,
48-
CONTEXT_DOMAIN_SEPARATOR_HASH,
4947
createContributionID,
5048
createEventID,
5149
fetchAccount,
@@ -112,24 +110,14 @@ export function handleOrdersMatched(event: OrdersMatchedEvent): void {
112110
if (params.isOk) {
113111
const bulkCid = params.value.toObject().getEntry('bulk_cid');
114112
if (bulkCid) {
115-
// the same bulk is used by any deal using the same requestorder => we use requestorderHash as bulk ID
113+
// the same bulk may be used by many deals => we use dealid as bulk ID to avoid collisions
116114
const bulkId = event.params.dealid.toHex();
117-
// create the bulk if not existing yet
118-
const indexedBulk = Bulk.load(bulkId);
119-
if (!indexedBulk) {
120-
let context = new DataSourceContext();
121-
// Pass onchain data that will be needed in file handlers
122-
const domainSeparator = contract.eip712domain_separator();
123-
context.setString(CONTEXT_DEAL, deal.id);
124-
context.setBigInt(CONTEXT_BOT_FIRST, deal.botFirst);
125-
context.setBigInt(CONTEXT_BOT_SIZE, deal.botSize);
126-
context.setBytes(CONTEXT_DOMAIN_SEPARATOR_HASH, domainSeparator);
127-
DataSourceTemplate.createWithContext(
128-
'Bulk',
129-
[bulkCid.value.toString()],
130-
context,
131-
);
132-
}
115+
let context = new DataSourceContext();
116+
// Pass onchain data that will be needed in file handlers
117+
context.setString(CONTEXT_DEAL, deal.id);
118+
context.setBigInt(CONTEXT_BOT_FIRST, deal.botFirst);
119+
context.setBigInt(CONTEXT_BOT_SIZE, deal.botSize);
120+
DataSourceTemplate.createWithContext('Bulk', [bulkCid.value.toString()], context);
133121
// bulk may not be indexed, this is not an issue, the model will prune it
134122
deal.bulk = bulkId;
135123
deal.save();

src/utils.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
WorkerpoolOrder,
2727
} from '../generated/schema';
2828

29-
import { IexecInterfaceToken__domainResultValue0Struct as IEIP712Domain } from '../generated/Core/IexecInterfaceToken';
30-
3129
export function createEventID(event: ethereum.Event): string {
3230
return event.block.number.toString().concat('-').concat(event.logIndex.toString());
3331
}
@@ -220,72 +218,6 @@ export function concatByteArrays(a: ByteArray, b: ByteArray): ByteArray {
220218
return changetype<ByteArray>(out); // Change from 'as T' to 'changetype<T>'
221219
}
222220

223-
function encodeStringValue(string: string): ethereum.Value {
224-
return ethereum.Value.fromFixedBytes(
225-
changetype<Bytes>(crypto.keccak256(ByteArray.fromUTF8(string))), // Change from 'as T' to 'changetype<T>'
226-
);
227-
}
228-
229-
export function hashDatasetOrder(
230-
dataset: Address,
231-
datasetprice: BigInt,
232-
volume: BigInt,
233-
tag: Bytes,
234-
apprestrict: Address,
235-
workerpoolrestrict: Address,
236-
requesterrestrict: Address,
237-
salt: Bytes,
238-
domainHash: ByteArray,
239-
): ByteArray {
240-
const structHash = crypto.keccak256(
241-
ethereum.encode(
242-
ethereum.Value.fromTuple(
243-
changetype<ethereum.Tuple>([
244-
encodeStringValue(
245-
'DatasetOrder(address dataset,uint256 datasetprice,uint256 volume,bytes32 tag,address apprestrict,address workerpoolrestrict,address requesterrestrict,bytes32 salt)',
246-
),
247-
ethereum.Value.fromAddress(dataset),
248-
ethereum.Value.fromUnsignedBigInt(datasetprice),
249-
ethereum.Value.fromUnsignedBigInt(volume),
250-
ethereum.Value.fromFixedBytes(tag),
251-
ethereum.Value.fromAddress(apprestrict),
252-
ethereum.Value.fromAddress(workerpoolrestrict),
253-
ethereum.Value.fromAddress(requesterrestrict),
254-
ethereum.Value.fromFixedBytes(salt),
255-
]),
256-
),
257-
)!,
258-
);
259-
return hashEIP712(domainHash, structHash);
260-
}
261-
262-
function hashEIP712(domainHash: ByteArray, structHash: ByteArray): ByteArray {
263-
return crypto.keccak256(
264-
concatByteArrays(
265-
ByteArray.fromHexString('0x1901'),
266-
concatByteArrays(domainHash, structHash),
267-
),
268-
);
269-
}
270-
271-
function hashDomain(domain: IEIP712Domain): ByteArray {
272-
return crypto.keccak256(
273-
ethereum.encode(
274-
ethereum.Value.fromTuple(
275-
changetype<ethereum.Tuple>([
276-
encodeStringValue(
277-
'EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)',
278-
),
279-
encodeStringValue(domain.name),
280-
encodeStringValue(domain.version),
281-
ethereum.Value.fromUnsignedBigInt(domain.chainId),
282-
ethereum.Value.fromAddress(domain.verifyingContract),
283-
]), // Change from 'as T' to 'changetype<T>'
284-
),
285-
)!,
286-
);
287-
}
288-
289221
export function isIntegerString(str: string): boolean {
290222
// empty string is not valid
291223
if (str.length == 0) {
@@ -352,8 +284,6 @@ export function isBytes32String(str: string): boolean {
352284

353285
export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
354286

355-
export const CONTEXT_REQUESTHASH = 'REQUESTHASH';
356-
export const CONTEXT_DOMAIN_SEPARATOR_HASH = 'DOMAIN_SEPARATOR_HASH';
357287
export const CONTEXT_DEAL = 'DEAL';
358288
export const CONTEXT_BULK = 'BULK';
359289
export const CONTEXT_INDEX = 'INDEX';

0 commit comments

Comments
 (0)