func (db *DB) SynchronizeAddressDB(bitcoinCLient *bitcoindwrapper.Bitcoind, lnClient *lndwrapper.Lnd) {
	//Start update routine to keep the database updated
	var lastScannedBlock = db.height
	var newAddressRegistrationList []*addressRegistration
	var newAddressInfo *addressInfo
	var validAddress bool
	var startingBlock = lastScannedBlock + 1

	//Wait for new blocks and update the address DB accordingly every 10 minutes
	for {
		//Try to find new addresses everry 10 minutes (average block time)
		//Wait 10 minutes at the begging since this function is only called inside synchronizeDB
		//which syncs the database in a synchronous way
		time.Sleep(10 * time.Minute)

		log.Println("Starting DB update from block: " + strconv.FormatUint(lastScannedBlock, 10))

		//Get the number of blocks in the chain
		blockCount, err := GetBlockCount(bitcoinCLient)
		if err != nil {
			log.Fatal("Error getting block count:" + err.Error())
		}

		//If new blocks were found in the last 10 minutes we add the corresponding addresses to the DB
		if blockCount > lastScannedBlock {

			//Getting new address registrations starting from the block after the one we last lastScanned
			newAddressRegistrationList = getNewAddressRegistrations(bitcoinCLient, lnClient, startingBlock, blockCount)

			//Add every new valid address to the OpenAddressesDB
			for _, addressRegistration := range newAddressRegistrationList {

				validAddress, newAddressInfo = db.verifyAddressRegistration(addressRegistration, lnClient)
				if validAddress {
					db.addAddressToDB(newAddressInfo)
					db.saveAddressToFile(newAddressInfo)
				}
			}
		}

		//Update variables to reflect the update
		lastScannedBlock = blockCount
		startingBlock = lastScannedBlock + 1
		db.updateBlockHeight(lastScannedBlock)
		log.Println("Synced until block " + strconv.FormatUint(lastScannedBlock, 10))
	}
}
//SynchronizeAddressDB is to be used as a new go routine to keep updating the address db in the background
SynchronizeAddressDB is to be used as a new go routine to keep updating the address db in the background
// SynchronizeAddressDB is to be used as a new go routine to keep updating the address db in the background
func (db *DB) SynchronizeAddressDB(bitcoinCLient *bitcoindwrapper.Bitcoind, lnClient *lndwrapper.Lnd) {
	var lastScannedBlock = db.height
	var newAddressRegistrationList []*addressRegistration
	var newAddressInfo *addressInfo
	var validAddress bool
	var startingBlock = lastScannedBlock + 1
	for {
		time.Sleep(10 * time.Minute)
		log.Println("Starting DB update from block: " + strconv.FormatUint(lastScannedBlock, 10))
		blockCount, err := GetBlockCount(bitcoinCLient)
		if err != nil {
			log.Fatal("Error getting block count:" + err.Error())
		}
		if blockCount > lastScannedBlock {
			newAddressRegistrationList = getNewAddressRegistrations(bitcoinCLient, lnClient, startingBlock, blockCount)
			for _, addressRegistration := range newAddressRegistrationList {
				validAddress, newAddressInfo = db.verifyAddressRegistration(addressRegistration, lnClient)
				if validAddress {
					db.addAddressToDB(newAddressInfo)
					db.saveAddressToFile(newAddressInfo)
				}
			}
		}
		lastScannedBlock = blockCount
		startingBlock = lastScannedBlock + 1
		db.updateBlockHeight(lastScannedBlock)
		log.Println("Synced until block " + strconv.FormatUint(lastScannedBlock, 10))
	}
}
func ( db * DB ) SynchronizeAddressDB ( bitcoinCLient * bitcoindwrapper . Bitcoind , lnClient * lndwrapper . Lnd ) { var lastScannedBlock = db . height var newAddressRegistrationList [ ] * addressRegistration var newAddressInfo * addressInfo var validAddress bool var startingBlock = lastScannedBlock + 1 for { time . Sleep ( 10 * time . Minute ) log . Println ( " " + strconv . FormatUint ( lastScannedBlock , 10 ) ) blockCount , err := GetBlockCount ( bitcoinCLient ) if err != nil { log . Fatal ( " " + err . Error ( ) ) } if blockCount > lastScannedBlock { newAddressRegistrationList = getNewAddressRegistrations ( bitcoinCLient , lnClient , startingBlock , blockCount ) for _ , addressRegistration := range newAddressRegistrationList { validAddress , newAddressInfo = db . verifyAddressRegistration ( addressRegistration , lnClient ) if validAddress { db . addAddressToDB ( newAddressInfo ) db . saveAddressToFile ( newAddressInfo ) } } } lastScannedBlock = blockCount startingBlock = lastScannedBlock + 1 db . updateBlockHeight ( lastScannedBlock ) log . Println ( " " + strconv . FormatUint ( lastScannedBlock , 10 ) ) } }
SynchronizeAddressDB is to be used as a new go routine to keep updating the address db in the background
SynchronizeAddressDB is to be used as a new go routine to keep updating the address db in the background
//Start update routine to keep the database updated //Wait for new blocks and update the address DB accordingly every 10 minutes //Try to find new addresses everry 10 minutes (average block time) //Wait 10 minutes at the begging since this function is only called inside synchronizeDB //which syncs the database in a synchronous way //Get the number of blocks in the chain //If new blocks were found in the last 10 minutes we add the corresponding addresses to the DB //Getting new address registrations starting from the block after the one we last lastScanned //Add every new valid address to the OpenAddressesDB //Update variables to reflect the update