前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >DAPP智能合约系统开发技术概念讲解方案

DAPP智能合约系统开发技术概念讲解方案

原创
作者头像
开发v_StPv888
发布2022-11-10 11:13:08
2820
发布2022-11-10 11:13:08
举报
文章被收录于专栏:makingmaking

  区块链中,交易信息以一个个信息块的形式记录,这些块以链条方式,按时间顺序连接起来。新生成的交易信息记录块,不断地被加到区块链中,交易一旦写入区块链中就不能被修改;

The Web 3.0 application is called DApp, and its full name is Decentralized Application. The main features of DApp include: decentralization, tamper proof, each piece of data is owned by users, and data can be bought and sold. Take decentralization as an example. No matter microblogging, WeChat reading or Tencent documents, they share the common features of Internet products: all data are collected, stored and used by an Internet company alone.

  去中心化

  去中心化(Decentralized)的意思就是用户可以不通过Google、Facebook、微博等中介的服务访问互联网上的数据和信息,而是由个人自己拥有和控制互联网的各个部分。也就是说,在Web3上,开发者不需要在一个单独的服务器上建立和部署应用,也不用在一个单独的数据库中储存数据,极大降低了单点故障的风险。

代码语言:javascript
复制
import requests

# If you are using a Jupyter notebook, uncomment the following line.
# %matplotlib inline
import matplotlib.pyplot as plt
import json
from PIL import Image
from io import BytesIO

# Replace <Subscription Key> with your valid subscription key.
subscription_key = "<Subscription Key>"
assert subscription_key

# You must use the same region in your REST call as you used to get your
# subscription keys. For example, if you got your subscription keys from
# westus, replace "westcentralus" in the URI below with "westus".

# Free trial subscription keys are generated in the "westus" region.
# If you use a free trial subscription key, you shouldn't need to change
# this region.
vision_base_url = "https://westcentralus.api.cognitive.microsoft.com/vision/v2.0/"

analyze_url = vision_base_url + "analyze"

  区块链是真正去中心化互联网的核心,它改变了数据存储和管理的方式,其独特的架构允许多个节点在没有一个集中的事实来源的情况下就数据集的当前状态保持一致。作为用户为去中心化执行而激活的自动执行代码,智能合约是加密难题的重要组成部分,这允许两方在彼此不知情的情况下进行价值转移。

代码语言:javascript
复制
def parser_image(image_url):
    # Set image_url to the URL of an image that you want to analyze.
    # image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/12/" + \
    #     "Broadway_and_Times_Square_by_night.jpg/450px-Broadway_and_Times_Square_by_night.jpg"

    headers = {'Ocp-Apim-Subscription-Key': subscription_key }
    params = {'visualFeatures': 'Categories,Description,Color'}
    data = {'url': image_url}
    response = requests.post(analyze_url, headers=headers, params=params, json=data)
    response.raise_for_status()

    # The 'analysis' object contains various fields that describe the image. The most
    # relevant caption for the image is obtained from the 'description' property.
    analysis = response.json()
    # print(json.dumps(response.json()))
    # image_caption = analysis["description"]["captions"][0]["text"].capitalize()

    # Display the image and overlay it with the caption.
    # image = Image.open(BytesIO(requests.get(image_url).content))
    # plt.imshow(image)
    # plt.axis("off")
    # _ = plt.title(image_caption, size="x-large", y=-0.1)
    # plt.show()

    # print("Analysis finish")
    return analysis

  gas费用

  链上交易需要手续费,手续费被称为gas(汽油),gas是用于评估在区块链上执行特定操作所需的计算工作量的单位。

  gas只是一个抽象单位,它仅存在于以太虚拟机中,用户实际上总是在以太网络中使用ETH(以太币)进行交易。

  为什么要引入gas呢?

  以太虚拟机可以执行任意代码,但它也更容易受到halting problem的影响。halting problem是指从一个任意计算机程序的代码和输入来确定该程序是会结束运行,还是会永远继续运行。如果没有gas,用户就可以执行一个永远不会停止的程序,为了防止这种情况发生,以太引入了与每个操作相关的gas成本,这将防止程序处于永远运行的状态,最终使整个网络陷入停滞状态。

代码语言:javascript
复制
if __name__ == '__main__':
    image_url = "http://img4.imgtn.bdimg.com/it/u=4020056921,51126977&fm=200&gp=0.jpg"
    analysis = parser_image(image_url)
    description = analysis.get("description")
    print(description["tags"])

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
区块链
云链聚未来,协同无边界。腾讯云区块链作为中国领先的区块链服务平台和技术提供商,致力于构建技术、数据、价值、产业互联互通的区块链基础设施,引领区块链底层技术及行业应用创新,助力传统产业转型升级,推动实体经济与数字经济深度融合。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档