update dummy account node

This commit is contained in:
zixuanzh 2019-03-31 22:16:49 -04:00 committed by Stuckinaboot
parent 87269a9524
commit 974cb0b06f

View File

@ -37,6 +37,7 @@ class DummyAccountNode():
We use create as this serves as a factory function and allows us We use create as this serves as a factory function and allows us
to use async await, unlike the init function to use async await, unlike the init function
""" """
print ("**DUMMY** CREATE ACCOUNT NODE")
self = DummyAccountNode() self = DummyAccountNode()
libp2p_node = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"]) libp2p_node = await new_node(transport_opt=["/ip4/127.0.0.1/tcp/0"])
@ -54,14 +55,17 @@ class DummyAccountNode():
""" """
while True: while True:
incoming = await self.q.get() incoming = await self.q.get()
rpc_incoming = rpc_pb2.RPC() print ("**DUMMY** HANDLE INCOMING")
rpc_incoming.ParseFromString(incoming) print (incoming)
for message in rpc_incoming.publish: print ("========================")
msg_comps = message.split(",")
if msg_comps[0] == "send": msg_comps = incoming.data.decode('utf-8').split(",")
self.handle_send_crypto(msg_comps[1], msg_comps[2], int(msg_comps[3])) print (msg_comps)
elif msg_comps[0] == "set": print ("--------")
self.handle_set_crypto_for_user(msg_comps[1], int(msg_comps[2])) if msg_comps[0] == "send":
self.handle_send_crypto(msg_comps[1], msg_comps[2], int(msg_comps[3]))
elif msg_comps[0] == "set":
self.handle_set_crypto(msg_comps[1], int(msg_comps[2]))
async def setup_crypto_networking(self): async def setup_crypto_networking(self):
""" """
@ -103,6 +107,7 @@ class DummyAccountNode():
:param dest_user: user to send crypto to :param dest_user: user to send crypto to
:param amount: amount of crypto to send :param amount: amount of crypto to send
""" """
print ("**DUMMY** IN HANDLE SEND CRYPTO")
if source_user in self.balances: if source_user in self.balances:
self.balances[source_user] -= amount self.balances[source_user] -= amount
else: else:
@ -113,12 +118,15 @@ class DummyAccountNode():
else: else:
self.balances[dest_user] = amount self.balances[dest_user] = amount
def handle_set_crypto_for_user(self, dest_user, amount): def handle_set_crypto(self, dest_user, amount):
""" """
Handle incoming set_crypto message Handle incoming set_crypto message
:param dest_user: user to set crypto for :param dest_user: user to set crypto for
:param amount: amount of crypto :param amount: amount of crypto
""" """
print ("**DUMMY** IN HANDLE SET CRYPTO")
print (type (dest_user))
print (amount)
self.balances[dest_user] = amount self.balances[dest_user] = amount
def get_balance(self, user): def get_balance(self, user):
@ -127,6 +135,9 @@ class DummyAccountNode():
:param user: user to get balance for :param user: user to get balance for
:return: balance of user :return: balance of user
""" """
print ("GET BALACNCE")
print (user)
print (self.balances)
if user in self.balances: if user in self.balances:
return self.balances[user] return self.balances[user]
else: else:
@ -155,7 +166,4 @@ def generate_RPC_packet(origin_id, topics, msg_content, msg_id):
)]) )])
packet.publish.extend([message]) packet.publish.extend([message])
print ("HEYHO")
print (packet)
return packet return packet