Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Atomic Swap
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirti
Atomic Swap
Commits
a892bbba
Commit
a892bbba
authored
Nov 27, 2022
by
kirtisingh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added checks while pushing to db
parent
758f1b80
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
26 deletions
+50
-26
app.js
app.js
+40
-22
contracts/EthereumContract.sol
contracts/EthereumContract.sol
+1
-1
models/txns.js
models/txns.js
+8
-0
public/script.js
public/script.js
+1
-3
No files found.
app.js
View file @
a892bbba
...
@@ -171,8 +171,8 @@ mongoose.connect(dbURI,connectionParams)
...
@@ -171,8 +171,8 @@ mongoose.connect(dbURI,connectionParams)
"
stateMutability
"
:
"
nonpayable
"
,
"
stateMutability
"
:
"
nonpayable
"
,
"
type
"
:
"
function
"
"
type
"
:
"
function
"
}
}
],
'
0x
8909Dff24b48790c9A0590F706Dc8f3B1709ce88
'
);
],
'
0x
1039A0fC57e69c6af748C6B56e02aC2E8FAEAb51
'
);
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);
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
)
=>
{
txn
.
save
().
then
((
result
)
=>
{
res
.
send
(
result
)
res
.
send
(
result
)
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
log
(
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
(
ar
r
);
// console.log(a
r);
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
);
...
...
contracts/EthereumContract.sol
View file @
a892bbba
...
@@ -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 {
...
...
models/txns.js
View file @
a892bbba
...
@@ -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
);
...
...
public/script.js
View file @
a892bbba
...
@@ -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
"
}
}
],
'
0x
8909Dff24b48790c9A0590F706Dc8f3B1709ce88
'
);
],
'
0x
1039A0fC57e69c6af748C6B56e02aC2E8FAEAb51
'
);
}
}
async
function
printOrderListEth
(
hashlock
){
async
function
printOrderListEth
(
hashlock
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment