def show_address(self): f = Tk() label = Label(f, text='PyCoin Address') label.pack() k = SHA.new(KeyStore.getPublicKey().exportKey()).hexdigest() key = Text(f, width=42, height=1) key.insert(INSERT, k) key.pack()
def initApp(self): #Connect Here self.client = P2PClientManager.getClient(port=random.randint(40000, 60000)) self.client.subscribe(Message.NEW_TRANSACTION, self.update_balance) self.client.subscribe_to_info(self.update_status) t = threading.Thread(target=self.start_miner) t.start() if not self.db.hasRanBefore(): c = CoinBase(owner=KeyStore.getPrivateKey(), amt=100) c.finish_transaction() self.db.setRanBefore() #messagebox.showinfo('Welcome', 'This is your first time running the app. You get to start off with 100 PyCoins!') #Get balance, Save to variable below self.coin_balance.set(str(KeyStore.get_balance())) print('PyCoin Address: ', SHA.new(KeyStore.getPublicKey().exportKey()).hexdigest()) log.debug("GUI created")
def __init__(self, host, port=None): if port: P2PClient.CLIENT_PORT = port else: P2PClient.CLIENT_PORT = 65000 log.debug('Creating client on port... %d', self.CLIENT_PORT) self.p2pserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM) log.debug('Connecting to host...') self.p2pserver.connect((host, P2PClient.PORT)) self.myIP = self.p2pserver.getsockname()[0] # the ip of this machine self.myPublicKey = KeyStore.getPublicKey().exportKey() self.trans_queue = [] self.received_trans = [] self.received_blocks = [] self.peer_list = [] self.trans_listeners = [] self.block_listeners = [] self.keyTable = {}
peer_list = pickle.loads(port) log.debug('peer list: %s', peer_list) client.update_peer_list(peer_list) client.broadcast_info('New peer added') if __name__ == '__main__': import sys from keystore import KeyStore from TransactionManager.transaction import Transaction port = sys.argv[1] P2PClient.CLIENT_PORT = int(port) trans = Transaction() trans.add_input(Transaction.Input(20, b'FFFFFFFF')) trans.add_output(Transaction.Output(10, KeyStore.getPublicKey())) # just pay to ourselves for now trans.add_input(Transaction.Input(5, b'FFFFFFFF')) s = trans.build_struct() c = P2PClient() c.send_message(Message.add) c.send_message(Message.NEW_TRANSACTION, s) import time time.sleep(5) trans = Transaction() trans.add_input(Transaction.Input(100, b'FFFFFFFF')) trans.add_output(Transaction.Output(55, KeyStore.getPublicKey())) # just pay to ourselves for now trans.add_input(Transaction.Input(4, b'FFFFFFFF')) s = trans.build_struct()
return P2PClientManager.p2p def deleteClient(): log.info('Deleting client...') P2PClientManager.p2p.stop() P2PClientManager.p2p = None if __name__ == '__main__': import sys from keystore import KeyStore port = sys.argv[1] P2PClient.CLIENT_PORT = int(port) trans = Transaction() trans.add_input(Transaction.Input(20, b'FFFFFFFF', 0)) trans.add_output(Transaction.Output(10, KeyStore.getPublicKey())) # just pay to ourselves for now trans.add_input(Transaction.Input(5, b'FFFFFFFF', 0)) s = trans.build_struct() c = P2PClient() c.send_message(Message.add) c.send_message(Message.NEW_TRANSACTION, s) import time time.sleep(5) trans = Transaction() trans.add_input(Transaction.Input(100, b'FFFFFFFF', 0)) trans.add_output(Transaction.Output(55, KeyStore.getPublicKey())) # just pay to ourselves for now trans.add_input(Transaction.Input(4, b'FFFFFFFF', 0)) s = trans.build_struct()
peer_list = pickle.loads(port) log.debug('peer list: %s', peer_list) client.update_peer_list(peer_list) client.broadcast_info('New peer added') if __name__ == '__main__': import sys from keystore import KeyStore from TransactionManager.transaction import Transaction port = sys.argv[1] P2PClient.CLIENT_PORT = int(port) trans = Transaction() trans.add_input(Transaction.Input(20, b'FFFFFFFF')) trans.add_output(Transaction.Output( 10, KeyStore.getPublicKey())) # just pay to ourselves for now trans.add_input(Transaction.Input(5, b'FFFFFFFF')) s = trans.build_struct() c = P2PClient() c.send_message(Message.add) c.send_message(Message.NEW_TRANSACTION, s) import time time.sleep(5) trans = Transaction() trans.add_input(Transaction.Input(100, b'FFFFFFFF')) trans.add_output(Transaction.Output( 55, KeyStore.getPublicKey())) # just pay to ourselves for now trans.add_input(Transaction.Input(4, b'FFFFFFFF'))