HK40055340B - Method and apparatus for deploying blockchain contract, device and storage medium - Google Patents
Method and apparatus for deploying blockchain contract, device and storage medium Download PDFInfo
- Publication number
- HK40055340B HK40055340B HK42021044826.2A HK42021044826A HK40055340B HK 40055340 B HK40055340 B HK 40055340B HK 42021044826 A HK42021044826 A HK 42021044826A HK 40055340 B HK40055340 B HK 40055340B
- Authority
- HK
- Hong Kong
- Prior art keywords
- contract
- address
- proxy
- business
- data
- Prior art date
Links
Description
本申请为在2019年11月27日提交中国专利局、申请号为201911180240.3、申请名称为“区块链合约部署方法、装置、设备以及存储介质”的中国专利申请的分案申请,其全部内容通过引用结合在本申请中。This application is a divisional application of the Chinese patent application filed with the China Patent Office on November 27, 2019, with application number 201911180240.3 and application name “Blockchain Contract Deployment Method, Device, Equipment and Storage Medium”, all contents of which are incorporated by reference into this application.
技术领域Technical Field
本申请涉及互联网技术领域,尤其涉及一种区块链合约部署方法、装置、设备以及存储介质。The present application relates to the field of Internet technology, and in particular to a blockchain contract deployment method, apparatus, device, and storage medium.
背景技术Background Art
智能合约是一种旨在以信息化方式传播、验证或执行合同的计算机协议,智能合约允许在没有第三方的情况下进行可信交易,这些交易可追踪且不可逆转。智能合约作为区块链上的程序,可以由创建者进行创建并部署到区块链上,当然,为了在区块链中部署可更新的智能合约,可以通过使用代理合约来实现。A smart contract is a computer protocol designed to communicate, verify, or execute contracts in an information-based manner. It allows for trusted, traceable, and irreversible transactions without a third party. Smart contracts, as programs on a blockchain, can be created and deployed by their creators. Of course, deploying updatable smart contracts on a blockchain can be achieved through the use of proxy contracts.
在现有技术中,可以为业务创建代理合约(即为一段程序代码),并将创建的代理合约部署到区块链中,然而,当存在多个业务时,需要依次为每个业务分别编写一个代理合约,涉及到大量的代码量,进而导致代理合约的开发效率低下。In the existing technology, a proxy contract (i.e., a piece of program code) can be created for a business and deployed to the blockchain. However, when there are multiple businesses, a proxy contract needs to be written for each business in turn, which involves a large amount of code and leads to low efficiency in the development of proxy contracts.
发明内容Summary of the Invention
本申请实施例提供一种区块链合约部署方法、装置、设备以及存储介质,可以提高区块链中合约的开发效率。The embodiments of the present application provide a blockchain contract deployment method, apparatus, device, and storage medium, which can improve the development efficiency of contracts in the blockchain.
本申请实施例一方面提供了一种区块链合约部署方法,包括:The present invention provides a blockchain contract deployment method, including:
接收请求节点发送的合约注册请求,获取合约注册请求携带的合约名称、数据合约对应的第一地址以及业务合约对应的第二地址;数据合约用于存储业务数据,业务合约用于存储业务逻辑;Receive the contract registration request sent by the requesting node, obtain the contract name, the first address corresponding to the data contract, and the second address corresponding to the business contract carried in the contract registration request; the data contract is used to store business data, and the business contract is used to store business logic;
从合约管理平台中获取合约模板,基于合约模板对第一地址和第二地址进行绑定,得到与业务合约和数据合约相关联的代理合约,生成代理合约对应的第三地址;Obtain a contract template from the contract management platform, bind the first address and the second address based on the contract template, obtain a proxy contract associated with the business contract and the data contract, and generate a third address corresponding to the proxy contract;
生成第三地址和合约名称之间的映射关系信息,将映射关系信息存储在合约管理平台中。Generate mapping relationship information between the third address and the contract name, and store the mapping relationship information in the contract management platform.
本申请实施例一方面提供了一种区块链合约部署装置,包括:An embodiment of the present application provides a blockchain contract deployment device, including:
接收模块,用于接收请求节点发送的合约注册请求,获取合约注册请求携带的合约名称、数据合约对应的第一地址以及业务合约对应的第二地址;数据合约用于存储业务数据,业务合约用于存储业务逻辑;The receiving module is used to receive the contract registration request sent by the requesting node and obtain the contract name, the first address corresponding to the data contract, and the second address corresponding to the business contract carried in the contract registration request; the data contract is used to store business data, and the business contract is used to store business logic;
创建模块,用于从合约管理平台中获取合约模板,基于合约模板对第一地址和第二地址进行绑定,得到与业务合约和数据合约相关联的代理合约,生成代理合约对应的第三地址;Create a module for obtaining a contract template from the contract management platform, binding the first address and the second address based on the contract template, obtaining a proxy contract associated with the business contract and the data contract, and generating a third address corresponding to the proxy contract;
存储模块,用于生成第三地址和合约名称之间的映射关系信息,将映射关系信息存储在合约管理平台中。The storage module is used to generate mapping relationship information between the third address and the contract name, and store the mapping relationship information in the contract management platform.
其中,该装置还包括:The device further comprises:
区块生成模块,用于获取请求节点上传的数据合约和业务合约,根据数据合约和业务合约生成合约区块;The block generation module is used to obtain the data contract and business contract uploaded by the requesting node and generate the contract block based on the data contract and business contract;
共识模块,用于当合约区块在区块链网络中共识通过时,将数据合约和业务合约确定为发布成功状态;The consensus module is used to determine the data contract and business contract as being released successfully when the contract block is passed by consensus in the blockchain network;
地址确定模块,用于根据请求节点对应的账号信息,确定处于发布成功状态的数据合约对应的第一地址,以及处于发布成功状态的业务合约对应的第二地址,将第一地址和第二地址发送至请求节点。The address determination module is used to determine the first address corresponding to the data contract in the successful release state and the second address corresponding to the business contract in the successful release state according to the account information corresponding to the requesting node, and send the first address and the second address to the requesting node.
其中,构建模块包括:The building blocks include:
参数输入单元,用于从合约管理平台中获取合约模板,将第一地址和第二地址作为参数输入合约模板中;A parameter input unit, configured to obtain a contract template from the contract management platform and input the first address and the second address as parameters into the contract template;
接口调用单元,用于基于合约模板,从第二地址对应的业务合约中调用地址设置接口;An interface calling unit, configured to call an address setting interface from a business contract corresponding to the second address based on the contract template;
绑定单元,用于根据地址设置接口,将第一地址输入业务合约中,对业务合约和数据合约进行绑定,得到代理合约。The binding unit is used to input the first address into the business contract according to the address setting interface, bind the business contract and the data contract, and obtain the proxy contract.
其中,该装置还包括:The device further comprises:
遍历模块,用于基于合约名称,对合约管理平台中存储的历史映射关系信息进行遍历;The traversal module is used to traverse the historical mapping relationship information stored in the contract management platform based on the contract name;
验证模块,用于若历史映射关系信息中存在合约名称,则向请求节点返回名称更改提示信息;The verification module is used to return a name change prompt to the requesting node if the contract name exists in the historical mapping relationship information;
验证模块,还用于若历史映射关系信息中不存在合约名称,则生成第三地址和合约名称之间的映射关系信息,将映射关系信息存储在合约管理平台中。The verification module is further used to generate mapping relationship information between the third address and the contract name if the contract name does not exist in the historical mapping relationship information, and store the mapping relationship information in the contract management platform.
其中,该装置还包括:The device further comprises:
查询请求接收模块,用于当接收到请求节点发送的合约查询请求时,获取合约查询请求所携带的合约名称;The query request receiving module is used to obtain the contract name carried in the contract query request when receiving the contract query request sent by the requesting node;
地址查询模块,用于从合约管理平台中获取与合约名称具有映射关系的第三地址,将第三地址返回至请求节点,以使请求节点将第三地址与合约名称存储在本地中。The address query module is used to obtain a third address that has a mapping relationship with the contract name from the contract management platform, and return the third address to the requesting node so that the requesting node stores the third address and the contract name locally.
其中,合约管理平台包括第三地址与多个节点之间的关联关系,多个节点包括代理合约对应的管理节点和授权访问节点;The contract management platform includes an association relationship between a third address and a plurality of nodes, wherein the plurality of nodes include a management node and an authorized access node corresponding to the proxy contract;
该装置还包括:The device also includes:
查询请求接收模块,用于当接收到请求节点发送的合约查询请求时,获取合约查询请求所携带的合约名称;The query request receiving module is used to obtain the contract name carried in the contract query request when receiving the contract query request sent by the requesting node;
关联节点获取模块,用于从合约管理平台中获取与合约名称具有映射关系的第三地址,获取与第三地址相关联的多个节点;An associated node acquisition module, configured to obtain a third address having a mapping relationship with the contract name from the contract management platform, and obtain multiple nodes associated with the third address;
查询权限确定模块,用于若多个节点中存在请求节点,则确定请求节点具有查询权限,将第三地址返回至请求节点,以使请求节点将第三地址与合约名称存储在本地中;a query authority determination module, configured to, if a requesting node exists among the plurality of nodes, determine that the requesting node has query authority, and return the third address to the requesting node, so that the requesting node stores the third address and the contract name locally;
该查询权限确定模,还用于若多个节点中不存在请求节点,则确定请求节点不具有查询权限,向请求节点返回权限提示信息。The query authority determination module is also used to determine that the requesting node does not have the query authority if the requesting node does not exist among the multiple nodes, and return authority prompt information to the requesting node.
其中,该装置还包括:The device further comprises:
交易数据获取模块,用于获取请求节点上传的交易数据,基于交易数据携带的第三地址获取代理合约;The transaction data acquisition module is used to obtain the transaction data uploaded by the requesting node and obtain the proxy contract based on the third address carried in the transaction data;
数据操作模块,用于根据代理合约调用业务合约,并基于业务合约中的业务逻辑,对数据合约和交易数据进行操作,生成交易数据对应的合约处理结果。The data operation module is used to call the business contract according to the proxy contract, and based on the business logic in the business contract, operate the data contract and transaction data to generate the contract processing results corresponding to the transaction data.
其中,该装置还包括:The device further comprises:
更新请求获取模块,用于获取针对代理合约的更新请求,基于更新请求获取第一地址以及更新业务合约对应的第四地址;An update request acquisition module, configured to obtain an update request for the proxy contract, and obtain the first address and the fourth address corresponding to the updated business contract based on the update request;
测试合约生成模块,用于将第四地址和第一地址作为参数输入至合约模板,生成测试代理合约;A test contract generation module, configured to input the fourth address and the first address as parameters into a contract template to generate a test proxy contract;
合约更新模块,用于当测试代理合约通过测试时,基于通过测试的测试代理合约,对代理合约进行更新。The contract update module is used to update the proxy contract based on the test proxy contract that passed the test when the test proxy contract passes the test.
其中,合约更新模块包括:Among them, the contract update module includes:
地址更新单元,用于当测试代理合约通过测试时,冻结代理合约,将代理合约中的第二地址更新为测试通过状态的测试代理合约中的第四地址;An address updating unit, configured to freeze the proxy contract when the test proxy contract passes the test, and update the second address in the proxy contract to the fourth address in the test proxy contract in the test passed state;
更新合约确定单元,用于将包含第一地址和第四地址的代理合约确定为更新后的代理合约;更新后的代理合约与第三地址相关联。The updated contract determining unit is configured to determine the proxy contract including the first address and the fourth address as an updated proxy contract; the updated proxy contract is associated with the third address.
本申请实施例一方面提供了一种节点设备,包括存储器和处理器,存储器存储有计算机程序,计算机程序被处理器执行时,使得处理器执行本申请实施例中一方面中方法的步骤。In one aspect, an embodiment of the present application provides a node device, including a memory and a processor. The memory stores a computer program. When the computer program is executed by the processor, the processor executes the steps of the method in one aspect of the embodiment of the present application.
本申请实施例一方面提供了一种计算机可读存储介质,计算机可读存储介质存储有计算机程序,计算机程序包括程序指令,程序指令当被处理器执行时,执行如本申请实施例中一方面中方法的步骤。On one hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. The computer program includes program instructions. When the program instructions are executed by a processor, the steps of the method in one aspect of the embodiment of the present application are executed.
在本申请实施例中,区块链节点在接收到请求节点发送的合约注册请求时,可以获取合约注册请求携带的合约名称、数据合约对应的第一地址以及业务合约对应的第二地址,基于合约管理平台中获取合约模板,基于合约模板对第一地址和第二地址进行绑定,得到与数据合约和业务合约相关联的代理合约,生成该代理合约对应的第三地址,将第三地址和合约名称之间的映射关系信息存储在合约管理平台中。可见,通过在区块链中创建合约管理平台,并在合约管理平台中编写一个合约模板,将业务合约地址和数据合约地址作为参数输入合约模板中即可将数据合约和业务合约进行绑定,完成代理合约在区块链中的部署过程,通过合约模板的方式可以减少代理合约的开发过程,进而可以提高区块链中合约的开发效率。In an embodiment of the present application, upon receiving a contract registration request from a requesting node, a blockchain node can obtain the contract name, the first address corresponding to the data contract, and the second address corresponding to the business contract carried in the contract registration request, obtain a contract template from the contract management platform, bind the first address and the second address based on the contract template, obtain a proxy contract associated with the data contract and the business contract, generate a third address corresponding to the proxy contract, and store the mapping relationship information between the third address and the contract name in the contract management platform. Thus, by creating a contract management platform in the blockchain and writing a contract template in the contract management platform, the business contract address and the data contract address can be input as parameters into the contract template to bind the data contract and the business contract, completing the deployment process of the proxy contract in the blockchain. The use of contract templates can reduce the development process of proxy contracts, thereby improving the efficiency of contract development in the blockchain.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
图1是本申请实施例提供的一种网络架构图;FIG1 is a diagram of a network architecture provided by an embodiment of the present application;
图2是本申请实施例提供的一种区块链合约部署场景示意图;FIG2 is a schematic diagram of a blockchain contract deployment scenario provided by an embodiment of the present application;
图3是本申请实施例提供的一种区块链合约部署方法的流程示意图;FIG3 is a flow chart of a blockchain contract deployment method provided in an embodiment of the present application;
图4是本申请实施例提供的一种智能合约执行场景示意图;FIG4 is a schematic diagram of a smart contract execution scenario provided by an embodiment of the present application;
图5是本申请实施例提供的另一种区块链合约部署方法的流程示意图;FIG5 is a flow chart of another blockchain contract deployment method provided in an embodiment of the present application;
图6是本申请实施例提供的一种合约升级场景示意图;FIG6 is a schematic diagram of a contract upgrade scenario provided by an embodiment of the present application;
图7是本申请实施例提供的一种区块链合约部署装置的结构示意图;FIG7 is a schematic diagram of the structure of a blockchain contract deployment device provided in an embodiment of the present application;
图8是本申请实施例提供的一种节点设备的结构示意图。FIG8 is a schematic structural diagram of a node device provided in an embodiment of the present application.
具体实施方式DETAILED DESCRIPTION
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
区块链(Blockchain)是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。区块链可以包括区块链底层平台、平台产品服务层以及应用服务层。Blockchain is a new application model for computer technologies, including distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a series of data blocks linked using cryptographic methods. Each block contains information about a batch of online transactions, used to verify the validity of this information (to prevent counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, the platform product and service layer, and the application service layer.
区块链底层平台可以包括用户管理、基础服务、智能合约以及运营监控等处理模块。其中,用户管理模块负责所有区块链参与者的身份信息管理,包括维护公私钥生成(账户管理)、密钥管理以及用户真实身份和区块链地址对应关系维护(权限管理)等,并且在授权的情况下,监管和审计某些真实身份的交易情况,提供风险控制的规则配置(风控审计);基础服务模块部署在所有区块链节点设备上,用来验证业务请求的有效性,并对有效请求完成共识后记录到存储上,对于一个新的业务请求,基础服务先对接口适配解析和鉴权处理(接口适配),然后通过共识算法将业务信息加密(共识管理),在加密之后完整一致的传输至共享账本上(网络通信),并进行记录存储;智能合约模块负责合约的注册发行以及合约触发和合约执行,开发人员可以通过某种编程语言定义合约逻辑,发布到区块链上(合约注册),根据合约条款的逻辑,调用密钥或者其它的事件触发执行,完成合约逻辑,同时还提供对合约升级注销的功能;运营监控模块主要负责产品发布过程中的部署、配置的修改、合约设置、云适配以及产品运行中的实时状态的可视化输出,例如:告警、监控网络情况、监控节点设备健康状态等。The underlying blockchain platform can include processing modules such as user management, basic services, smart contracts, and operation monitoring. Among them, the user management module is responsible for the identity information management of all blockchain participants, including maintaining public and private key generation (account management), key management, and maintaining the corresponding relationship between the user's real identity and the blockchain address (authority management), etc., and under authorization, it supervises and audits the transactions of certain real identities and provides risk control rule configuration (risk control audit); the basic service module is deployed on all blockchain node devices to verify the validity of business requests, and records the valid requests to the storage after consensus is reached. For a new business request, the basic service first adapts the interface to parse and authenticate the request (interface adaptation), and then encrypts the business information through the consensus algorithm (consensus management). The smart contract module is responsible for the registration, issuance, triggering and execution of contracts. Developers can define the contract logic in a programming language and publish it to the blockchain (contract registration). According to the logic of the contract terms, the contract logic is triggered by calling keys or other events to trigger execution. The contract logic is completed, and the contract upgrade and cancellation functions are also provided. The operation monitoring module is mainly responsible for the deployment, configuration modification, contract setting, cloud adaptation and real-time status visualization output of the product during the product release process, such as alarms, network status monitoring, and node device health monitoring.
智能合约可以理解为运行在分布式账本(即区块链)上预置规则、具有状态、条件响应的,可封装、验证、执行分布式节点复杂行为,完成信息交换、价值转移和资产管理的计算机程序。基于区块链的分布式架构、共识算法等,智能合约允许相互不信任的用户在不需要任何第三方可信中介或权威的情况下完成交易,同时,数字形式的智能合约可灵活嵌入各种有形或无形的资产、交易和数据中,实现主动或被动的资产、信息管理与控制,逐步构建可编程的智能资产、系统等。Smart contracts can be understood as computer programs that run on a distributed ledger (i.e., blockchain) with pre-set rules, state, and conditional responses. They can encapsulate, verify, and execute complex behaviors of distributed nodes to facilitate information exchange, value transfer, and asset management. Based on blockchain's distributed architecture and consensus algorithms, smart contracts allow mutually untrusting users to complete transactions without the need for any trusted third-party intermediary or authority. Furthermore, digital smart contracts can be flexibly embedded in various tangible or intangible assets, transactions, and data, enabling active or passive asset and information management and control, and gradually building programmable intelligent assets and systems.
请参见图1,是本申请实施例提供的一种网络架构图。如图1所示,该网络架构可以包括多个节点服务器(如图1所示,具体可以包括节点服务器10a、节点服务器10b、节点服务器10c以及节点服务器10d)和请求终端10e。其中,节点服务器10a、节点服务器10b、节点服务器10c以及节点服务器10d均表示为区块链网络中的区块链节点,请求终端10e可以是指用户终端,该请求终端10e可以将需要上链的数据(如新产生的交易数据、编写的智能合约等)上传至区块链网络,并向区块链网络请求将上传的数据进行上链。当请求终端10e向区块链网络上传数据后,区块链网络中的任一区块链节点(如节点服务器10a)可以根据请求终端10e上传的数据生成新区块,并将新生成的区块在区块链网络中进行广播,以使区块链网络中的节点对新生成的区块进行共识,即节点服务器10a在新生成区块后,可以将新生成的区块广播给节点服务器10b、节点服务器10c以及节点服务器10d,共识通过的数据即可进行正式上链,区块链网络中的节点可以在本地存储区块链。区块链网络中的节点中可以创建合约管理平台(即可以实现合约管理功能的计算机程序),该合约管理平台具有智能合约注册、代理、升级等功能。本申请实施例中的智能合约是由合约请求终端与区块链节点共同参与的业务处理合约,每个区块链节点均可以触发并执行智能合约,即均可以为智能合约提供运行环境(以太坊虚拟机)。Please refer to Figure 1, which is a network architecture diagram provided by an embodiment of the present application. As shown in Figure 1, the network architecture may include multiple node servers (as shown in Figure 1, specifically including node server 10a, node server 10b, node server 10c and node server 10d) and a request terminal 10e. Among them, node server 10a, node server 10b, node server 10c and node server 10d are all represented as blockchain nodes in the blockchain network, and the request terminal 10e may refer to a user terminal. The request terminal 10e can upload data that needs to be on the chain (such as newly generated transaction data, written smart contracts, etc.) to the blockchain network, and request the blockchain network to upload the uploaded data to the chain. After the request terminal 10e uploads data to the blockchain network, any blockchain node in the blockchain network (such as node server 10a) can generate a new block based on the data uploaded by the request terminal 10e, and broadcast the newly generated block in the blockchain network so that the nodes in the blockchain network can reach a consensus on the newly generated block, that is, after the node server 10a generates a new block, it can broadcast the newly generated block to node server 10b, node server 10c and node server 10d. The data passed by consensus can be formally uploaded to the chain, and the nodes in the blockchain network can store the blockchain locally. A contract management platform (i.e., a computer program that can implement contract management functions) can be created in the nodes in the blockchain network. The contract management platform has functions such as smart contract registration, agency, and upgrade. The smart contract in the embodiment of the present application is a business processing contract jointly participated in by the contract request terminal and the blockchain node. Each blockchain node can trigger and execute the smart contract, that is, it can provide an operating environment (Ethereum virtual machine) for the smart contract.
其中,请求终端10e可以包括手机、平板电脑、笔记本电脑、掌上电脑、移动互联网设备(mobile internet device,MID)、可穿戴设备(例如智能手表、智能手环等)等。The requesting terminal 10e may include a mobile phone, a tablet computer, a laptop computer, a PDA, a mobile internet device (MID), a wearable device (such as a smart watch, a smart bracelet, etc.), etc.
请一并参见图2,是本申请实施例提供的一种区块链合约部署场景示意图。由于区块链的不可篡改性,智能合约在区块链中部署完成后,就无法进行源代码的修改,若业务需求变更时,就需要重新部署智能合约,并会造成原有数据的丢失,因此提出了可升级式智能合约。可升级式智能合约的原理是将数据合约和数据合约进行分离,使用业务合约调用数据合约,当业务需求变更时,通过重新部署业务合约即可,而数据合约中所存储的数据则不会丢失,其中,数据合约用于存储业务数据,业务合约用于维护业务逻辑。本申请实施例中,可以通过代理合约的方式对业务合约和数据合约进行分离,代理合约的本质是通过新部署一个合约的方式,来实现升级主要的处理逻辑的目的。Please refer to Figure 2, which is a schematic diagram of a blockchain contract deployment scenario provided by an embodiment of the present application. Due to the immutability of the blockchain, the source code of the smart contract cannot be modified after it is deployed in the blockchain. If the business requirements change, the smart contract needs to be redeployed, and the original data will be lost. Therefore, an upgradeable smart contract is proposed. The principle of the upgradeable smart contract is to separate the data contract from the data contract, and use the business contract to call the data contract. When the business requirements change, the business contract can be redeployed, and the data stored in the data contract will not be lost. The data contract is used to store business data, and the business contract is used to maintain business logic. In the embodiment of the present application, the business contract and the data contract can be separated by means of a proxy contract. The essence of the proxy contract is to achieve the purpose of upgrading the main processing logic by newly deploying a contract.
如图2所示,以请求终端10e和图1所对应实施例中的节点服务器10a为例,对代理合约的部署过程进行说明。请求终端10e可以将开发人员编写的数据合约和业务合约随发起的交易提交至区块链网络,区块链网络中的节点服务器10a在接收到请求终端10e提交的携带数据合约和业务合约的交易后,可以对接收到的携带数据合约和业务合约的交易进行验签,验签的目的在于检测携带数据合约和业务合约的交易在传输过程中是否被篡改。若验签不通过,则表示请求终端10e在上传交易的过程中可能被篡改,可以将携带数据合约和业务合约的交易进行删除;若验签通过,则表示节点服务器10a实际接收到的交易与请求终端10e提交的交易相同,即携带数据合约和业务合约的交易在传输过程中没有被篡改。As shown in Figure 2, the proxy contract deployment process is described using a requesting terminal 10e and the node server 10a of the embodiment corresponding to Figure 1 as examples. Requesting terminal 10e can submit the developer's data contract and business contract to the blockchain network along with the initiated transaction. Upon receiving the transaction containing the data contract and business contract submitted by requesting terminal 10e, node server 10a in the blockchain network can verify the signature of the received transaction containing the data contract and business contract. The purpose of the signature verification is to detect whether the transaction containing the data contract and business contract has been tampered with during transmission. If the signature verification fails, it indicates that requesting terminal 10e may have been tampered with during the transaction upload process, and the transaction containing the data contract and business contract can be deleted. If the signature verification passes, it indicates that the transaction actually received by node server 10a is the same as the transaction submitted by requesting terminal 10e, that is, the transaction containing the data contract and business contract has not been tampered with during transmission.
节点服务器10a可以将验签通过的携带数据合约和业务合约的交易打包成区块20a,区块20a的区块头中包含区块链中具有最大区块高度的区块对应的哈希(Hash),区块20a的区块体中可以用于存储业务合约和数据合约。节点服务器10a可以将新生成的区块20a在区块链网络中进行广播,即将区块20a发送至区块链网络中的每个节点(此处默认区块链网络中的所有节点均为共识节点),以使区块链网络中的每个节点对区块20a进行共识验证,当区块20a通过共识后(如区块链网络中超过51%的节点通过了区块20a的共识验证等),可以将区块20a添加至区块链进行正式上链,即表示数据合约和业务合约在区块链中创建成功。Node server 10a can package the signed transactions carrying data contracts and business contracts into block 20a. The block header of block 20a contains the hash corresponding to the block with the highest block height in the blockchain. The block body of block 20a can be used to store the business contract and data contract. Node server 10a can broadcast the newly generated block 20a in the blockchain network, that is, send block 20a to each node in the blockchain network (here, it is assumed that all nodes in the blockchain network are consensus nodes) so that each node in the blockchain network can perform consensus verification on block 20a. Once block 20a passes consensus (such as more than 51% of the nodes in the blockchain network pass the consensus verification of block 20a), block 20a can be added to the blockchain for formal on-chain, indicating that the data contract and business contract have been successfully created in the blockchain.
在数据合约和业务合约创建成功后,节点服务器10a中的以太坊虚拟机20b(environment virtual machine,EVM)可以根据请求终端10e的账户信息生成合约地址,即生成数据合约对应的地址1,以及业务合约对应的地址2,其中,地址1用于指示数据合约,可以理解为数据合约对应的标识信息,地址2用于指示业务合约,可以理解为业务合约对应的标识信息,不同的合约对应不同的地址。节点服务器10a可以将生成的地址1和地址2返回至请求终端10e。After the data contract and business contract are successfully created, the Ethereum virtual machine 20b (EVM) in the node server 10a can generate contract addresses based on the account information of the requesting terminal 10e, namely, address 1 corresponding to the data contract and address 2 corresponding to the business contract. Address 1 is used to indicate the data contract and can be understood as the identification information corresponding to the data contract. Address 2 is used to indicate the business contract and can be understood as the identification information corresponding to the business contract. Different contracts correspond to different addresses. Node server 10a can return the generated address 1 and address 2 to the requesting terminal 10e.
请求终端10e在接收到节点服务器10a返回的地址1和地址2后,请求终端10e可以向区块链发送合约注册请求,并将合约名称,地址1以及地址2发送至节点服务器10a。节点服务器10a在接收到请求终端10e的合约注册请求后,可以将从合约管理平台20c中获取合约模板20d,并将地址1和地址2作为参数输入到合约模板20d中,由于业务合约中包含设置数据合约地址接口,因此输入地址1和地址2的合约模板20d可以调用数据合约地址接口中的set(设置)方法,将地址1传入到业务合约中,完成业务合约和数据合约的绑定,此时可以得到与数据合约和数据合约相关联的代理合约20e。After receiving address 1 and address 2 returned by node server 10a, request terminal 10e can send a contract registration request to the blockchain and send the contract name, address 1, and address 2 to node server 10a. After receiving the contract registration request from request terminal 10e, node server 10a can obtain contract template 20d from contract management platform 20c and input address 1 and address 2 as parameters into contract template 20d. Since the business contract contains an interface for setting the data contract address, the contract template 20d with address 1 and address 2 input can call the set method in the data contract address interface to pass address 1 into the business contract, completing the binding of the business contract and the data contract. At this time, the data contract and the proxy contract 20e associated with the data contract can be obtained.
节点服务器10a同样可以根据请求终端10e的账户信息生成代理合约20e对应的代理合约地址,并将代理名称和代理合约地址进行绑定,生成合约名称和代理合约地址之间的映射关系信息,并将合约名称和代理合约地址之间的映射关系信息存储在合约管理平台中,如代理合约地址1与合约名称1之间具有映射关系,代理合约地址2与合约名2之间具有映射关系等。The node server 10a can also generate a proxy contract address corresponding to the proxy contract 20e based on the account information of the requesting terminal 10e, and bind the proxy name and the proxy contract address, generate mapping relationship information between the contract name and the proxy contract address, and store the mapping relationship information between the contract name and the proxy contract address in the contract management platform, such as there is a mapping relationship between the proxy contract address 1 and the contract name 1, there is a mapping relationship between the proxy contract address 2 and the contract name 2, and so on.
其中,需要说明的是,数据合约、业务合约以及代理合约20e均为计算机程序代码,开发人员可以使用智能合约高级语言进行编写,通过编译器可以将高级语言编写的合约编译成区块链节点(如节点服务器10a)的以太坊虚拟机中的字节码,以太坊虚拟机可以用于解释执行智能合约中的字节码。智能合约高级语言包括但不限于Solidity(一种智能合约编程语言)、Serpent(一种智能合约编程语言)、LLL(一种智能合约编程语言),如开发人员可以使用Solidity编写数据合约和业务合约,并使用编译器将Solidity编写的数据合约和业务合约分别编译成以太坊虚拟机字节码,进而将编译成以太坊虚拟机字节码随请求终端10e发起的交易提交至区块链网络并进行上链。It should be noted that the data contract, business contract, and proxy contract 20e are all computer program codes. Developers can use a high-level smart contract language to write them. A compiler can compile the contracts written in the high-level language into bytecode for the Ethereum virtual machine of a blockchain node (such as node server 10a). The Ethereum virtual machine can be used to interpret and execute the bytecode in the smart contract. High-level smart contract languages include, but are not limited to, Solidity (a smart contract programming language), Serpent (a smart contract programming language), and LLL (a smart contract programming language). For example, developers can use Solidity to write data contracts and business contracts, and use a compiler to compile the data contracts and business contracts written in Solidity into Ethereum virtual machine bytecode, respectively. The compiled Ethereum virtual machine bytecode is then submitted to the blockchain network along with the transaction initiated by the requesting terminal 10e for on-chain storage.
请参见图3,是本申请实施例提供的一种区块链合约部署方法的流程示意图。可以理解的是,该方法可以由计算机设备执行,计算机设备可以是区块链网络中的节点服务器,或者是区块链网络中的其他节点设备,如图3所示,该方法可以包括以下步骤:Please refer to Figure 3, which is a flowchart of a blockchain contract deployment method provided in an embodiment of the present application. It is understood that the method can be executed by a computer device, which can be a node server in a blockchain network or other node device in a blockchain network. As shown in Figure 3, the method may include the following steps:
步骤S101,接收请求节点发送的合约注册请求,获取合约注册请求携带的合约名称、数据合约对应的第一地址以及业务合约对应的第二地址;数据合约用于存储业务数据,业务合约用于存储业务逻辑;Step S101: Receive a contract registration request from a requesting node and obtain the contract name, the first address corresponding to the data contract, and the second address corresponding to the business contract carried in the contract registration request; the data contract is used to store business data, and the business contract is used to store business logic;
具体的,请求节点(如上述图2所对应实施例中的请求终端10e)可以向区块链网络发送合约注册请求,即向区块链网络申请生成代理合约,并将合约名称、数据合约对应的第一地址以及业务合约对应的第二地址上传至区块链网络。区块链网络中的节点服务器(如上述图2所对应实施例中的节点服务器10a)在接收到请求节点发送的合约注册请求后,可以获取请求节点上传的合约名称、第一地址以及第二地址。其中,数据合约用于存储业务数据(变量、结构以及映射等);业务合约用于维护业务逻辑,业务合约中包含用于设置数据合约地址的接口,因此业务合约可以调用数据合约,基于业务合约中的业务逻辑可以对数据合约中存储的业务数据进行操作。Specifically, the requesting node (such as the requesting terminal 10e in the embodiment corresponding to FIG2 above) can send a contract registration request to the blockchain network, that is, apply to the blockchain network to generate a proxy contract and upload the contract name, the first address corresponding to the data contract, and the second address corresponding to the business contract to the blockchain network. After receiving the contract registration request sent by the requesting node, the node server in the blockchain network (such as the node server 10a in the embodiment corresponding to FIG2 above) can obtain the contract name, first address, and second address uploaded by the requesting node. Among them, the data contract is used to store business data (variables, structures, and mappings, etc.); the business contract is used to maintain business logic. The business contract contains an interface for setting the data contract address. Therefore, the business contract can call the data contract, and based on the business logic in the business contract, the business data stored in the data contract can be operated.
其中,请求节点在向区块链网络发送合约注册请求之前,还需要将开发人员编写的数据合约和业务合约上传至区块链网络进行上链,以得到数据合约对应的第一地址和业务合约对应的第二地址。当数据合约和业务合约随请求节点发起的交易提交至区块链网络时,区块链网络中的节点服务器可以获取请求节点所提交的数据合约和业务合约,根据数据合约和业务合约生成合约区块;当合约区块在区块链网络中共识通过时,将数据合约和业务合约确定为发布成功状态;根据请求节点对应的账号信息,确定处于发布成功状态的数据合约对应的第一地址,以及处于发布成功状态的业务合约对应的第二地址,将第一地址和第二地址发送至请求节点。换言之,数据合约和业务合约由开发人员进行编写,在经过多方共同协定、各自签署后可以随请求节点发起的交易提交至区块链网络,区块链网络中的节点服务器可以将携带数据合约和业务合约的交易打包成合约区块,基于区块链中的点对点传输方式,对合约区块进行网络传播,以使区块链网络中的其余节点对合约区块进行共识验证,共识通过后的合约区块可以进行正式上链,合约区块共识通过即表明数据合约和业务合约发布成功,且数据合约和业务合约可以存储在区块链的区块中,节点服务器可以根据请求节点的账号信息确定数据合约和业务合约分别对应的地址,即确定数据合约对应的第一地址和业务合约对应的第二地址,进而节点服务器可以将数据合约对应的第一地址和业务合约对应的第二地址返回至请求节点,以使请求节点可以根据第一地址和第二地址申请生成代理合约。Before sending a contract registration request to the blockchain network, the requesting node must also upload the data contract and business contract written by the developer to the blockchain network for on-chain processing, in order to obtain the first address corresponding to the data contract and the second address corresponding to the business contract. When the data contract and business contract are submitted to the blockchain network along with the transaction initiated by the requesting node, the node server in the blockchain network can obtain the data contract and business contract submitted by the requesting node and generate a contract block based on the data contract and business contract. When the contract block is passed by consensus in the blockchain network, the data contract and business contract are determined to be in a successfully published state. Based on the account information corresponding to the requesting node, the first address corresponding to the data contract in the successfully published state and the second address corresponding to the business contract in the successfully published state are determined, and the first and second addresses are sent to the requesting node. In other words, data contracts and business contracts are written by developers, and after being agreed upon and signed by multiple parties, they can be submitted to the blockchain network along with the transaction initiated by the requesting node. The node server in the blockchain network can package the transactions carrying data contracts and business contracts into contract blocks, and based on the point-to-point transmission method in the blockchain, the contract blocks are transmitted over the network so that the remaining nodes in the blockchain network can perform consensus verification on the contract blocks. After the consensus is passed, the contract blocks can be officially uploaded to the chain. The passing of the contract block consensus indicates that the data contract and business contract have been successfully released, and the data contract and business contract can be stored in the blocks of the blockchain. The node server can determine the addresses corresponding to the data contract and the business contract based on the account information of the requesting node, that is, determine the first address corresponding to the data contract and the second address corresponding to the business contract. Then, the node server can return the first address corresponding to the data contract and the second address corresponding to the business contract to the requesting node, so that the requesting node can apply to generate a proxy contract based on the first address and the second address.
步骤S102,从合约管理平台中获取合约模板,基于合约模板对第一地址和第二地址进行绑定,得到与业务合约和数据合约相关联的代理合约,生成代理合约对应的第三地址;Step S102: Obtain a contract template from the contract management platform, bind the first address and the second address based on the contract template, obtain a proxy contract associated with the business contract and the data contract, and generate a third address corresponding to the proxy contract;
具体的,节点服务器可以从合约管理平台中获取合约模板,将数据合约对应的第一地址和业务合约对应的第二地址作为参数输入合约模板中,通过已输入参数的合约模板,从第二地址对应的业务合约中调用地址设置接口,根据地址设置接口将第一地址输入业务合约中,对业务合约和数据合约进行绑定,得到针对上述数据合约和业务合约的代理合约。其中,区块链网络中的每个节点服务器均可以预先创建一个合约管理平台(该合约管理平台同样可以理解为一个智能合约),在合约管理平台中可以存储一份代理合约代码(即合约模板),用于高效率生成新的代理合约,合约模板可以理解为一个代理合约框架,当将数据合约地址和业务合约地址作为参数输入合约模板时,可以快速创建一个新的代理合约。代理合约具有代理、管理以及更新等功能。地址设置接口中可以包括用于设置数据合约地址的方法,在设置数据合约地址的方法中存储数据合约地址,即可将地址合约和业务合约进行绑定,如数据合约对应的地址为:地址1,通过调用设置数据合约地址的方法(如setDataContractAddr()方法),将地址1传入业务合约中,则可以实现数据合约和业务合约之间的绑定。Specifically, the node server can obtain a contract template from the contract management platform, input the first address corresponding to the data contract and the second address corresponding to the business contract as parameters into the contract template, call the address setting interface from the business contract corresponding to the second address through the contract template with the input parameters, input the first address into the business contract according to the address setting interface, bind the business contract and the data contract, and obtain a proxy contract for the above-mentioned data contract and business contract. Among them, each node server in the blockchain network can pre-create a contract management platform (this contract management platform can also be understood as a smart contract), and a proxy contract code (i.e., a contract template) can be stored in the contract management platform for efficient generation of new proxy contracts. The contract template can be understood as a proxy contract framework. When the data contract address and the business contract address are input as parameters into the contract template, a new proxy contract can be quickly created. The proxy contract has functions such as agency, management, and update. The address setting interface may include a method for setting the data contract address. By storing the data contract address in the method for setting the data contract address, the address contract and the business contract can be bound. For example, if the address corresponding to the data contract is: address 1, by calling the method for setting the data contract address (such as the setDataContractAddr() method) and passing address 1 into the business contract, the binding between the data contract and the business contract can be achieved.
其中,生成代理合约首先需要创建数据合约,数据合约可以提供一个数据存储结构,以供后面的合约继承此结构;创建业务合约,业务合约可以用于维护业务逻辑,且业务合约可以继承数据合约中的数据存储结构;代理合约可以根据合约模板生成,代理合约可以继承数据合约中的数据存储结构,在代理合约中可以定义一个业务合约地址变量,并提供一个用于替换业务合约地址的方法。本申请实施例中,将数据合约对应的第一地址和业务合约对应的第二地址作为参数输入合约模板后,调用合约模板中的设置业务合约地址的方法,存储业务合约的第二地址,调用业务合约中的设置数据合约地址的方法,将第一地址传入业务合约中,此时可以得到针对上述数据合约和上述业务合约的代理合约。例如,数据合约1对应的地址为:地址1,业务合约2对应的地址为:地址2,将地址1和地址2作为参数输入合约模板中后,可以调用业务合约2中的设置数据合约地址的方法,将地址1传入业务合约2中,可以完成数据合约1和业务合约2之间的绑定,即此时生成的代理合约1是针对数据合约1和业务合约2的代理合约。若将地址1和业务合约3对应的地址3作为参数输入合约模板中,则可以调用业务合约3中的设置数据合约地址的方法,将地址1传入业务合约3中,可以完成数据合约1和业务合约3之间的绑定,即此时生成的代理合约2是针对数据合约1和业务合约3的代理合约。Among them, generating a proxy contract first requires creating a data contract. The data contract can provide a data storage structure for subsequent contracts to inherit this structure; creating a business contract. The business contract can be used to maintain business logic, and the business contract can inherit the data storage structure in the data contract; the proxy contract can be generated according to the contract template. The proxy contract can inherit the data storage structure in the data contract. A business contract address variable can be defined in the proxy contract, and a method for replacing the business contract address can be provided. In the embodiment of the present application, after the first address corresponding to the data contract and the second address corresponding to the business contract are input into the contract template as parameters, the method for setting the business contract address in the contract template is called to store the second address of the business contract, and the method for setting the data contract address in the business contract is called to pass the first address into the business contract. At this time, a proxy contract for the above-mentioned data contract and the above-mentioned business contract can be obtained. For example, the address corresponding to Data Contract 1 is: Address 1, and the address corresponding to Business Contract 2 is: Address 2. After entering Address 1 and Address 2 as parameters into the contract template, you can call the method for setting the data contract address in Business Contract 2 and pass Address 1 into Business Contract 2 to complete the binding between Data Contract 1 and Business Contract 2. That is, the proxy contract 1 generated at this time is a proxy contract for Data Contract 1 and Business Contract 2. If Address 1 and Address 3 corresponding to Business Contract 3 are entered as parameters into the contract template, you can call the method for setting the data contract address in Business Contract 3 and pass Address 1 into Business Contract 3 to complete the binding between Data Contract 1 and Business Contract 3. That is, the proxy contract 2 generated at this time is a proxy contract for Data Contract 1 and Business Contract 3.
在节点服务器的本地得到与数据合约和业务合约相关联的代理合约后,可以将代理合约打包成区块,经点对点网络传播和区块链节点验证通过后,将用于存储代理合约的区块进行正式上链,进而可以根据请求节点的账户信息,由节点服务器中的以太坊虚拟机确定该地理合约对应的代理合约地址,也可以称为第三地址。After obtaining the proxy contract associated with the data contract and business contract locally on the node server, the proxy contract can be packaged into blocks. After being transmitted through the peer-to-peer network and verified by the blockchain node, the block used to store the proxy contract will be officially uploaded to the chain. Then, based on the account information of the requesting node, the Ethereum virtual machine in the node server can determine the proxy contract address corresponding to the geographic contract, which can also be called the third address.
步骤S103,生成第三地址和合约名称之间的映射关系信息,将映射关系信息存储在合约管理平台中。Step S103: Generate mapping relationship information between the third address and the contract name, and store the mapping relationship information in the contract management platform.
具体的,节点服务器可以将合约注册请求中携带的合约名称和代理合约对应的第三地址进行绑定,生成第三地址与合约名称之间的映射关系信息,并将所生成的映射关系信息存储在合约管理平台中。应当理解,每生成一个新的代理合约,均可以将新代理合约的地址与代理合约名称之间的映射关系信息存储在合约管理平台中,即合约管理平台可以存储多个映射关系信息,每个映射关系信息均包含一个代理合约和一个合约名称之间的绑定关系。Specifically, the node server may bind the contract name carried in the contract registration request to the third address corresponding to the proxy contract, generate mapping relationship information between the third address and the contract name, and store the generated mapping relationship information in the contract management platform. It should be understood that each time a new proxy contract is generated, the mapping relationship information between the address of the new proxy contract and the proxy contract name may be stored in the contract management platform. In other words, the contract management platform may store multiple mapping relationship information, each mapping relationship information including a binding relationship between a proxy contract and a contract name.
其中,节点服务器在获取到合约注册请求中携带的合约名称后,基于合约名称,可以对合约管理平台中存储的历史映射关系信息进行遍历;若历史映射关系信息中存在合约名称,则向请求节点返回名称更改提示信息;若历史映射关系信息中不存在合约名称,则在生成代理合约后,可以生成代理合约对应的第三地址和合约名称之间的映射关系信息,并将映射关系信息存储在合约管理平台中。换言之,当请求节点向区块链网络申请生成代理合约时,除了向区块链网络提交数据合约对应的第一地址和业务合约对应的第二地址之外,还需要向区块链网络提交所申请的代理合约的名称,即上述合约名称。节点服务器在接收到请求节点的合约注册请求时,可以对请求节点提交的合约名称进行校验,检测该合约名称是否已被注册。对合约名称的具体校验过程包括:以合约名称作为关键词在合约管理平台所存储的历史映射关系信息中进行查询,历史映射关系信息是指截止到当前系统时间,合约管理平台中所存储的所有代理合约地址与对应代理合约名称之间的映射关系;若检测到合约管理平台中已经存在请求节点所提交的合约名称,则可以向请求节点返回名称更改提示信息,该名称更改提示信息可以为:该合约名称已被注册,请更改合约名称并重新提交;若检测到合约管理平台中不存在请求节点所提交的合约名称,即该合约名称未被注册,则节点服务器可以生成该合约名称与第三地址之间的映射关系信息,并将映射关系信息存储在合约管理平台中。Among them, after obtaining the contract name carried in the contract registration request, the node server can traverse the historical mapping relationship information stored in the contract management platform based on the contract name; if the contract name exists in the historical mapping relationship information, a name change prompt information is returned to the requesting node; if the contract name does not exist in the historical mapping relationship information, after generating the proxy contract, the mapping relationship information between the third address corresponding to the proxy contract and the contract name can be generated, and the mapping relationship information is stored in the contract management platform. In other words, when the requesting node applies to the blockchain network to generate a proxy contract, in addition to submitting the first address corresponding to the data contract and the second address corresponding to the business contract to the blockchain network, it is also necessary to submit the name of the requested proxy contract, that is, the above-mentioned contract name, to the blockchain network. When the node server receives the contract registration request from the requesting node, it can verify the contract name submitted by the requesting node to detect whether the contract name has been registered. The specific verification process of the contract name includes: using the contract name as a keyword to query the historical mapping relationship information stored in the contract management platform. The historical mapping relationship information refers to the mapping relationship between all proxy contract addresses and corresponding proxy contract names stored in the contract management platform as of the current system time; if it is detected that the contract name submitted by the requesting node already exists in the contract management platform, a name change prompt message can be returned to the requesting node. The name change prompt message can be: the contract name has been registered, please change the contract name and resubmit; if it is detected that the contract name submitted by the requesting node does not exist in the contract management platform, that is, the contract name has not been registered, then the node server can generate a mapping relationship information between the contract name and the third address, and store the mapping relationship information in the contract management platform.
当请求节点需要调用某个业务时,请求节点可以向节点服务器发送合约查询请求,当节点服务器接收到请求节点发送的合约查询请求时,获取合约查询请求所携带的合约名称;从合约管理平台中获取与合约名称具有映射关系的第三地址,将第三地址返回至请求节点。请求节点接收到节点服务器返回的第三地址,将第三地址与合约名称存储在本地中,当请求节点产生新的交易数据后,可以将存储的第三地址与新的交易数据一并上传至区块链网络,区块链网络中的节点服务器可以获取该新的交易数据,并调用第三地址对应的代理合约,根据该代理合约调用业务合约,进一步根据业务合约中的业务逻辑,对数据合约和新的交易数据进行操作,生成新的交易数据对应的合约处理结果,该新的交易数据以及合约处理结果可以打包成区块进行上链处理。When a requesting node needs to call a certain service, it can send a contract query request to the node server. When the node server receives the contract query request sent by the requesting node, it obtains the contract name carried in the contract query request; obtains a third address that has a mapping relationship with the contract name from the contract management platform, and returns the third address to the requesting node. The requesting node receives the third address returned by the node server and stores the third address and the contract name locally. When the requesting node generates new transaction data, it can upload the stored third address and the new transaction data to the blockchain network. The node server in the blockchain network can obtain the new transaction data and call the proxy contract corresponding to the third address. Based on the proxy contract, it calls the business contract. Further, based on the business logic in the business contract, it operates on the data contract and the new transaction data to generate the contract processing result corresponding to the new transaction data. The new transaction data and contract processing result can be packaged into blocks for on-chain processing.
可选的,节点服务器在接收到请求节点上传的交易数据时,节点服务器还可以对接收的交易数据进行验签,具体的验签过程为:节点服务器可以获取交易数据所携带的数字签名,并获取请求节点对应的公钥;基于公钥对数字签名进行解密,得到数字签名对应的第一摘要信息;基于哈希算法对交易数据进行哈希运算,得到交易数据对应的第二摘要信息;若第一摘要信息与第二摘要信息相同,则交易数据验签通过。具体来说,为了防止交易数据在传输过程中被恶意篡改,请求节点可以生成密钥对(包括私钥和公钥,私钥由请求节点自己管理,公钥可以通知给区块链网络中的所有节点服务器),请求节点可以采用哈希算法对交易数据进行哈希运算,生成交易数据对应的第一摘要信息,并采用生成的私钥对第一摘要信息进行加密,加密之后的第一摘要信息即为交易数据对应的数字签名。请求节点将携带数字签名的交易数据以及第三地址上传至区块链网络,区块链网络中的节点服务器在接收到请求节点上传的携带数字签名的交易数据后,可以获取请求节点对应的公钥,根据公钥对数字签名进行解密,得到数字签名对应的第一摘要信息,进而根据哈希算法(即请求节点生成数字签名所采用的哈希算法)对节点服务器接收到的交易数据进行哈希运算,得到接收到的交易数据对应的第二摘要信息,若第一摘要信息与第二摘要信息相同,则表示交易数据在上传过程中没有被篡改,验签通过;若第一摘要信息与第二摘要信息不相同,则表示交易数据在上传过程中可能存在篡改,验签不通过。Optionally, when the node server receives the transaction data uploaded by the requesting node, the node server can also verify the signature of the received transaction data. The specific verification process is as follows: the node server can obtain the digital signature carried by the transaction data and obtain the public key corresponding to the requesting node; decrypt the digital signature based on the public key to obtain the first summary information corresponding to the digital signature; perform a hash operation on the transaction data based on the hash algorithm to obtain the second summary information corresponding to the transaction data; if the first summary information is the same as the second summary information, the transaction data verification is passed. Specifically, in order to prevent the transaction data from being maliciously tampered with during transmission, the requesting node can generate a key pair (including a private key and a public key, the private key is managed by the requesting node itself, and the public key can be notified to all node servers in the blockchain network). The requesting node can use a hash algorithm to perform a hash operation on the transaction data to generate the first summary information corresponding to the transaction data, and use the generated private key to encrypt the first summary information. The encrypted first summary information is the digital signature corresponding to the transaction data. The requesting node uploads the transaction data carrying the digital signature and the third address to the blockchain network. After receiving the transaction data carrying the digital signature uploaded by the requesting node, the node server in the blockchain network can obtain the public key corresponding to the requesting node, decrypt the digital signature according to the public key, and obtain the first summary information corresponding to the digital signature. Then, according to the hash algorithm (that is, the hash algorithm used by the requesting node to generate the digital signature), a hash operation is performed on the transaction data received by the node server to obtain the second summary information corresponding to the received transaction data. If the first summary information is the same as the second summary information, it indicates that the transaction data has not been tampered with during the upload process and the signature verification is passed; if the first summary information is different from the second summary information, it indicates that the transaction data may have been tampered with during the upload process and the signature verification fails.
应当理解的是,请求节点在上传交易数据之前,已经将公钥与生成数字签名所使用的哈希算法通知给区块链网络中的节点服务器,若交易数据在上传过程中被篡改,节点服务器接收到的数字签名并不是请求节点原本生成的数字签名,则节点服务器采用请求节点对应的公钥对数字签名进行解密时,无法进行求解。其中,哈希算法可以包括但不限于SHA-1、SHA-224、SHA-256、SHA-384以及SHA-512。It should be understood that before uploading transaction data, the requesting node has already notified the node server in the blockchain network of the public key and the hash algorithm used to generate the digital signature. If the transaction data is tampered with during the upload process, the digital signature received by the node server is not the digital signature originally generated by the requesting node. The node server will be unable to decrypt the digital signature using the public key corresponding to the requesting node. Hash algorithms include but are not limited to SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512.
可选的,在生成代理合约后,可以确定代理合约的管理节点,管理节点可以访问该代理合约,该管理节点还可以将该代理合约的访问权限授权给其余节点,将具有访问该代理合约权限的其余节点确定为授权访问节点,并在合约管理平台中建立代理合约与管理节点以及授权节点的绑定关系。换言之,合约管理平台可以用于维护代理合约、代理合约与管理者以及授权访问用户的映射关系。Optionally, after generating a proxy contract, a management node for the proxy contract can be identified. The management node can access the proxy contract and authorize other nodes to access the proxy contract. These other nodes with access to the proxy contract are designated as authorized access nodes. Binding relationships between the proxy contract, the management node, and the authorized nodes are established on the contract management platform. In other words, the contract management platform can maintain mappings between proxy contracts, managers, and authorized access users.
节点服务器在接收到请求节点发送的合约查询请求时,获取合约查询请求所携带的合约名称;从合约管理平台中获取与合约名称具有映射关系的第三地址,获取与第三地址相关联的多个节点;若多个节点中存在该请求节点,则确定该请求节点具有查询权限(当请求节点具有访问代理合约的权限时,该请求节点就具有查询该代理合约地址的权限),将第三地址返回至请求节点,请求节点可以接收节点服务器返回的第三地址,并将第三地址与合约名称存储在本地中;若多个节点中不存在请求节点,则确定请求节点不具有查询权限,向请求节点返回权限提示信息。换言之,节点服务器在接收到合约查询请求时,可以检测发起该合约查询请求的请求节点是否具有查询权限,若请求节点为代理合约对应的管理节点、权限访问节点中的任一个,则确定该请求节点具有查询权限,并将合约名称对应的第三地址返回至请求节点;若代理合约对应的管理节点和权限访问节点中均不包括该请求节点,则确定该请求节点不具有查询权限,向该请求节点返回权限提示信息。When the node server receives the contract query request sent by the requesting node, it obtains the contract name carried in the contract query request; obtains a third address that has a mapping relationship with the contract name from the contract management platform, and obtains multiple nodes associated with the third address; if the requesting node exists among the multiple nodes, it is determined that the requesting node has query authority (when the requesting node has the authority to access the proxy contract, the requesting node has the authority to query the proxy contract address), and the third address is returned to the requesting node. The requesting node can receive the third address returned by the node server and store the third address and the contract name locally; if the requesting node does not exist among the multiple nodes, it is determined that the requesting node does not have query authority, and permission prompt information is returned to the requesting node. In other words, when the node server receives a contract query request, it can detect whether the requesting node that initiates the contract query request has query authority. If the requesting node is any of the management node and permission access node corresponding to the proxy contract, it is determined that the requesting node has query authority, and the third address corresponding to the contract name is returned to the requesting node; if the requesting node is not included in the management node and permission access node corresponding to the proxy contract, it is determined that the requesting node does not have query authority, and permission prompt information is returned to the requesting node.
请参见图4,是本申请实施例提供的一种智能合约执行场景示意图。如图4所示,请求方(即请求节点,对应于图2所对应实施例中的请求终端10e)可以根据合约管理平台提供的接口向区块链网络中的节点(如节点1)发送合约查询请求,如用户输入代理合约名称“名称aaa”进行代理合约地址查询,用户对应的请求终端即可生成合约查询请求,并将生成的合约查询请求发送给区块链节点1。节点1在接收到请求方发送的合约查询请求后,可以从合约管理平台存储的映射关系表中查找与“名称aaa”具有映射关系的代理合约地址,如地址a,则节点1可以将地址a返回至请求方,并在请求方的本地存储中进行缓存。当请求方的本地存储中已经缓存有代理合约对应的地址a后,后续请求方需要调用该代理合约时,就可以直接使用,不需要再次查询该代理合约对应的地址,即对于每个代理合约,只有在请求方未存储相应的代理合约地址时,才会向节点发送合约查询请求,以从合约管理平台获得相应的代理合约地址。Please refer to Figure 4, which is a schematic diagram of a smart contract execution scenario provided by an embodiment of the present application. As shown in Figure 4, the requester (i.e., the requesting node, corresponding to the requesting terminal 10e in the embodiment corresponding to Figure 2) can send a contract query request to a node (such as node 1) in the blockchain network according to the interface provided by the contract management platform. For example, if a user enters the proxy contract name "name aaa" to query the proxy contract address, the requesting terminal corresponding to the user can generate a contract query request and send the generated contract query request to blockchain node 1. After receiving the contract query request sent by the requester, node 1 can search the mapping relationship table stored in the contract management platform for the proxy contract address that has a mapping relationship with "name aaa", such as address a. Node 1 can return address a to the requester and cache it in the requester's local storage. When the requester's local storage has cached the address a corresponding to the proxy contract, the subsequent requester can use it directly when it needs to call the proxy contract without having to query the address corresponding to the proxy contract again. That is, for each proxy contract, only when the requester does not store the corresponding proxy contract address will a contract query request be sent to the node to obtain the corresponding proxy contract address from the contract management platform.
请求方得到返回的地址a后,请求方可以通过发起交易来调用代理合约,即请求方可以将携带地址a的交易数据上传至区块链网络中的节点1,并请求调用地址a对应的代理合约,节点1在接收到请求方上传的交易数据后,可以对接收到的交易数据进行验签,验签通过后,节点1可以根据地址a调用相对应的代理合约,进而根据代理合约调用业务合约,根据业务合约中的业务逻辑对数据合约和交易数据进行交易处理,即可以在节点1的以太坊虚拟机中执行代理合约中的合约代码,合约代码可以自动判断当前所处的场景是否满足合约触发条件,并严格执行合约响应规则,根据合约代码执行结果确定交易数据是否有效,当交易数据验证有效后,可以将交易数据打包进新的数据区块(即区块30a),节点1可以将区块30a在区块链网络中进行广播,以使区块链网络中的其余节点根据共识算法对区块30a进行共识验证,当该区块30a共识通过时,可以将区块30a进行正式上链,即区块30a在共识通过后,可以根据节点1所存储的区块链中的最大区块高度,对区块30a的区块高度进行更新,将更新后的区块30a存储在节点1的本地数据库中,此时更新后的区块30a即为节点1本地数据库中的区块N+i,N+i用于表征更新后的区块30a在本地区块链中的区块顺序,N和i均为大于或等于0的整数。After the requester obtains the returned address a, the requester can call the proxy contract by initiating a transaction, that is, the requester can upload the transaction data carrying address a to node 1 in the blockchain network and request to call the proxy contract corresponding to address a. After receiving the transaction data uploaded by the requester, node 1 can verify the signature of the received transaction data. After the signature is verified, node 1 can call the corresponding proxy contract according to address a, and then call the business contract according to the proxy contract, and process the data contract and transaction data according to the business logic in the business contract, that is, the contract code in the proxy contract can be executed in the Ethereum virtual machine of node 1. The contract code can automatically determine whether the current scenario meets the contract triggering conditions, and strictly implement the contract response rules, and determine whether the transaction data is satisfied according to the contract code execution result. Valid. After the transaction data is verified to be valid, the transaction data can be packaged into a new data block (i.e., block 30a). Node 1 can broadcast block 30a in the blockchain network so that the remaining nodes in the blockchain network can perform consensus verification on block 30a according to the consensus algorithm. When the consensus of block 30a is passed, block 30a can be formally put on the chain. That is, after the consensus is passed, the block height of block 30a can be updated according to the maximum block height in the blockchain stored by node 1, and the updated block 30a can be stored in the local database of node 1. At this time, the updated block 30a is block N+i in the local database of node 1. N+i is used to represent the block order of the updated block 30a in the local blockchain. N and i are both integers greater than or equal to 0.
在本申请实施例中,区块链节点在接收到请求节点发送的合约注册请求时,可以获取合约注册请求携带的合约名称、数据合约对应的第一地址以及业务合约对应的第二地址,基于合约管理平台中获取合约模板,基于合约模板对第一地址和第二地址进行绑定,得到与数据合约和业务合约相关联的代理合约,生成该代理合约对应的第三地址,将第三地址和合约名称之间的映射关系信息存储在合约管理平台中。可见,通过在区块链中创建合约管理平台,并在合约管理平台中编写一个合约模板,将业务合约地址和数据合约地址作为参数输入合约模板中即可将数据合约和业务合约进行绑定,完成代理合约在区块链中的部署过程,通过合约模板的方式可以减少代理合约的开发过程,进而可以提高区块链中合约的开发效率。In an embodiment of the present application, upon receiving a contract registration request from a requesting node, a blockchain node can obtain the contract name, the first address corresponding to the data contract, and the second address corresponding to the business contract carried in the contract registration request, obtain a contract template from the contract management platform, bind the first address and the second address based on the contract template, obtain a proxy contract associated with the data contract and the business contract, generate a third address corresponding to the proxy contract, and store the mapping relationship information between the third address and the contract name in the contract management platform. Thus, by creating a contract management platform in the blockchain and writing a contract template in the contract management platform, the business contract address and the data contract address can be input as parameters into the contract template to bind the data contract and the business contract, completing the deployment process of the proxy contract in the blockchain. The use of contract templates can reduce the development process of proxy contracts, thereby improving the efficiency of contract development in the blockchain.
请参见图5,是本申请实施例提供的另一种区块链合约部署方法的流程示意图。如图5所示,该方法可以包括以下步骤:Please refer to Figure 5, which is a flowchart of another blockchain contract deployment method provided by an embodiment of the present application. As shown in Figure 5, the method may include the following steps:
步骤S201,接收请求节点发送的合约注册请求,获取合约注册请求携带的合约名称、数据合约对应的第一地址以及业务合约对应的第二地址;数据合约用于存储业务数据,业务合约用于存储业务逻辑;Step S201: Receive a contract registration request from a requesting node and obtain the contract name, the first address corresponding to the data contract, and the second address corresponding to the business contract carried in the contract registration request; the data contract is used to store business data, and the business contract is used to store business logic;
步骤S202,从合约管理平台中获取合约模板,基于合约模板对第一地址和第二地址进行绑定,得到与业务合约和数据合约相关联的代理合约,生成代理合约对应的第三地址;Step S202: Obtain a contract template from the contract management platform, bind the first address and the second address based on the contract template, obtain a proxy contract associated with the business contract and the data contract, and generate a third address corresponding to the proxy contract;
步骤S203,生成第三地址和合约名称之间的映射关系信息,将映射关系信息存储在合约管理平台中;Step S203: Generate mapping relationship information between the third address and the contract name, and store the mapping relationship information in the contract management platform;
其中,步骤S201-步骤S202的具体实现过程可以参见上述图3所对应实施例中的步骤S101-步骤S103,这里不再进行赘述。The specific implementation process of step S201 - step S202 can refer to step S101 - step S103 in the embodiment corresponding to FIG3 , and will not be described in detail here.
步骤S204,获取针对代理合约的更新请求,基于更新请求获取第一地址以及更新业务合约对应的第四地址;Step S204: Obtain an update request for the proxy contract, and obtain the first address and the fourth address corresponding to the updated business contract based on the update request;
具体的,当业务需求变更时,需要对部署在区块链中的合约进行更新,由于业务合约与数据合约是分离开的,业务需求的变更只需重新部署业务合约即可完成区块链中智能合约的更新。请求节点可以向区块链节点发送针对代理合约的更新请求,区块链网络中的节点服务器在接收到请求节点的更新请求后,可以获取与更新请求相关联的第一地址以及更新业务合约对应的第四地址,其中,更新业务地址用于存储更新后的业务逻辑,第四地址为更新业务合约创建成功后,节点服务器中的以太坊虚拟机根据请求节点账户信息所确定的更新业务合约地址。Specifically, when business requirements change, contracts deployed on the blockchain need to be updated. Since business contracts are separate from data contracts, changes in business requirements only require redeploying the business contract to complete the update of the smart contract on the blockchain. The requesting node can send an update request for the proxy contract to the blockchain node. After receiving the update request from the requesting node, the node server in the blockchain network can obtain the first address associated with the update request and the fourth address corresponding to the updated business contract. The updated business address is used to store the updated business logic, and the fourth address is the updated business contract address determined by the Ethereum Virtual Machine in the node server based on the requesting node's account information after the updated business contract is successfully created.
需要说明的是,请求节点在向区块链网络发送更新请求之前,还需要将开发人员编写的更新业务合约上传至区块链网络,并在区块链上进行发布,得到返回的第四地址,具体的发布过程可以参见上述图3所对应实施例中对步骤S101的描述,这里不再进行赘述。It should be noted that before sending an update request to the blockchain network, the requesting node also needs to upload the updated business contract written by the developer to the blockchain network and publish it on the blockchain to obtain the fourth address returned. The specific publishing process can be found in the description of step S101 in the embodiment corresponding to Figure 3 above, and will not be repeated here.
步骤S205,将第四地址和第一地址作为参数输入至合约模板,生成测试代理合约;Step S205: Input the fourth address and the first address as parameters into the contract template to generate a test proxy contract;
具体的,节点服务器可以从合约管理平台中获取合约模板,将数据合约第一地址和第四地址作为参数输入合约模板中,通过输入参数之后的合约模板,可以从第四地址对应的更新业务合约中调用设置数据合约地址的方法,将第一地址输入更新业务合约中,可以将数据合约和更新业务合约进行绑定,得到新的代理合约,也可以成为测试代理合约。测试代理合约的具体生成过程可以参见上述图3所对应实施例中对代理合约生成过程的描述,这里不再进行赘述。Specifically, the node server can obtain a contract template from the contract management platform and input the first and fourth addresses of the data contract as parameters into the contract template. Using the contract template after inputting the parameters, the method for setting the data contract address can be called from the update business contract corresponding to the fourth address. By inputting the first address into the update business contract, the data contract and the update business contract can be bound to obtain a new proxy contract, which can also become a test proxy contract. The specific generation process of the test proxy contract can be found in the description of the proxy contract generation process in the embodiment corresponding to Figure 3 above, and will not be repeated here.
步骤S206,当测试代理合约通过测试时,冻结代理合约,将代理合约中的第二地址更新为测试通过状态的测试代理合约中的第四地址;Step S206: When the test proxy contract passes the test, freeze the proxy contract and update the second address in the proxy contract to the fourth address in the test proxy contract that passed the test;
具体的,在生成测试代理合约后,需要对生成的测试代理合约进行测试,即检测测试代理合约中的合约代码是否存在漏洞。测试代理合约的测试实质上是合约方法的测试过程,在测试代理合约部署成功后,节点服务器可以调用测试代理合约中的合约方法,完成一次交易数据的处理过程,当交易数据的处理结果满足预期结果时,表示测试代理合约测试通过,如进行一次转账交易,若转账成功,则表示测试代理合约测试通过;若转账不成功,则表示测试代理合约测试未通过。在测试代理合约通过测试时,可以冻结区块链中的代理合约,即暂时停止对代理合约的调用,将代理合约中的第二地址更新为测试通过的测试代理合约中的第四地址。换言之,测试代理合约测试通过之后,将代理合约中原有业务合约的第二地址更换为更新业务合约对应的第四地址,此时更新后的代理合约中包含数据合约对应的第一地址和更新业务合约对应的第四地址。Specifically, after generating a test proxy contract, it needs to be tested to detect vulnerabilities in the contract code within the test proxy contract. Testing a test proxy contract essentially involves testing its methods. After the test proxy contract is successfully deployed, the node server can call the contract method within the test proxy contract to complete a transaction data processing process. When the transaction data processing results meet the expected results, the test proxy contract has passed. For example, if a transfer transaction is successful, the test proxy contract has passed; if the transfer is unsuccessful, the test proxy contract has failed. If the test proxy contract passes the test, the proxy contract can be frozen in the blockchain, temporarily halting calls to the proxy contract. The second address in the proxy contract is updated to the fourth address in the tested proxy contract. In other words, after the test proxy contract passes the test, the second address of the original business contract in the proxy contract is replaced with the fourth address corresponding to the updated business contract. The updated proxy contract now contains both the first address corresponding to the data contract and the fourth address corresponding to the updated business contract.
步骤S207,将包含第一地址和第四地址的代理合约确定为更新后的代理合约;更新后的代理合约与第三地址相关联。Step S207: Determine the proxy contract containing the first address and the fourth address as the updated proxy contract; and associate the updated proxy contract with the third address.
具体的,在代理合约中的第二地址更换为更新业务合约对应的第四地址后,可以得到更新后的代理合约,更新后的代理合约对应的地址保持不变,仍然为更新之前的第三地址,激活更新后的代理合约,完成合约的更新。可见,可以在不影响现有线上业务的情形下,对测试代理合约进行测试,在测试通过后再冻结代理合约,更新代理合约中的业务合约地址,完成合约的更新过程,更新后的代理合约同样需要进行正式上链,存储在区块链中。Specifically, after the second address in the proxy contract is replaced with the fourth address corresponding to the updated business contract, the updated proxy contract can be obtained. The address corresponding to the updated proxy contract remains unchanged, still the third address before the update. The updated proxy contract is activated, completing the contract update. It can be seen that the test proxy contract can be tested without affecting existing online businesses. After the test passes, the proxy contract can be frozen and the business contract address in the proxy contract can be updated to complete the contract update process. The updated proxy contract also needs to be formally uploaded to the blockchain and stored.
请一并参见图6,是本申请实施例提供的一种合约升级场景示意图。如图6所示,区块链中的智能合约是在以太坊虚拟机40a中解释执行的,若在区块链中已部署了代理合约40c,该代理合约40c是将数据合约40e对应的地址1和业务合约40d对应的地址2作为参数,输入合约管理平台40b中的合约模板所生成的,代理合约40c可以调用业务合约40d,业务合约40d可以调用数据合约40e。当业务需求变更时,需要对业务合约40d进行更新,开发人员可以编写更新业务合约40f,并由请求节点将更新业务合约40f上传至区块链网络中,在更新业务合约40f存储于区块链中后,区块链节点可以向请求节点返回更新业务合约40f对应的地址3,进而请求节点可以向区块链节点发送针对代理合约40c的更新请求,区块链网络中的节点1在获取到该更新请求后,可以获取该更新请求携带的地址1以及地址3,节点1可以从合约管理平台40b中获取合约模板,将地址1和地址3作为参数输入合约模板中,将地址1对应的数据合约40e与地址3对应的更新业务合约40f进行绑定,生成测试代理合约40g。Please also refer to Figure 6, which is a schematic diagram of a contract upgrade scenario provided by an embodiment of the present application. As shown in Figure 6, the smart contract in the blockchain is interpreted and executed in the Ethereum virtual machine 40a. If a proxy contract 40c has been deployed in the blockchain, the proxy contract 40c is generated by inputting the address 1 corresponding to the data contract 40e and the address 2 corresponding to the business contract 40d as parameters into the contract template in the contract management platform 40b. The proxy contract 40c can call the business contract 40d, and the business contract 40d can call the data contract 40e. When business requirements change, the business contract 40d needs to be updated. The developer can write an updated business contract 40f, and the requesting node uploads the updated business contract 40f to the blockchain network. After the updated business contract 40f is stored in the blockchain, the blockchain node can return the address 3 corresponding to the updated business contract 40f to the requesting node, and then the requesting node can send an update request for the proxy contract 40c to the blockchain node. After receiving the update request, node 1 in the blockchain network can obtain the address 1 and address 3 carried in the update request. Node 1 can obtain the contract template from the contract management platform 40b, input address 1 and address 3 as parameters into the contract template, bind the data contract 40e corresponding to address 1 with the updated business contract 40f corresponding to address 3, and generate a test proxy contract 40g.
节点1可以对测试代理合约40g进行测试,如调用测试代理合约40g中的合约方法,即通过地址3调用测试代理合约40g,测试代理合约40g调用更新业务合约40f,更新业务合约40f调用数据合约40e,如调用测试代理合约40g中的合约方法进行一次转账交易处理,若转账交易成功,则表示测试代理合约40g测试通过。在测试代理合约40g测试通过后,可以冻结代理合约40c,将代理合约40c中的地址2更新为测试代理合约40g中的地址4,得到更新后的代理合约40h。换言之,更新后的代理合约40h对应的合约地址与代理合约40c对应的地址相同(地址保持不变),更新后的代理合约40h可以调用更新业务合约40f,更新业务合约40f可以调用数据合约40e。节点1可以将更新后的代理合约40h打包成区块40i,在区块40i根据共识算法在区块链网络中通过共识验证后,可以将区块40i进行正式上链,并将区块40i存储至节点1的本地数据库40j中。Node 1 can test test proxy contract 40g by calling a contract method in test proxy contract 40g, i.e., calling test proxy contract 40g through address 3. Test proxy contract 40g calls update business contract 40f, which in turn calls data contract 40e. For example, calling a contract method in test proxy contract 40g to process a transfer transaction. If the transfer transaction is successful, test proxy contract 40g has passed the test. After test proxy contract 40g passes the test, proxy contract 40c can be frozen, and address 2 in proxy contract 40c can be updated to address 4 in test proxy contract 40g, resulting in an updated proxy contract 40h. In other words, the contract address corresponding to the updated proxy contract 40h is the same as the address corresponding to proxy contract 40c (the address remains unchanged). The updated proxy contract 40h can call update business contract 40f, and update business contract 40f can call data contract 40e. Node 1 can package the updated proxy contract 40h into block 40i. After block 40i passes consensus verification in the blockchain network according to the consensus algorithm, block 40i can be officially put on the chain and stored in the local database 40j of node 1.
在本申请实施例中,通过在区块链中创建合约管理平台,并在合约管理平台中编写一个合约模板,将业务合约地址和数据合约地址作为参数输入合约模板中即可生成代理合约,即区块链节点可以基于合约管理平台中的合约模板,将数据合约和业务合约进行绑定,完成代理合约在区块链中的部署过程,当区块链中需要部署多个代理合约时,根据合约模板可以快速生成多个代理合约,减少代理合约的开发过程,进而可以提高区块链中合约的开发效率;通过将代理合约中的业务合约地址更新为新业务合约地址,即可完成合约的升级过程,可以提高合约升级效率。In an embodiment of the present application, a proxy contract can be generated by creating a contract management platform in the blockchain and writing a contract template in the contract management platform. The business contract address and the data contract address are input as parameters into the contract template. That is, the blockchain node can bind the data contract and the business contract based on the contract template in the contract management platform to complete the deployment process of the proxy contract in the blockchain. When multiple proxy contracts need to be deployed in the blockchain, multiple proxy contracts can be quickly generated according to the contract template, reducing the development process of the proxy contract, thereby improving the development efficiency of the contract in the blockchain; by updating the business contract address in the proxy contract to the new business contract address, the contract upgrade process can be completed, which can improve the contract upgrade efficiency.
请参见图7,是本申请实施例提供的一种区块链合约部署装置的结构示意图,该区块链合约部署装置1可以应用于区块链节点。如图7所示,该区块链合约部署装置1可以包括:接收模块10,创建模块11,存储模块12;Please refer to Figure 7, which is a schematic diagram of the structure of a blockchain contract deployment device provided in an embodiment of the present application. The blockchain contract deployment device 1 can be applied to a blockchain node. As shown in Figure 7, the blockchain contract deployment device 1 may include: a receiving module 10, a creation module 11, and a storage module 12;
接收模块10,用于接收请求节点发送的合约注册请求,获取合约注册请求携带的合约名称、数据合约对应的第一地址以及业务合约对应的第二地址;数据合约用于存储业务数据,业务合约用于存储业务逻辑;Receiving module 10, used to receive the contract registration request sent by the requesting node, and obtain the contract name, the first address corresponding to the data contract, and the second address corresponding to the business contract carried in the contract registration request; the data contract is used to store business data, and the business contract is used to store business logic;
创建模块11,用于从合约管理平台中获取合约模板,基于合约模板对第一地址和第二地址进行绑定,得到与业务合约和数据合约相关联的代理合约,生成代理合约对应的第三地址;Creation module 11 is used to obtain a contract template from the contract management platform, bind the first address and the second address based on the contract template, obtain a proxy contract associated with the business contract and the data contract, and generate a third address corresponding to the proxy contract;
存储模块12,用于生成第三地址和合约名称之间的映射关系信息,将映射关系信息存储在合约管理平台中。The storage module 12 is used to generate mapping relationship information between the third address and the contract name, and store the mapping relationship information in the contract management platform.
其中,接收模块10,创建模块11,存储模块12的具体功能实现方式可以参见上述图3所对应实施例中的步骤S101-步骤S103,这里不再进行赘述。The specific functional implementation of the receiving module 10, the creating module 11, and the storing module 12 can refer to steps S101 to S103 in the embodiment corresponding to FIG3 above, and will not be repeated here.
请一并参见图7,区块链合约部署装置1还可以包括:区块生成模块13,共识模块14,地址确定模块15,遍历模块16,验证模块17,查询请求接收模块18,地址查询模块19,交易数据获取模块22,数据操作模块23;Please refer to FIG7 , the blockchain contract deployment device 1 may further include: a block generation module 13 , a consensus module 14 , an address determination module 15 , a traversal module 16 , a verification module 17 , a query request receiving module 18 , an address query module 19 , a transaction data acquisition module 22 , and a data operation module 23 ;
区块生成模块13,用于获取请求节点上传的数据合约和业务合约,根据数据合约和业务合约生成合约区块;The block generation module 13 is used to obtain the data contract and business contract uploaded by the requesting node and generate a contract block based on the data contract and business contract;
共识模块14,用于当合约区块在区块链网络中共识通过时,将数据合约和业务合约确定为发布成功状态;Consensus module 14 is used to determine the data contract and business contract as being in a successful release state when the contract block is agreed upon in the blockchain network;
地址确定模块15,用于根据请求节点对应的账号信息,确定处于发布成功状态的数据合约对应的第一地址,以及处于发布成功状态的业务合约对应的第二地址,将第一地址和第二地址发送至请求节点;An address determination module 15 is configured to determine, based on the account information corresponding to the requesting node, a first address corresponding to the data contract in a successfully published state and a second address corresponding to the business contract in a successfully published state, and send the first address and the second address to the requesting node;
遍历模块16,用于基于合约名称,对合约管理平台中存储的历史映射关系信息进行遍历;A traversal module 16 is used to traverse the historical mapping relationship information stored in the contract management platform based on the contract name;
验证模块17,用于若历史映射关系信息中存在合约名称,则向请求节点返回名称更改提示信息;Verification module 17, used to return a name change prompt to the requesting node if the contract name exists in the historical mapping relationship information;
验证模块17,还用于若历史映射关系信息中不存在合约名称,则生成第三地址和合约名称之间的映射关系信息,将映射关系信息存储在合约管理平台中;The verification module 17 is further configured to generate mapping relationship information between the third address and the contract name if the contract name does not exist in the historical mapping relationship information, and store the mapping relationship information in the contract management platform;
查询请求接收模块18,用于当接收到请求节点发送的合约查询请求时,获取合约查询请求所携带的合约名称;The query request receiving module 18 is used to obtain the contract name carried in the contract query request when receiving the contract query request sent by the requesting node;
地址查询模块19,用于从合约管理平台中获取与合约名称具有映射关系的第三地址,将第三地址返回至请求节点,以使请求节点将第三地址与合约名称存储在本地中;An address query module 19 is configured to obtain a third address that is mapped to the contract name from the contract management platform, and return the third address to the requesting node so that the requesting node stores the third address and the contract name locally;
交易数据获取模块22,用于获取请求节点上传的交易数据,基于交易数据携带的第三地址获取代理合约;The transaction data acquisition module 22 is used to obtain the transaction data uploaded by the requesting node and obtain the proxy contract based on the third address carried in the transaction data;
数据操作模块23,用于根据代理合约调用业务合约,并基于业务合约中的业务逻辑,对数据合约和交易数据进行操作,生成交易数据对应的合约处理结果。The data operation module 23 is used to call the business contract according to the proxy contract, and based on the business logic in the business contract, operate the data contract and transaction data to generate the contract processing result corresponding to the transaction data.
其中,合约管理平台包括第三地址与多个节点之间的关联关系,多个节点包括代理合约对应的管理节点和授权访问节点;The contract management platform includes an association relationship between a third address and a plurality of nodes, wherein the plurality of nodes include a management node and an authorized access node corresponding to the proxy contract;
区块链合约部署装置1还可以包括:关联节点获取模块20,查询权限确定模块21;The blockchain contract deployment device 1 may further include: an associated node acquisition module 20, a query authority determination module 21;
关联节点获取模块20,用于从合约管理平台中获取与合约名称具有映射关系的第三地址,获取与第三地址相关联的多个节点;An associated node acquisition module 20 is configured to acquire a third address that has a mapping relationship with the contract name from the contract management platform, and acquire multiple nodes associated with the third address;
查询权限确定模块21,用于若多个节点中存在请求节点,则确定请求节点具有查询权限,将第三地址返回至请求节点,以使请求节点将第三地址与合约名称存储在本地中;A query authority determination module 21 is configured to determine, if a requesting node exists among the multiple nodes, whether the requesting node has query authority, and return the third address to the requesting node, so that the requesting node stores the third address and the contract name locally;
查询权限确定模21,还用于若多个节点中不存在请求节点,则确定请求节点不具有查询权限,向请求节点返回权限提示信息。The query authority determination module 21 is further used to determine that the requesting node does not have the query authority if the requesting node does not exist among the multiple nodes, and return authority prompt information to the requesting node.
其中,区块链合约部署装置1还可以包括:更新请求获取模块24,测试合约生成模块25,合约更新模块26;The blockchain contract deployment device 1 may further include: an update request acquisition module 24, a test contract generation module 25, and a contract update module 26;
更新请求获取模块24,用于获取针对代理合约的更新请求,基于更新请求获取第一地址以及更新业务合约对应的第四地址;An update request acquisition module 24 is configured to acquire an update request for the proxy contract, and acquire the first address and the fourth address corresponding to the updated business contract based on the update request;
测试合约生成模块25,用于将第四地址和第一地址作为参数输入至合约模板,生成测试代理合约;A test contract generation module 25 is configured to input the fourth address and the first address as parameters into a contract template to generate a test proxy contract;
合约更新模块26,用于当测试代理合约通过测试时,基于通过测试的测试代理合约,对代理合约进行更新。The contract updating module 26 is configured to update the proxy contract based on the tested proxy contract when the test proxy contract passes the test.
其中,区块生成模块13,共识模块14,地址确定模块15的具体功能实现方式可以参见上述图3所对应实施例中的步骤S101,遍历模块16,验证模块17的具体功能实现方式可以参见上述图3所对应实施例中的步骤S103,查询请求接收模块18,地址查询模块19,关联节点获取模块20,查询权限确定模块21,交易数据获取模块22,数据操作模块23的具体功能实现方式可以参见上述图3所对应实施例中的步骤S103以及图4所对应的实施例,更新请求获取模块24,测试合约生成模块25,合约更新模块26的具体功能实现方式可以参见上述图5所对应实施例中的步骤S204-步骤S207,这里不再进行赘述。Among them, the specific functional implementation of the block generation module 13, the consensus module 14, and the address determination module 15 can refer to step S101 in the embodiment corresponding to Figure 3 above, the specific functional implementation of the traversal module 16 and the verification module 17 can refer to step S103 in the embodiment corresponding to Figure 3 above, the specific functional implementation of the query request receiving module 18, the address query module 19, the associated node acquisition module 20, the query authority determination module 21, the transaction data acquisition module 22, and the data operation module 23 can refer to step S103 in the embodiment corresponding to Figure 3 above and the embodiment corresponding to Figure 4, the specific functional implementation of the update request acquisition module 24, the test contract generation module 25, and the contract update module 26 can refer to steps S204-S207 in the embodiment corresponding to Figure 5 above, and will not be repeated here.
请一并参见图7,构建模块11可以包括:参数输入单元111,接口调用单元112,绑定单元113;Please refer to FIG7 , the construction module 11 may include: a parameter input unit 111 , an interface calling unit 112 , and a binding unit 113 ;
参数输入单元111,用于从合约管理平台中获取合约模板,将第一地址和第二地址作为参数输入合约模板中;The parameter input unit 111 is used to obtain a contract template from the contract management platform and input the first address and the second address as parameters into the contract template;
接口调用单元112,用于基于合约模板,从第二地址对应的业务合约中调用地址设置接口;The interface calling unit 112 is configured to call an address setting interface from the business contract corresponding to the second address based on the contract template;
绑定单元113,用于根据地址设置接口,将第一地址输入业务合约中,对业务合约和数据合约进行绑定,得到代理合约。The binding unit 113 is used to input the first address into the business contract according to the address setting interface, bind the business contract and the data contract, and obtain the proxy contract.
其中,参数输入单元111,接口调用单元112,绑定单元113的具体功能实现方式可以参见上述图3所对应实施例中的步骤S102,这里不再进行赘述。The specific functional implementation of the parameter input unit 111, the interface calling unit 112, and the binding unit 113 can be found in step S102 of the embodiment corresponding to FIG. 3 above, and will not be described in detail here.
请一并参见图7,合约更新模块26可以包括:地址更新单元261,更新合约确定单元262;Please refer to FIG7 , the contract updating module 26 may include: an address updating unit 261 , an updated contract determining unit 262 ;
地址更新单元261,用于当测试代理合约通过测试时,冻结代理合约,将代理合约中的第二地址更新为测试通过状态的测试代理合约中的第四地址;The address updating unit 261 is used to freeze the proxy contract when the test proxy contract passes the test, and update the second address in the proxy contract to the fourth address in the test proxy contract in the test passed state;
更新合约确定单元262,用于将包含第一地址和第四地址的代理合约确定为更新后的代理合约;更新后的代理合约与第三地址相关联。The updated contract determining unit 262 is configured to determine the proxy contract including the first address and the fourth address as an updated proxy contract; the updated proxy contract is associated with the third address.
其中,地址更新单元261,更新合约确定单元262的具体功能实现方式可以参见上述图5所对应实施例中的步骤S206-步骤S207,这里不再进行赘述。Among them, the specific functional implementation of the address updating unit 261 and the updated contract determining unit 262 can refer to steps S206 and S207 in the embodiment corresponding to Figure 5 above, and will not be repeated here.
在本申请实施例中,通过在区块链中创建合约管理平台,并在合约管理平台中编写一个合约模板,将业务合约地址和数据合约地址作为参数输入合约模板中即可生成代理合约,即区块链节点可以基于合约管理平台中的合约模板,将数据合约和业务合约进行绑定,完成代理合约在区块链中的部署过程,当区块链中需要部署多个代理合约时,根据合约模板可以快速生成多个代理合约,减少代理合约的开发过程,进而可以提高区块链中合约的开发效率;通过将代理合约中的业务合约地址更新为新业务合约地址,即可完成合约的升级过程,可以提高合约升级效率。In an embodiment of the present application, a proxy contract can be generated by creating a contract management platform in the blockchain and writing a contract template in the contract management platform. The business contract address and the data contract address are input as parameters into the contract template. That is, the blockchain node can bind the data contract and the business contract based on the contract template in the contract management platform to complete the deployment process of the proxy contract in the blockchain. When multiple proxy contracts need to be deployed in the blockchain, multiple proxy contracts can be quickly generated according to the contract template, reducing the development process of the proxy contract, thereby improving the development efficiency of the contract in the blockchain; by updating the business contract address in the proxy contract to the new business contract address, the contract upgrade process can be completed, which can improve the contract upgrade efficiency.
请参见图8,是本申请实施例提供的一种节点设备的结构示意图。如图8所示,该节点设备1000可以包括:处理器1001,网络接口1004和存储器1005,此外,上述节点设备1000还可以包括:用户接口1003,和至少一个通信总线1002。其中,通信总线1002用于实现这些组件之间的连接通信。其中,用户接口1003可以包括显示屏(Display)、键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口)。存储器1004可以是高速RAM存储器,也可以是非不稳定的存储器(non-volatile memory),例如至少一个磁盘存储器。存储器1005可选的还可以是至少一个位于远离前述处理器1001的存储装置。如图8所示,作为一种计算机可读存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及设备控制应用程序。Please refer to Figure 8, which is a structural diagram of a node device provided in an embodiment of the present application. As shown in Figure 8, the node device 1000 may include: a processor 1001, a network interface 1004 and a memory 1005. In addition, the node device 1000 may also include: a user interface 1003, and at least one communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. Among them, the user interface 1003 may include a display screen (Display), a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1004 may be a high-speed RAM memory or a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 1005 may also be at least one storage device located away from the aforementioned processor 1001. As shown in Figure 8, the memory 1005 as a computer-readable storage medium may include an operating system, a network communication module, a user interface module and a device control application.
在如图8所示的节点设备1000中,网络接口1004可提供网络通讯功能;而用户接口1003主要用于为用户提供输入的接口;而处理器1001可以用于调用存储器1005中存储的设备控制应用程序,以实现:In the node device 1000 shown in FIG8 , the network interface 1004 can provide network communication functions; the user interface 1003 is mainly used to provide an interface for user input; and the processor 1001 can be used to call the device control application stored in the memory 1005 to achieve:
接收请求节点发送的合约注册请求,获取合约注册请求携带的合约名称、数据合约对应的第一地址以及业务合约对应的第二地址;数据合约用于存储业务数据,业务合约用于存储业务逻辑;Receive the contract registration request sent by the requesting node, obtain the contract name, the first address corresponding to the data contract, and the second address corresponding to the business contract carried in the contract registration request; the data contract is used to store business data, and the business contract is used to store business logic;
从合约管理平台中获取合约模板,基于合约模板对第一地址和第二地址进行绑定,得到与业务合约和数据合约相关联的代理合约,生成代理合约对应的第三地址;Obtain a contract template from the contract management platform, bind the first address and the second address based on the contract template, obtain a proxy contract associated with the business contract and the data contract, and generate a third address corresponding to the proxy contract;
生成第三地址和合约名称之间的映射关系信息,将映射关系信息存储在合约管理平台中。Generate mapping relationship information between the third address and the contract name, and store the mapping relationship information in the contract management platform.
应当理解,本申请实施例中所描述的节点设备1000可执行前文图3、图5任一个所对应实施例中对区块链合约部署方法的描述,也可执行前文图7所对应实施例中对区块链合约部署装置1的描述,在此不再赘述。另外,对采用相同方法的有益效果描述,也不再进行赘述。It should be understood that the node device 1000 described in the embodiments of the present application can execute the description of the blockchain contract deployment method in any of the embodiments corresponding to Figures 3 and 5 above, and can also execute the description of the blockchain contract deployment device 1 in the embodiment corresponding to Figure 7 above, and will not be repeated here. In addition, the description of the beneficial effects of using the same method will not be repeated here.
此外,这里需要指出的是:本申请实施例还提供了一种计算机可读存储介质,且计算机可读存储介质中存储有前文提及的区块链合约部署装置1所执行的计算机程序,且计算机程序包括程序指令,当处理器执行程序指令时,能够执行前文图3、图5任一个所对应实施例中对区块链合约部署方法的描述,因此,这里将不再进行赘述。另外,对采用相同方法的有益效果描述,也不再进行赘述。对于本申请所涉及的计算机可读存储介质实施例中未披露的技术细节,请参照本申请方法实施例的描述。In addition, it should be noted that the embodiment of the present application also provides a computer-readable storage medium, and the computer-readable storage medium stores a computer program executed by the aforementioned blockchain contract deployment device 1, and the computer program includes program instructions. When the processor executes the program instructions, it can execute the description of the blockchain contract deployment method in any of the embodiments corresponding to Figures 3 and 5 above. Therefore, it will not be repeated here. In addition, the description of the beneficial effects of using the same method will not be repeated. For technical details not disclosed in the computer-readable storage medium embodiment involved in this application, please refer to the description of the method embodiment of this application.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,计算机程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,可读存储介质可为磁碟、光盘、只读存储存储器(Read-Only Memory,ROM)或随机存储存储器(Random AccessMemory,RAM)等。Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing related hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When executed, the program can include the processes in the above-described method embodiments. The computer-readable storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
以上所揭露的仅为本申请较佳实施例而已,当然不能以此来限定本申请之权利范围,因此依本申请权利要求所作的等同变化,仍属本申请所涵盖的范围。The above disclosure is only a preferred embodiment of the present application, and certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims (10)
Publications (2)
| Publication Number | Publication Date |
|---|---|
| HK40055340A HK40055340A (en) | 2022-03-11 |
| HK40055340B true HK40055340B (en) | 2022-09-09 |
Family
ID=
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN110933163B (en) | Blockchain contract deployment method, device, device and storage medium | |
| JP7076682B2 (en) | Data processing methods, devices, electronic devices and computer programs based on blockchain networks | |
| JP7710448B2 (en) | Partially Ordered Blockchain | |
| US11611560B2 (en) | Systems, methods, and apparatuses for implementing consensus on read via a consensus on write smart contract trigger for a distributed ledger technology (DLT) platform | |
| CN111090876B (en) | Method and device for calling a contract | |
| CN110598434B (en) | House information processing method and device based on blockchain network, electronic equipment and storage medium | |
| CN110597832A (en) | Government affair information processing method and device based on block chain network, electronic equipment and storage medium | |
| CN111934870B (en) | Method, apparatus, device and medium for updating root certificate in block chain network | |
| US20250328903A1 (en) | Blockchain-based data processing method and apparatus, device, and medium | |
| CN111127021B (en) | Service request method and device based on block chain | |
| CN111488372A (en) | Data processing method, device and storage medium | |
| JP2023525576A (en) | Scope of control of authentication keys for software updates | |
| CN111311211A (en) | A blockchain-based data processing method and device | |
| WO2025036418A1 (en) | Blockchain-based data management method, apparatus, and system and electronic device | |
| García-Martínez et al. | Design and implementation of InBlock—A distributed IP address registration system | |
| CN117014176A (en) | Data processing methods, devices, equipment and readable storage media based on blockchain | |
| CN117333175A (en) | Blockchain system, intelligent contract synchronization method, computer equipment and storage medium | |
| CN119203152B (en) | A privacy protection method for blockchain smart contracts based on trusted execution environment and assembly comparison calculation | |
| HK40055340B (en) | Method and apparatus for deploying blockchain contract, device and storage medium | |
| HK40055340A (en) | Method and apparatus for deploying blockchain contract, device and storage medium | |
| HK40021568A (en) | Method, apparatus, device and storage medium for blockchain contract deployment | |
| HK40021568B (en) | Method, apparatus, device and storage medium for blockchain contract deployment | |
| CN113574483A (en) | Method and control system for controlling the execution of transactions | |
| CN118350031A (en) | Blockchain-based data processing method, device, equipment, and medium | |
| HK40026397B (en) | Block generation method and apparatus, computer device, and storage medium |