-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add publish rsr to smart contract (#383)
* add `rsrContract` * add `storacha` * persist round `cids` and `details` * add publish rsr (untested) * add git commit * update env var name * refactor `createStorachaClient()` * update schema * hide `GIT_COMMIT` in scope * `gitCommit` -> `sparkEvaluateVersion` * `postEvaluate` -> `prepareAcceptedRetrievalTaskMeasurementsCommitment` * `round.cids` -> `round.measurementCommitments` * fix `.total` * `publish_rsr_rounds` -> `unpublished_rsr_rounds` * update contract * update contract * fix rsr calculation * share logic for building retrieval stats * rename method to match contract * Update lib/publish-rsr.js Co-authored-by: Miroslav Bajtoš <oss@bajtos.net> * get date string from db * fix deletion logic * format * always publish oldest publishable date * update column to match smart contract * add contract address * consistent naming * measurement_commitments -> _batches * update schema (wip) * upload dag-json * unify terminology * upload round details to storacha * minerId -> providerId * update schema * refactor * consistent naming * consistent naming * doc * add passing tests * add passing test * improve error message * add passing test * move stuff around * fix lint * add passing test * add passing test * fix * add passing test * consistent naming * add passing test * improve car/cid tests * fix query with test * docs: fix CID * add test and fixes * add passing test * fix lint * add passing test * fix test name * refactor * add passing test * add test and fix * clean up * add passing tests * add passing test * add passing test * consistent naming * refactor * fix lint --------- Co-authored-by: Miroslav Bajtoš <oss@bajtos.net>
- Loading branch information
1 parent
c74b4bc
commit 100aa85
Showing
25 changed files
with
1,857 additions
and
105 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { CarWriter } from '@ipld/car' | ||
import * as dagJSON from '@ipld/dag-json' | ||
import { sha256 } from 'multiformats/hashes/sha2' | ||
import { CID } from 'multiformats' | ||
|
||
/** | ||
* @param {*} json | ||
* @returns {Promise<{ cid: CID, car: Blob }>} | ||
*/ | ||
export async function createDagJsonCar (json) { | ||
const bytes = dagJSON.encode(json) | ||
const hash = await sha256.digest(bytes) | ||
const cid = CID.create(1, dagJSON.code, hash) | ||
const car = await createCar({ cid, bytes }, cid) | ||
return { cid, car } | ||
} | ||
|
||
/** | ||
* @param {{ cid: CID, bytes: dagJSON.ByteView<any> }} block | ||
* @param {CID} root | ||
* @returns {Promise<Blob>} | ||
*/ | ||
export async function createCar (block, root) { | ||
const { writer, out } = CarWriter.create(root) | ||
const [chunks] = await Promise.all([ | ||
(async () => { | ||
const chunks = [] | ||
for await (const chunk of out) chunks.push(chunk) | ||
return chunks | ||
})(), | ||
(async () => { | ||
await writer.put(block) | ||
await writer.close() | ||
})() | ||
]) | ||
return Object.assign(new Blob(chunks), { version: 1, roots: [root] }) | ||
} |
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
Oops, something went wrong.