File tree 4 files changed +21
-1
lines changed
4 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -546,7 +546,12 @@ class OrderBook extends EventEmitter {
546
546
*/
547
547
public executeSwap = async ( maker : PeerOrder , taker : OwnOrder ) : Promise < SwapSuccess > => {
548
548
// make sure the order is in the database before we begin the swap
549
- await this . repository . addOrderIfNotExists ( maker ) ;
549
+ if ( ! ( await this . repository . getOrder ( maker . id ) ) ) {
550
+ await this . repository . addOrderIfNotExists ( {
551
+ ...maker ,
552
+ nodeId : this . pool . getNodeId ( maker . peerPubKey ) ,
553
+ } ) ;
554
+ }
550
555
try {
551
556
const swapResult = await this . swaps . executeSwap ( maker , taker ) ;
552
557
this . emit ( 'peerOrder.filled' , maker ) ;
@@ -583,6 +588,7 @@ class OrderBook extends EventEmitter {
583
588
if ( takerOrder ) {
584
589
addOrderPromises . push ( this . repository . addOrderIfNotExists ( takerOrder ) ) ;
585
590
}
591
+
586
592
await Promise . all ( addOrderPromises ) ;
587
593
await this . repository . addTrade ( {
588
594
quantity,
Original file line number Diff line number Diff line change @@ -48,6 +48,12 @@ class OrderbookRepository {
48
48
}
49
49
}
50
50
51
+ public getOrder = ( id : string ) => {
52
+ return this . models . Order . findOne ( {
53
+ where : { id } ,
54
+ } ) ;
55
+ }
56
+
51
57
public addTrade = ( trade : db . TradeFactory ) => {
52
58
return this . models . Trade . create ( trade ) ;
53
59
}
Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ class NodeList extends EventEmitter {
52
52
this . nodes . forEach ( callback ) ;
53
53
}
54
54
55
+ public getId = ( nodePubKey : string ) => {
56
+ return this . nodes . get ( nodePubKey ) ?. id ;
57
+ }
58
+
55
59
/**
56
60
* Return list of public keys of all banned nodes with a given alias.
57
61
*/
Original file line number Diff line number Diff line change @@ -153,6 +153,10 @@ class Pool extends EventEmitter {
153
153
return this . nodeState . tokenIdentifiers [ currency ] ;
154
154
}
155
155
156
+ public getNodeId = ( nodePubKey : string ) => {
157
+ return this . nodes . getId ( nodePubKey ) ;
158
+ }
159
+
156
160
/**
157
161
* Initialize the Pool by connecting to known nodes and listening to incoming peer connections, if configured to do so.
158
162
*/
You can’t perform that action at this time.
0 commit comments