mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-15 12:50:47 +02:00
Include peer name in sent payment result (#433)
* Include peer_name sent payment rpc result * Show peer name in sent payment in frontend
This commit is contained in:
parent
298d34efe8
commit
fa9a84c1df
6 changed files with 63 additions and 18 deletions
|
|
@ -31,6 +31,10 @@ export default function SentPayment({
|
|||
|
||||
const history = useHistory();
|
||||
|
||||
const peerName = sentPayment.getPeerName();
|
||||
const peerId = sentPayment.getPeerId();
|
||||
const peerDisplay = peerName ? peerName : peerId;
|
||||
|
||||
const goToSqueakPage = (hash) => {
|
||||
history.push("/app/squeak/" + hash);
|
||||
};
|
||||
|
|
@ -132,7 +136,7 @@ export default function SentPayment({
|
|||
<Link href="#"
|
||||
onClick={onPeerClick}
|
||||
>
|
||||
<span> </span>{sentPayment.getPeerId()}
|
||||
<span> </span>{peerDisplay}
|
||||
</Link>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -585,26 +585,29 @@ message SentPayment {
|
|||
/// The peer id
|
||||
int32 peer_id = 3;
|
||||
|
||||
/// The peer name
|
||||
string peer_name = 4;
|
||||
|
||||
/// The squeak hash
|
||||
string squeak_hash = 4;
|
||||
string squeak_hash = 5;
|
||||
|
||||
/// The preimage hash
|
||||
string preimage_hash = 5;
|
||||
string preimage_hash = 6;
|
||||
|
||||
/// The preimage
|
||||
string preimage = 6;
|
||||
string preimage = 7;
|
||||
|
||||
/// The price_msat
|
||||
int64 price_msat = 7;
|
||||
int64 price_msat = 8;
|
||||
|
||||
/// The seller node pubkey
|
||||
string node_pubkey = 8;
|
||||
string node_pubkey = 9;
|
||||
|
||||
/// Valid preimage
|
||||
bool preimage_is_valid = 9;
|
||||
bool preimage_is_valid = 10;
|
||||
|
||||
/// time_ms
|
||||
int64 time_ms = 10;
|
||||
int64 time_ms = 11;
|
||||
}
|
||||
|
||||
message SyncSqueakRequest {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from squeaknode.admin.util import squeak_entry_to_message
|
|||
from squeaknode.admin.util import squeak_peer_to_message
|
||||
from squeaknode.admin.util import squeak_profile_to_message
|
||||
from squeaknode.admin.util import offer_entry_to_message
|
||||
from squeaknode.admin.util import sent_payment_to_message
|
||||
from squeaknode.admin.util import sent_payment_with_peer_to_message
|
||||
from squeaknode.admin.util import sync_result_to_message
|
||||
from squeaknode.admin.util import squeak_entry_to_detail_message
|
||||
|
||||
|
|
@ -391,7 +391,7 @@ class SqueakAdminServerHandler(object):
|
|||
def handle_get_sent_payments(self, request):
|
||||
logger.info("Handle get sent payments")
|
||||
sent_payments = self.squeak_node.get_sent_payments()
|
||||
sent_payment_msgs = [sent_payment_to_message(sent_payment) for sent_payment in sent_payments]
|
||||
sent_payment_msgs = [sent_payment_with_peer_to_message(sent_payment) for sent_payment in sent_payments]
|
||||
return squeak_admin_pb2.GetSentPaymentsReply(
|
||||
sent_payments=sent_payment_msgs,
|
||||
)
|
||||
|
|
@ -400,7 +400,7 @@ class SqueakAdminServerHandler(object):
|
|||
sent_payment_id = request.sent_payment_id
|
||||
logger.info("Handle get sent payment with id: {}".format(sent_payment_id))
|
||||
sent_payment = self.squeak_node.get_sent_payment(sent_payment_id)
|
||||
sent_payment_msg = sent_payment_to_message(sent_payment)
|
||||
sent_payment_msg = sent_payment_with_peer_to_message(sent_payment)
|
||||
return squeak_admin_pb2.GetSentPaymentReply(
|
||||
sent_payment=sent_payment_msg,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -73,13 +73,16 @@ def offer_entry_to_message(offer_entry):
|
|||
invoice_expiry=offer.invoice_expiry,
|
||||
)
|
||||
|
||||
def sent_payment_to_message(sent_payment):
|
||||
if sent_payment is None:
|
||||
def sent_payment_with_peer_to_message(sent_payment_with_peer):
|
||||
if sent_payment_with_peer is None:
|
||||
return None
|
||||
sent_payment = sent_payment_with_peer.sent_payment
|
||||
peer = sent_payment_with_peer.peer
|
||||
return squeak_admin_pb2.SentPayment(
|
||||
sent_payment_id=sent_payment.sent_payment_id,
|
||||
offer_id=sent_payment.offer_id,
|
||||
peer_id=sent_payment.peer_id,
|
||||
peer_name=peer.peer_name,
|
||||
squeak_hash=sent_payment.squeak_hash,
|
||||
preimage_hash=sent_payment.preimage_hash,
|
||||
preimage=sent_payment.preimage,
|
||||
|
|
|
|||
9
squeaknode/core/sent_payment_with_peer.py
Normal file
9
squeaknode/core/sent_payment_with_peer.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from collections import namedtuple
|
||||
|
||||
SentPaymentWithPeer = namedtuple(
|
||||
"SentPaymentWithPeer",
|
||||
[
|
||||
"sent_payment",
|
||||
"peer",
|
||||
],
|
||||
)
|
||||
|
|
@ -22,6 +22,7 @@ from squeak.core import CSqueak
|
|||
from squeaknode.blockchain.util import parse_block_header
|
||||
from squeaknode.core.offer import Offer
|
||||
from squeaknode.core.offer_with_peer import OfferWithPeer
|
||||
from squeaknode.core.sent_payment_with_peer import SentPaymentWithPeer
|
||||
from squeaknode.core.squeak_entry import SqueakEntry
|
||||
from squeaknode.core.squeak_entry_with_profile import SqueakEntryWithProfile
|
||||
from squeaknode.server.squeak_peer import SqueakPeer
|
||||
|
|
@ -900,7 +901,13 @@ class SqueakDb:
|
|||
def get_sent_payments(self):
|
||||
""" Get all sent payments. """
|
||||
s = (
|
||||
select([self.sent_payments])
|
||||
select([self.sent_payments, self.peers])
|
||||
.select_from(
|
||||
self.offers.outerjoin(
|
||||
self.peers,
|
||||
self.peers.c.id == self.sent_payments.c.peer_id,
|
||||
)
|
||||
)
|
||||
.order_by(
|
||||
self.sent_payments.c.created.desc(),
|
||||
)
|
||||
|
|
@ -908,16 +915,25 @@ class SqueakDb:
|
|||
with self.get_connection() as connection:
|
||||
result = connection.execute(s)
|
||||
rows = result.fetchall()
|
||||
sent_payments = [self._parse_sent_payment(row) for row in rows]
|
||||
sent_payments = [self._parse_sent_payment_with_peer(row) for row in rows]
|
||||
return sent_payments
|
||||
|
||||
def get_sent_payment(self, sent_payment_id):
|
||||
""" Get sent payment by id. """
|
||||
s = select([self.sent_payments]).where(self.sent_payments.c.sent_payment_id == sent_payment_id)
|
||||
s = (
|
||||
select([self.sent_payments, self.peers])
|
||||
.select_from(
|
||||
self.offers.outerjoin(
|
||||
self.peers,
|
||||
self.peers.c.id == self.sent_payments.c.peer_id,
|
||||
)
|
||||
)
|
||||
.where(self.sent_payments.c.sent_payment_id == sent_payment_id)
|
||||
)
|
||||
with self.get_connection() as connection:
|
||||
result = connection.execute(s)
|
||||
row = result.fetchone()
|
||||
return self._parse_sent_payment(row)
|
||||
return self._parse_sent_payment_with_peer(row)
|
||||
|
||||
def _parse_squeak_entry(self, row):
|
||||
if row is None:
|
||||
|
|
@ -1030,5 +1046,15 @@ class SqueakDb:
|
|||
price_msat=row["price_msat"],
|
||||
node_pubkey=row["node_pubkey"],
|
||||
preimage_is_valid=row["preimage_is_valid"],
|
||||
time_ms=row["created"],
|
||||
time_ms=row[self.sent_payments.c.created],
|
||||
)
|
||||
|
||||
def _parse_sent_payment_with_peer(self, row):
|
||||
if row is None:
|
||||
return None
|
||||
sent_payment = self._parse_sent_payment(row)
|
||||
peer = self._parse_squeak_peer(row)
|
||||
return SentPaymentWithPeer(
|
||||
sent_payment=sent_payment,
|
||||
peer=peer,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue