Skip to content

Commit

Permalink
Merge pull request #36 from DIG-Network/release/v0.0.1-alpha.38
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.38
  • Loading branch information
MichaelTaylor3D authored Sep 19, 2024
2 parents 20d712d + 65b366f commit a9c3f21
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.1-alpha.38](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.37...v0.0.1-alpha.38) (2024-09-19)


### Bug Fixes

* findPeerWithStoreKey ([3d8a48a](https://github.com/DIG-Network/dig-chia-sdk/commit/3d8a48a12b5926a63b92aacae8f4e712667ddb9e))

### [0.0.1-alpha.37](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.36...v0.0.1-alpha.37) (2024-09-19)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dignetwork/dig-sdk",
"version": "0.0.1-alpha.37",
"version": "0.0.1-alpha.38",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
36 changes: 19 additions & 17 deletions src/DigNetwork/DigNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,11 @@ export class DigNetwork {
try {
const rootHistory: RootHistoryItem[] =
await this.dataStore.getRootHistory();
if (!rootHistory.length)
if (!rootHistory.length) {
throw new Error(
"No roots found in rootHistory. Cannot proceed with file download."
);
}

await this.downloadHeightFile(forceDownload);

Expand All @@ -248,28 +249,29 @@ export class DigNetwork {
`${rootInfo.root_hash}.dat`
);

console.log(rootResponse);

const root = JSON.parse(rootResponse);

console.log(root)

if (!skipData) {
// Use Object.entries() to iterate over the map (root.files)
await Promise.all(
root.files.map(async (file: any) => {
const filePath = getFilePathFromSha256(
file.sha256,
this.storeDir
);
if (!fs.existsSync(filePath) || forceDownload) {
console.log(`Downloading ${file.sha256}...`);
await this.downloadFileFromPeers(
file.sha256.match(/.{1,2}/g)!.join("/"),
filePath,
forceDownload
Object.entries(root.files).map(
async ([storeKey, file]: [string, any]) => {
const filePath = getFilePathFromSha256(
file.sha256,
this.storeDir
);
if (!fs.existsSync(filePath) || forceDownload) {
console.log(
`Downloading file with sha256: ${file.sha256}...`
);
await this.downloadFileFromPeers(
file.sha256.match(/.{1,2}/g)!.join("/"),
filePath,
forceDownload
);
}
}
})
)
);
}
}
Expand Down

0 comments on commit a9c3f21

Please sign in to comment.