diff --git a/frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js b/frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js
index 4c4c8d83..0dcda91c 100644
--- a/frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js
+++ b/frontend/src/components/BuyOfferDetailItem/BuyOfferDetailItem.js
@@ -25,6 +25,7 @@ import moment from 'moment';
import {
goToPeerPage,
+ goToPeerAddressPage,
goToLightningNodePage,
} from "../../navigation/navigation"
@@ -40,12 +41,11 @@ export default function BuyOfferDetailItem({
const onPeerClick = (event) => {
event.preventDefault();
- const peerId = getPeerId();
- if (peerId == null) {
- return;
- }
- console.log("Handling peer click for peerId: " + peerId);
- goToPeerPage(history, peerId);
+ goToPeerAddressPage(
+ history,
+ offer.getPeerHost(),
+ offer.getPeerPort(),
+ );
}
const onLightningNodeClick = (event) => {
@@ -58,16 +58,6 @@ export default function BuyOfferDetailItem({
)
}
- const getPeerId = () => {
- if (!offer.getHasPeer()) {
- return null;
- }
- const peer = offer.getPeer();
- return peer.getPeerId();
- }
-
-
-
const handleClickPayOffer = () => {
console.log("Handle click pay offer.");
setPayOfferDialogOpen(true);
@@ -86,43 +76,17 @@ export default function BuyOfferDetailItem({
)
}
-
- function PeerDisplay() {
- if (offer.getHasPeer()) {
- return HasPeerDisplay(offer.getPeer());
- } else {
- return HasNoPeerDisplay();
- }
- }
-
- function HasPeerDisplay(peer) {
- const peerId = peer.getPeerId();
- const peerName = peer.getPeerName();
- const peerDisplayName = peerName ? peerName : peerId;
- return (
- {peerDisplayName}
-
- )
- }
-
- function HasNoPeerDisplay() {
- return (
- <>
- Unknown Peer
- >
- )
- }
-
-
- function ProfileInfoContent() {
+ function PeerInfoContent() {
+ console.log(offer);
+ const peerAddress = offer.getPeerHost() + ":" + offer.getPeerPort();
return (
Peer: {PeerDisplay()}
-
+ >Peer:
+ {peerAddress}
+
+
)
}
@@ -142,7 +106,7 @@ export default function BuyOfferDetailItem({
)
}
- function PeerNodeInfoContent(offer) {
+ function LightningPeerInfoContent(offer) {
const lightningAddress = offer.getNodeHost() + ":" + offer.getNodePort();
const lightningPubkey = offer.getNodePubkey();
return (
@@ -181,7 +145,7 @@ export default function BuyOfferDetailItem({
alignItems="flex-start"
>
- {ProfileInfoContent()}
+ {PeerInfoContent()}
- {PeerNodeInfoContent(offer)}
+ {LightningPeerInfoContent(offer)}
squeak_admin_pb2.SqueakPe
)
-def offer_entry_to_message(received_offer_entry: ReceivedOfferWithPeer) -> squeak_admin_pb2.OfferDisplayEntry:
- received_offer = received_offer_entry.received_offer
+def offer_entry_to_message(received_offer: ReceivedOffer) -> squeak_admin_pb2.OfferDisplayEntry:
if received_offer.received_offer_id is None:
raise Exception("Received offer id cannot be None.")
- peer = received_offer_entry.peer
- has_peer = False
- peer_msg = None
- if peer is not None:
- has_peer = True
- peer_msg = squeak_peer_to_message(peer)
return squeak_admin_pb2.OfferDisplayEntry(
offer_id=received_offer.received_offer_id,
squeak_hash=received_offer.squeak_hash.hex(),
@@ -101,10 +93,10 @@ def offer_entry_to_message(received_offer_entry: ReceivedOfferWithPeer) -> squea
node_pubkey=received_offer.destination,
node_host=received_offer.lightning_address.host,
node_port=received_offer.lightning_address.port,
- has_peer=has_peer,
- peer=peer_msg,
invoice_timestamp=received_offer.invoice_timestamp,
invoice_expiry=received_offer.invoice_expiry,
+ peer_host=received_offer.peer_address.host,
+ peer_port=received_offer.peer_address.port,
)
diff --git a/squeaknode/admin/squeak_admin_server_handler.py b/squeaknode/admin/squeak_admin_server_handler.py
index b34204c1..1dd25334 100644
--- a/squeaknode/admin/squeak_admin_server_handler.py
+++ b/squeaknode/admin/squeak_admin_server_handler.py
@@ -462,7 +462,7 @@ class SqueakAdminServerHandler(object):
squeak_hash = bytes.fromhex(squeak_hash_str)
logger.info(
"Handle get received offers for hash: {}".format(squeak_hash_str))
- offers = self.squeak_controller.get_received_offers_with_peer(
+ offers = self.squeak_controller.get_received_offers(
squeak_hash)
offer_msgs = [offer_entry_to_message(offer) for offer in offers]
return squeak_admin_pb2.GetBuyOffersReply(
@@ -472,7 +472,7 @@ class SqueakAdminServerHandler(object):
def handle_get_buy_offer(self, request):
offer_id = request.offer_id
logger.info("Handle get buy offer for hash: {}".format(offer_id))
- offer = self.squeak_controller.get_buy_offer_with_peer(offer_id)
+ offer = self.squeak_controller.get_received_offer(offer_id)
if offer is None:
return squeak_admin_pb2.GetBuyOfferReply(
offer=None,
diff --git a/squeaknode/db/squeak_db.py b/squeaknode/db/squeak_db.py
index 9a92dd7a..f3f0aa3f 100644
--- a/squeaknode/db/squeak_db.py
+++ b/squeaknode/db/squeak_db.py
@@ -18,7 +18,6 @@ from squeaknode.bitcoin.util import parse_block_header
from squeaknode.core.lightning_address import LightningAddressHostPort
from squeaknode.core.peer_address import PeerAddress
from squeaknode.core.received_offer import ReceivedOffer
-from squeaknode.core.received_offer_with_peer import ReceivedOfferWithPeer
from squeaknode.core.received_payment import ReceivedPayment
from squeaknode.core.received_payment_summary import ReceivedPaymentSummary
from squeaknode.core.sent_offer import SentOffer
@@ -743,17 +742,10 @@ class SqueakDb:
received_offer_id = res.inserted_primary_key[0]
return received_offer_id
- def get_received_offers_with_peer(self, squeak_hash: bytes) -> List[ReceivedOfferWithPeer]:
+ def get_received_offers(self, squeak_hash: bytes) -> List[ReceivedOffer]:
""" Get offers with peer for a squeak hash. """
s = (
- select([self.received_offers, self.peers])
- .select_from(
- self.received_offers.outerjoin(
- self.peers,
- self.peers.c.host == self.received_offers.c.peer_host,
- self.peers.c.port == self.received_offers.c.peer_port,
- )
- )
+ select([self.received_offers])
.where(self.received_offers.c.squeak_hash == squeak_hash.hex())
.where(self.received_offer_is_not_paid)
.where(self.received_offer_is_not_expired)
@@ -761,21 +753,16 @@ class SqueakDb:
with self.get_connection() as connection:
result = connection.execute(s)
rows = result.fetchall()
- offers_with_peer = [
- self._parse_received_offer_with_peer(row) for row in rows]
- return offers_with_peer
+ offers = [
+ self._parse_received_offer(row)
+ for row in rows
+ ]
+ return offers
- def get_offer_with_peer(self, received_offer_id: int) -> Optional[ReceivedOfferWithPeer]:
+ def get_received_offer(self, received_offer_id: int) -> Optional[ReceivedOffer]:
""" Get offer with peer for an offer id. """
s = (
- select([self.received_offers, self.peers])
- .select_from(
- self.received_offers.outerjoin(
- self.peers,
- self.peers.c.host == self.received_offers.c.peer_host,
- self.peers.c.port == self.received_offers.c.peer_port,
- )
- )
+ select([self.received_offers])
.where(self.received_offers.c.received_offer_id == received_offer_id)
)
with self.get_connection() as connection:
@@ -783,24 +770,17 @@ class SqueakDb:
row = result.fetchone()
if row is None:
return None
- offer_with_peer = self._parse_received_offer_with_peer(row)
- return offer_with_peer
+ offer = self._parse_received_offer(row)
+ return offer
def get_received_offer_for_squeak_and_peer(
self,
squeak_hash: bytes,
peer_address: PeerAddress,
- ) -> Optional[ReceivedOfferWithPeer]:
+ ) -> Optional[ReceivedOffer]:
""" Get offer with peer for a given peer address and squeak hash . """
s = (
- select([self.received_offers, self.peers])
- .select_from(
- self.received_offers.outerjoin(
- self.peers,
- self.peers.c.host == self.received_offers.c.peer_host,
- self.peers.c.port == self.received_offers.c.peer_port,
- )
- )
+ select([self.received_offers])
.where(self.received_offers.c.squeak_hash == squeak_hash.hex())
.where(self.received_offers.c.peer_host == peer_address.host)
.where(self.received_offers.c.peer_port == peer_address.port)
@@ -812,8 +792,8 @@ class SqueakDb:
row = result.fetchone()
if row is None:
return None
- offer_with_peer = self._parse_received_offer_with_peer(row)
- return offer_with_peer
+ offer = self._parse_received_offer(row)
+ return offer
def delete_expired_received_offers(self):
""" Delete all expired offers. """
@@ -1179,16 +1159,16 @@ class SqueakDb:
),
)
- def _parse_received_offer_with_peer(self, row) -> ReceivedOfferWithPeer:
- offer = self._parse_received_offer(row)
- if row[self.peers.c.peer_id] is None:
- peer = None
- else:
- peer = self._parse_squeak_peer(row)
- return ReceivedOfferWithPeer(
- received_offer=offer,
- peer=peer,
- )
+ # def _parse_received_offer_with_peer(self, row) -> ReceivedOfferWithPeer:
+ # offer = self._parse_received_offer(row)
+ # if row[self.peers.c.peer_id] is None:
+ # peer = None
+ # else:
+ # peer = self._parse_squeak_peer(row)
+ # return ReceivedOfferWithPeer(
+ # received_offer=offer,
+ # peer=peer,
+ # )
def _parse_sent_payment(self, row) -> SentPayment:
return SentPayment(
diff --git a/squeaknode/node/squeak_controller.py b/squeaknode/node/squeak_controller.py
index 9f7294cd..33327091 100644
--- a/squeaknode/node/squeak_controller.py
+++ b/squeaknode/node/squeak_controller.py
@@ -20,7 +20,6 @@ from squeaknode.core.block_range import BlockRange
from squeaknode.core.offer import Offer
from squeaknode.core.peer_address import PeerAddress
from squeaknode.core.received_offer import ReceivedOffer
-from squeaknode.core.received_offer_with_peer import ReceivedOfferWithPeer
from squeaknode.core.received_payment_summary import ReceivedPaymentSummary
from squeaknode.core.sent_offer import SentOffer
from squeaknode.core.sent_payment_summary import SentPaymentSummary
@@ -269,32 +268,31 @@ class SqueakController:
def delete_peer(self, peer_id: int):
self.squeak_db.delete_peer(peer_id)
- def get_received_offers_with_peer(self, squeak_hash: bytes) -> List[ReceivedOfferWithPeer]:
- return self.squeak_db.get_received_offers_with_peer(squeak_hash)
+ def get_received_offers(self, squeak_hash: bytes) -> List[ReceivedOffer]:
+ return self.squeak_db.get_received_offers(squeak_hash)
def get_received_offer_for_squeak_and_peer(
self,
squeak_hash: bytes,
peer_addresss: PeerAddress,
- ) -> Optional[ReceivedOfferWithPeer]:
+ ) -> Optional[ReceivedOffer]:
return self.squeak_db.get_received_offer_for_squeak_and_peer(
squeak_hash,
peer_addresss,
)
- def get_buy_offer_with_peer(self, received_offer_id: int) -> Optional[ReceivedOfferWithPeer]:
- return self.squeak_db.get_offer_with_peer(
+ def get_received_offer(self, received_offer_id: int) -> Optional[ReceivedOffer]:
+ return self.squeak_db.get_received_offer(
received_offer_id)
def pay_offer(self, received_offer_id: int) -> int:
# Get the offer from the database
- received_offer_with_peer = self.squeak_db.get_offer_with_peer(
+ received_offer = self.squeak_db.get_received_offer(
received_offer_id)
- if received_offer_with_peer is None:
+ if received_offer is None:
raise Exception("Received offer with id {} not found.".format(
received_offer_id,
))
- received_offer = received_offer_with_peer.received_offer
logger.info("Paying received offer: {}".format(received_offer))
sent_payment = self.squeak_core.pay_offer(received_offer)
sent_payment_id = self.squeak_db.insert_sent_payment(sent_payment)