接着上一篇,这里继续整合交易类。

import datetime
#交易类,后期需要整合公钥,私钥
class Transaction:
  #payer 付款方,receiver收款方
  def __init__(self,payer,receiver,money):
    self.payer = payer
    self.receiver = receiver
    self.money = money
    self.timestamp = datetime.datetime.now() #交易时间
  def __repr__(self):
    return str(self.payer)+" pay "+str(self.receiver)+" "+str(self.money)+" "+str(self.timestamp)
if __name__=="__main__":
  t = Transaction("yicheng","ddd",100)
  print(t)

测试模块:

if __name__=="__main__":
  t1 = Transaction("yicheng", "ddd1", 100)
  t2 = Transaction("yicheng", "ddd2", 200)
  t3 = Transaction("yicheng", "ddd3", 300)
  m1 = DaDaMessage(t1)
  m2 = DaDaMessage(t2)
  m3 = DaDaMessage(t3)
  try:
    m1.seal()
    m2.link(m1)
    m2.seal()
    m3.link(m2)
    m3.seal()
    #m1.hash = "0xaaaajjjjj"
    #m1.data = "I don't love "
    m1.validate()
    m2.validate()
    m3.validate()
    print(m1)
    print(m2)
    print(m3)
  except InvalidateMessage as e:
    print(e)

查看打印结果:

python交易记录整合交易类详解

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com