Skip to content

Commit

Permalink
initialEncrypToUTXO
Browse files Browse the repository at this point in the history
  • Loading branch information
rchak007 committed Oct 21, 2023
1 parent 3c2a5dd commit 6933c69
Show file tree
Hide file tree
Showing 5 changed files with 2,495 additions and 1 deletion.
47 changes: 47 additions & 0 deletions pages/api/read-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { readFirstLineFromFile } from '../../utils/fileUtils';

import fs from 'fs';
import path from 'path';

export default function handler(req: NextApiRequest, res: NextApiResponse) {
console.log("from read-file")
if (req.method === 'GET') {
console.log("from read-file handler 1st line ")
const filePath = path.join(process.cwd(), '/Wallets/Contributor/contributor.seed');
// const filePath = '/Wallets/Contributor/contributor.seed'; // Replace this with your file's path
try {
console.log("From read-file.ts -file name is ", filePath)
const firstLine = readFirstLineFromFile(filePath);
console.log("firstLine is = ", firstLine)
res.status(200).json({ firstLine });
} catch (error) {
res.status(500).json({ error: 'Error reading file from read-file.' });
}
} else {
res.status(405).json({ error: 'Method not allowed from read-file.' });
}
}


// import fs from 'fs';
// import path from 'path';

// export default function handler(req, res) {
// if (req.method === 'POST') {
// const filePath = path.join(process.cwd(), 'testfile.txt');
// const dataToWrite = 'This is the data that will be written to the file.\n';

// fs.writeFile(filePath, dataToWrite, (error) => {
// if (error) {
// console.error('Error writing to the file:', error);
// res.status(500).json({ error: 'Error writing to the file.' });
// } else {
// console.log('Data has been written to the file successfully!');
// res.status(200).json({ message: 'Data written to the file successfully!' });
// }
// });
// } else {
// res.status(405).json({ error: 'Method not allowed.' });
// }
// }
22 changes: 22 additions & 0 deletions pages/api/writeToFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from 'fs';
import path from 'path';

export default function handler(req, res) {
console.log("from writeToFile")
if (req.method === 'POST') {
const filePath = path.join(process.cwd(), 'testfile.txt');
const dataToWrite = 'This is the data that will be written to the file.\n';
console.log("from write-toFile= ", filePath)
fs.writeFile(filePath, dataToWrite, (error) => {
if (error) {
console.error('Error writing to the file:', error);
res.status(500).json({ error: 'Error writing to the file.' });
} else {
console.log('From WriteToFile--- Data has been written to the file successfully!');
res.status(200).json({ message: 'Data written to the file successfully!' });
}
});
} else {
res.status(405).json({ error: 'Method not allowed.' });
}
}
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const Home: NextPage = () => {
<div>Your NFTs:</div>
<NftGrid nfts={nftList} />
<div className="mx-40 my-10">
<Link href="/crowdfund">
<Link href="offChain">
<button className="btn btn-primary m-5" >Smart Contract example</button>
</Link>
{/* <div>Your NFTs:</div>
Expand Down
Loading

0 comments on commit 6933c69

Please sign in to comment.