from __future__ import unicode_literals

import json
from time import sleep, time # 中文编码
def encode_str(_str):
try:
return bytearray(_str, "utf-8").hex()
except Exception as e:
print(e) # 中文解码
def decode_str(_str):
try:
return bytearray.fromhex(_str).decode("utf-8")
except Exception as e:
print(e) MATH_BYTECODE = "6060604052341561000f57600080fd5b5b60c08061001e6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663696c75c68114603c575b600080fd5b3415604657600080fd5b60526004356024356054565b005b817f3ea5d667934df8dbb4978ddd30e65375fd1bf06f8ed39d033379c5cd3efb102c428360405191825260208201526040908101905180910390a25b50505600a165627a7a723058208d6649bbcad0893ba1e52ea3904adaf2ff4b9ed80f71f5ac5c6b982ce5bac3a20029"
# 6060604052341561000f57600080fd5b5b6105078061001f6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630c90d8448114610048578063d10fa94614610111575b600080fd5b341561005357600080fd5b61009960046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506101e395505050505050565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100d65780820151818401525b6020016100bd565b50505050905090810190601f1680156101035780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561011c57600080fd5b61016260046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506102fa95505050505050565b604051821515815260406020820181815290820183818151815260200191508051906020019080838360005b838110156101a75780820151818401525b60200161018e565b50505050905090810190601f1680156101d45780820380516001836020036101000a031916815260200191505b50935050505060405180910390f35b6101eb610429565b600080836040518082805190602001908083835b6020831061021f57805182525b601f1990920191602091820191016101ff565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390209050806001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102ec5780601f106102c1576101008083540402835291602001916102ec565b820191906000526020600020905b8154815290600101906020018083116102cf57829003601f168201915b505050505091505b50919050565b6000610304610429565b60408051908101604052808481526020016040805190810160405280600981526020017fe4b88de5ad98e59ca800000000000000000000000000000000000000000000008152508152506000846040518082805190602001908083835b6020831061038157805182525b601f199092019160209182019101610361565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040519081900390208151819080516103c992916020019061043b565b506020820151816001019080516103e492916020019061043b565b50905050600060408051908101604052600681527f6f6b6f6b31310000000000000000000000000000000000000000000000000000602082015290925090505b915091565b60206040519081016040526000815290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061047c57805160ff19168380011785556104a9565b828001600101855582156104a9579182015b828111156104a957825182559160200191906001019061048e565b5b506104b69291506104ba565b5090565b6104d891905b808211156104b657600081556001016104c0565b5090565b905600a165627a7a72305820faf711785ac7369219291016aa91535aa22004c60da82a8fcd956777c3b7a7000029
MATH_ABI = json.loads("""
[
{
"constant": false,
"inputs": [
{
"name": "_type",
"type": "bytes32"
},
{
"name": "_metadata",
"type": "bytes32"
}
],
"name": "publish",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_type",
"type": "bytes32"
},
{
"indexed": false,
"name": "_created",
"type": "uint256"
},
{
"indexed": false,
"name": "_metadata",
"type": "bytes32"
}
],
"name": "ArticleOperationLog",
"type": "event"
}
]
""") import web3.personal as wp
from web3 import Web3, HTTPProvider web3 = Web3(HTTPProvider('http://localhost:8545'))
web3.eth.defaultAccount = b'0x3364aa6342c8c18' print("unlockAccount")
p = wp.Personal(web3)
print(p.unlockAccount("0x336394f4b93aa6342c8c18", "123456"))
print("unlockAccount ok") MathContract = web3.eth.contract(
abi=MATH_ABI,
# bytecode=MATH_BYTECODE,
) # deploy_txn = MathContract.deploy()
# transaction={
# 'from': b'0x336495440ce8dd55029bd394f4b93aa6342c8c18',
# 'value': 12345,
# },
# args=('DGD', 18) print("isConnected:", web3.isConnected()) # print(deploy_txn)
# deploy_receipt = web3.eth.getTransactionReceipt("0x71ce48069f2e17079c2cf016f40bd47d995f4c77aab74d12ae89a9cf13cfeb77")
# print(deploy_receipt, "\n\n") # print(deploy_txn)
# deploy_receipt = web3.eth.getTransactionReceipt(b"0xb2e4aacfbd147ddd6f807c0f4d47cc77c6a21ce7e2c9cbd17b7ba3d410473bd4")
# print(deploy_receipt)
# assert deploy_receipt is not None # deploy_receipt["contractAddress"]
# math_contract = MathContract(address=deploy_receipt["contractAddress"])
import re def my_callback(a):
# print(a)
args = a.get("args")
print(decode_str(re.split(r"\W+", args.get("_type"))[0]))
print(str(args.get("_created")))
print(decode_str(re.split(r"\W+", args.get("_metadata"))[0]))
print("\n\n") def my_callback1(a):
print("\n\n\n\npastEvents")
# print(a)
args = a.get("args")
print(decode_str(re.split(r"\W+", args.get("_type"))[0]))
print(str(args.get("_created")))
print(decode_str(re.split(r"\W+", args.get("_metadata"))[0])) math_contract = MathContract(address="0x8851accb27fc4b149bda886d6d579f2fb5c1a492")
# math_contract.on("ArticleOperationLog",{'filter': {'_type': 'hello'}}).watch(my_callback) # math_contract.on("ArticleOperationLog").watch(my_callback)
# math_contract.on("ArticleOperationLog", {"filter": {"_type": encode_str("hello")}}).watch(my_callback) # 历史日志
math_contract.pastEvents("ArticleOperationLog", {"filter": {"_type": encode_str("hello1")}}).watch(my_callback1) # 历史日志
# math_contract.pastEvents("ArticleOperationLog").watch(my_callback1) while 1:
# math_contract.transact().publish(encode_str("hello1"), encode_str("hello1上海"))
print(time())
sleep(2) # _a = "1234562" # print(math_contract.encodeABI("addDNA", args=(_a,_a,_a))) # 发送一个tx到区块链上
# print(math_contract.transact().addDNA(_a, _a, _a)) # 发送一个tx到本地执行,不会写入到区块链上
# print(math_contract.call().addDNA(_a, _a, _a))
# print(math_contract.call().getDNA(_a))

python 智能合约日志操作的更多相关文章

  1. python中的日志操作和发送邮件

    1.python中的日志操作 安装log模块:pip install nnlog 参数:my_log = nnlog.Logger('server_log.log',level='debug',bac ...

  2. [Python之路] 日志操作

    使用logging模块来写日志 日志直接输出到准备输出 import logging logging.basicConfig(level=logging.WARNING, format="% ...

  3. EOS开发基础之六:使用cleos命令行客户端操作EOS——智能合约之eosio.msig和eosio.system

    上一节我们搞了老半天,也没整明白Exchange这个合约到底干啥用的.就它官方提供的说法,是用于货币的创造和交易.我没整明白,所以去看了下代码,发现代码头文件里面有下面这段话: This contra ...

  4. EOS开发基础之四:使用cleos命令行客户端操作EOS——智能合约之eosio.bios和eosio.token

    现实世界中的合约,简单地说,是一个参与活动的所有人都需要遵循的协议.合约可以是正式的法律合同(例如,金融交易),或者是简单的游戏规则.典型的活动可以是诸如资金转移(在金融合约的情况下)或游戏动作(在游 ...

  5. 从零开始的Python学习Episode 14——日志操作

    日志操作 一.logging模块 %(message)s 日志信息 %(levelno)s 日志级别 datefmt 设置时间格式 filename 设置日志保存的路径 level 设置日志记录的级别 ...

  6. Python之日志操作(logging)

    import logging   1.自定义日志级别,日志格式,输出位置 logging.basicConfig( level=logging.DEBUG, format='%(asctime)s | ...

  7. Hyperledger Fabric Chaincode for Operators——实操智能合约

    什么是Chaincode(智能合约)? chaincode是一个程序,它是使用Go语言编写的,最终在Java等其他编程语言中实现了指定的接口.chaincode运行在一个被背书peer进程独立出来的安 ...

  8. 【精解】EOS智能合约演练

    EOS,智能合约,abi,wasm,cleos,eosiocpp,开发调试,钱包,账户,签名权限 热身 本文旨在针对EOS智能合约进行一个完整的实操演练,过程中深入熟悉掌握整个EOS智能合约的流程,过 ...

  9. 以太坊智能合约虚拟机(EVM)原理与实现

    以太坊 EVM原理与实现 以太坊底层通过EVM模块支持合约的执行与调用,调用时根据合约地址获取到代码,生成环境后载入到EVM中运行.通常智能合约的开发流程是用solidlity编写逻辑代码,再通过编译 ...

随机推荐

  1. 【Oracle】Oracle安装配置、创建数据库实例及用户和连接

    https://blog.csdn.net/wudiyong22/article/details/78904361 参考资料:https://www.cnblogs.com/hoobey/p/6010 ...

  2. mpvue开发美团外卖点餐小程序

    mpvue-meituan mpvue-meituan 是一款使用mpvue开发的实战小程序项目,完全仿制美团官方外卖点餐小程序开发而成,项目的框架结构完全按照企业开发架构搭建而成.结合了原生小程序的 ...

  3. UICollectionView的水平流水布局自定义layout

    最近做合创共美的商城项目,遇到发货地址的不配送地区,是做一个弹出框,弹出框的布局是根据地名字数长短不齐的标签. 本来也可以用tableview来做的.只不过多建几个tableviewcell就可以了. ...

  4. 网站程序application, session, cookie区别的一点小总结

    cookie:是存放于本地的文件,可以设置期限,一般来讲是比较小文本或键值对等,主要用于记录用户浏览信息,账号密码等等.可以让人们的登录变得方便,因为有了cookie,在一段时间内就可以自动登录以前所 ...

  5. 微信小程序新版用户授权方式处理

    最新更新(2018-12-27): 最近做了改版,做成默认进来就是首页,然后去判断有没有用户信息,没有的话再去判断用没授权过,如果授权过直接自动去获取,没有的话再跳转到授权页面.因为用户授权主要就是针 ...

  6. webstorm如何支持markdown

    首先安装markdown 插件 第一个即可.

  7. java8的新特性,Collections.sort(排序的List集合)的使用,对list封装Map里面的某个值进行排序

    --------------------------对简单list的排序---------------------------------- List<Integer> list = ne ...

  8. 如何解决php无法存储session中的问题?

    场景:前几天在一个技术群里面,看到一个小伙伴提出了一个问题------在thinkphp框架中,使用用户登录将用户信息存储在session,始终是无法存储的. 解决思路:先查看了代码逻辑(确证无误)- ...

  9. 请求报文的方法及get与post的区别

    请求报文的方法及get与post的区别 请求的起始以方法作为开始,方法用来告诉服务器要如何做. 在开发中通常有两种请求方式. get方式: 是以实体的方式得到由请求 URI 所指定资源的信息,如果请求 ...

  10. Java设计模式(18)——行为模式之迭代子模式(Iterator)

    一.概述 概念 UML简图 // Aggregate:聚集(集合) 角色 抽象迭代子:定义遍历元素所需要的接口 具体迭代子:实现抽象迭代子接口,保持游标 聚集/具体聚集:定义/实现创建迭代子对象的接口 ...