Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit e3fdbdf

Browse files
committed
Refresh libbitcoin socket before check_for_payment api call
1 parent c50cb90 commit e3fdbdf

3 files changed

Lines changed: 27 additions & 34 deletions

File tree

api/restapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ def check_for_payment(self, request):
920920
with open(file_path, 'r') as filename:
921921
order = json.load(filename, object_pairs_hook=OrderedDict)
922922
c = Contract(self.db, contract=order, testnet=self.protocol.testnet)
923+
self.protocol.blockchain.refresh_connection()
923924
c.blockchain = self.protocol.blockchain
924925
c.notification_listener = self.mserver.protocol.get_notification_listener()
925926
c.is_purchase = True

net/rpcudp.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ class RPCProtocol:
3232
def __init__(self, sourceNode, router, waitTimeout=4):
3333
"""
3434
Args:
35-
proto: A protobuf `Node` object containing info about this node.
35+
sourceNode: A protobuf `Node` object containing info about this node.
3636
router: A `RoutingTable` object from dht.routing. Implies a `network.Server` object
3737
must be started first.
3838
waitTimeout: Consider it a connetion failure if no response
3939
within this time window.
40-
noisy: Whether or not to log the output for this class.
41-
testnet: The network parameters to use.
4240
4341
"""
4442
self.sourceNode = sourceNode
@@ -47,30 +45,23 @@ def __init__(self, sourceNode, router, waitTimeout=4):
4745
self._outstanding = {}
4846
self.log = Logger(system=self)
4947

50-
def receive_message(self, datagram, connection, ban_score):
51-
m = Message()
52-
try:
53-
m.ParseFromString(datagram)
54-
sender = Node(m.sender.guid,
55-
m.sender.nodeAddress.ip,
56-
m.sender.nodeAddress.port,
57-
m.sender.signedPublicKey,
58-
None if not m.sender.HasField("relayAddress") else
59-
(m.sender.relayAddress.ip, m.sender.relayAddress.port),
60-
m.sender.natType,
61-
m.sender.vendor)
62-
except Exception:
63-
# If message isn't formatted property then ignore
64-
self.log.warning("received unknown message from %s, ignoring" % str(connection.dest_addr))
65-
return False
66-
67-
if m.testnet != self.multiplexer.testnet:
48+
def receive_message(self, message, connection, ban_score):
49+
sender = Node(message.sender.guid,
50+
message.sender.nodeAddress.ip,
51+
message.sender.nodeAddress.port,
52+
message.sender.signedPublicKey,
53+
None if not message.sender.HasField("relayAddress") else
54+
(message.sender.relayAddress.ip, message.sender.relayAddress.port),
55+
message.sender.natType,
56+
message.sender.vendor)
57+
58+
if message.testnet != self.multiplexer.testnet:
6859
self.log.warning("received message from %s with incorrect network parameters." %
6960
str(connection.dest_addr))
7061
connection.shutdown()
7162
return False
7263

73-
if m.protoVer < PROTOCOL_VERSION:
64+
if message.protoVer < PROTOCOL_VERSION:
7465
self.log.warning("received message from %s with incompatible protocol version." %
7566
str(connection.dest_addr))
7667
connection.shutdown()
@@ -79,32 +70,33 @@ def receive_message(self, datagram, connection, ban_score):
7970
# Check that the GUID is valid. If not, ignore
8071
if self.router.isNewNode(sender):
8172
try:
82-
pubkey = m.sender.signedPublicKey[len(m.sender.signedPublicKey) - 32:]
73+
pubkey = message.sender.signedPublicKey[len(message.sender.signedPublicKey) - 32:]
8374
verify_key = nacl.signing.VerifyKey(pubkey)
84-
verify_key.verify(m.sender.signedPublicKey)
85-
h = nacl.hash.sha512(m.sender.signedPublicKey)
75+
verify_key.verify(message.sender.signedPublicKey)
76+
h = nacl.hash.sha512(message.sender.signedPublicKey)
8677
pow_hash = h[64:128]
87-
if int(pow_hash[:6], 16) >= 50 or hexlify(m.sender.guid) != h[:40]:
78+
if int(pow_hash[:6], 16) >= 50 or hexlify(message.sender.guid) != h[:40]:
8879
raise Exception('Invalid GUID')
8980

9081
except Exception:
9182
self.log.warning("received message from sender with invalid GUID, ignoring")
9283
connection.shutdown()
9384
return False
9485

95-
if m.sender.vendor:
96-
self.db.VendorStore().save_vendor(m.sender.guid.encode("hex"), m.sender.SerializeToString())
86+
if message.sender.vendor:
87+
self.db.VendorStore().save_vendor(message.sender.guid.encode("hex"),
88+
message.sender.SerializeToString())
9789

98-
msgID = m.messageID
99-
if m.command == NOT_FOUND:
90+
msgID = message.messageID
91+
if message.command == NOT_FOUND:
10092
data = None
10193
else:
102-
data = tuple(m.arguments)
94+
data = tuple(message.arguments)
10395
if msgID in self._outstanding:
10496
self._acceptResponse(msgID, data, sender)
105-
elif m.command != NOT_FOUND:
97+
elif message.command != NOT_FOUND:
10698
#ban_score.process_message(m)
107-
self._acceptRequest(msgID, str(Command.Name(m.command)).lower(), data, sender, connection)
99+
self._acceptRequest(msgID, str(Command.Name(message.command)).lower(), data, sender, connection)
108100

109101
def _acceptResponse(self, msgID, data, sender):
110102
if data is not None:

net/wireprotocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def receive_message(self, datagram):
8282
m.sender.vendor)
8383
for processor in self.processors:
8484
if m.command in processor or m.command == NOT_FOUND:
85-
processor.receive_message(datagram, self.connection, self.ban_score)
85+
processor.receive_message(m, self.connection, self.ban_score)
8686
except Exception:
8787
# If message isn't formatted property then ignore
8888
self.log.warning("received unknown message from %s, ignoring" % self.addr)

0 commit comments

Comments
 (0)