Comments (4)
Here is the index.js File
const bodyParser = require('body-parser');
const express = require('express');
const request = require('request');
//const path = require('path');
const Blockchain = require('./blockchain');
const PubSub = require('./app/pubsub');
const TransactionPool = require('./wallet/transaction-pool');
const Wallet = require('./wallet');
const app = express();
const blockchain = new Blockchain();
const transactionPool = new TransactionPool();
const wallet = new Wallet();
const pubsub = new PubSub({ blockchain, transactionPool });
//const transactionMiner = new TransactionMiner({ blockchain, transactionPool, wallet, pubsub });
const DEFAULT_PORT = 3000;
const ROOT_NODE_ADDRESS = `http://localhost:${DEFAULT_PORT}`;
app.use(bodyParser.json());
app.get('/api/blocks', (req, res) => {
res.json(blockchain.chain);
});
app.post('/api/mine', (req, res) => {
const { data } = req.body;
blockchain.addBlock({ data });
pubsub.broadcastChain();
res.redirect('/api/blocks');
});
app.post('/api/transact', (req, res) => {
const { amount, recipient } = req.body;
let transaction = transactionPool
.existingTransaction({ inputAddress: wallet.publicKey });
try {
if (transaction) {
transaction.update({ senderWallet: wallet, recipient, amount });
} else {
transaction = wallet.createTransaction({ recipient, amount });
}
} catch(error) {
return res.status(400).json({ type: 'error', message: error.message });
}
transactionPool.setTransaction(transaction);
pubsub.broadcastTransaction(transaction);
console.log('transactionPool()', transactionPool);
// let transaction = transactionPool
// .existingTransaction({ inputAddress: wallet.publicKey });
res.json({ type: 'success', transaction });
});
app.get('/api/transaction-pool-map', (req, res) => {
res.json(transactionPool.transactionMap);
});
const syncChains = ()=> {
request({ url: `${ROOT_NODE_ADDRESS}/api/bocks` }, (error, response, body)=> {
if (!error && response.statusCode === 200) {
const rootChain = JSON.parse(body);
console.log('replace transaction pool map on a sync with', rootChain);
blockchain.replaceChain(rootChain);
}
});
}
let PEER_PORT;
if (process.env.GENERATE_PEER_PORT === 'true') {
PEER_PORT = DEFAULT_PORT + Math.ceil(Math.random() * 1000);
}
const PORT = PEER_PORT || DEFAULT_PORT;
app.listen(PORT, () => {
console.log(`listening at localhost: ${PORT}`);
if (PORT !== DEFAULT_PORT) {
syncChains();
}
});
when I try to send a get request using postman by following command
http://localhost:3000/api/transaction-pool-map
I got the above error.
from cryptochain.
How did you fix this?
from cryptochain.
How did you fix this?
yeah. how?
from cryptochain.
Fixed this by removing the mine block endpoint. Once being able to send proper transactions is implemented mining blocks is apart of that process. Do not strobe the mine-blocks endpoint via postman was my fix
from cryptochain.
Related Issues (13)
- i cannot connect to local host 3000 refuse to connect HOT 2
- Frontend Development Workflow HOT 2
- $node pubsub.js issue. Lecture 37
- Mining transactions where there are null transactions
- Minus amount , is a huge miss
- TypeError: Cannot read properties of undefined (reading 'hash')
- Duplicate code
- validating transaction data bug
- Orphan blocks and stale blocks HOT 1
- transaction.input.address error
- What are all the changes needs to done in package.json for Windows OS. HOT 1
- i cannot connect to local host 3000
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cryptochain.