迈克尔逊干涉仪仿真程序_迈克尔逊入门:Tezos的脚本语言(第3部分)

迈克尔逊干涉仪仿真程序

(Please check first Part 1 and Part 2)

(请先检查 第1 部分 第2部分 )

In this new installment of our series about Michelson language, we are going to crank it up a notch!

在我们有关迈克尔逊语言的系列的这一新部分中,我们将把它提高一个等级!

In the last parts, we were having a quite simple stack and doing some basic manipulations, adding elements, removing them, duplicating them, etc. However, one of the powers of smart contracts is access-control: you can request your smart contract to verify if the person sending a request is allowed to modify the storage. If they are allowed, they can continue performing their operation. If they are not, the execution of the smart contract stops and all subsequent code is ignored.

在最后一部分中,我们有一个非常简单的堆栈,并进行了一些基本操作,添加元素,删除它们,复制它们等。但是,智能合约的功能之一是访问控制:您可以请求智能合约来验证是否允许发送请求的人修改存储。 如果允许,他们可以继续执行操作。 如果不是,则智能合约的执行将停止,并且所有后续代码都将被忽略。

Unlike Ethereum smart contracts, smart contracts on Tezos do not modify the storage at any point in the execution of the transaction. The new storage is returned at the end of the execution if everything went well. This makes smart contracts on Tezos extremely secure: Michelson will make sure that everything is executed as it should before modifying the storage. Solidity will modify the storage and hope there will be no problem down the road 😊

与以太坊智能合约不同,Tezos上的智能合约在执行交易的任何时候都不会修改存储。 如果一切顺利,新存储将在执行结束时返回。 这使Tezos上的智能合约极为安全:Michelson将确保在修改存储之前一切都应按规定执行。 坚固会改变存储,并希望以后不会出现问题😊

In this article, we are going to write a smart contract that verifies that the sender of the transaction is allowed to modify the storage. If they are, we are going to concatenate the string they provide with the string in the storage. If they are not, the contract will just stop executing and return an error.

在本文中,我们将编写一个智能合约,以验证是否允许交易的发送者修改存储。 如果是这样,我们将把它们提供的字符串与存储中的字符串连接起来。 如果不是,则合同将停止执行并返回错误。

Get Best Crypto Deals Directly in your Inbox

直接在收件箱中获得最佳的加密交易

迈克尔逊码 (The Michelson code)

The whole code of the smart contract is available in the Jupyter notebook binder. After navigating to the page and waiting a minute for the Michelson kernel to load, select MichelsonTutorial-Demo4.ipynb to see the code. As for the last lesson, you can see the inline code or run the code step-by-step.

Jupyter笔记本活页夹中提供了智能合约的全部代码。 导航到该页面并等待一分钟以加载Michelson内核后,选择MichelsonTutorial-Demo4.ipynb以查看代码。 至于上一课,您可以查看内联代码或逐步运行该代码。

Let’s have a look at the inline code:

让我们看一下内联代码:

Image for post
The Michelson code for the smart contract
智能合约的迈克尔逊代码

It is amazing how much power such a small piece of code packs 😅

如此小巧的代码包具有如此强大的功能,实在令人惊讶。

The storage looks different this time: it contains a pair with an address on the left side and a string on the right side. We are going to use the address in the storage to compare it to the sender’s address and give/refuse access.

这次的存储看起来有所不同:它包含一对,左边有一个地址,右边是一个字符串。 我们将使用存储中的地址将其与发件人的地址进行比较,并授予/拒绝访问权限。

You probably recognized a few opcodes that were introduced in the previous lessons: DUP, CAR, PAIR, NIL, etc. There are also new instructions: DIG, SENDER, IFCMPEQ, FAIL, etc. No worries, we are about to see what they do.

您可能已经认识到上一课中介绍的一些操作码: DUPCARPAIR

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值