以太坊/ Solidity开发人员在这里,希望将一些Solidity合同迁移到Tezos上。希望阐明一些问题
-
-
欢迎使用,如果您将其分为多个问题会更好.对于这些问题的一般讨论,Agora/Riot/Reddit更合适.对于本网站上的特定问答,您对流动性的第一个问题将引起更多的意见,因此,如果您想要特定的答案,请考虑重述.如果您决定编辑此帖子的标题,则第二个问题已经在下面得到了最佳答案.第三个问题对于一个新问题将非常有用.Welcome, would be better if you split this up into multiple questions. For general discussion on these issues Agora/Riot/Reddit are better fits. For specific Q&A on this site, your first question on Liquidity will lead more to opinions so please consider restating it if you want a specific answer. The second question has already received an answer below and best candidate if you decide to edit the title of this post. The third one would be great for a new question.
- 1
- 2020-01-10
- cousinit
-
tezos不支持流动性.另一方面,SmartPy可能应该在您的列表中Liquidity is not a supported language in tezos. On the other hand SmartPy should probably be in your list
- 2
- 2020-01-12
- Ezy
-
@Ezy,我们研究了Liquidity以及在developers.tezos.com上列出的所有其他股票,并开始缩小到主要为Ligo/Archetype.SmartPyi̶s̶n̶'̶t̶̶o̶p̶e̶n̶-̶s̶o̶u̶r̶c̶e̶̶y̶e̶t̶https://medium.com/@SmartPy_io/new-release-for-smartpy-and-smartpy-io-89d11dc5146a←是!,它在清单上@Ezy, we looked at Liquidity, along with all the others listed on developers.tezos.com, and began narrowing down to mainly Ligo/Archetype. SmartPy i̶s̶n̶'̶t̶ ̶o̶p̶e̶n̶-̶s̶o̶u̶r̶c̶e̶ ̶y̶e̶t̶ https://medium.com/@SmartPy_io/new-release-for-smartpy-and-smartpy-io-89d11dc5146a ← Yay!, it's back on the list =)
- 1
- 2020-01-14
- Justin
-
@Ezy Liquidity在其网站上表示,他们同时支持Dune和Tezos.是什么让Tezos不支持它?@Ezy Liquidity states on their website that they support both Dune and Tezos. What makes it unsupported for Tezos?
- 0
- 2020-01-14
- Justin
-
@Justin ocamlpro是流动性的作者,他离开了tezos项目,走了自己的路.它没有积极维护与tezos一起使用,因此停止在tezos上编译只是时间问题.@Justin ocamlpro who is the author of liquidity left the tezos project to follow their own path. It is not actively maintained to work with tezos so it is only a matter of time before it stops compiling on tezos.
- 1
- 2020-01-15
- Ezy
-
4 个回答
- 投票数
-
- 2020-01-14
针对问题4:
重用和模块化
我们讨论重用和模块化,其中继承是许多机制之一:
- Michelson 没有用于代码重用的机制,除了调用 现有的"图书馆"直接签约.
- 据我了解,原型不包含用户可扩展的内容
代码重用的机制.动作(类似于方法)不能
在不同状态机之间共享(类似于
合同).此外,动作不能互相调用,所以
无法组成.状态机无法扩展或
组成.原型合同由一个文件组成.然而,
原型包含一组扩展,它们通常封装在一起
使用诸如
signed
之类的模式,该模式要求 一个动作应该是另一个参数的签名. - LIGO 合同,无论使用哪种语法,均由
一组功能.这些功能可以重复使用,并且位于
可以根据任何函数的期望进行组合
语言,递归除外.此外,Ligo编译器
在输入合同上调用 C预处理程序(
cpp
) 通过使用实现一定程度的重用性和可组合性 #code#include 指令.道德上,这相当于 复制粘贴包含的文件:没有命名空间可以保存您 从名称冲突.最后,cpp
的使用未记录在案,并且 可能会更改,如以下消息所证实 #ligo频道在tezos-dev松弛上显示消息:
目前,LIGO随C预处理程序cpp一起提供, 穷人模块系统laC.有几个原因我们应该 立即和长期摆脱它[...]
- 最后, SmartPy 合同,实际上是Python程序 使用SmartPy库构建合同的用户 在元编程级别上的所有Python功能(在 换句话说,就是生成合同的代码).那是, 模块,类(具有继承性),函数,高级 功能,装饰器和组成.
合同间沟通
- Michelson 没有简化合同间的特定机制
通讯.调用其他合同必须通过
TRANSFER_TOKENS
指令.回调必须再次编码 手动使用连续传递样式(CPS ). - LIGO 和 SmartPy .
- 在当前版本中, Archetype 几乎不支持合同间的通信.如
据我所知,只有
transfer
指令, 不能指定参数或输入点 被称为合同(大概只有unit
类型的合同是 支持的目标).没有用于编码CPS样式的特定帮助器.但是,如下面的贝诺伊特答案所指示的那样,在原型的将来版本中对此做了修改.
In response to question 4:
Reuse and modularity
We discuss reuse and modularity, of which inheritance is one of many mechanisms:
- Michelson has no mechanism for code reuse, except for calling existing "library" contracts directly.
- As far as I understand, Archetype includes no user-extendable
mechanisms for code reuse. Actions (akin to methods) cannot be
shared between different state machines (akin to
contracts). Furthermore, actions cannot not call each other, so
cannot be composed. State machines cannot be extended or
composed. Archetypes contracts are composed of one file. However,
Archetype contains a set of extensions, that encapsulate commonly
used patterns such as
signed
, which requires that one argument of an action should be the signature of another argument. - LIGO contracts, irrespective of the syntax used, are composed of
a set of functions. These functions can be reused, and are in
general composable as one would expect from functions in any
language, with exception of recursion. What's more, the Ligo compiler
calls the C preprocessor (
cpp
) on input contracts, which enables a certain degree of reuse and composability through the use of#include
directives. Morally, this is equivalent to copy-pasting the included file: there is no namespacing to save you from name clashes. Finally, the use ofcpp
is undocumented and subject to change, as testified to by this message by the following message on the #ligo channel on the tezos-dev slack:
Currently, LIGO is shipped with the C preprocessor cpp which acts as a poor man's module system a la C. There several reasons why we should get rid of it, both immediately and in the long term [...]
- Finally, SmartPy contracts, which are actually Python programs that use the SmartPy library to construct a contract, have access to all the Python features on the meta-programming level (in other words, the code that generates the contract). That is, modules, classes (with inheritance), functions, high-level functions, decorators and compositions.
Inter-contract communication
- Michelson has no specific mechanisms to simplify inter-contract
communication. Calls to other contracts must be crafted manually through the
TRANSFER_TOKENS
instruction. Callbacks must be encoded (again) manually using continuation-passing style (CPS). - The same holds for LIGO and SmartPy.
- In the current version, Archetype has little support for inter-contract communication. As
far a I can see, there is only the
transfer
instruction, with which it is not possible to specify the argument nor the entry-point of the called contract (presumably, only contracts of typeunit
are supported targets). No specific helpers for coding CPS style. However, this is amended in future versions of Archetype, as indicated by Benoit's answer below.
-
- 2020-01-14
以下是Arvid关于 Archetype 的答案的补充:
重复使用和模块化
Indeed Archetype的扩展是可重用的代码,可将特征添加到合同中.例如,在角色上使用" 可转让"扩展名可将合同添加到将角色转移到另一个地址的必要操作(例如入口点).
例如,以管理员角色调用"transferable"扩展名:
variable admin[%transferable%] role := @tz1iawHeddgggn6P5r5jtq2wDRqcJVksGVSa
将生成两个入口点
assign_new_admin
和confirm_new_admin
.从设计的角度来看,我们已尝试将合同尽可能地保存在单个源文件中,以便于阅读和进行信任. 例如,以太坊的大多数合同通常都通过继承机制在数十个源文件中破碎,我们认为这与智能合同的外观相反.
扩展名在当前版本(0.1.12)中尚不可用,但将很快推出(它们有一些拉取请求...).
合同间沟通
在原型中支持合同调用.例如,以下原型合同在地址KT1RNB9PXsnp7KMkiMrWNMRzPjuefSWojBAm处调用合同
archetype contract_caller contract contract_called_sig { action set_value (n : int) action add_value (a : int, b : int) } variable c : contract_called_sig = @KT1RNB9PXsnp7KMkiMrWNMRzPjuefSWojBAm action update_value(n : int) { effect { c.set_value(n) } } action add_one(n : int) { effect { c.add_value(n, 2) } }
我们看到必须为合同签名提供合同关键字,并且对合同的调用类似于在对象上调用方法.
此功能可在dev分支中使用,并将在下一个版本(通常在几周内0.1.13)中很快使用.
Here is a complement to Arvid's answer regarding Archetype:
Reuse and modularity
Indeed Archetype's extensions are reusable codes to add features to a contract. For example, using the 'transferable' extension on a role adds to the contract the necessary actions (ie entry points) to transfer the role to another address.
For example, invoking the 'transferable' extension on an admin role:
variable admin[%transferable%] role := @tz1iawHeddgggn6P5r5jtq2wDRqcJVksGVSa
will generate the two entry points
assign_new_admin
andconfirm_new_admin
.From a design perspective, we have tried to keep the contract in a single source file as much as possible, for ease of reading and trust-carrying purposes. Most of Ethereum's contracts, for example, are usually shattered in literally dozens of source files by inheritance mechanisms, and we thought it was the opposite as what a smart contract should look like.
Extensions are not available yet in the current version (0.1.12) but will be soon (they are a few pull requests away ...).
Inter contract communication
There is support for contract calling in Archetype. For example, the following Archetype contract calls a contract at address KT1RNB9PXsnp7KMkiMrWNMRzPjuefSWojBAm
archetype contract_caller contract contract_called_sig { action set_value (n : int) action add_value (a : int, b : int) } variable c : contract_called_sig = @KT1RNB9PXsnp7KMkiMrWNMRzPjuefSWojBAm action update_value(n : int) { effect { c.set_value(n) } } action add_one(n : int) { effect { c.add_value(n, 2) } }
We see that the contract signature must be provided with the contract keyword and that the call to the contract is similar to invoking a method on an object.
This feature is available in the dev branch and will be available soon in the next release (0.1.13 typically in a couple of weeks).
-
- 2020-01-10
Archetype/Ligo是否提供了Michelson目前可以做的所有事情,还是两者都有局限性?
我认为,如果在Michelson而非Ligo中有可能,这可能是一个值得报告的错误,那么Ligo开发人员通常会迅速回答此类问题.
但是,Archetype故意不是图灵完整的,特别是您不能在Archetype中进行无界循环(LOOP和LOOP_LEFT支持无界循环).
Do Archetype/Ligo provide everything that Michelson can currently do, or are there limitations with either?
I think if something is possible in Michelson and not in Ligo, it is probably a bug worth reporting, the Ligo devs usually quickly answer these kinds of issues.
Archetype however is purposely not Turing complete and in particular you cannot do unbounded loops in Archetype (unbounded loops are supported by the LOOP and LOOP_LEFT).
-
- 2020-01-12
关于问题3,在@ezy注释之后,SmartPy具有一些内联功能,包括内联Michelson模板(新版本,当前为 https://SmartPy.io/dev ).
可在此处访问: https://smartpy.io/dev/index.html?template=inlineMichelson.py .
import smartpy_michelson as mi ... @sp.entry_point def concat(self, params): concat = mi.operator("CONCAT", [sp.TList(sp.TString)], [sp.TString]) self.data.s = concat(["a", "b", "c"]) @sp.entry_point def seq(self, params): self.data.value = abs(mi.seq([mi.ADD(), mi.MUL(), mi.DUP(), mi.MUL()], 15, 16, 17))
With respect to question 3, following @ezy remark, SmartPy has some inlining capabilities including with new opcodes as shown in the Inline Michelson template (of the new version, currently https://SmartPy.io/dev).
It's accessible here: https://smartpy.io/dev/index.html?template=inlineMichelson.py.
import smartpy_michelson as mi ... @sp.entry_point def concat(self, params): concat = mi.operator("CONCAT", [sp.TList(sp.TString)], [sp.TString]) self.data.s = concat(["a", "b", "c"]) @sp.entry_point def seq(self, params): self.data.value = abs(mi.seq([mi.ADD(), mi.MUL(), mi.DUP(), mi.MUL()], 15, 16, 17))
希望对一些问题有所了解.
使用Ligo,原型或流动性来缩小范围.
(或者,如果开始一些新的事情,使用其他方法中的一项是您的最大利益?)