Skip to content

Commit

Permalink
Merge pull request #52 from DIG-Network/release/v0.0.1-alpha.55
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.55
  • Loading branch information
MichaelTaylor3D authored Sep 22, 2024
2 parents a9062da + c778221 commit 08ae29f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 99 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.55](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.54...v0.0.1-alpha.55) (2024-09-22)


### Bug Fixes

* replace chalk with colorette ([5d3bc2c](https://github.com/DIG-Network/dig-chia-sdk/commit/5d3bc2c218d5885660707dd4b1b7b27913e49202))

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


Expand Down
71 changes: 8 additions & 63 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-sdk",
"version": "0.0.1-alpha.54",
"version": "0.0.1-alpha.55",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down Expand Up @@ -29,13 +29,13 @@
"archiver": "^7.0.1",
"axios": "^1.7.7",
"bip39": "^3.1.0",
"chalk": "^5.3.0",
"chia-bls": "^1.0.2",
"chia-config-loader": "^1.0.1",
"chia-root-resolver": "^1.0.0",
"chia-server-coin": "^0.0.5",
"chia-wallet": "^1.0.18",
"cli-progress": "^3.12.0",
"colorette": "^2.0.20",
"crypto-js": "^4.2.0",
"figures": "^6.1.0",
"fs-extra": "^11.2.0",
Expand Down
62 changes: 31 additions & 31 deletions src/DigNetwork/PropagationServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getOrCreateSSLCerts } from "../utils/ssl";
import { promptCredentials } from "../utils/credentialsUtils";
import https from "https";
import cliProgress from "cli-progress";
import chalk from "chalk"; // For colored output
import { green, red, cyan, yellow, blue } from "colorette"; // For colored output
import ora from "ora"; // For spinners
import { STORE_PATH } from "../utils/config";
import { getFilePathFromSha256 } from "../utils/hashUtils";
Expand All @@ -31,8 +31,8 @@ export class PropagationServer {
clearOnComplete: false,
hideCursor: true,
format:
chalk.green(" {bar} ") +
chalk.cyan(" | {filename} | {percentage}% | {value}/{total} bytes"),
green(" {bar} ") +
cyan(" | {filename} | {percentage}% | {value}/{total} bytes"),
barsize: 40,
stopOnComplete: true,
align: "center",
Expand Down Expand Up @@ -98,27 +98,27 @@ export class PropagationServer {
const rootHashExists = response.headers["x-has-root-hash"] === "true";

if (storeExists) {
spinner.succeed(chalk.green(`Store ${this.storeId} exists!`));
spinner.succeed(green(`Store ${this.storeId} exists!`));
} else {
spinner.fail(chalk.red(`Store ${this.storeId} does not exist.`));
spinner.fail(red(`Store ${this.storeId} does not exist.`));
}

if (rootHash) {
if (rootHashExists) {
console.log(
chalk.green(`Root hash ${rootHash} exists in the store.`)
green(`Root hash ${rootHash} exists in the store.`)
);
} else {
console.log(
chalk.red(`Root hash ${rootHash} does not exist in the store.`)
red(`Root hash ${rootHash} does not exist in the store.`)
);
}
}

return { storeExists, rootHashExists };
} catch (error) {
spinner.fail(chalk.red("Error checking if store exists:"));
console.error(chalk.red(error));
} catch (error: any) {
spinner.fail(red("Error checking if store exists:"));
console.error(red(error));
throw error;
}
}
Expand Down Expand Up @@ -152,13 +152,13 @@ export class PropagationServer {

this.sessionId = response.data.sessionId;
spinner.succeed(
chalk.green(
green(
`Upload session started for DataStore ${this.storeId} with session ID ${this.sessionId}`
)
);
} catch (error) {
spinner.fail(chalk.red("Error starting upload session:"));
console.error(chalk.red(error));
} catch (error: any) {
spinner.fail(red("Error starting upload session:"));
console.error(red(error));
throw error;
}
}
Expand All @@ -175,11 +175,11 @@ export class PropagationServer {
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${filename}`;
const response = await axios.head(url, config);
const nonce = response.headers["x-nonce"];
console.log(chalk.blue(`Nonce received for file ${filename}: ${nonce}`));
console.log(blue(`Nonce received for file ${filename}: ${nonce}`));
return nonce;
} catch (error) {
console.error(
chalk.red(`Error generating nonce for file ${filename}:`),
red(`Error generating nonce for file ${filename}:`),
error
);
throw error;
Expand All @@ -204,7 +204,7 @@ export class PropagationServer {

// Create a new progress bar for each file
const progressBar = PropagationServer.multiBar.create(fileSize, 0, {
filename: chalk.yellow(filename),
filename: yellow(filename),
percentage: 0,
});

Expand All @@ -231,15 +231,15 @@ export class PropagationServer {
try {
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${filename}`;
const response = await axios.put(url, formData, config);
console.log(chalk.green(`✔ File ${filename} uploaded successfully.`));
console.log(green(`✔ File ${filename} uploaded successfully.`));

// Complete the progress bar
progressBar.update(fileSize, { percentage: 100 });
progressBar.stop();

return response.data;
} catch (error) {
console.error(chalk.red(`✖ Error uploading file ${filename}:`), error);
console.error(red(`✖ Error uploading file ${filename}:`), error);
progressBar.stop(); // Stop the progress bar in case of error
throw error;
}
Expand Down Expand Up @@ -268,7 +268,7 @@ export class PropagationServer {
// If the store does not exist, prompt for credentials
if (!storeExists) {
console.log(
chalk.red(
red(
`Store ${storeId} does not exist. Prompting for credentials...`
)
);
Expand All @@ -292,7 +292,7 @@ export class PropagationServer {
PropagationServer.multiBar.stop();

console.log(
chalk.green(`✔ All files have been uploaded to DataStore ${storeId}.`)
green(`✔ All files have been uploaded to DataStore ${storeId}.`)
);
}

Expand All @@ -314,11 +314,11 @@ export class PropagationServer {
const response = await axios.get(url, config);
const totalLength = parseInt(response.headers["content-length"], 10);

console.log(chalk.cyan(`Starting fetch for ${dataPath}...`));
console.log(cyan(`Starting fetch for ${dataPath}...`));

// Create a progress bar for the download
const progressBar = PropagationServer.multiBar.create(totalLength, 0, {
dataPath: chalk.yellow(dataPath),
dataPath: yellow(dataPath),
percentage: 0,
});

Expand All @@ -336,12 +336,12 @@ export class PropagationServer {
progressBar.update(totalLength, { percentage: 100 });
progressBar.stop();

console.log(chalk.green(`✔ File ${dataPath} fetched successfully.`));
console.log(green(`✔ File ${dataPath} fetched successfully.`));

// Return the file contents as a Buffer
return Buffer.from(response.data);
} catch (error) {
console.error(chalk.red(`✖ Error fetching file ${dataPath}:`), error);
console.error(red(`✖ Error fetching file ${dataPath}:`), error);
throw error;
}
}
Expand Down Expand Up @@ -369,11 +369,11 @@ export class PropagationServer {
const response = await axios.get(url, config);
const totalLength = parseInt(response.headers["content-length"], 10);

console.log(chalk.cyan(`Starting download for ${dataPath}...`));
console.log(cyan(`Starting download for ${dataPath}...`));

// Create a progress bar for the download
const progressBar = PropagationServer.multiBar.create(totalLength, 0, {
dataPath: chalk.yellow(dataPath),
dataPath: yellow(dataPath),
percentage: 0,
});

Expand All @@ -395,7 +395,7 @@ export class PropagationServer {
progressBar.update(totalLength, { percentage: 100 });
progressBar.stop();
console.log(
chalk.green(
green(
`✔ File ${dataPath} downloaded successfully to ${downloadPath}.`
)
);
Expand All @@ -405,14 +405,14 @@ export class PropagationServer {
fileWriteStream.on("error", (error) => {
progressBar.stop();
console.error(
chalk.red(`✖ Error downloading file ${dataPath}:`),
red(`✖ Error downloading file ${dataPath}:`),
error
);
reject(error);
});
});
} catch (error) {
console.error(chalk.red(`✖ Error downloading file ${dataPath}:`), error);
console.error(red(`✖ Error downloading file ${dataPath}:`), error);
throw error;
}
}
Expand Down Expand Up @@ -452,6 +452,6 @@ export class PropagationServer {
await propagationServer.downloadFile(dataPath);
}

console.log(chalk.green(`✔ All files have been downloaded to ${storeId}.`));
console.log(green(`✔ All files have been downloaded to ${storeId}.`));
}
}
6 changes: 3 additions & 3 deletions src/blockchain/DataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from "../utils/config";
import { selectUnspentCoins, calculateFeeForCoinSpends } from "./coins";
import { RootHistoryItem, DatFile } from "../types";
import chalk from "chalk";
import { green, red } from "colorette";
import { getFilePathFromSha256 } from "../utils/hashUtils";
import {
DataIntegrityTree,
Expand Down Expand Up @@ -584,12 +584,12 @@ export class DataStore {

if (integrityCheck) {
console.log(
chalk.green(`File ${fileKey} has passed the integrity check.`)
green(`File ${fileKey} has passed the integrity check.`)
);
// Add the file to the file set only if the integrity check passes
filesInvolved.push(filePath);
} else {
console.error(chalk.red(`File ${fileKey} failed the integrity check.`));
console.error(red(`File ${fileKey} failed the integrity check.`));
throw new Error(
`Integrity check failed for file: ${fileKey}. Aborting.`
);
Expand Down

0 comments on commit 08ae29f

Please sign in to comment.