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

yipeiwu_com6年前Python基础

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

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设计】。

相关文章

Python连接SQLServer2000的方法详解

本文实例讲述了Python连接SQLServer2000的方法。分享给大家供大家参考,具体如下: http://pymssql.sourceforge.net/  介绍PYTH...

批量获取及验证HTTP代理的Python脚本

HTTP暴力破解、撞库,有一些惯用的技巧,比如: 1. 在扫号人人网时,我遇到单个账号错误两次,强制要求输入验证码,而对方并未实施IP策略。 我采用维护10万(用户名,密码) 队列的方式...

Python操作csv文件实例详解

Python操作csv文件实例详解

一、Python读取csv文件 说明:以Python3.x为例 #读取csv文件方法1 import csv csvfile = open('csvWrite.csv',newl...

python openpyxl使用方法详解

openpyxl特点 openpyxl(可读写excel表)专门处理Excel2007及以上版本产生的xlsx文件,xls和xlsx之间转换容易 注意:如果文字编码是“gb2312”...

python reduce 函数使用详解

python reduce 函数使用详解

reduce() 函数在 python 2 是内置函数, 从python 3 开始移到了 functools 模块。 官方文档是这样介绍的 reduce(...) reduce(fu...