Skip to content

Commit

Permalink
refactor!: filecoin api services events and tests (#974)
Browse files Browse the repository at this point in the history
Implements `filecoin-api` services, events and tests all over the place.

BREAKING CHANGE: see latest specs https://github.com/web3-storage/specs/blob/cbdb706f18567900c5c24d7fb16ccbaf93d0d023/w3-filecoin.md
  • Loading branch information
vasco-santos committed Oct 23, 2023
1 parent 20f80af commit edb76a3
Show file tree
Hide file tree
Showing 51 changed files with 7,234 additions and 1,064 deletions.
2 changes: 1 addition & 1 deletion packages/capabilities/src/filecoin/dealer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const aggregateOffer = capability({
* CID of the DAG-CBOR encoded block with offer details.
* Service will queue given offer to be validated and handled.
*/
pieces: Schema.link(),
pieces: Schema.link({ version: 1 }),
}),
derives: (claim, from) => {
return (
Expand Down
30 changes: 24 additions & 6 deletions packages/capabilities/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,20 @@ export type Space = InferInvokedCapability<typeof space>
export type SpaceInfo = InferInvokedCapability<typeof info>

// filecoin
export interface DealMetadata {
dataType: uint64
dataSource: SingletonMarketSource
}
/** @see https://github.com/filecoin-project/go-data-segment/blob/e3257b64fa2c84e0df95df35de409cfed7a38438/datasegment/verifier.go#L8-L14 */
export interface DataAggregationProof {
/**
* Proof the piece is included in the aggregate.
*/
inclusion: InclusionProof
auxDataType: uint64
auxDataSource: SingletonMarketSource
/**
* Filecoin deal metadata.
*/
aux: DealMetadata
}
/** @see https://github.com/filecoin-project/go-data-segment/blob/e3257b64fa2c84e0df95df35de409cfed7a38438/datasegment/inclusion.go#L30-L39 */
export interface InclusionProof {
Expand Down Expand Up @@ -233,15 +239,25 @@ export interface FilecoinSubmitSuccess {

export type FilecoinSubmitFailure = InvalidPieceCID | Ucanto.Failure

export type FilecoinAcceptSuccess = DataAggregationProof
export interface FilecoinAcceptSuccess extends DataAggregationProof {
aggregate: PieceLink
piece: PieceLink
}

export type FilecoinAcceptFailure = InvalidContentPiece | Ucanto.Failure
export type FilecoinAcceptFailure =
| InvalidContentPiece
| ProofNotFound
| Ucanto.Failure

export interface InvalidContentPiece extends Ucanto.Failure {
name: 'InvalidContentPiece'
content: PieceLink
}

export interface ProofNotFound extends Ucanto.Failure {
name: 'ProofNotFound'
}

// filecoin aggregator
export interface PieceOfferSuccess {
/**
Expand Down Expand Up @@ -276,7 +292,9 @@ export interface AggregateOfferSuccess {
}
export type AggregateOfferFailure = Ucanto.Failure

export type AggregateAcceptSuccess = DataAggregationProof
export interface AggregateAcceptSuccess extends DealMetadata {
aggregate: PieceLink
}
export type AggregateAcceptFailure = InvalidPiece | Ucanto.Failure

export interface InvalidPiece extends Ucanto.Failure {
Expand All @@ -303,7 +321,7 @@ export interface DealDetails {
// TODO: start/end epoch? etc.
}

export type FilecoinAddress = `f${string}`
export type FilecoinAddress = string

export type DealInfoFailure = DealNotFound | Ucanto.Failure

Expand Down
14 changes: 8 additions & 6 deletions packages/filecoin-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"dealer": [
"dist/src/dealer.d.ts"
],
"chain-tracker": [
"dist/src/chain-tracker.d.ts"
"deal-tracker": [
"dist/src/deal-tracker.d.ts"
],
"errors": [
"dist/src/errors.d.ts"
Expand Down Expand Up @@ -54,9 +54,9 @@
"types": "./dist/src/dealer.d.ts",
"import": "./src/dealer.js"
},
"./chain-tracker": {
"types": "./dist/src/chain-tracker.d.ts",
"import": "./src/chain-tracker.js"
"./deal-tracker": {
"types": "./dist/src/deal-tracker.d.ts",
"import": "./src/deal-tracker.js"
},
"./storefront": {
"types": "./dist/src/storefront.d.ts",
Expand Down Expand Up @@ -108,7 +108,9 @@
"project": "./tsconfig.json"
},
"rules": {
"unicorn/expiring-todo-comments": "off"
"unicorn/expiring-todo-comments": "off",
"unicorn/prefer-number-properties": "off",
"jsdoc/check-indentation": "off"
},
"env": {
"mocha": true
Expand Down
119 changes: 0 additions & 119 deletions packages/filecoin-api/src/aggregator.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/filecoin-api/src/aggregator/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
Loading

0 comments on commit edb76a3

Please sign in to comment.