Commit a892bbba authored by kirtisingh's avatar kirtisingh

Added checks while pushing to db

parent 758f1b80
...@@ -171,8 +171,8 @@ mongoose.connect(dbURI,connectionParams) ...@@ -171,8 +171,8 @@ mongoose.connect(dbURI,connectionParams)
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
} }
], '0x8909Dff24b48790c9A0590F706Dc8f3B1709ce88'); ], '0x1039A0fC57e69c6af748C6B56e02aC2E8FAEAb51');
var x = await contract.methods.orderList('0xfb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603').call(); var x = await contract.methods.orderList(hashlock).call();
var contractont = await new web3ont.eth.Contract([ var contractont = await new web3ont.eth.Contract([
{ {
"inputs": [ "inputs": [
...@@ -306,8 +306,8 @@ mongoose.connect(dbURI,connectionParams) ...@@ -306,8 +306,8 @@ mongoose.connect(dbURI,connectionParams)
"type": "function" "type": "function"
} }
], '0xC6CD342cEba445bBfB98B9d5Da99c62B2B98CFbe'); ], '0xC6CD342cEba445bBfB98B9d5Da99c62B2B98CFbe');
var y = await contractont.methods.orderList('0xfb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603').call(); var y = await contractont.methods.orderList(hashlock).call();
return {'hashlock':hashlock, 'amountOnt': y['amountOnt'], 'bidTimelock':x['bidTimelock']}; return {'hashlock':hashlock, 'amountOnt': y['amountOnt'], 'bidTimelock':x['bidTimelock'], 'refundTimelockETH':x['refundTimelock'], 'refundTimelockONT':y['refundTimelock']};
} }
// register view engine // register view engine
...@@ -322,34 +322,52 @@ app.use((req, res, next) => { ...@@ -322,34 +322,52 @@ app.use((req, res, next) => {
next(); next();
}); });
app.post('/txns', (req, res) => { app.post('/txns', async (req, res) => {
console.log(req.body); console.log(req.body);
const txn = new txns(req.body); // const txn = new txns(req.body);
txn.save().then((result) => { var obj = await func(req.body['hashlock']);
res.send(result) var a = parseInt(obj['refundTimelockONT']);
}) // console.log(obj['amountOnt']);
.catch((err) => { var b = parseInt(obj['refundTimelockETH']);
console.log(err); var diff = a-b;
}) if(obj['amountOnt']!="0" && diff>120){
console.log(diff);
const txn = new txns(obj);
txn.save().then((result) => {
res.send(result)
})
.catch((err) => {
console.log(err);
})
}
else{
console.log('Empty or time exceeded');
}
}); });
app.get('/txns', (req,res) => { app.get('/txns', (req,res) => {
txns.find().then((result) => { txns.find().then((result) => {
// let ar = [];
// console.log(typeof(result)); // console.log(typeof(result));
var arr = []; // result.forEach(async txn => {
result.forEach(async txn => {
// console.log(txn.hashlock); // console.log(txn.hashlock);
// var obj = {'hashlock': txn.hashlock, // var obj = {'hashlock': txn.hashlock,
// 'amountOnt': txn.amountOnt, // 'amountOnt': txn.amountOnt,
// 'bidTimelock': txn.bidTimelock}; // 'bidTimelock': txn.bidTimelock};
var obj = await func(txn.hashlock); // var obj = await func(txn.hashlock);
if(obj['amountOnt']!=""){ // // console.log(obj);
arr.push(obj); // var a = parseInt(obj['refundTimelockONT']);
} // console.log(obj['amountOnt']);
// var b = parseInt(obj['refundTimelockETH']);
// console.log(a);
// console.log(b);
// ar.push(obj);
// if(obj['amountOnt']!="" && diff>120){
// arr.push(obj);
// }
// console.log(obj); // console.log(obj);
}); // });
console.log(arr); // console.log(ar);
res.render('orderbook', {title: 'All Transactions', txns: arr}); res.render('orderbook', {title: 'All Transactions', txns: result});
}) })
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
......
...@@ -74,7 +74,7 @@ contract EthereumContract { ...@@ -74,7 +74,7 @@ contract EthereumContract {
payable(msg.sender).transfer(orderList[hashlock].mxbid); payable(msg.sender).transfer(orderList[hashlock].mxbid);
//Transaction Finished. Make the hash ready for probable other txn //Transaction Finished. Make the hash ready for probable other txn
clear(hashlock); // clear(hashlock);
} }
function refundEth (bytes32 hashlock) public { function refundEth (bytes32 hashlock) public {
......
...@@ -14,6 +14,14 @@ const txnsSchema = new Schema({ ...@@ -14,6 +14,14 @@ const txnsSchema = new Schema({
type: String, type: String,
required: true required: true
}, },
refundTimelockETH: {
type: String,
required: true
},
refundTimelockONT: {
type: String,
required: true
}
}, { timestamps: true }); }, { timestamps: true });
const txns = mongoose.model('txns', txnsSchema); const txns = mongoose.model('txns', txnsSchema);
......
...@@ -153,10 +153,8 @@ async function printOrderListOnt(hashlock){ ...@@ -153,10 +153,8 @@ async function printOrderListOnt(hashlock){
<tr><td class="pd">Initiator ONT Address:</td> <td>${orderList["initiatorOntAddress"]}</td></tr> <tr><td class="pd">Initiator ONT Address:</td> <td>${orderList["initiatorOntAddress"]}</td></tr>
<tr><td class="pd">Initiator ETH Address:</td> <td>${orderList["initiatorEthAddress"]}</td></tr> <tr><td class="pd">Initiator ETH Address:</td> <td>${orderList["initiatorEthAddress"]}</td></tr>
<tr><td class="pd">Buyer ONT Address:</td> <td>${orderList["buyerOntAddress"]}</td></tr> <tr><td class="pd">Buyer ONT Address:</td> <td>${orderList["buyerOntAddress"]}</td></tr>
<tr><td class="pd">Buyer ETH Address:</td> <td>${orderList["buyerEthAddress"]}</td></tr>
<tr><td class="pd">Amount Ont:</td> <td>${orderList["amountOnt"]}</td></tr> <tr><td class="pd">Amount Ont:</td> <td>${orderList["amountOnt"]}</td></tr>
<tr><td class="pd">Refund Time:</td> <td>${t}</td></tr> <tr><td class="pd">Refund Time:</td> <td>${t}</td></tr>
<tr><td class="pd">Secret:</td> <td>${orderList["secret"]}</td></tr>
<tr><td class="pd">Status:</td> <td>${orderList["status"]}</td></tr> <tr><td class="pd">Status:</td> <td>${orderList["status"]}</td></tr>
</table>`; </table>`;
// console.log(orderList); // console.log(orderList);
...@@ -431,7 +429,7 @@ async function loadContract2() { ...@@ -431,7 +429,7 @@ async function loadContract2() {
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
} }
], '0x8909Dff24b48790c9A0590F706Dc8f3B1709ce88'); ], '0x1039A0fC57e69c6af748C6B56e02aC2E8FAEAb51');
} }
async function printOrderListEth(hashlock){ async function printOrderListEth(hashlock){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment