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
10 changes: 10 additions & 0 deletions packages/synapse-sdk/src/pdp/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ export class PDPVerifier {
}
}

/**
* Get pieces scheduled for removal from a data set
* @param dataSetId - The PDPVerifier data set ID
* @returns Array of piece IDs scheduled for removal
*/
async getScheduledRemovals(dataSetId: number): Promise<number[]> {
const result = await this._contract.getScheduledRemovals(dataSetId)
return result.map((pieceId: bigint) => Number(pieceId))
}

/**
* Get the PDPVerifier contract address for the current network
*/
Expand Down
1 change: 1 addition & 0 deletions packages/synapse-sdk/src/test/mocks/jsonrpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ export const presets = {
getActivePieces: () => [[], [], false],
getDataSetStorageProvider: () => [ADDRESSES.serviceProvider1, ADDRESSES.zero],
getDataSetLeafCount: () => [0n],
getScheduledRemovals: () => [[]],
},
serviceRegistry: {
getProviderByAddress: (data) => [
Expand Down
12 changes: 12 additions & 0 deletions packages/synapse-sdk/src/test/mocks/jsonrpc/pdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type getDataSetStorageProvider = ExtractAbiFunction<
'getDataSetStorageProvider'
>
export type getDataSetLeafCount = ExtractAbiFunction<typeof CONTRACT_ABIS.PDP_VERIFIER, 'getDataSetLeafCount'>
export type getScheduledRemovals = ExtractAbiFunction<typeof CONTRACT_ABIS.PDP_VERIFIER, 'getScheduledRemovals'>

export interface PDPVerifierOptions {
dataSetLive?: (args: AbiToType<dataSetLive['inputs']>) => AbiToType<dataSetLive['outputs']>
Expand All @@ -24,6 +25,7 @@ export interface PDPVerifierOptions {
args: AbiToType<getDataSetStorageProvider['inputs']>
) => AbiToType<getDataSetStorageProvider['outputs']>
getDataSetLeafCount?: (args: AbiToType<getDataSetLeafCount['inputs']>) => AbiToType<getDataSetLeafCount['outputs']>
getScheduledRemovals?: (args: AbiToType<getScheduledRemovals['inputs']>) => AbiToType<getScheduledRemovals['outputs']>
}

/**
Expand Down Expand Up @@ -95,6 +97,16 @@ export function pdpVerifierCallHandler(data: Hex, options: JSONRPCOptions): Hex
options.pdpVerifier.getDataSetLeafCount(args)
)
}
case 'getScheduledRemovals': {
if (!options.pdpVerifier?.getScheduledRemovals) {
throw new Error('PDP Verifier: getScheduledRemovals is not defined')
}
return encodeAbiParameters(
CONTRACT_ABIS.PDP_VERIFIER.find((abi) => abi.type === 'function' && abi.name === 'getScheduledRemovals')!
.outputs,
options.pdpVerifier.getScheduledRemovals(args)
)
}
default: {
throw new Error(`PDP Verifier: unknown function: ${functionName} with args: ${args}`)
}
Expand Down
37 changes: 37 additions & 0 deletions packages/synapse-sdk/src/test/pdp-verifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,41 @@ describe('PDPVerifier', () => {
assert.equal(address, testAddress)
})
})

describe('getScheduledRemovals', () => {
it('should get scheduled removals for a data set', async () => {
server.use(
JSONRPC({
...presets.basic,
pdpVerifier: {
...presets.basic.pdpVerifier,
getScheduledRemovals: () => [[1n, 2n, 5n]],
},
})
)

const scheduledRemovals = await pdpVerifier.getScheduledRemovals(123)
assert.isArray(scheduledRemovals)
assert.equal(scheduledRemovals.length, 3)
assert.equal(scheduledRemovals[0], 1)
assert.equal(scheduledRemovals[1], 2)
assert.equal(scheduledRemovals[2], 5)
})

it('should return empty array when no removals scheduled', async () => {
server.use(
JSONRPC({
...presets.basic,
pdpVerifier: {
...presets.basic.pdpVerifier,
getScheduledRemovals: () => [[]],
},
})
)

const scheduledRemovals = await pdpVerifier.getScheduledRemovals(123)
assert.isArray(scheduledRemovals)
assert.equal(scheduledRemovals.length, 0)
})
})
})