func (db *DB) UpdatePeer(addr lncore.LnAddr, pi *lncore.PeerInfo) (err error) {

	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		return
	}

	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while updating peer: \n%s", err)
			return
		}
		err = tx.Commit()
	}()

	// use peer schema
	if _, err = tx.Exec("USE " + db.peerSchema + ";"); err != nil {
		return
	}

	// this should not be a bug, if you tell the database to update a lnaddr with a new lnaddr it will do it for you, right?
	updatePeerQuery := fmt.Sprintf("UPDATE %s SET lnaddr='%s', netaddr='%s', name='%s', peerIdx=%d WHERE lnaddr='%s';", db.peerTableName, pi.LnAddr.ToString(), *pi.NetAddr, *pi.Nickname, pi.PeerIdx, addr.ToString())
	if _, err = tx.Exec(updatePeerQuery); err != nil {
		return
	}

	return
}
// UpdatePeer updates a peer with addr with new peerinfo
UpdatePeer updates a peer with addr with new peerinfo
// UpdatePeer updates a peer with addr with new peerinfo
func (db *DB) UpdatePeer(addr lncore.LnAddr, pi *lncore.PeerInfo) (err error) {
	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		return
	}
	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while updating peer: \n%s", err)
			return
		}
		err = tx.Commit()
	}()
	if _, err = tx.Exec("USE " + db.peerSchema + ";"); err != nil {
		return
	}
	updatePeerQuery := fmt.Sprintf("UPDATE %s SET lnaddr='%s', netaddr='%s', name='%s', peerIdx=%d WHERE lnaddr='%s';", db.peerTableName, pi.LnAddr.ToString(), *pi.NetAddr, *pi.Nickname, pi.PeerIdx, addr.ToString())
	if _, err = tx.Exec(updatePeerQuery); err != nil {
		return
	}
	return
}
func ( db * DB ) UpdatePeer ( addr lncore . LnAddr , pi * lncore . PeerInfo ) ( err error ) { var tx * sql . Tx if tx , err = db . DBHandler . Begin ( ) ; err != nil { return } defer func ( ) { if err != nil { tx . Rollback ( ) err = fmt . Errorf ( " \n " , err ) return } err = tx . Commit ( ) } ( ) if _ , err = tx . Exec ( " " + db . peerSchema + " " ) ; err != nil { return } updatePeerQuery := fmt . Sprintf ( " " , db . peerTableName , pi . LnAddr . ToString ( ) , * pi . NetAddr , * pi . Nickname , pi . PeerIdx , addr . ToString ( ) ) if _ , err = tx . Exec ( updatePeerQuery ) ; err != nil { return } return }
UpdatePeer updates a peer with addr with new peerinfo
UpdatePeer updates a peer with addr with new peerinfo
// use peer schema // this should not be a bug, if you tell the database to update a lnaddr with a new lnaddr it will do it for you, right?