合同工厂
-
-
看起来像`CREATE_CONTRACT {storage'g;参数'p;代码...}`可以工作,但这会使合同的大小膨胀一些,并且感觉应该像Solidity的Java样式类实例化那样,应该有一种优雅地处理此问题的方法.It appears like `CREATE_CONTRACT { storage 'g ; parameter 'p ; code ... }` would work, but this will bloat the size of a contract a bit, and it feels like there should be a way to handle this gracefully like in Solidity's Java style class instantiation.
- 0
- 2019-03-11
- Rob
-
如果没有,那么在米歇尔森的一个干净的例子将是很好的.If not, a clean example in Michelson would be nice.
- 0
- 2019-03-11
- Rob
-
好的,可能是一个出路.ok cool, probably a ways out then.
- 0
- 2019-03-12
- Rob
-
我发表了一条删除的评论,将其转换为答案.我想念您后来添加的评论.我对此表示歉意.I put a comment that I deleted to convert it into an answer. I missed your comment that was added afterwards. My apologies for this.
- 1
- 2019-03-12
- FFF
-
2 个回答
- 投票数
-
- 2019-03-12
在有关SmartPy的公告中,讨论非常简洁.> https://medium.com/@SmartPy_io/introducing-smartpy-and-smartpy-io-d4013bee7d4e#15ee .
想法是要有一个包含big_map的合同,并且big_map的每个元素都代表一个合同.
这绝对不限于SmartPy,它可以直接在Michelson,Liquidity或Fi中使用.
此主题也出现在这里: 什么是BigMap容器及其重要性?
There is a very succinct discussion in the announcement for SmartPy https://medium.com/@SmartPy_io/introducing-smartpy-and-smartpy-io-d4013bee7d4e#15ee.
The idea is to have a contract that holds a big_map and each element of the big_map represents a contract.
This is absolutely not restricted to SmartPy and it is directly doable in Michelson, Liquidity or Fi.
This subject also appeared here: What is the BigMap container and why does it matter?
-
我感谢您的回应,不希望这会带来负面影响,但我认为我们需要在短期内针对此问题提出更全面的解决方案,以提高DAPP开发的效率.I appreciate your response and don't want this to come across negative, but I feel we need to come up with a more comprehensive solution to this problem in the near term to make DAPP development productive.
- 0
- 2019-03-12
- Rob
-
我可以很容易地同意,这不是最终的唯一解决方案.I can easily agree that this is not the final and only solution.
- 0
- 2019-03-12
- FFF
-
参考下面的内容以查看我在想什么reference below to see an example of what I was thinking
- 0
- 2019-03-14
- Rob
-
- 2019-03-14
这是处理流动资金的合同示例.编写仅在执行结束时才能利用远程过程调用的函数就有一个独特的挑战:
type plus_storage = { count: nat, plus_owner: address, }; contract PlusOne = { type storage = plus_storage; let%init storage = (y: nat) => { count: y, plus_owner: Current.sender(), }; let%entry main = (p: nat, storage) => { if (Current.sender() != storage.plus_owner) { failwith("invalid caller"); }; ([], storage); } }; type storage = { owner: key, pl: address, }; let%init storage = (contract_owner: key) => { owner: contract_owner, pl: KT1111111111111111111111111111111111, } let%entry other = (param: nat, storage) => { let t: option(PlusOne.instance) = Contract.at(storage.pl); let t = switch(t) { | None => Current.failwith() | Some(inst) => inst }; let op = Contract.call( ~dest=t, ~amount=0tz, ~entry=main, ~parameter=param); ([op], storage); }; let%entry main = ((), storage) => { let manager = Crypto.hash_key(storage.owner); let delegate = Some(manager); let spendable = false; let amount = Current.amount(); let init_value: nat = 0; let (c_op, c_addr) = Contract.create( ~manager, ~delegate, ~spendable, ~delegatable=false, ~amount, ~storage={count: init_value, plus_owner: Contract.address(Contract.self())}, (contract PlusOne), ); let storage = storage.pl = c_addr; ([c_op], storage); };
这使我想知道这是否会导致诸如"订购"和"提货"之类的终点,即餐馆.
Here's an example of a contract handling this in liquidity. There's the unique challenge of writing functions that can only utilize remote procedure calls at the end of their execution:
type plus_storage = { count: nat, plus_owner: address, }; contract PlusOne = { type storage = plus_storage; let%init storage = (y: nat) => { count: y, plus_owner: Current.sender(), }; let%entry main = (p: nat, storage) => { if (Current.sender() != storage.plus_owner) { failwith("invalid caller"); }; ([], storage); } }; type storage = { owner: key, pl: address, }; let%init storage = (contract_owner: key) => { owner: contract_owner, pl: KT1111111111111111111111111111111111, } let%entry other = (param: nat, storage) => { let t: option(PlusOne.instance) = Contract.at(storage.pl); let t = switch(t) { | None => Current.failwith() | Some(inst) => inst }; let op = Contract.call( ~dest=t, ~amount=0tz, ~entry=main, ~parameter=param); ([op], storage); }; let%entry main = ((), storage) => { let manager = Crypto.hash_key(storage.owner); let delegate = Some(manager); let spendable = false; let amount = Current.amount(); let init_value: nat = 0; let (c_op, c_addr) = Contract.create( ~manager, ~delegate, ~spendable, ~delegatable=false, ~amount, ~storage={count: init_value, plus_owner: Contract.address(Contract.self())}, (contract PlusOne), ); let storage = storage.pl = c_addr; ([c_op], storage); };
It makes me wonder if this will lead to endpoints that are like "order" and "pickup", ie a restaurant.
是否有关于如何在Michelson/Liquidity建立合同工厂的研究?
要详细说明,在Solidity中,合同工厂可能看起来像:
(引用自 https://ethereum.stackexchange.com/questions/13415/从实体合同中部署合同)
这是DAPP开发中的一项强大功能,因为它允许您为DAPP构建面向对象的结构,请求可以在其中创建新合同.这是一个完善的设计模式,那么在Tezos生态系统中将是什么?