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
74 changes: 69 additions & 5 deletions subgraph/src/pdp-verifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigInt, Bytes, log, store, Value } from "@graphprotocol/graph-ts";
import { Address, BigInt, Bytes, log, store } from "@graphprotocol/graph-ts";
import {
NextProvingPeriod as NextProvingPeriodEvent,
PossessionProven as PossessionProvenEvent,
Expand Down Expand Up @@ -60,10 +60,74 @@ function getEventLogEntityId(txHash: Bytes, logIndex: BigInt): Bytes {

// -----------------------------------------

class ListenerAddrResult {
constructor(
public addr: Address,
public method: string
) {}
}

// DataSetCreated is emitted by two entry points:
// createDataSet(address listenerAddr, bytes extraData) selector 0xbbae41cb
// → listenerAddr is param 0, ABI slot at input[4..36], address bytes at input[16..36]
// addPieces(uint256 setId, address listenerAddr, ...) selector 0x9afd37f2
// → listenerAddr is param 1, ABI slot at input[36..68], address bytes at input[48..68]
function decodeListenerAddrFromInput(input: Bytes): ListenerAddrResult {
if (input.length < 4) {
log.warning("decodeListenerAddrFromInput: input too short ({})", [
input.length.toString(),
]);
return new ListenerAddrResult(Address.zero(), "unknown");
}
Comment thread
silent-cipher marked this conversation as resolved.

if (
input[0] == 0xbb &&
input[1] == 0xae &&
input[2] == 0x41 &&
input[3] == 0xcb
) {
if (input.length < 36) {
log.warning(
"decodeListenerAddrFromInput: createDataSet input too short ({})",
[input.length.toString()]
);
return new ListenerAddrResult(Address.zero(), "createDataSet");
}
return new ListenerAddrResult(
Address.fromBytes(Bytes.fromUint8Array(input.slice(16, 36))),
"createDataSet"
);
}

if (
input[0] == 0x9a &&
input[1] == 0xfd &&
input[2] == 0x37 &&
input[3] == 0xf2
) {
if (input.length < 68) {
log.warning(
"decodeListenerAddrFromInput: addPieces input too short ({})",
[input.length.toString()]
);
return new ListenerAddrResult(Address.zero(), "addPieces");
}
return new ListenerAddrResult(
Address.fromBytes(Bytes.fromUint8Array(input.slice(48, 68))),
"addPieces"
);
}

const funcSelector = Bytes.fromUint8Array(input.slice(0, 4));
log.warning("decodeListenerAddrFromInput: unknown function selector {}", [
funcSelector.toHexString(),
]);
return new ListenerAddrResult(Address.zero(), "unknown");
}

export function handleDataSetCreated(event: DataSetCreatedEvent): void {
const listenerAddr = Bytes.fromUint8Array(
event.transaction.input.subarray(16, 36)
);
const decoded = decodeListenerAddrFromInput(event.transaction.input);
const listenerAddr = decoded.addr;

const proofSetEntityId = getProofSetEntityId(event.params.setId);
const transactionEntityId = getTransactionEntityId(event.transaction.hash);
Expand Down Expand Up @@ -99,7 +163,7 @@ export function handleDataSetCreated(event: DataSetCreatedEvent): void {
transaction.fromAddress = event.transaction.from;
transaction.toAddress = event.transaction.to; // Can be null for contract creation
transaction.value = event.transaction.value;
transaction.method = "createDataSet"; // Or derive from input data if possible
transaction.method = decoded.method;
transaction.status = true; // Assuming success if event emitted
transaction.createdAt = event.block.timestamp;
// Link entities
Expand Down
10 changes: 0 additions & 10 deletions subgraph/tests/dataset-status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe("DataSetStatus Lifecycle Tests", () => {
let mockDataSetCreatedEvent = createDataSetCreatedEvent(
SET_ID,
SENDER_ADDRESS,
Bytes.fromI32(123),
CONTRACT_ADDRESS,
BigInt.fromI32(100),
BigInt.fromI32(1678886400),
Expand All @@ -62,7 +61,6 @@ describe("DataSetStatus Lifecycle Tests", () => {
let mockDataSetCreatedEvent = createDataSetCreatedEvent(
SET_ID,
SENDER_ADDRESS,
Bytes.fromI32(123),
CONTRACT_ADDRESS,
BigInt.fromI32(100),
BigInt.fromI32(1678886400),
Expand Down Expand Up @@ -96,7 +94,6 @@ describe("DataSetStatus Lifecycle Tests", () => {
let mockDataSetCreatedEvent = createDataSetCreatedEvent(
SET_ID,
SENDER_ADDRESS,
Bytes.fromI32(123),
CONTRACT_ADDRESS,
BigInt.fromI32(100),
BigInt.fromI32(1678886400),
Expand Down Expand Up @@ -143,7 +140,6 @@ describe("DataSetStatus Lifecycle Tests", () => {
let mockDataSetCreatedEvent = createDataSetCreatedEvent(
SET_ID,
SENDER_ADDRESS,
Bytes.fromI32(123),
CONTRACT_ADDRESS,
BigInt.fromI32(100),
BigInt.fromI32(1678886400),
Expand Down Expand Up @@ -190,7 +186,6 @@ describe("DataSetStatus Lifecycle Tests", () => {
let mockDataSetCreatedEvent = createDataSetCreatedEvent(
SET_ID,
SENDER_ADDRESS,
Bytes.fromI32(123),
CONTRACT_ADDRESS,
BigInt.fromI32(100),
BigInt.fromI32(1678886400),
Expand Down Expand Up @@ -236,7 +231,6 @@ describe("DataSetStatus Lifecycle Tests", () => {
let mockDataSetCreatedEvent = createDataSetCreatedEvent(
SET_ID,
SENDER_ADDRESS,
Bytes.fromI32(123),
CONTRACT_ADDRESS,
BigInt.fromI32(100),
BigInt.fromI32(1678886400),
Expand Down Expand Up @@ -293,7 +287,6 @@ describe("DataSetStatus Lifecycle Tests", () => {
let mockDataSetCreatedEvent = createDataSetCreatedEvent(
SET_ID,
SENDER_ADDRESS,
Bytes.fromI32(123),
CONTRACT_ADDRESS,
BigInt.fromI32(100),
BigInt.fromI32(1678886400),
Expand Down Expand Up @@ -350,7 +343,6 @@ describe("DataSetStatus Lifecycle Tests", () => {
let mockDataSetCreatedEvent = createDataSetCreatedEvent(
SET_ID,
SENDER_ADDRESS,
Bytes.fromI32(123),
CONTRACT_ADDRESS,
BigInt.fromI32(100),
BigInt.fromI32(1678886400),
Expand All @@ -370,7 +362,6 @@ describe("DataSetStatus Lifecycle Tests", () => {
let mockDataSetCreatedEvent = createDataSetCreatedEvent(
SET_ID,
SENDER_ADDRESS,
Bytes.fromI32(123),
CONTRACT_ADDRESS,
BigInt.fromI32(100),
BigInt.fromI32(1678886400),
Expand Down Expand Up @@ -416,7 +407,6 @@ describe("DataSetStatus Lifecycle Tests", () => {
let mockDataSetCreatedEvent = createDataSetCreatedEvent(
SET_ID,
SENDER_ADDRESS,
Bytes.fromI32(123),
CONTRACT_ADDRESS,
BigInt.fromI32(100),
BigInt.fromI32(1678886400),
Expand Down
40 changes: 20 additions & 20 deletions subgraph/tests/fault-calculation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ describe("Fault Calculation Tests", () => {
SET_ID,
PROVIDER_ADDRESS,
CONTRACT_ADDRESS,
LISTENER_ADDRESS,
blockNumber,
timestamp,
generateTxHash(100),
BigInt.fromI32(0)
BigInt.fromI32(0),
LISTENER_ADDRESS
);

handleDataSetCreated(dataSetCreatedEvent);
Expand Down Expand Up @@ -121,11 +121,11 @@ describe("Fault Calculation Tests", () => {
SET_ID,
PROVIDER_ADDRESS,
CONTRACT_ADDRESS,
LISTENER_ADDRESS,
createBlockNumber,
createTimestamp,
generateTxHash(200),
BigInt.fromI32(0)
BigInt.fromI32(0),
LISTENER_ADDRESS
);
handleDataSetCreated(dataSetCreatedEvent);
addRootToDataSet(SET_ID, ROOT_ID_1);
Expand Down Expand Up @@ -231,11 +231,11 @@ describe("Fault Calculation Tests", () => {
SET_ID,
PROVIDER_ADDRESS,
CONTRACT_ADDRESS,
LISTENER_ADDRESS,
createBlockNumber,
BigInt.fromI32(1000),
generateTxHash(300),
BigInt.fromI32(0)
BigInt.fromI32(0),
LISTENER_ADDRESS
);
handleDataSetCreated(dataSetCreatedEvent);
addRootToDataSet(SET_ID, ROOT_ID_1);
Expand Down Expand Up @@ -312,11 +312,11 @@ describe("Fault Calculation Tests", () => {
SET_ID,
PROVIDER_ADDRESS,
CONTRACT_ADDRESS,
LISTENER_ADDRESS,
createBlockNumber,
BigInt.fromI32(1000),
generateTxHash(400),
BigInt.fromI32(0)
BigInt.fromI32(0),
LISTENER_ADDRESS
);
handleDataSetCreated(dataSetCreatedEvent);
addRootToDataSet(SET_ID, ROOT_ID_1);
Expand Down Expand Up @@ -376,11 +376,11 @@ describe("Fault Calculation Tests", () => {
SET_ID,
PROVIDER_ADDRESS,
CONTRACT_ADDRESS,
LISTENER_ADDRESS,
createBlockNumber,
BigInt.fromI32(1000),
generateTxHash(500),
BigInt.fromI32(0)
BigInt.fromI32(0),
LISTENER_ADDRESS
);
handleDataSetCreated(dataSetCreatedEvent);
addRootToDataSet(SET_ID, ROOT_ID_1);
Expand Down Expand Up @@ -458,11 +458,11 @@ describe("Fault Calculation Tests", () => {
SET_ID,
PROVIDER_ADDRESS,
CONTRACT_ADDRESS,
LISTENER_ADDRESS,
createBlockNumber,
BigInt.fromI32(1000),
generateTxHash(600),
BigInt.fromI32(0)
BigInt.fromI32(0),
LISTENER_ADDRESS
);
handleDataSetCreated(dataSetCreatedEvent);
addRootToDataSet(SET_ID, ROOT_ID_1);
Expand Down Expand Up @@ -549,11 +549,11 @@ describe("Fault Calculation Tests", () => {
SET_ID,
PROVIDER_ADDRESS,
CONTRACT_ADDRESS,
LISTENER_ADDRESS,
createBlockNumber,
BigInt.fromI32(1000),
generateTxHash(700),
BigInt.fromI32(0)
BigInt.fromI32(0),
LISTENER_ADDRESS
);
handleDataSetCreated(dataSetCreatedEvent);
addRootToDataSet(SET_ID, ROOT_ID_1);
Expand Down Expand Up @@ -624,11 +624,11 @@ describe("Fault Calculation Tests", () => {
SET_ID,
PROVIDER_ADDRESS,
CONTRACT_ADDRESS,
LISTENER_ADDRESS,
createBlockNumber,
BigInt.fromI32(1000),
generateTxHash(800),
BigInt.fromI32(0)
BigInt.fromI32(0),
LISTENER_ADDRESS
);
handleDataSetCreated(dataSetCreatedEvent);
addRootToDataSet(SET_ID, ROOT_ID_1);
Expand Down Expand Up @@ -699,11 +699,11 @@ describe("Fault Calculation Tests", () => {
SET_ID,
PROVIDER_ADDRESS,
CONTRACT_ADDRESS,
LISTENER_ADDRESS,
createBlockNumber,
BigInt.fromI32(1000),
generateTxHash(900),
BigInt.fromI32(0)
BigInt.fromI32(0),
LISTENER_ADDRESS
);
handleDataSetCreated(dataSetCreatedEvent);
addRootToDataSet(SET_ID, ROOT_ID_1);
Expand Down Expand Up @@ -862,11 +862,11 @@ describe("Fault Calculation Tests", () => {
SET_ID,
PROVIDER_ADDRESS,
CONTRACT_ADDRESS,
LISTENER_ADDRESS,
createBlockNumber,
BigInt.fromI32(1000),
generateTxHash(1000),
BigInt.fromI32(0)
BigInt.fromI32(0),
LISTENER_ADDRESS
);
handleDataSetCreated(dataSetCreatedEvent);
addRootToDataSet(SET_ID, ROOT_ID_1);
Expand Down
Loading
Loading