platon-aide


Nameplaton-aide JSON
Version 1.3.11 PyPI version JSON
download
home_pagehttps://github.com/PlatONnetwork/platon-aide
SummaryAn aide that helps you quickly access the platon chain and use its basic functions.
upload_time2023-01-16 03:39:24
maintainer
docs_urlNone
authorqiusese
requires_python
licenseMIT
keywords platon
VCS
bugtrack_url
requirements gql hexbytes platon.py platon_account platon_hash platon_keys platon_typing platon_utils pytest rlp
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # platon-aide
它是一个小助手,能够帮助您快速访问PlatON区块链,并使用其基本功能 


# 安装方法
```shell
pip install platon_aide
```


# 使用方法

```python
from platon_account import Account

from platon_aide import Aide
from platon_aide.economic import new_economic

uri = 'http://192.168.120.121:6789'

"""
初始化部分
"""
# 实例化aide
aide = Aide(uri)

# 特殊情况实例化aide
# 这里因为节点关闭了admin、debug的api,aide将无法自动获取经济模型参数和节点信息
# 为了避免aide自动获取报错,需要自己生成经济模型对象,并指定关闭的接口
data = {"common": {"maxEpochMinutes": 3, "nodeBlockTimeWindow": 10, "perRoundBlocks": 10, "maxConsensusVals": 4, "additionalCycleTime": 28},
        "staking": {"stakeThreshold": 100000000000000000000000, "operatingThreshold": 10000000000000000000, "maxValidators": 5, "unStakeFreezeDuration": 2,
                    "rewardPerMaxChangeRange": 500, "rewardPerChangeInterval": 2},
        "slashing": {"slashFractionDuplicateSign": 100, "duplicateSignReportReward": 50, "maxEvidenceAge": 1, "slashBlocksReward": 5, "zeroProduceCumulativeTime": 1,
                     "zeroProduceNumberThreshold": 1, "zeroProduceFreezeDuration": 1},
        "gov": {"versionProposalVoteDurationSeconds": 1600, "versionProposalSupportRate": 6670, "textProposalVoteDurationSeconds": 160, "textProposalVoteRate": 5000,
                "textProposalSupportRate": 6670, "cancelProposalVoteRate": 5000, "cancelProposalSupportRate": 6670, "paramProposalVoteDurationSeconds": 160,
                "paramProposalVoteRate": 5000, "paramProposalSupportRate": 6670},
        "reward": {"newBlockRate": 50, "platonFoundationYear": 10, "increaseIssuanceRatio": 250, "theNumberOfDelegationsReward": 2},
        "restricting": {"minimumRelease": 100000000000000000000},
        "innerAcc": {"platonFundAccount": "lat1drz94my95tskswnrcnkdvnwq43n8jt6dmzf8h8", "platonFundBalance": 0, "cdfAccount": "lat1kvurep20767ahvrkraglgd9t34w0w2g059pmlx",
                     "cdfBalance": 421411981000000000000000000}}
economic = new_economic(data)
aide = Aide(uri, economic=economic, exclude_api=['admin', 'debug'])

"""
交易签名部分
"""
# 设置默认账户,后续使用aide发交易,如果不指定私钥,则都会使用默认账户签名交易
account = Account.from_key('f51ca759562e1daf9e5302d121f933a8152915d34fcbc27e542baf256b5e4b74', aide.hrp)
aide.set_default_account(account)
to_account = Account.create(hrp='lat')
print(aide.transfer.transfer(to_account.address, 10 * 10 ** 18))

# 使用特定私钥签名,附带自主指定交易信息方法
txn = {'gas': 21000, 'gasPrice': 1 * 10 ** 9, 'nonce': 100}
private_key = 'f51ca759562e1daf9e5302d121f933a8152915d34fcbc27e542baf256b5e4b74'
print(aide.transfer.transfer(to_account.address, 10 * 10 ** 18, txn=txn, private_key=private_key))

"""
普通交易部分
"""
# 发送转账
to_account = Account.create(hrp='lat')
print(aide.transfer.transfer(to_account.address, 10 * 10 ** 18))

# 调用web3
print(aide.web3.clientVersion)

# 调用内置合约
print(aide.delegate.get_delegate_lock_info())

"""
调用合约部分
"""
false = False
ture = True
abi = [{"anonymous": false, "inputs": [{"indexed": false, "internalType": "uint256", "name": "_chainId", "type": "uint256"}], "name": "_putChainID", "type": "event"},
       {"inputs": [], "name": "getChainID", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "stateMutability": "view", "type": "function"},
       {"inputs": [], "name": "putChainID", "outputs": [], "stateMutability": "nonpayable", "type": "function"}]
bytecode = '608060405234801561001057600080fd5b50610107806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806336319ab0146037578063564b81ef14603f575b600080fd5b603d6059565b005b60456099565b6040516050919060ae565b60405180910390f35b466000819055507f68e891aec7f9596d6e192c48cb82364ec392d423bce80abd6e1ee5ad05860256600054604051608f919060ae565b60405180910390a1565b600046905090565b60a88160c7565b82525050565b600060208201905060c1600083018460a1565b92915050565b600081905091905056fea264697066735822122037a1668252253271128182c71109922cb1e300fb08a7080a0587f360df4071ba64736f6c63430008060033'

# 部署新的合约
contract = aide.contract.deploy(abi=abi, bytecode=bytecode)
print(contract.ADDRESS)

# 已有合约,直接初始化
contract_address = '0x00'
contract = aide.contract.init(abi=abi, address=contract_address)
print(contract.ADDRESS)

# call调用
print(aide.contract.getChainID())

# 发送交易,和call一样
res = aide.contract.putChainID()

# 解析event
print(aide.contract.PutChainID(res))
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PlatONnetwork/platon-aide",
    "name": "platon-aide",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "platon",
    "author": "qiusese",
    "author_email": "230469827@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/19/e9/be9d5445c1292fa745d0b3f374da076cc350899c87edc279d5d59bf8bc54/platon-aide-1.3.11.tar.gz",
    "platform": null,
    "description": "# platon-aide\r\n\u5b83\u662f\u4e00\u4e2a\u5c0f\u52a9\u624b\uff0c\u80fd\u591f\u5e2e\u52a9\u60a8\u5feb\u901f\u8bbf\u95eePlatON\u533a\u5757\u94fe\uff0c\u5e76\u4f7f\u7528\u5176\u57fa\u672c\u529f\u80fd \r\n\r\n\r\n# \u5b89\u88c5\u65b9\u6cd5\r\n```shell\r\npip install platon_aide\r\n```\r\n\r\n\r\n# \u4f7f\u7528\u65b9\u6cd5\r\n\r\n```python\r\nfrom platon_account import Account\r\n\r\nfrom platon_aide import Aide\r\nfrom platon_aide.economic import new_economic\r\n\r\nuri = 'http://192.168.120.121:6789'\r\n\r\n\"\"\"\r\n\u521d\u59cb\u5316\u90e8\u5206\r\n\"\"\"\r\n# \u5b9e\u4f8b\u5316aide\r\naide = Aide(uri)\r\n\r\n# \u7279\u6b8a\u60c5\u51b5\u5b9e\u4f8b\u5316aide\r\n# \u8fd9\u91cc\u56e0\u4e3a\u8282\u70b9\u5173\u95ed\u4e86admin\u3001debug\u7684api\uff0caide\u5c06\u65e0\u6cd5\u81ea\u52a8\u83b7\u53d6\u7ecf\u6d4e\u6a21\u578b\u53c2\u6570\u548c\u8282\u70b9\u4fe1\u606f\r\n# \u4e3a\u4e86\u907f\u514daide\u81ea\u52a8\u83b7\u53d6\u62a5\u9519\uff0c\u9700\u8981\u81ea\u5df1\u751f\u6210\u7ecf\u6d4e\u6a21\u578b\u5bf9\u8c61\uff0c\u5e76\u6307\u5b9a\u5173\u95ed\u7684\u63a5\u53e3\r\ndata = {\"common\": {\"maxEpochMinutes\": 3, \"nodeBlockTimeWindow\": 10, \"perRoundBlocks\": 10, \"maxConsensusVals\": 4, \"additionalCycleTime\": 28},\r\n        \"staking\": {\"stakeThreshold\": 100000000000000000000000, \"operatingThreshold\": 10000000000000000000, \"maxValidators\": 5, \"unStakeFreezeDuration\": 2,\r\n                    \"rewardPerMaxChangeRange\": 500, \"rewardPerChangeInterval\": 2},\r\n        \"slashing\": {\"slashFractionDuplicateSign\": 100, \"duplicateSignReportReward\": 50, \"maxEvidenceAge\": 1, \"slashBlocksReward\": 5, \"zeroProduceCumulativeTime\": 1,\r\n                     \"zeroProduceNumberThreshold\": 1, \"zeroProduceFreezeDuration\": 1},\r\n        \"gov\": {\"versionProposalVoteDurationSeconds\": 1600, \"versionProposalSupportRate\": 6670, \"textProposalVoteDurationSeconds\": 160, \"textProposalVoteRate\": 5000,\r\n                \"textProposalSupportRate\": 6670, \"cancelProposalVoteRate\": 5000, \"cancelProposalSupportRate\": 6670, \"paramProposalVoteDurationSeconds\": 160,\r\n                \"paramProposalVoteRate\": 5000, \"paramProposalSupportRate\": 6670},\r\n        \"reward\": {\"newBlockRate\": 50, \"platonFoundationYear\": 10, \"increaseIssuanceRatio\": 250, \"theNumberOfDelegationsReward\": 2},\r\n        \"restricting\": {\"minimumRelease\": 100000000000000000000},\r\n        \"innerAcc\": {\"platonFundAccount\": \"lat1drz94my95tskswnrcnkdvnwq43n8jt6dmzf8h8\", \"platonFundBalance\": 0, \"cdfAccount\": \"lat1kvurep20767ahvrkraglgd9t34w0w2g059pmlx\",\r\n                     \"cdfBalance\": 421411981000000000000000000}}\r\neconomic = new_economic(data)\r\naide = Aide(uri, economic=economic, exclude_api=['admin', 'debug'])\r\n\r\n\"\"\"\r\n\u4ea4\u6613\u7b7e\u540d\u90e8\u5206\r\n\"\"\"\r\n# \u8bbe\u7f6e\u9ed8\u8ba4\u8d26\u6237\uff0c\u540e\u7eed\u4f7f\u7528aide\u53d1\u4ea4\u6613\uff0c\u5982\u679c\u4e0d\u6307\u5b9a\u79c1\u94a5\uff0c\u5219\u90fd\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u8d26\u6237\u7b7e\u540d\u4ea4\u6613\r\naccount = Account.from_key('f51ca759562e1daf9e5302d121f933a8152915d34fcbc27e542baf256b5e4b74', aide.hrp)\r\naide.set_default_account(account)\r\nto_account = Account.create(hrp='lat')\r\nprint(aide.transfer.transfer(to_account.address, 10 * 10 ** 18))\r\n\r\n# \u4f7f\u7528\u7279\u5b9a\u79c1\u94a5\u7b7e\u540d\uff0c\u9644\u5e26\u81ea\u4e3b\u6307\u5b9a\u4ea4\u6613\u4fe1\u606f\u65b9\u6cd5\r\ntxn = {'gas': 21000, 'gasPrice': 1 * 10 ** 9, 'nonce': 100}\r\nprivate_key = 'f51ca759562e1daf9e5302d121f933a8152915d34fcbc27e542baf256b5e4b74'\r\nprint(aide.transfer.transfer(to_account.address, 10 * 10 ** 18, txn=txn, private_key=private_key))\r\n\r\n\"\"\"\r\n\u666e\u901a\u4ea4\u6613\u90e8\u5206\r\n\"\"\"\r\n# \u53d1\u9001\u8f6c\u8d26\r\nto_account = Account.create(hrp='lat')\r\nprint(aide.transfer.transfer(to_account.address, 10 * 10 ** 18))\r\n\r\n# \u8c03\u7528web3\r\nprint(aide.web3.clientVersion)\r\n\r\n# \u8c03\u7528\u5185\u7f6e\u5408\u7ea6\r\nprint(aide.delegate.get_delegate_lock_info())\r\n\r\n\"\"\"\r\n\u8c03\u7528\u5408\u7ea6\u90e8\u5206\r\n\"\"\"\r\nfalse = False\r\nture = True\r\nabi = [{\"anonymous\": false, \"inputs\": [{\"indexed\": false, \"internalType\": \"uint256\", \"name\": \"_chainId\", \"type\": \"uint256\"}], \"name\": \"_putChainID\", \"type\": \"event\"},\r\n       {\"inputs\": [], \"name\": \"getChainID\", \"outputs\": [{\"internalType\": \"uint256\", \"name\": \"\", \"type\": \"uint256\"}], \"stateMutability\": \"view\", \"type\": \"function\"},\r\n       {\"inputs\": [], \"name\": \"putChainID\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\"}]\r\nbytecode = '608060405234801561001057600080fd5b50610107806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806336319ab0146037578063564b81ef14603f575b600080fd5b603d6059565b005b60456099565b6040516050919060ae565b60405180910390f35b466000819055507f68e891aec7f9596d6e192c48cb82364ec392d423bce80abd6e1ee5ad05860256600054604051608f919060ae565b60405180910390a1565b600046905090565b60a88160c7565b82525050565b600060208201905060c1600083018460a1565b92915050565b600081905091905056fea264697066735822122037a1668252253271128182c71109922cb1e300fb08a7080a0587f360df4071ba64736f6c63430008060033'\r\n\r\n# \u90e8\u7f72\u65b0\u7684\u5408\u7ea6\r\ncontract = aide.contract.deploy(abi=abi, bytecode=bytecode)\r\nprint(contract.ADDRESS)\r\n\r\n# \u5df2\u6709\u5408\u7ea6\uff0c\u76f4\u63a5\u521d\u59cb\u5316\r\ncontract_address = '0x00'\r\ncontract = aide.contract.init(abi=abi, address=contract_address)\r\nprint(contract.ADDRESS)\r\n\r\n# call\u8c03\u7528\r\nprint(aide.contract.getChainID())\r\n\r\n# \u53d1\u9001\u4ea4\u6613\uff0c\u548ccall\u4e00\u6837\r\nres = aide.contract.putChainID()\r\n\r\n# \u89e3\u6790event\r\nprint(aide.contract.PutChainID(res))\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An aide that helps you quickly access the platon chain and use its basic functions.",
    "version": "1.3.11",
    "project_urls": {
        "Homepage": "https://github.com/PlatONnetwork/platon-aide"
    },
    "split_keywords": [
        "platon"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "95b63103eecc7228c8ba87857d17f46f78d9882c814c4827df496866c17b18c5",
                "md5": "5e1f9fa93dc7541e44ea2379c42d1b18",
                "sha256": "24f694c8329b21385dd071635d0e3c67fb991e1daac1e4530c5160628f9eaff1"
            },
            "downloads": -1,
            "filename": "platon_aide-1.3.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5e1f9fa93dc7541e44ea2379c42d1b18",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 24206,
            "upload_time": "2023-01-16T03:39:22",
            "upload_time_iso_8601": "2023-01-16T03:39:22.390683Z",
            "url": "https://files.pythonhosted.org/packages/95/b6/3103eecc7228c8ba87857d17f46f78d9882c814c4827df496866c17b18c5/platon_aide-1.3.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "19e9be9d5445c1292fa745d0b3f374da076cc350899c87edc279d5d59bf8bc54",
                "md5": "bb1d64a58454e77c8aec203cb89aaf4e",
                "sha256": "49bb555161d4d23bb93555da06d0d7feb203d1f360e8b3d73eded55dbdcff674"
            },
            "downloads": -1,
            "filename": "platon-aide-1.3.11.tar.gz",
            "has_sig": false,
            "md5_digest": "bb1d64a58454e77c8aec203cb89aaf4e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 21382,
            "upload_time": "2023-01-16T03:39:24",
            "upload_time_iso_8601": "2023-01-16T03:39:24.925070Z",
            "url": "https://files.pythonhosted.org/packages/19/e9/be9d5445c1292fa745d0b3f374da076cc350899c87edc279d5d59bf8bc54/platon-aide-1.3.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-16 03:39:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PlatONnetwork",
    "github_project": "platon-aide",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "gql",
            "specs": [
                [
                    "==",
                    "3.0.0rc0"
                ]
            ]
        },
        {
            "name": "hexbytes",
            "specs": [
                [
                    "==",
                    "0.2.1"
                ]
            ]
        },
        {
            "name": "platon.py",
            "specs": [
                [
                    ">=",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "platon_account",
            "specs": [
                [
                    ">=",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "platon_hash",
            "specs": [
                [
                    ">=",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "platon_keys",
            "specs": [
                [
                    ">=",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "platon_typing",
            "specs": [
                [
                    ">=",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "platon_utils",
            "specs": [
                [
                    ">=",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "6.2.4"
                ]
            ]
        },
        {
            "name": "rlp",
            "specs": [
                [
                    "==",
                    "1.2.0"
                ]
            ]
        }
    ],
    "lcname": "platon-aide"
}
        
Elapsed time: 0.42020s