-
美图APP上线“魔法照片”:静态秒变动态
突然!微信新功能关闭 刚火两天-威斯尼斯人官网入口
辽宁:辽宁法库县进一步促进农机管理与服务能力的提高_威斯尼斯人老品牌
在前两期的本体技术视点中,网卓新闻网,我们讲解了横跨合约静态调用与动态调用,描写了如何用于 RegisterAppCall API 与 DynamicAppCall API 横跨合约调用其他合约的函数。本期将转入本体 Python 智能合约语法专辑的终极篇,探究如何用于合约继续执行引擎 API,即 ExecutionEngine API。它包括了3个 API,用法如下:本期语法可玩性较小,堪比 Python 智能合约界的九阴真经,完成学业了你就得意了!下面我们明确描写一下 ExecutionEngine API 的用于方法。在这之前,小伙伴们可以在本体智能合约开发工具 SmartX 中新建一个合约,回来我们展开操作者。
某种程度,在文章最后我们将得出这次介绍的所有源代码以及视频介绍。02 ExecutionEngine API 用于方法用于 ExecutionEngine API 前必须将其引进。
这可以通过下面的语句构建上述三个函数的构建:from ontology.interop.System.ExecutionEngine import GetExecutingScriptHash, GetCallingScriptHash, GetEntryScriptHash2.1 GetExcutingScriptHashGetExecutingScriptHash API 尤为非常简单,它的起到是回到当前合约的合约哈希反序,即当前合约账户地址。from ontology.interop.System.ExecutionEngine import GetExecutingScriptHashdef Main(operation, args):if operation == "get_contract_hash":return get_contract_hash() return Falsedef get_contract_hash():return GetExecutingScriptHash()如图,右上角 Basic Info 表明了合约哈希,左下角控制器回到了当前合约哈希的反序。
2.2 GetCallingScriptHashGetCallingScriptHash API 回到上一级调用者,即必要调用者的脚本哈希,该返回值与合约以及调用函数涉及。因此有所不同合约、有所不同函数调用 GetCallingScriptHash 都会获得有所不同的脚本哈希,因为合约和函数是有所不同的调用者。from ontology.interop.System.ExecutionEngine import GetExecutingScriptHash, GetCallingScriptHashdef Main(operation, args):if operation == "GetCallingScriptHash_test1":return GetCallingScriptHash_test1()if operation == "GetCallingScriptHash_test2":return GetCallingScriptHash_test2() return Falsedef GetCallingScriptHash_test1():return GetCallingScriptHash() def GetCallingScriptHash_test2():return GetCallingScriptHash()如图所示,GetCallingScriptHash_test1 函数与 GetCallingScriptHash_test2 函数回到了两个有所不同的脚本哈希。此外,将完全相同的函数放进有所不同的合约,也不会回到有所不同的脚本哈希。
2.3 GetEntryScriptHash在智能合约的调用中,有必要调用者就有间接调用者(横跨合约调用)。GetEntryScriptHash,它不会回到入口(最初)调用者的脚本哈希。我们打算两个智能合约,合约 A 与合约 B,假设合约 A 来调用合约 B 的功能函数。
合约B的代码如下:from ontology.interop.System.ExecutionEngine import GetExecutingScriptHash, GetCallingScriptHash, GetEntryScriptHashfrom ontology.interop.System.Runtime import CheckWitness, GetTime, Notify, Serialize, Deserializedef Main(operation, args):if operation == "invokeB":return invokeB()if operation == "avoidToBeInvokedByContract":return avoidToBeInvokedByContract() return Falsedef invokeB():# the result of GetCallingScriptHash and GetEntryScriptHash is same# if they are invoked by the same contractcallerHash = GetCallingScriptHash()entryHash = GetEntryScriptHash()Notify([callerHash, entryHash])return [callerHash, entryHash]def avoidToBeInvokedByContract():# the purpose is to prevent hack from other contractcallerHash = GetCallingScriptHash()entryHash = GetEntryScriptHash()if callerHash != entryHash:Notify(["You are not allowed to invoke this method through contract"])return Falseelse:Notify(["You can implement what you need to do here!"])return True合约 A 的代码如下,该合约调用合约 B。from ontology.interop.System.App import RegisterAppCallfrom ontology.interop.System.ExecutionEngine import GetExecutingScriptHash, GetCallingScriptHash, GetEntryScriptHashfrom ontology.interop.System.Runtime import CheckWitness, GetTime, Notify, Serialize, DeserializeContractB = RegisterAppCall('0f44f18d37515a917364362ec256c2110a7b1377', 'operation', 'args')def Main(operation, args):if operation == "invokeA":opt = args[0]return invokeA(opt)if operation == "checkHash":return checkHash()return Falsedef invokeA(opt):callerHash = GetCallingScriptHash()entryHash = GetEntryScriptHash()Notify(["111_invokeA",callerHash, entryHash])return ContractB(opt, [])def checkHash():Notify(["111_checkHash"])callerHash = GetCallingScriptHash()entryHash = GetEntryScriptHash()Notify([callerHash, entryHash])return True如图,首先运营 checkHash 函数,我们找到在同一个合约的同一个函数中,调用GetCallingScriptHash与GetEntryScriptHash API返回值完全相同,都是"a37ca1f1a3421d36b504769a96c06024a07b2bfa"。这是因为他们既是必要调用者,也是最初调用者(没横跨合约调用),所以两个 API 返回值完全相同。
但如果横跨合约调用呢?。
本文关键词:威斯尼斯人老品牌,威斯尼斯人,威斯尼斯人官网入口
本文来源:威斯尼斯人老品牌-www.sd-duck.com
推荐资讯
- 28684次浏览北京优耐特燃气工程技术有限公司大力推进农村煤改气工作
- 50587次浏览农业市场:生猪收购价突破历史高点:威斯尼斯人官网入口
- 64842次浏览被蜜蜂蛰了会出现怎样的症状?如何消肿?都有哪些注意事项?|威斯尼斯人老品牌
- 55695次浏览激光设备制造行业发展前景分析:威斯尼斯人
- 24285次浏览【威斯尼斯人老品牌】中国移动9月1日起全面取消手机国内长途和漫游费
- 64470次浏览安徽庐江自主研发“阳光追踪器”助力光伏农业
- 7818次浏览苏州设计新股上市定价报告:威斯尼斯人官网入口
- 68308次浏览威斯尼斯人_MVRDV公布里昂La Part Dieu购物中心改造方案
- 37028次浏览威斯尼斯人官网入口|种植户心安 山东泰安马铃薯加入目标价格保险
- 596次浏览【威斯尼斯人】植物油真的致癌吗?以后还能不能吃?
- 71195次浏览全新马自达3的改变 能带着马自达向“上”走?-威斯尼斯人官网入口
- 59121次浏览两会焦点:不拘一格引人才发展机器人产业:威斯尼斯人老品牌