Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v0.0.1 alpha.40 #39

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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.40](https://github.com/DIG-Network/dig-cli/compare/v0.0.1-alpha.39...v0.0.1-alpha.40) (2024-10-10)

### [0.0.1-alpha.39](https://github.com/DIG-Network/dig-cli/compare/v0.0.1-alpha.38...v0.0.1-alpha.39) (2024-10-08)

### [0.0.1-alpha.38](https://github.com/DIG-Network/dig-cli/compare/v0.0.1-alpha.37...v0.0.1-alpha.38) (2024-10-03)
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dignetwork/dig-chia-cli",
"version": "0.0.1-alpha.39",
"version": "0.0.1-alpha.40",
"description": "",
"type": "commonjs",
"main": "./dist/cli.js",
Expand All @@ -24,7 +24,7 @@
"LICENSE"
],
"dependencies": {
"@dignetwork/dig-sdk": "^0.0.1-alpha.167",
"@dignetwork/dig-sdk": "^0.0.1-alpha.169",
"bip39": "^3.1.0",
"datalayer-driver": "^0.1.21",
"inquirer": "^10.1.8",
Expand Down
62 changes: 40 additions & 22 deletions src/actions/commit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from "path";
import fs from "fs";
import {
addDirectory,
listFilesRecursively,
asyncPool,
calculateFolderSize,
waitForPromise,
DataStore,
Expand Down Expand Up @@ -29,34 +30,51 @@ export const commit = async (): Promise<void> => {

const digConfig = await loadDigConfig(process.cwd());

await addDirectory(
dataStore.Tree,
path.join(process.cwd(), digConfig.deploy_dir)
// Group into 1000 files per batch to make management and upload easier
const fileGroups = listFilesRecursively(
path.join(process.cwd(), digConfig.deploy_dir),
1000
);

const newRootHash = dataStore.Tree.commit();
const concurrencyLimit = 10;

if (!newRootHash) {
return;
}
for (const files of fileGroups) {
await asyncPool(concurrencyLimit, files as string[], async (file) => {
const filePath = path.join(process.cwd(), digConfig.deploy_dir, file);
const relativePath = file.replace(/\\/g, "/");
const stream = fs.createReadStream(filePath);
await dataStore.Tree.upsertKey(
stream,
Buffer.from(relativePath).toString("hex")
);
});

const totalBytes = calculateFolderSize(
path.resolve(STORE_PATH, dataStore.StoreId)
);
const newRootHash = dataStore.Tree.commit();

console.log(
`Updating store metadata with new root hash: ${newRootHash}, bytes: ${totalBytes}`
);
if (!newRootHash) {
return;
}

const updatedStoreInfo = await dataStore.updateMetadata({
...latestStore.metadata,
rootHash: Buffer.from(newRootHash, "hex"),
bytes: totalBytes,
});
const totalBytes = calculateFolderSize(
path.resolve(STORE_PATH, dataStore.StoreId)
);

await FullNodePeer.waitForConfirmation(
updatedStoreInfo.coin.parentCoinInfo
);
console.log(
`Updating store metadata with new root hash: ${newRootHash}, bytes: ${totalBytes}`
);

const updatedStoreInfo = await dataStore.updateMetadata({
...latestStore.metadata,
rootHash: Buffer.from(newRootHash, "hex"),
bytes: totalBytes,
});

await FullNodePeer.waitForConfirmation(
updatedStoreInfo.coin.parentCoinInfo
);

await dataStore.fetchCoinInfo();
}

await waitForPromise(
() => dataStore.fetchCoinInfo(),
Expand Down
Loading