Skip to content

Commit

Permalink
Merge pull request #39 from DIG-Network/release/v0.0.1-alpha.40
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.40
  • Loading branch information
MichaelTaylor3D authored Oct 10, 2024
2 parents fd29e4c + fc93e0b commit b2bbbd5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 30 deletions.
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

0 comments on commit b2bbbd5

Please sign in to comment.