Exemple #1
0
def send(dir, coin, to):
 try:
  receipt=Send(None, pub, epoch(), coin, loadPublic(to))
  receipt.setPrivate(priv)
  receipt.sign()

  receipts=Receipts()
  receipts.load(dir+'/receipts.dat')
  receipts.add(receipt)

  smsg=json.dumps(receipt.save(True))

  print('sending')
  client=Client()
  yield client.connect('localhost', 7050)
  yield client.write(smsg+"\n")

  s=yield client.read_until("\n")
  msg=json.loads(s)
  receipt=Receive()
  receipt.load(msg)

  if receipt.cmd!='receive':
    print('Unknown command: '+str(receipt.cmd))
    return
  if receipt.args.save_pkcs1('DER')!=pub.save_pkcs1('DER'):
    print('Not me')
    return
  if not rsa.verify(str(receipt.sig), receipt.pub):
    print('Not verified')
    return

  cs.save(dir+'/coins.dat')
  receipts.add(receipt)
  print('saving '+str(len(receipts.receipts)))
  receipts.save(dir+'/receipts.dat')

  eventloop.halt()
 except Exception, e:
  print('Exception:')
  print(e)
  traceback.print_exc()
Exemple #2
0
def handle_recv(conn):
  print('connected')
  s=yield conn.read_until("\n")
  print('read')
  print(s)
  smsg=json.loads(s)

  receipts=Receipts()
  receipts.load(dir+'/receipts.dat')  
  
  receipt=Send()
  receipt.load(smsg)
  
  if receipt.cmd!='send':
    print('Unknown command: '+str(receipt.cmd))
    return
  if receipt.args!=pub:
    print('Not me: '+str(receipt.args)+' '+str(pub))
    return
  if not rsa.verify(str(receipt.sig), receipt.pub):
    print('Not verified')
    return
  cs.add(receipt.coin)
  cs.save(dir+'/coins.dat')
  receipts.add(receipt)
  receipts.save(dir+'/receipts.dat')

  receipt=Receive(None, pub, epoch(), receipt.coin, receipt.pub)
  receipt.setPrivate(priv)
  receipt.sign()
  receipts.add(receipt)
  receipts.save(dir+'/receipts.dat')    

  smsg=json.dumps(receipt.save(True))

  print('sending')  
  print(smsg)
  yield conn.write(smsg+"\n")
  print('sent')