FIX: deduplicate groundcontrol calls
This commit is contained in:
		
							parent
							
								
									69ce4d032a
								
							
						
					
					
						commit
						ac14a50137
					
				@ -1,4 +1,4 @@
 | 
				
			|||||||
import { User, Lock, Paym } from '../class/';
 | 
					import { User, Lock, Paym, Invo } from '../class/';
 | 
				
			||||||
import Frisbee from 'frisbee';
 | 
					import Frisbee from 'frisbee';
 | 
				
			||||||
const config = require('../config');
 | 
					const config = require('../config');
 | 
				
			||||||
let express = require('express');
 | 
					let express = require('express');
 | 
				
			||||||
@ -63,6 +63,15 @@ subscribeInvoicesCall.on('data', async function (response) {
 | 
				
			|||||||
      hash: response.r_hash.toString('hex'),
 | 
					      hash: response.r_hash.toString('hex'),
 | 
				
			||||||
      amt_paid_sat: response.amt_paid_sat,
 | 
					      amt_paid_sat: response.amt_paid_sat,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					    // obtaining a lock, to make sure we push to groundcontrol only once
 | 
				
			||||||
 | 
					    // since this web server can have several instances running, and each will get the same callback from LND
 | 
				
			||||||
 | 
					    // and dont release the lock - it will autoexpire in a while
 | 
				
			||||||
 | 
					    let lock = new Lock(redis, 'groundcontrol_hash_' + LightningInvoiceSettledNotification.hash);
 | 
				
			||||||
 | 
					    if (!(await lock.obtainLock())) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let invoice = new Invo(redis, bitcoinclient, lightning);
 | 
				
			||||||
 | 
					    await invoice._setIsPaymentHashPaidInDatabase(LightningInvoiceSettledNotification.hash, true);
 | 
				
			||||||
    console.log('payment', LightningInvoiceSettledNotification.hash, 'was paid, posting to GroundControl...');
 | 
					    console.log('payment', LightningInvoiceSettledNotification.hash, 'was paid, posting to GroundControl...');
 | 
				
			||||||
    const baseURI = process.env.GROUNDCONTROL;
 | 
					    const baseURI = process.env.GROUNDCONTROL;
 | 
				
			||||||
    if (!baseURI) return;
 | 
					    if (!baseURI) return;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user