예제 #1
0
  def deserialize(self, l):
    self.sig=decode(l[0])
    self.pub=l[1]
    self.pub=loadPublic(self.pub)
    self.time=l[2]
    self.cmd=l[3]
    self.coin=Coin()
    self.coin.deserialize(l[4])

    if len(l)==6:
      if self.cmd=='create':
        self.args=l[5]
      else:
        self.args=loadPublic(l[5])
예제 #2
0
def send(args):
    to = args[0]

    f = open("participants.json", "rb")
    participants = json.loads(f.read())
    f.close()

    if not to in participants:
        print("Unknown participant: " + str(to))
        return

    toPub = participants[to]
    to = loadPublic(toPub, format="PEM")

    (pub, priv) = loadKeys("GitBank")

    cs = Coins("GitBank")
    coin = cs.get()

    if not coin:
        print("No coins!")
        return

    receipt = Send(None, pub, epoch(), coin, to)
    receipt.setPrivate(priv)
    receipt.sign()

    receipts = Receipts("GitBank")
    receipts.add(receipt)
예제 #3
0
파일: send.py 프로젝트: antiface/CreditCoin
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()