-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show deal info from w3up (#2573)
Fetch deal information from w3up. There's no way to "multi-get" deal info for more than one upload so I've reworked the deal info in the files list - if it has deals from dagcargo it will just use those, and if it doesn't, it will display a "load deals" button: <img width="1172" alt="Screenshot 2024-04-12 at 12 07 20 PM" src="https://github.com/nftstorage/nft.storage/assets/1113/4799bc48-391d-4d82-9678-93406abfb622"> When clicked, it will find the shards of the upload and find filecoin info for each of them. If it doesn't find any filecoin info in w3up it will display the "queuing" status and tooltip as it did in the past: <img width="1105" alt="Screenshot 2024-04-12 at 12 07 27 PM" src="https://github.com/nftstorage/nft.storage/assets/1113/3151986a-5c96-43b5-b4f7-c9ae2b3a5d3a"> <img width="1155" alt="Screenshot 2024-04-12 at 12 07 34 PM" src="https://github.com/nftstorage/nft.storage/assets/1113/8829c3c0-0a91-4eb4-bb26-a46bda9b82c9"> This required updating the "get NFT" API endpoint to look for filecoin info from w3up. --------- Co-authored-by: Alan Shaw <[email protected]>
- Loading branch information
Showing
12 changed files
with
616 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,146 @@ | ||
import test from 'ava' | ||
import { createServer } from 'node:http' | ||
import { ed25519 } from '@ucanto/principal' | ||
import { delegate, parseLink } from '@ucanto/core' | ||
import { base64 } from 'multiformats/bases/base64' | ||
import { createClientWithUser } from './scripts/helpers.js' | ||
import { fixtures } from './scripts/fixtures.js' | ||
import { | ||
getMiniflareContext, | ||
setupMiniflareContext, | ||
} from './scripts/test-context.js' | ||
import { | ||
createMockW3up, | ||
locate, | ||
encodeDelegationAsCid, | ||
} from './utils/w3up-testing.js' | ||
|
||
const nftStorageSpace = ed25519.generate() | ||
const nftStorageApiPrincipal = ed25519.generate() | ||
const nftStorageAccountEmailAllowListedForW3up = '[email protected]' | ||
const mockW3upDID = 'did:web:test.web3.storage' | ||
/** | ||
* @type {import('@web3-storage/access').PieceLink} | ||
*/ | ||
const mockPieceLink = parseLink( | ||
'bafkzcibeslzwmewd4pugjanyiayot5m76a67dvdir25v6ms6kbuozy2sxotplrrrce' | ||
) | ||
/** | ||
* @type {import('@web3-storage/access').FilecoinInfoAcceptedDeal[]} | ||
*/ | ||
const mockDeals = [ | ||
{ | ||
aggregate: parseLink( | ||
'bafkzcibcaapen7lfjgljzi523a5rau2l5pwpwseita6uunqy5otrlxa2l2pouca' | ||
), | ||
aux: { | ||
dataSource: { | ||
dealID: BigInt(1), | ||
}, | ||
dataType: BigInt(1), | ||
}, | ||
provider: 'f01240', | ||
}, | ||
] | ||
const cidWithShards = parseLink( | ||
'bafybeiccy35oi3gajocq5bbg7pnaxb3kv5ibtdz3tc3kari53qhbjotzey' | ||
) | ||
const mockW3up = Promise.resolve( | ||
(async function () { | ||
const server = createServer( | ||
await createMockW3up({ | ||
did: mockW3upDID, | ||
// @ts-expect-error not returning a full upload get response for now | ||
async onHandleUploadGet(invocation) { | ||
if (invocation.capability.nb.root?.equals(cidWithShards)) { | ||
return { | ||
// grabbed this shard CID from staging, it should correspond to a piece named bafkzcibeslzwmewd4pugjanyiayot5m76a67dvdir25v6ms6kbuozy2sxotplrrrce | ||
shards: [ | ||
parseLink( | ||
'bagbaieragf62xatg3bqrfafdy3lpk2fte7526kvxnltqsnhjr45cz6jjk7mq' | ||
), | ||
], | ||
} | ||
} else { | ||
return { | ||
shards: [], | ||
} | ||
} | ||
}, | ||
async onHandleFilecoinInfo(invocation) { | ||
if (invocation.capability.nb.piece.equals(mockPieceLink)) { | ||
return { | ||
deals: mockDeals, | ||
aggregates: [], | ||
piece: mockPieceLink, | ||
} | ||
} else { | ||
return undefined | ||
} | ||
}, | ||
}) | ||
) | ||
server.listen(0) | ||
await new Promise((resolve) => | ||
server.addListener('listening', () => resolve(undefined)) | ||
) | ||
return { | ||
server, | ||
} | ||
})() | ||
) | ||
|
||
test.before(async (t) => { | ||
await setupMiniflareContext(t) | ||
await setupMiniflareContext(t, { | ||
overrides: { | ||
W3UP_URL: locate((await mockW3up).server).url.toString(), | ||
W3UP_DID: mockW3upDID, | ||
W3_NFTSTORAGE_SPACE: (await nftStorageSpace).did(), | ||
W3_NFTSTORAGE_PRINCIPAL: ed25519.format(await nftStorageApiPrincipal), | ||
W3_NFTSTORAGE_PROOF: ( | ||
await encodeDelegationAsCid( | ||
await delegate({ | ||
issuer: await nftStorageSpace, | ||
audience: await nftStorageApiPrincipal, | ||
capabilities: [ | ||
{ can: 'upload/get', with: (await nftStorageSpace).did() }, | ||
{ can: 'filecoin/info', with: (await nftStorageSpace).did() }, | ||
], | ||
}) | ||
) | ||
).toString(base64), | ||
W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS: JSON.stringify([ | ||
nftStorageAccountEmailAllowListedForW3up, | ||
]), | ||
}, | ||
}) | ||
}) | ||
|
||
test.serial('should fetch deal details from w3up', async (t) => { | ||
const cid = cidWithShards.toString() | ||
const client = await createClientWithUser(t) | ||
const mf = getMiniflareContext(t) | ||
await client.addPin({ | ||
cid, | ||
name: 'test-filecoin-info', | ||
}) | ||
|
||
const res = await mf.dispatchFetch(`http://miniflare.test/${cid}`, { | ||
headers: { Authorization: `Bearer ${client.token}` }, | ||
}) | ||
const { ok, value } = await res.json() | ||
t.assert(ok) | ||
t.deepEqual( | ||
value.deals, | ||
mockDeals.map((deal) => ({ | ||
pieceCid: mockPieceLink.toString(), | ||
status: 'published', | ||
datamodelSelector: '', | ||
batchRootCid: deal.aggregate.toString(), | ||
miner: deal.provider, | ||
chainDealID: Number(deal.aux.dataSource.dealID), | ||
})) | ||
) | ||
}) | ||
|
||
test.serial('should return proper response for cid v1', async (t) => { | ||
|
Oops, something went wrong.