Skip to content

Commit

Permalink
chore: upgrade to new version
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Aug 9, 2023
1 parent bbc09f6 commit 85771c0
Show file tree
Hide file tree
Showing 13 changed files with 1,084 additions and 1,105 deletions.
2 changes: 1 addition & 1 deletion packages/capabilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@ucanto/principal": "^8.0.0",
"@ucanto/transport": "^8.0.0",
"@ucanto/validator": "^8.0.0",
"@web3-storage/data-segment": "^3.0.0"
"@web3-storage/data-segment": "^3.0.1"
},
"devDependencies": {
"@types/assert": "^1.5.6",
Expand Down
29 changes: 5 additions & 24 deletions packages/capabilities/src/filecoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,14 @@ const FR32_SHA2_256_TRUNC254_PADDED_BINARY_TREE = 0x1011
*/
const RAW_CODE = 0x55

/**
* @see https://github.com/multiformats/go-multihash/blob/dc3bd6897fcd17f6acd8d4d6ffd2cea3d4d3ebeb/multihash.go#L73
*/
const SHA2_256_TRUNC254_PADDED = 0x1012
/**
* @see https://github.com/ipfs/go-cid/blob/829c826f6be23320846f4b7318aee4d17bf8e094/cid.go#L104
*/
const FilCommitmentUnsealed = 0xf101

const PIECE_CID_V2 = Schema.link({
const PIECE_LINK = Schema.link({
code: RAW_CODE,
version: 1,
multihash: {
code: FR32_SHA2_256_TRUNC254_PADDED_BINARY_TREE,
},
})

const PIECE_CID_V1 = Schema.link({
code: FilCommitmentUnsealed,
version: 1,
multihash: {
code: SHA2_256_TRUNC254_PADDED,
},
})

/**
* `filecoin/add` capability allows agent to add a filecoin piece to be aggregated
* so that it can be stored by a Storage provider on a future time.
Expand All @@ -66,7 +49,7 @@ export const filecoinAdd = capability({
*
* @see https://github.com/filecoin-project/FIPs/pull/758/files
*/
piece: /** @type {import('./types').PieceLinkSchema} */ (PIECE_CID_V2),
piece: /** @type {import('./types').PieceLinkSchema} */ (PIECE_LINK),
}),
derives: (claim, from) => {
return (
Expand Down Expand Up @@ -94,7 +77,7 @@ export const aggregateAdd = capability({
*
* @see https://github.com/filecoin-project/FIPs/pull/758/files
*/
piece: /** @type {import('./types').PieceLinkSchema} */ (PIECE_CID_V2),
piece: /** @type {import('./types').PieceLinkSchema} */ (PIECE_LINK),
/**
* Storefront requestin piece to be aggregated
*/
Expand Down Expand Up @@ -137,9 +120,7 @@ export const dealAdd = capability({
* @see https://github.com/filecoin-project/go-state-types/blob/1e6cf0d47cdda75383ef036fc2725d1cf51dbde8/abi/piece.go#L47-L50
* @see https://github.com/filecoin-project/FIPs/pull/758/files
*/
aggregate: /** @type {import('./types').LegacyPieceLinkSchema} */ (
PIECE_CID_V1
),
aggregate: /** @type {import('./types').PieceLinkSchema} */ (PIECE_LINK),
/**
* Storefront requesting deal
*/
Expand Down Expand Up @@ -176,7 +157,7 @@ export const chainTrackerInfo = capability({
*
* @see https://github.com/filecoin-project/FIPs/pull/758/files
*/
piece: /** @type {import('./types').PieceLinkSchema} */ (PIECE_CID_V2),
piece: /** @type {import('./types').PieceLinkSchema} */ (PIECE_LINK),
}),
derives: (claim, from) => {
return (
Expand Down
8 changes: 3 additions & 5 deletions packages/capabilities/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { TupleToUnion } from 'type-fest'
import * as Ucanto from '@ucanto/interface'
import type { Schema } from '@ucanto/core'
import { InferInvokedCapability, Unit, DID } from '@ucanto/interface'
import type { PieceLink, LegacyPieceLink } from '@web3-storage/data-segment'
import type { PieceLink } from '@web3-storage/data-segment'
import { space, info, recover, recoverValidation } from './space.js'
import * as provider from './provider.js'
import { top } from './top.js'
Expand All @@ -26,8 +26,6 @@ export interface InsufficientStorage {
*/
export type PieceLinkSchema = Schema.Schema<PieceLink>

export type LegacyPieceLinkSchema = Schema.Schema<LegacyPieceLink>

// Access
export type Access = InferInvokedCapability<typeof AccessCaps.access>
export type AccessAuthorize = InferInvokedCapability<
Expand Down Expand Up @@ -91,14 +89,14 @@ export interface FilecoinAddFailure extends Ucanto.Failure {

export interface AggregateAddSuccess {
piece: PieceLink
aggregate?: LegacyPieceLink
aggregate?: PieceLink
}
export interface AggregateAddFailure extends Ucanto.Failure {
name: string
}

export interface DealAddSuccess {
aggregate?: LegacyPieceLink
aggregate?: PieceLink
}

export type DealAddFailure = DealAddParseFailure | DealAddFailureWithBadPiece
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"@ucanto/server": "^8.0.0",
"@ucanto/transport": "^8.0.0",
"@web3-storage/capabilities": "workspace:^",
"@web3-storage/data-segment": "^3.0.0"
"@web3-storage/data-segment": "^3.0.1"
},
"devDependencies": {
"@ipld/car": "^5.1.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/filecoin-api/src/dealer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const add = async ({ capability, invocation }, context) => {
}

/**
* @param {import('@web3-storage/data-segment').LegacyPieceLink} aggregate
* @param {import('@web3-storage/data-segment').PieceLink} aggregate
* @param {Server.API.Link<unknown, number, number, 0 | 1>} offerCid
* @param {string} storefront
* @param {string | undefined} label
Expand Down Expand Up @@ -85,7 +85,7 @@ async function enqueue(
}

/**
* @param {import('@web3-storage/data-segment').LegacyPieceLink} aggregate
* @param {import('@web3-storage/data-segment').PieceLink} aggregate
* @param {import('@web3-storage/data-segment').PieceLink[]} pieces
* @param {string} storefront
* @param {string | undefined} label
Expand Down
4 changes: 2 additions & 2 deletions packages/filecoin-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
Match,
} from '@ucanto/interface'
import type { ProviderInput } from '@ucanto/server'
import { PieceLink, LegacyPieceLink } from '@web3-storage/data-segment'
import { PieceLink } from '@web3-storage/data-segment'
import { UnknownLink } from '@ucanto/interface'

export * as UcantoInterface from '@ucanto/interface'
Expand Down Expand Up @@ -70,7 +70,7 @@ export interface AggregatorRecord {
}

export interface DealerRecord {
aggregate: LegacyPieceLink
aggregate: PieceLink
pieces: PieceLink[]
storefront: string
label?: string
Expand Down
4 changes: 2 additions & 2 deletions packages/filecoin-api/test/services/dealer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const test = {
throw new Error('invocation failed', { cause: response.out.error })
}
assert.ok(response.out.ok)
assert.deepEqual(response.out.ok.aggregate, aggregate.link)
assert.ok(response.out.ok.aggregate?.equals(aggregate.link))

// Validate effect in receipt
const fx = await Filecoin.dealAdd
Expand Down Expand Up @@ -111,7 +111,7 @@ export const test = {
throw new Error('invocation failed', { cause: response.out.error })
}
assert.ok(response.out.ok)
assert.deepEqual(response.out.ok.aggregate, aggregate.link)
assert.ok(response.out.ok.aggregate?.equals(aggregate.link))

// Validate queue and store
await pWaitFor(() => context.queuedMessages.length === 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ export async function randomAggregate(length, size) {

return {
pieces,
aggregate: aggregateBuild.toInfo(),
aggregate: aggregateBuild,
}
}
2 changes: 1 addition & 1 deletion packages/filecoin-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@types/mocha": "^10.0.1",
"@ucanto/principal": "^8.0.0",
"@ucanto/server": "^8.0.1",
"@web3-storage/data-segment": "^3.0.0",
"@web3-storage/data-segment": "^3.0.1",
"assert": "^2.0.0",
"c8": "^7.13.0",
"hd-scripts": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-client/src/dealer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const connection = connect({
* Add a piece (aggregate) to the dealer system of the filecoin pipeline to offer to SPs.
*
* @param {import('./types.js').InvocationConfig} conf - Configuration
* @param {import('@web3-storage/data-segment').LegacyPieceLink} aggregate
* @param {import('@web3-storage/data-segment').PieceLink} aggregate
* @param {import('@web3-storage/data-segment').PieceLink[]} pieces
* @param {string} storefront
* @param {string} label
Expand Down
4 changes: 2 additions & 2 deletions packages/filecoin-client/test/dealer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('dealer.add', () => {
)

assert.ok(res.out.ok)
assert.deepEqual(res.out.ok, dealAddResponse)
assert.ok(res.out.ok.aggregate?.equals(dealAddResponse.aggregate))
// includes effect fx in receipt
assert.ok(res.fx.join)
})
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('dealer.add', () => {
)

assert.ok(res.out.ok)
assert.deepEqual(res.out.ok, dealAddResponse)
assert.ok(res.out.ok.aggregate?.equals(dealAddResponse.aggregate))
// does not include effect fx in receipt
assert.ok(!res.fx.join)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-client/test/helpers/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ export async function randomAggregate(length, size) {

return {
pieces,
aggregate: aggregateBuild.toInfo(),
aggregate: aggregateBuild,
}
}
Loading

0 comments on commit 85771c0

Please sign in to comment.