区块链中,交易信息以一个个信息块的形式记录,这些块以链条方式,按时间顺序连接起来。新生成的交易信息记录块,不断地被加到区块链中,交易一旦写入区块链中就不能被修改;
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上,开发者不需要在一个单独的服务器上建立和部署应用,也不用在一个单独的数据库中储存数据,极大降低了单点故障的风险。
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 with your valid 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"
复制
区块链是真正去中心化互联网的核心,它改变了数据存储和管理的方式,其独特的架构允许多个节点在没有一个集中的事实来源的情况下就数据集的当前状态保持一致。作为用户为去中心化执行而激活的自动执行代码,智能合约是加密难题的重要组成部分,这允许两方在彼此不知情的情况下进行价值转移。
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成本,这将防止程序处于永远运行的状态,最终使整个网络陷入停滞状态。
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"])