Unverified Commit b3939bed authored by cyjseagull's avatar cyjseagull Committed by GitHub
Browse files

Merge pull request #97 from coderkentzhang/refactor202003

Refactor202003
parents 8927d9cd edc33d5d
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/FISCO-BCOS)
bcosliteclientpy is free software: you can redistribute it and/or modify it
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0
(https://github.com/FISCO-BCOS/FISCO-BCOS)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it
under the terms of the MIT License as published by the Free Software Foundation
This project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
......@@ -14,10 +15,10 @@
import os
import sys
import platform
from client_config import client_config
from client_config import client_config
platsys = platform.system()
solc_bin = client_config.solc_path
solc_option = "--abi --bin --overwrite"
solc_option = "--abi --bin --bin-runtime --overwrite"
solc_default_output = "./contracts"
if platsys.lower().startswith("win"):
......@@ -90,7 +91,8 @@ def print_solc_url():
i += 1
print("{} ): {} : {}".format(i, url[0], url[1]))
print("\n>>>TIPS:")
print('''1. Download the solc binary according to your OS type (e.g. Linux/Windows) and solidity version.
print(
'''1. Download the solc binary according to your OS type (e.g. Linux/Windows) and solidity version.
2. Copy the solc binary to {python-sdk}/bin/solc/.
3. Make sure that the name of solc binary file is renamed to "solc",
or update the solc binary path constant in python-sdk/solcpy.py.''')
......
......@@ -32,6 +32,9 @@ cur_path=$(execute_cmd "pwd")
# build blockchain
function build_blockchain()
{
if [ -f "nodes/127.0.0.1/stop_all.sh" ];then
execute_cmd "bash nodes/127.0.0.1/stop_all.sh"
fi
execute_cmd "rm -rf nodes"
# download build_chain.sh
execute_cmd "curl -LO https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master/tools/build_chain.sh && chmod u+x build_chain.sh"
......@@ -64,7 +67,7 @@ function stop_nodes()
function getBlockNumber()
{
execute_cmd "python console.py getBlockNumber | grep -v INFO | awk -F'>' '{print \$3}' | awk '\$1=\$1'"
execute_cmd "python console.py getBlockNumber | grep -v INFO | awk -F':' '{print \$2}' | awk '\$1=\$1'"
}
# test the common jsonRPC interface
......@@ -308,7 +311,7 @@ function test_consensus_precompile()
function get_config_by_key()
{
key="${1}"
value=$(execute_cmd "python console.py \"getSystemConfigByKey\" \${key} | grep -v INFO | awk -F'>' '{print \$3}' | awk '\$1=\$1'")
value=$(execute_cmd "python console.py \"getSystemConfigByKey\" \${key} | grep -v INFO | awk -F':' '{print \$2}' | awk '\$1=\$1'")
echo "${value}"
}
......
......@@ -3,7 +3,9 @@
set -e
scan_code_script="python ~/cobra/cobra.py -t "
ignore_files=(.ci README.md)
ignore_files=(ci README.md console.py event_callback.py eth_account eth_abi \
eth_hash eth_keys eth_rlp eth_typing eth_utils tests gmssl \
hexbytes utils rlp client eth_account/account.py)
LOG_ERROR() {
content=${1}
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......@@ -34,13 +34,18 @@ from utils.abi import itertools, get_fn_abi_types_single
from eth_abi import decode_single
from utils.contracts import get_aligned_function_data
from client.gm_account import GM_Account
from eth_utils.crypto import CRYPTO_TYPE_GM
from eth_utils.crypto import CRYPTO_TYPE_GM
from client.signtransaction import SignTx
from client.bcoskeypair import BcosKeyPair
class BcosClient:
client_account = None
keystore_file =""
ecdsa_account = None
keystore_file = ""
gm_account = None
gm_account_file = ""
address_from = None
keypair = None
rpc = None
channel_handler = None
fiscoChainId = None
......@@ -66,30 +71,30 @@ class BcosClient:
# load the account from keyfile
def load_default_account(self):
if client_config.crypto_type == CRYPTO_TYPE_GM:
#加载国密账号
# 加载国密账号
if self.gm_account is not None:
return
return # 不需要重复加载
try:
self.gm_account = GM_Account()
self.gm_account_file = "{}/{}".format(client_config.account_keyfile_path,
client_config.gm_account_keyfile)
client_config.gm_account_keyfile)
if os.path.exists(self.gm_account_file) is False:
raise BcosException(("gm account keyfile file {} doesn't exist, "
"please check client_config.py again "
"and make sure this account exist")
.format(self.keystore_file))
self.gm_account.load_from_file(self.gm_account_file,client_config.gm_account_password)
self.address_from = self.gm_account.address
self.gm_account.load_from_file(
self.gm_account_file, client_config.gm_account_password)
self.keypair = self.gm_account.keypair
return
except Exception as e:
raise BcosException("load gm account from {} failed, reason: {}"
.format(self.keystore_file, e))
#默认的 ecdsa 账号
# 默认的 ecdsa 账号
try:
if self.client_account is not None:
return;
if self.ecdsa_account is not None:
return # 不需要重复加载
# check account keyfile
self.keystore_file = "{}/{}".format(client_config.account_keyfile_path,
client_config.account_keyfile)
......@@ -101,8 +106,12 @@ class BcosClient:
with open(self.keystore_file, "r") as dump_f:
keytext = json.load(dump_f)
privkey = Account.decrypt(keytext, client_config.account_password)
self.client_account = Account.from_key(privkey)
self.address_from = self.client_account.address
self.ecdsa_account = Account.from_key(privkey)
keypair = BcosKeyPair()
keypair.private_key = self.ecdsa_account.privateKey
keypair.public_key = self.ecdsa_account.publickey
keypair.address = self.ecdsa_account.address
self.keypair = keypair
except Exception as e:
raise BcosException("load account from {} failed, reason: {}"
.format(self.keystore_file, e))
......@@ -119,7 +128,6 @@ class BcosClient:
raise BcosException("invalid configuration, must be: {}".
format(''.join(BcosClient.protocol_list)))
self.fiscoChainId = client_config.fiscoChainId
self.groupid = client_config.groupid
......@@ -163,8 +171,8 @@ class BcosClient:
if client_config.client_protocol == client_config.PROTOCOL_CHANNEL:
info = "channel {}:{}".format(self.channel_handler.host, self.channel_handler.port)
info += ",groupid :{}\n".format(self.groupid)
if self.client_account is not None:
info += "account address: {}\n".format(self.address_from)
if self.ecdsa_account is not None:
info += "account address: {}\n".format(self.keypair.address)
return info
def is_error_response(self, response):
......@@ -428,16 +436,15 @@ class BcosClient:
cmd = "call"
if to_address != "":
common.check_and_format_address(to_address)
if self.client_account is None:
self.load_default_account()
self.load_default_account()
functiondata = encode_transaction_data(fn_name, contract_abi, None, args)
callmap = dict()
callmap["data"] = functiondata
callmap["from"] = self.address_from
callmap["from"] = self.keypair.address
callmap["to"] = to_address
callmap["value"] = 0
# send transaction to the given group
params = [client_config.groupid, callmap]
# 发送
......@@ -484,9 +491,8 @@ class BcosClient:
to_address = to_checksum_address(to_address)
# load default account if not set .notice: account only use for
# sign transaction for sendRawTransaction
if self.client_account is None:
self.load_default_account()
# sign transaction for sendRawTransa# if self.client_account is None:
self.load_default_account()
# 填写一个bcos transaction 的 mapping
import random
txmap = dict()
......@@ -502,19 +508,15 @@ class BcosClient:
txmap["groupId"] = self.groupid
txmap["extraData"] = ""
#print("\n>>>>functiondata ",functiondata)
from client.signtransaction import SignTx
if client_config.crypto_type is CRYPTO_TYPE_GM:
#国密签名,国密版本将account和交易签名的流程解耦了
sign = SignTx()
sign.account = self.gm_account
signedTxResult = sign.sign_transaction(txmap)
else:
# 只需要用sign_transaction就可以获得rawTransaction的编码数据了,input :txmap,私钥
signedTxResult = Account.sign_transaction(txmap, self.client_account.privateKey)
sign = SignTx()
sign.crypto_type = client_config.crypto_type
# 关键流程:对交易签名,重构后全部统一到 SignTx 类(client/signtransaction.py)完成
sign.gm_account = self.gm_account
sign.ecdsa_account = self.ecdsa_account
signed_result = sign.sign_transaction(txmap)
#print("@@@@@rawTransaction : ",encode_hex(signedTxResult.rawTransaction))
# signedTxResult.rawTransaction是二进制的,要放到rpc接口里要encode下
params = [self.groupid, encode_hex(signedTxResult.rawTransaction)]
params = [self.groupid, encode_hex(signed_result.rawTransaction)]
result = self.common_request(cmd, params, packet_type)
return result
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......
class BcosKeyPair:
private_key = None
public_key = None
address = None
def getdetail(self, sep="\n"):
strmsg = "private key: %s%spublic key %s%saddress %s" % (
self.private_key, sep, self.public_key, sep, self.address)
return strmsg
......@@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......@@ -28,7 +28,7 @@ class ChannelPushDispatcher (threading.Thread):
dispatch_register = dict()
keepWorking = False
logger = clientlogger.logger
pushQueue = queue.Queue(1024*10)
pushQueue = queue.Queue(1024 * 10)
lock = threading.RLock()
def __init__(self):
......@@ -96,8 +96,9 @@ class ChannelPushDispatcher (threading.Thread):
handler.on_push(packmsg)
except Exception as e:
print("{} push handler error {},{},{}".format(self.name, e, packmsg.type, packmsg.data))
self.logger.error("{} push handler error {},{},{}".format(
self.name, e, packmsg.type, packmsg.data))
self.logger.error(
"{} push handler error {},{},{}".format(
self.name, e, packmsg.type, packmsg.data))
finally:
self.lock.release()
......
......@@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......@@ -31,6 +31,7 @@ from client.bcoserror import BcosError, ChannelException
from eth_utils import (to_text, to_bytes)
from client.channel_push_dispatcher import ChannelPushDispatcher
class ChannelHandler(threading.Thread):
context = None
CA_File = None
......@@ -113,8 +114,8 @@ class ChannelHandler(threading.Thread):
self.callbackEmitter.emit(emitter_str, responsepack)
self.lock.release()
else:
#并非客户端指定的等待接受的来自节点的包,可能是push来的消息,包括amop,event push等
#独立接口处理
# 并非客户端指定的等待接受的来自节点的包,可能是push来的消息,包括amop,event push等
# 独立接口处理
# print("push type ",hex(responsepack.type) )
self.pushDispacher.push(responsepack)
except Empty:
......@@ -174,7 +175,7 @@ class ChannelHandler(threading.Thread):
errorMsg[101] = "sdk unreachable"
errorMsg[102] = "timeout"
def make_channel_request(self,data, packet_type,
def make_channel_request(self, data, packet_type,
response_type=None):
seq = ChannelPack.make_seq32()
request_pack = ChannelPack(packet_type, seq, 0, data)
......@@ -191,7 +192,7 @@ class ChannelHandler(threading.Thread):
rpc_onresponse_emitter_str = None
rpc_result_emitter_str = None
if response_type is ChannelPack.TYPE_TX_COMMITTED \
or response_type is ChannelPack.CLIENT_REGISTER_EVENT_LOG:
or response_type is ChannelPack.CLIENT_REGISTER_EVENT_LOG:
rpc_onresponse_emitter_str = ChannelHandler.getEmitterStr(self.onResponsePrefix,
seq, packet_type)
self.requests.append(rpc_onresponse_emitter_str)
......@@ -202,6 +203,7 @@ class ChannelHandler(threading.Thread):
self.lock.release()
emitter_str = ChannelHandler.getEmitterStr(self.getResultPrefix,
seq, response_type)
def resolve_promise(resolve, reject):
"""
resolve promise
......@@ -229,9 +231,7 @@ class ChannelHandler(threading.Thread):
response_type=ChannelPack.TYPE_RPC):
rpc_data = self.encode_rpc_request(method, params)
self.logger.debug("request rpc_data : {}".format(rpc_data))
return self.make_channel_request(rpc_data,packet_type,response_type)
return self.make_channel_request(rpc_data, packet_type, response_type)
def setBlockNumber(self, blockNumber):
"""
......@@ -315,7 +315,7 @@ class ChannelHandler(threading.Thread):
#print("receive event register result: seq: {} type:{}".format(responsepack.seq, responsepack.type))
self.callbackEmitter.emit(emitter_str, responsepack.data, 0)
elif responsepack.type == ChannelPack.EVENT_LOG_PUSH:
print("event log push:",responsepack.data)
print("event log push:", responsepack.data)
except Exception as e:
self.logger.error("decode response failed, seq:{}, type:{}, error info: {}"
.format(responsepack.seq, responsepack.type, e))
......@@ -376,7 +376,7 @@ class ChannelRecvThread(threading.Thread):
# -1 means no enough bytes for decode, should break to continue read and wait
while code != -1:
(code, decodelen, responsePack) = ChannelPack.unpack(bytes(self.respbuffer))
#print("respbuffer:",self.respbuffer)
# print("respbuffer:",self.respbuffer)
if decodelen > 0:
# cut the buffer from last decode pos
self.respbuffer = self.respbuffer[decodelen:]
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......@@ -113,15 +113,15 @@ class ChannelPack:
@staticmethod
def unpack_amop_topic_message(data):
(headerlen,) = struct.unpack_from("!B",data,0)
(headerlen,) = struct.unpack_from("!B", data, 0)
if headerlen > 1:
fmt = "%ds"%(headerlen - 1)
(topic,) = struct.unpack_from(fmt,data,1)
fmt = "%ds" % (headerlen - 1)
(topic,) = struct.unpack_from(fmt, data, 1)
else:
topic = ""
fmt = "%ds"%(len(data) - headerlen)
(content,) = struct.unpack_from(fmt,data,headerlen)
return (topic,content)
fmt = "%ds" % (len(data) - headerlen)
(content,) = struct.unpack_from(fmt, data, headerlen)
return (topic, content)
@staticmethod
def pack_amop_topic_message(topic, data):
......@@ -134,6 +134,7 @@ class ChannelPack:
resbytes = struct.pack(fmt, headerlen, topic, data)
return resbytes
'''
x pad byte no value
c char string of length 1 1
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......@@ -47,7 +47,11 @@ def backup_file(file_name):
if(forcewrite):
filestat = os.stat(file_name)
filetime = time.strftime("%Y%m%d%H%M%S", time.localtime(filestat.st_ctime))
backupfile = "{}.{}".format(file_name, filetime)
filepath, shortname = os.path.split(file_name)
backuppath = "{}/{}".format(filepath, "backup")
if not os.path.exists(backuppath):
os.mkdir(backuppath)
backupfile = "{}/{}.{}".format(backuppath, shortname, filetime)
print("backup [{}] to [{}]".format(file_name, backupfile))
shutil.move(file_name, backupfile)
return forcewrite
......@@ -57,7 +61,7 @@ def print_info(level, cmd):
"""
print information
"""
print("{} >> {}".format(level, cmd))
print("{} : {}".format(level, cmd))
def print_result(ret):
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......@@ -64,7 +64,7 @@ class Compiler:
# sol_file
command = "{} --bin --abi {} -o {} --overwrite".format(
Compiler.compiler_path, sol_file, output_path)
print("INFO >> compile with solc compiler : ",command)
print("INFO >> compile with solc compiler : ", command)
common.execute_cmd(command)
@staticmethod
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thanks for
......@@ -18,6 +18,21 @@ import os
class ContractNote:
@staticmethod
def get_last_contracts():
config = ConfigObj(client_config.contract_info_file, encoding='UTF8')
if "address" not in config:
return None
return config["address"]
@staticmethod
def get_history_list():
config = ConfigObj(client_config.contract_info_file, encoding='UTF8')
if "history" not in config:
return None
return config["history"]
@staticmethod
def get_last(name):
config = ConfigObj(client_config.contract_info_file, encoding='UTF8')
......@@ -28,24 +43,52 @@ class ContractNote:
return address
@staticmethod
def save_address(contractname, newaddress, blocknum=None, memo=None):
def get_address_history(address):
config = ConfigObj(client_config.contract_info_file,
encoding='UTF8')
try:
if address in config["history"]:
historystr = config["history"][address]
res = historystr.split("|")
detail = {}
detail["name"] = res[0].strip()
detail["timestr"] = res[1].strip()
detail["blocknum"] = res[2].strip()
detail["txhash"] = res[3].strip()
return detail
except Exception as e:
print(e)
import traceback
traceback.print_exc()
return None
return None
@staticmethod
def save_address_to_contract_note(contractname, newaddress):
# write to file
config = ConfigObj(client_config.contract_info_file,
encoding='UTF8')
if 'address' not in config:
# print("address not in config",config)
config['address'] = {}
print("save new address {} -> {}".format(contractname, newaddress))
config['address'][contractname] = newaddress
config.write()
@staticmethod
def save_history(contractname, newaddress, blocknum=None, txhash=None):
# print (config)
config = ConfigObj(client_config.contract_info_file,
encoding='UTF8')
if blocknum is not None:
if "history" not in config:
config["history"] = {}
timestr = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
detail = "{}:{},block:{}".format(contractname, timestr, blocknum)
if memo is not None:
detail = "{},{}".format(detail, memo)
if blocknum is None:
blocknum = "-1" # -1 means unknown
if txhash is None:
txhash = ""
detail = "{} | {} | {} | {}".format(contractname, timestr, blocknum, txhash)
config["history"][newaddress] = detail
config.write()
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
bcosliteclientpy is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
bcosliteclientpy is free software: you can redistribute it and/or modify it under the
FISCO BCOS/Python-SDK is a python client for FISCO BCOS2.0 (https://github.com/FISCO-BCOS/)
FISCO BCOS/Python-SDK is free software: you can redistribute it and/or modify it under the
terms of the MIT License as published by the Free Software Foundation. This project is