阿西莫夫链sdk

py-asimov的Python项目详细描述


简介

本文描述了如何使用高级pythonapi开发python脚本来测试和部署Asimov上的契约。在

依赖关系

安装Python Environment

在运行python脚本之前,您需要安装python并设置虚拟环境。 按照python.orgpyenv上的说明完成安装。 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 execute pip install py-asimov. You can add LIBDIR to the LD_LIBRARY_PATH environment variable like export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib on Fedora/CentOS/RHEL. (Let's assume LIBDIR 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 templatedeploy contractexecute/vote on contract methodsread 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或{}。这通常是从 主分支机构。要包括每个版本所做的更改,请更新“docs/版本.rst“随着变化, 并在发布前直接向master应用commit。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring安全编程授权   java Android库AAR取决于另一个库   Java/Groovy双精度语句问题   爪哇。查看安卓监视器图形时,release()不会减少我的内存   java无法在子类中使用EventFiringWebDriver对象   java第一个if语句始终为true,但第二个if语句不为true   java如何从作为字符串提供的XML源代码创建可绘制(或XmlResourceParser对象)?   多线程Java并发问题锁和同步方法   java Android Studio注册链接   java ArrayList of ArrayList of String   使用Shadow重新定位的包中的java Kotlin属性不起作用   java在接口org上找不到方法。阿帕奇。伊巴蒂斯。遗嘱执行人。陈述名为prepare的语句处理程序   如何在Java中放大2倍?   java当参数作为RequestBody和RequestParam发送时,sprig控制器无法识别发送的请求