func (server *OpencxServer) LinkOneWallet(wallet *wallit.Wallit, tower bool) (err error) {
	// we don't need param passed as a parameter to this function, the wallet already has it so we have to substitute a bunch of stuff
	WallitIdx := wallet.Param.HDCoinType

	// see if we've already attached a wallet for this coin type
	if server.ExchangeNode.SubWallet[WallitIdx] != nil {
		err = fmt.Errorf("coin type %d already linked", WallitIdx)
		return
	}

	// see if there are other wallets already linked
	if len(server.ExchangeNode.SubWallet) != 0 {
		// there are; assert multiwallet (may already be asserted)
		server.ExchangeNode.MultiWallet = true
	}

	// Have to do this because we deleted the lines actually creating the wallet, we already have it created.
	server.ExchangeNode.SubWallet[WallitIdx] = wallet

	// if there aren't, Multiwallet will still be false; set new wallit to
	// be the first & default

	if server.ExchangeNode.ConnectedCoinTypes == nil {
		server.ExchangeNode.ConnectedCoinTypes = make(map[uint32]bool)
	}

	// why is this needed in 2 places, can't this be the only time this is run?
	server.ExchangeNode.ConnectedCoinTypes[WallitIdx] = true

	// re-register channel addresses
	qChans, err := server.ExchangeNode.GetAllQchans()
	if err != nil {
		return err
	}

	for _, qChan := range qChans {
		var pkh [20]byte
		pkhSlice := btcutil.Hash160(qChan.MyRefundPub[:])
		copy(pkh[:], pkhSlice)
		server.ExchangeNode.SubWallet[WallitIdx].ExportHook().RegisterAddress(pkh)

		logging.Infof("Registering outpoint %v", qChan.PorTxo.Op)

		server.ExchangeNode.SubWallet[WallitIdx].WatchThis(qChan.PorTxo.Op)
	}

	go server.ExchangeNode.OPEventHandler(server.ExchangeNode.SubWallet[WallitIdx].LetMeKnow())
	go server.ExchangeNode.HeightEventHandler(server.HeightEventChanMap[int(WallitIdx)])

	// If this is the first coin we're linking then set that one to default.
	if !server.ExchangeNode.MultiWallet {
		server.ExchangeNode.DefaultCoin = wallet.Param.HDCoinType
	}

	// if this node is running a watchtower, link the watchtower to the
	// new wallet block events

	if tower {
		err = server.ExchangeNode.Tower.HookLink(
			server.ExchangeNode.LitFolder, wallet.Param, server.ExchangeNode.SubWallet[WallitIdx].ExportHook())
		if err != nil {
			return err
		}
	}

	return nil
}
// LinkOneWallet is a modified version of linkwallet in lit that doesn't make the wallet but links it with an already running one. Your responsibility to pass the correct cointype and tower.
LinkOneWallet is a modified version of linkwallet in lit that doesn't make the wallet but links it with an already running one. Your responsibility to pass the correct cointype and tower.
// LinkOneWallet is a modified version of linkwallet in lit that doesn ' t make the wallet but links it with an already running one . Your responsibility to pass the correct cointype and tower .
func (server *OpencxServer) LinkOneWallet(wallet *wallit.Wallit, tower bool) (err error) {
	WallitIdx := wallet.Param.HDCoinType
	if server.ExchangeNode.SubWallet[WallitIdx] != nil {
		err = fmt.Errorf("coin type %d already linked", WallitIdx)
		return
	}
	if len(server.ExchangeNode.SubWallet) != 0 {
		server.ExchangeNode.MultiWallet = true
	}
	server.ExchangeNode.SubWallet[WallitIdx] = wallet
	if server.ExchangeNode.ConnectedCoinTypes == nil {
		server.ExchangeNode.ConnectedCoinTypes = make(map[uint32]bool)
	}
	server.ExchangeNode.ConnectedCoinTypes[WallitIdx] = true
	qChans, err := server.ExchangeNode.GetAllQchans()
	if err != nil {
		return err
	}
	for _, qChan := range qChans {
		var pkh [20]byte
		pkhSlice := btcutil.Hash160(qChan.MyRefundPub[:])
		copy(pkh[:], pkhSlice)
		server.ExchangeNode.SubWallet[WallitIdx].ExportHook().RegisterAddress(pkh)
		logging.Infof("Registering outpoint %v", qChan.PorTxo.Op)
		server.ExchangeNode.SubWallet[WallitIdx].WatchThis(qChan.PorTxo.Op)
	}
	go server.ExchangeNode.OPEventHandler(server.ExchangeNode.SubWallet[WallitIdx].LetMeKnow())
	go server.ExchangeNode.HeightEventHandler(server.HeightEventChanMap[int(WallitIdx)])
	if !server.ExchangeNode.MultiWallet {
		server.ExchangeNode.DefaultCoin = wallet.Param.HDCoinType
	}
	if tower {
		err = server.ExchangeNode.Tower.HookLink(
			server.ExchangeNode.LitFolder, wallet.Param, server.ExchangeNode.SubWallet[WallitIdx].ExportHook())
		if err != nil {
			return err
		}
	}
	return nil
}
func ( server * OpencxServer ) LinkOneWallet ( wallet * wallit . Wallit , tower bool ) ( err error ) { WallitIdx := wallet . Param . HDCoinType if server . ExchangeNode . SubWallet [ WallitIdx ] != nil { err = fmt . Errorf ( " " , WallitIdx ) return } if len ( server . ExchangeNode . SubWallet ) != 0 { server . ExchangeNode . MultiWallet = true } server . ExchangeNode . SubWallet [ WallitIdx ] = wallet if server . ExchangeNode . ConnectedCoinTypes == nil { server . ExchangeNode . ConnectedCoinTypes = make ( map [ uint32 ] bool ) } server . ExchangeNode . ConnectedCoinTypes [ WallitIdx ] = true qChans , err := server . ExchangeNode . GetAllQchans ( ) if err != nil { return err } for _ , qChan := range qChans { var pkh [ 20 ] byte pkhSlice := btcutil . Hash160 ( qChan . MyRefundPub [ : ] ) copy ( pkh [ : ] , pkhSlice ) server . ExchangeNode . SubWallet [ WallitIdx ] . ExportHook ( ) . RegisterAddress ( pkh ) logging . Infof ( " " , qChan . PorTxo . Op ) server . ExchangeNode . SubWallet [ WallitIdx ] . WatchThis ( qChan . PorTxo . Op ) } go server . ExchangeNode . OPEventHandler ( server . ExchangeNode . SubWallet [ WallitIdx ] . LetMeKnow ( ) ) go server . ExchangeNode . HeightEventHandler ( server . HeightEventChanMap [ int ( WallitIdx ) ] ) if ! server . ExchangeNode . MultiWallet { server . ExchangeNode . DefaultCoin = wallet . Param . HDCoinType } if tower { err = server . ExchangeNode . Tower . HookLink ( server . ExchangeNode . LitFolder , wallet . Param , server . ExchangeNode . SubWallet [ WallitIdx ] . ExportHook ( ) ) if err != nil { return err } } return nil }
LinkOneWallet is a modified version of linkwallet in lit that doesn't make the wallet but links it with an already running one.
LinkOneWallet is a modified version of linkwallet in lit that doesn ' t make the wallet but links it with an already running one .
// we don't need param passed as a parameter to this function, the wallet already has it so we have to substitute a bunch of stuff // see if we've already attached a wallet for this coin type // see if there are other wallets already linked // there are; assert multiwallet (may already be asserted) // Have to do this because we deleted the lines actually creating the wallet, we already have it created. // if there aren't, Multiwallet will still be false; set new wallit to // be the first & default // why is this needed in 2 places, can't this be the only time this is run? // re-register channel addresses // If this is the first coin we're linking then set that one to default. // if this node is running a watchtower, link the watchtower to the // new wallet block events