Package: py-equity
PY-EQUITYPython wrapper around the BUTXO Equity compiler for Bytom protocol.Installation$pipinstallpy-equityDevelopmentWe welcome pull requests. To get started, just fork this repo, clone it locally, and run:$ pip install -e . -r requirements.txtQuick UsagefromequityimportEquityLOCK_WITH_PUBLIC_KEY_SOURCE="""contract LockWithPublicKey(publicKey: PublicKey) locks valueAmount of valueAsset {clause spend(sig: Signature) {verify checkTxSig(publicKey, sig)unlock valueAmount of valueAsset}}"""LOCK_WITH_PUBLIC_KEY_PATH="./LockWithPublicKey.equity"# LOCK_WITH_PUBLIC_KEY_ARGS = [#     "e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78"# ]equity=Equity("http://localhost:9888")COMPILED=equity.compile_source(LOCK_WITH_PUBLIC_KEY_SOURCE,"e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78")print(COMPILED["name"])print(COMPILED["program"])print(COMPILED["opcodes"])print(COMPILED)# Save compiled contractequity.save()OUTPUT'LockWithPublicKey''20e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e787403ae7cac00c0''0xe9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78DEPTH0xae7cacFALSECHECKPREDICATE'{'name':'LockWithPublicKey','source':'\ncontractLockWithPublicKey(publicKey:PublicKey)locksvalueAmountofvalueAsset{\nclausespend(sig:Signature){\nverifycheckTxSig(publicKey,sig)\nunlockvalueAmountofvalueAsset\n}\n}\n','program':'20e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e787403ae7cac00c0','params':[{'name':'publicKey','type':'PublicKey'}],'value':'valueAmountofvalueAsset','clause_info':[{'name':'spend','params':[{'name':'sig','type':'Signature'}],'values':[{'name':'','asset':'valueAsset','amount':'valueAmount'}]}],'opcodes':'0xe9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78DEPTH0xae7cacFALSECHECKPREDICATE','error':''}CLICommand line interface, run the following command:$eqt--versionExampleeqt:$eqt--fileLockWithPublicKey.equity--args"e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78"Get help:$eqt--helpFrom there, you can run eqt more commands,-s\--saveto save your contract,-u\--urlto change Bytom API url. by default (http://localhost:9888).TestingYou can run the tests with:$ pytest testsOr usetoxto run the complete suite against the full set of build targets, or pytest to run specific
tests against a specific version of Python.APIClass Equity()ParametersOptional:String-url, Bytom API url, by default (http://localhost:9888).String-api_key, Bytom API key.Integer-timeout, request timeout, by default (1).compile_source(): It is to compiling Bytom smart contract(Equity source).ParametersObject:String-equity_source, Equity source code.Optional:Boolean/String/Integer/Array- *argv.Boolean-boolean, boolean parameter.String-string, string parameter.Integer-integer, integer parameter.ReturnsObject:String-name, contract name.String-source, contract source code.String-program, contract program.Array-params, contract params.String-value, contract value.Array-clause_info, contract clause_info.Array-values, contract values.String-opcodes, contract opcodes.String-error, contract error.ExampleLOCK_WITH_PUBLIC_KEY_SOURCE="""contract LockWithPublicKey(publicKey: PublicKey) locks valueAmount of valueAsset {clause spend(sig: Signature) {verify checkTxSig(publicKey, sig)unlock valueAmount of valueAsset}}"""equity=Equity("http://localhost:9888",timeout=5)COMPILED=equity.compile_source(LOCK_WITH_PUBLIC_KEY_SOURCE,"e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78")print(COMPILED)Output{'name': 'LockWithPublicKey', 'source': '\n    contract LockWithPublicKey(publicKey: PublicKey) locks valueAmount of valueAsset {\n      clause spend(sig: Signature) {\n        verify checkTxSig(publicKey, sig)\n        unlock valueAmount of valueAsset\n      }\n    }\n', 'program': '20e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e787403ae7cac00c0', 'params': [{'name': 'publicKey', 'type': 'PublicKey'}], 'value': 'valueAmount of valueAsset', 'clause_info': [{'name': 'spend', 'params': [{'name': 'sig', 'type': 'Signature'}], 'values': [{'name': '', 'asset': 'valueAsset', 'amount': 'valueAmount'}]}], 'opcodes': '0xe9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78 DEPTH 0xae7cac FALSE CHECKPREDICATE', 'error': ''}compile_file(): It is to compiling Bytom smart contract form Equity file.ParametersObject:String-equity_source, Equity source code file(.equity or .eqt).Optional:Boolean/String/Integer/Array- *argv.Boolean-boolean, boolean parameter.String-string, string parameter.Integer-integer, integer parameter.ReturnsObject:String-name, contract name.String-source, contract source code.String-program, contract program.Array-params, contract params.String-value, contract value.Array-clause_info, contract clause_info.Array-values, contract values.String-opcodes, contract opcodes.String-error, contract error.ExampleLOCK_WITH_PUBLIC_KEY_PATH="./LockWithPublicKey.equity"equity=Equity("http://localhost:9888",timeout=5)COMPILED=equity.compile_file(LOCK_WITH_PUBLIC_KEY_PATH,"e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78")print(COMPILED)Output{'name': 'LockWithPublicKey', 'source': '\n    contract LockWithPublicKey(publicKey: PublicKey) locks valueAmount of valueAsset {\n      clause spend(sig: Signature) {\n        verify checkTxSig(publicKey, sig)\n        unlock valueAmount of valueAsset\n      }\n    }\n', 'program': '20e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e787403ae7cac00c0', 'params': [{'name': 'publicKey', 'type': 'PublicKey'}], 'value': 'valueAmount of valueAsset', 'clause_info': [{'name': 'spend', 'params': [{'name': 'sig', 'type': 'Signature'}], 'values': [{'name': '', 'asset': 'valueAsset', 'amount': 'valueAmount'}]}], 'opcodes': '0xe9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78 DEPTH 0xae7cac FALSE CHECKPREDICATE', 'error': ''}save(): Save compiled equity source.ParametersOptional:String-file_path, It is for full path with name.String-dir_path, It is for only dir path.ReturnsObject:String-name, contract name.AUTHORMEHERET TESFAYELICENSEAGPLv3+