阿西莫夫链sdk
py-asimov的Python项目详细描述
简介
本文描述了如何使用高级pythonapi开发python脚本来测试和部署Asimov上的契约。在
依赖关系
安装Python Environment
在运行python脚本之前,您需要安装python并设置虚拟环境。 按照python.org和pyenv上的说明完成安装。 Asimov PythonSDK已经在Python3.7+上进行了全面测试。在
安装secp256k1
它是在曲线secp256k1上进行EC操作的优化C库。 按照specp256k1上的说明完成安装。在
You need to install automake on MacOS to run the scripts in secp256k1. Run
brew install automake
.
Note: If you see the error message like
Cannot import secp256k1: libsecp256k1.so.0: cannot open shared object file...
when executepip install py-asimov
. You can addLIBDIR
to theLD_LIBRARY_PATH
environment variable likeexport LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
on Fedora/CentOS/RHEL. (Let's assumeLIBDIR
is/usr/local/lib
in this case).
为fastecdsa安装gmp
Py-Asimov使用fastecdsa库进行快速椭圆曲线加密。
请注意,您需要一个C编译器。您还需要在您的系统上有GMP,因为这个包中的底层C代码包括gmp.h
头(以及通过-lgmp
标志链接gmp)。可以按如下方式安装所有依赖项:
apt
$ apt-get install python-dev libgmp3-dev
百胜
^{pr2}$
mac
$ brew install gmp
安装Asimov Python SDK
pip install -i https://pypi.python.org/simple/ py-asimov
我们通过pythonsdk提供高级pythonapi。请访问Python API阅读api规范。在
movehasi3智能合约安装>
按照Asimov上的说明完成安装。在
教程
我们提供一个tutorial.py来覆盖Python SDK中最常用的函数, 包括submit template,deploy contract,execute/vote on contract methods, read contract states和检查事务状态等等。在
上面脚本中针对的智能合约测试是tutorial.sol。在
初始化节点实例
fromasimovimportNodenode=Node()
设置RPC服务器和私钥
# set rpc servernode.set_rpc_server("http://seed.asimov.tech")# set private keynode.set_private_key("your private key")
提交模板
fromasimovimportTemplatefromasimov.constantimportSUCCESS# initialize template instancet=Template(node)# submit a contract template to Asimov blockchaintx=t.submit("./contracts/tutorial.sol","template_name",'Tutorial')# make sure the transaction is confirmed on chain before moving on to next stepasserttx.check()isSUCCESS
部署合同
fromasimovimportContract# deploy a contract instance to Asimov blockchaindeploy_tx,contract_address=t.deploy_contract(tx.id)# make sure the transaction is confirmed on chain before moving on to next stepasserttx.check()isSUCCESS# initialize contract instancecontract=Contract(node,contract_address)
执行合同方法
fromasimovimportconstant# mint assettx=contract.execute("mint",[10000*constant.COIN])# make sure the transaction is confirmed on chain and the contract execution is successfulasserttx.check()isconstant.SUCCESS# call contract's read only function.We get new asset type and convert to string type.asset_type=Asset.asset2str(contract.read("assettype"))# transfer assetassertcontract.execute("transfer",[node.address,100*constant.COIN]).check()isconstant.SUCCESS
投票合同方法
# call the vote method to vote using the utxo asset mint in the above stepassertcontract.vote("vote",[88],1,asset_type).check()isconstant.SUCCESS
开发人员设置
如果您想破解py asimov,请遵循以下步骤:
- 测试
- 拉取请求
- 代码样式
- 文件
开发环境设置
您可以使用以下工具设置开发环境:
git clone git@gitlab.asimov.work:asimov/asimov-python-sdk.git cd pyasimov pyenv virtualenv 3.7.3 env-asimov pyenv activate env-asimov pip install -e .[dev]# If you're using zsh you need to escape square brackets: pip install -e .\[extra\]
测试设置
在开发期间,您可能希望对每个文件保存运行测试。在
# in the project root: make test
释放设置
要发布新版本:
make release bump=$$VERSION_PART_TO_BUMP$$
如何缓冲版本
此repo的版本格式为{major}.{minor}.{patch}
,表示稳定
要发布下一个版本,请指定要碰撞的零件,
比如make release bump=minor
或{
- 项目
标签: