func (db *DB) GetPeerInfo(addr lncore.LnAddr) (peerInfo *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 getting peer info for a single peer: \n%s", err)
			return
		}
		err = tx.Commit()
	}()

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

	var rows *sql.Rows
	getPeerInfoQuery := fmt.Sprintf("SELECT name, netaddr, peerIdx FROM %s WHERE lnaddr='%s';", db.peerTableName, addr.ToString())
	if rows, err = tx.Query(getPeerInfoQuery); err != nil {
		return
	}

	// Add row close to defer stack
	defer func() {
		if err = rows.Close(); err != nil {
			err = fmt.Errorf("Error closing peer rows: \n%s", err)
		}
	}()

	// init the data
	var nickname string
	var netAddr string
	var peerIdx uint32

	// only get one, that's why we use if instead of for
	if rows.Next() {

		if err = rows.Scan(&nickname, &netAddr, &peerIdx); err != nil {
			err = fmt.Errorf("Error scanning for peer info: \n%s", err)
			return
		}

	} else {
		err = fmt.Errorf("No peers found for that address")
		return
	}

	// actually set the data to return
	peerInfo = &lncore.PeerInfo{
		LnAddr:   &addr,
		Nickname: &nickname,
		NetAddr:  &netAddr,
		PeerIdx:  peerIdx,
	}

	return
}
// GetPeerInfo gets the peer info for a specific lnaddr
GetPeerInfo gets the peer info for a specific lnaddr
// GetPeerInfo gets the peer info for a specific lnaddr
func (db *DB) GetPeerInfo(addr lncore.LnAddr) (peerInfo *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 getting peer info for a single peer: \n%s", err)
			return
		}
		err = tx.Commit()
	}()
	if _, err = tx.Exec("USE " + db.peerSchema + ";"); err != nil {
		return
	}
	var rows *sql.Rows
	getPeerInfoQuery := fmt.Sprintf("SELECT name, netaddr, peerIdx FROM %s WHERE lnaddr='%s';", db.peerTableName, addr.ToString())
	if rows, err = tx.Query(getPeerInfoQuery); err != nil {
		return
	}
	defer func() {
		if err = rows.Close(); err != nil {
			err = fmt.Errorf("Error closing peer rows: \n%s", err)
		}
	}()
	var nickname string
	var netAddr string
	var peerIdx uint32
	if rows.Next() {
		if err = rows.Scan(&nickname, &netAddr, &peerIdx); err != nil {
			err = fmt.Errorf("Error scanning for peer info: \n%s", err)
			return
		}
	} else {
		err = fmt.Errorf("No peers found for that address")
		return
	}
	peerInfo = &lncore.PeerInfo{
		LnAddr:   &addr,
		Nickname: &nickname,
		NetAddr:  &netAddr,
		PeerIdx:  peerIdx,
	}
	return
}
func ( db * DB ) GetPeerInfo ( addr lncore . LnAddr ) ( peerInfo * 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 } var rows * sql . Rows getPeerInfoQuery := fmt . Sprintf ( " " , db . peerTableName , addr . ToString ( ) ) if rows , err = tx . Query ( getPeerInfoQuery ) ; err != nil { return } defer func ( ) { if err = rows . Close ( ) ; err != nil { err = fmt . Errorf ( " \n " , err ) } } ( ) var nickname string var netAddr string var peerIdx uint32 if rows . Next ( ) { if err = rows . Scan ( & nickname , & netAddr , & peerIdx ) ; err != nil { err = fmt . Errorf ( " \n " , err ) return } } else { err = fmt . Errorf ( " " ) return } peerInfo = & lncore . PeerInfo { LnAddr : & addr , Nickname : & nickname , NetAddr : & netAddr , PeerIdx : peerIdx , } return }
GetPeerInfo gets the peer info for a specific lnaddr
GetPeerInfo gets the peer info for a specific lnaddr
// use peer schema // Add row close to defer stack // init the data // only get one, that's why we use if instead of for // actually set the data to return