Commit a892bbba authored by kirtisingh's avatar kirtisingh

Added checks while pushing to db

parent 758f1b80
......@@ -171,8 +171,8 @@ mongoose.connect(dbURI,connectionParams)
"stateMutability": "nonpayable",
"type": "function"
}
], '0x8909Dff24b48790c9A0590F706Dc8f3B1709ce88');
var x = await contract.methods.orderList('0xfb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603').call();
], '0x1039A0fC57e69c6af748C6B56e02aC2E8FAEAb51');
var x = await contract.methods.orderList(hashlock).call();
var contractont = await new web3ont.eth.Contract([
{
"inputs": [
......@@ -306,8 +306,8 @@ mongoose.connect(dbURI,connectionParams)
"type": "function"
}
], '0xC6CD342cEba445bBfB98B9d5Da99c62B2B98CFbe');
var y = await contractont.methods.orderList('0xfb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603').call();
return {'hashlock':hashlock, 'amountOnt': y['amountOnt'], 'bidTimelock':x['bidTimelock']};
var y = await contractont.methods.orderList(hashlock).call();
return {'hashlock':hashlock, 'amountOnt': y['amountOnt'], 'bidTimelock':x['bidTimelock'], 'refundTimelockETH':x['refundTimelock'], 'refundTimelockONT':y['refundTimelock']};
}
// register view engine
......@@ -322,34 +322,52 @@ app.use((req, res, next) => {
next();
});
app.post('/txns', (req, res) => {
app.post('/txns', async (req, res) => {
console.log(req.body);
const txn = new txns(req.body);
// const txn = new txns(req.body);
var obj = await func(req.body['hashlock']);
var a = parseInt(obj['refundTimelockONT']);
// console.log(obj['amountOnt']);
var b = parseInt(obj['refundTimelockETH']);
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) => {
txns.find().then((result) => {
// let ar = [];
// console.log(typeof(result));
var arr = [];
result.forEach(async txn => {
// result.forEach(async txn => {
// console.log(txn.hashlock);
// var obj = {'hashlock': txn.hashlock,
// 'amountOnt': txn.amountOnt,
// 'bidTimelock': txn.bidTimelock};
var obj = await func(txn.hashlock);
if(obj['amountOnt']!=""){
arr.push(obj);
}
// var obj = await func(txn.hashlock);
// // console.log(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(arr);
res.render('orderbook', {title: 'All Transactions', txns: arr});
// });
// console.log(ar);
res.render('orderbook', {title: 'All Transactions', txns: result});
})
.catch((err) => {
console.log(err);
......
......@@ -74,7 +74,7 @@ contract EthereumContract {
payable(msg.sender).transfer(orderList[hashlock].mxbid);
//Transaction Finished. Make the hash ready for probable other txn
clear(hashlock);
// clear(hashlock);
}
function refundEth (bytes32 hashlock) public {
......
......@@ -14,6 +14,14 @@ const txnsSchema = new Schema({
type: String,
required: true
},
refundTimelockETH: {
type: String,
required: true
},
refundTimelockONT: {
type: String,
required: true
}
}, { timestamps: true });
const txns = mongoose.model('txns', txnsSchema);
......
......@@ -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 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 ETH Address:</td> <td>${orderList["buyerEthAddress"]}</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">Secret:</td> <td>${orderList["secret"]}</td></tr>
<tr><td class="pd">Status:</td> <td>${orderList["status"]}</td></tr>
</table>`;
// console.log(orderList);
......@@ -431,7 +429,7 @@ async function loadContract2() {
"stateMutability": "nonpayable",
"type": "function"
}
], '0x8909Dff24b48790c9A0590F706Dc8f3B1709ce88');
], '0x1039A0fC57e69c6af748C6B56e02aC2E8FAEAb51');
}
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