Skip to content

Commit

Permalink
feat: wip events
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Oct 10, 2023
1 parent 4562f13 commit 8142de1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/filecoin-api/src/dealer/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const aggregateOffer = async ({ capability, invocation }, context) => {
* @param {import('./api').ServiceContext} context
* @returns {Promise<API.UcantoInterface.Result<API.DealAddSuccess, API.DealAddFailure> | API.UcantoInterface.JoinBuilder<API.DealAddSuccess>>}
*/
export const add = async ({ capability, invocation }, context) => {
export const aggregateAccept = async ({ capability, invocation }, context) => {
const { aggregate, pieces: offerCid, storefront } = capability.nb
const pieces = getOfferBlock(offerCid, invocation.iterateIPLDBlocks())

Expand Down
49 changes: 49 additions & 0 deletions packages/filecoin-api/src/storefront/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { StoreOperationFailed } from '../errors.js'

/**
* @param {import('./api').ServiceContext} context
* @param {import('./api').FilecoinSubmitMessage} message
*/
export const handleFilecoinSubmitMessage = async (context, message) => {
// TODO: verify piece

const putRes = await context.pieceStore.put({
piece: message.piece,
content: message.content,
group: message.group,
status: 'submitted',
insertedAt: Date.now(),
updatedAt: Date.now()
})
if (putRes.error) {
return { error: new StoreOperationFailed(putRes.error.message) }
}
return { ok: {} }
}

/**
* @param {import('./api').ServiceContext} context
* @param {import('./api').PieceRecord} record
*/
export const handlePieceInsert = async (context, record) => {
// TODO: invoke filecoin/submit
return { ok: {} }
}

/**
* @param {import('./api').ServiceContext} context
*/
export const handleCronTick = async (context) => {
// TODO: get pieces where status === submitted
// read receipts to determine if an aggregate accepted for each piece
// update piece status to accepted if yes
}

/**
* @param {import('./api').ServiceContext} context
* @param {import('./api').PieceRecord} record
*/
export const handlePieceStatusAccepted = async (context, record) => {
// TODO: invoke filecoin/accept /w content & piece
return { ok: {} }
}
12 changes: 0 additions & 12 deletions packages/filecoin-api/src/storefront/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@ export const filecoinOffer = async ({ capability }, context) => {
const group = context.id.did()

if (!exists) {
const putRes = await context.pieceStore.put({
piece,
content,
group,
status: 'offered',
insertedAt: Date.now(),
updatedAt: Date.now()
})
if (putRes.error) {
return { error: new StoreOperationFailed(putRes.error.message) }
}

// Queue the piece for validation etc.
const queueRes = await context.filecoinSubmitQueue.add({
piece,
Expand Down

0 comments on commit 8142de1

Please sign in to comment.