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. Spring入门第一课:Spring基础与配置Bean

    1.入门 Spring是简化java开发的一个框架,其中IoC和AOP是Spring的两个重要核心.由于Spring是非侵入性的,通过Ioc容器来管理bean的生命周期,还整合了许多其他的优秀框架,所 ...

  2. jQuery 属性操作 - addClass() 和 removeClass() 方法

    实例 向第一个 p 元素添加一个类: $("button").click(function(){ $("p:first").addClass("int ...

  3. PPTP

    一: VPN企业应用分类 1:远程访问VPN服务 员工个人电脑通过远程拨号到企业办公网络,如公司的OA系统. 运维人员远程拨号到DC机房,远程维护服务器. 2:企业内部网络之间VPN服务 公司分支机构 ...

  4. 附件上传——mysql blob类型的数据(springboot)1

    作为一个初出茅庐的菜鸟,这几天做了一下附件的上传与下载,附件文件存储在mysql中,数据类型为blob.在此做一下总结.望指正. 一.先总结附件的上传.(实质是将文件传到controller,后处理成 ...

  5. 【mongdb主从复制和同步】

    主从同步: Master: Slave: 副本集: #在卷本中加任意主机 #登录从 #登录主 #同步日志 #仲裁: 向集群中添加主机成为仲裁 #查看集群里的成员角色参数:

  6. yii学习笔记(3),自定义全局工具函数

    在平时开发是经常需要打印数据来调试 常见的打印方式有print_r和var_dump,但是这样打印出来格式很乱不好浏览 在打印函数前后加上<pre></pre>就可以将内容原样 ...

  7. 二、linux编译环境的搭建

    1.linux编译工具安装 vim安装:apt-get install vim 注意:使用C语言源代码语法加亮功能,需要配置文件/etc/vim/vimrc,加入代码syntaxon.文件后缀必须为. ...

  8. 03以太网帧结构(链路层 IEEE802.3)

    OSI七层模型:从底往上记(研究细致时用) 物理层:单位bit,字节byte,同轴电缆,光纤,二进制,比特流 数据链路层:帧,16进制,0-9,A-FMac地址->全网唯一性     mac地址 ...

  9. BAPC 2014 Preliminary

    // 题目链接: https://nanti.jisuanke.com/t/282041 //动态规划,重复利用子问题的最优,来求解当前最优问题 #include <iostream> # ...

  10. MySQL入门第一天——概述、数据表与约束操作

    一.概述 1.安装 初学MySQL,我们下载msi的安装版:http://dev.mysql.com/downloads/file.php?id=457403 安装的过程文字简述可以参考之前随笔:ht ...