Method and server for providing intelligent contract service
By providing methods and servers for smart contract services, and encapsulating contract deployment and calling operations as API interfaces, the problem of complexity and high cost of using smart contracts is solved, and a user-friendly smart contract deployment and calling experience is achieved.
Patent Information
- Application Number
- CN202410741629.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2024-08-30
AI Technical Summary
There are barriers to the development and use of smart contracts in existing blockchain technology. Users need to operate contract codes, accounts on the blockchain, and contract deployment, resulting in high cost and complexity.
By providing methods and servers for smart contract services, contract deployment and calling operations are encapsulated as service interfaces, allowing applications to call contract services through APIs without users being aware of contract code and deployment details.
It reduces the cost and complexity of smart contracts, enables users to easily deploy and call contracts, and reduces the difficulty of operating blockchain technology.
Smart Images

Figure CN118569864A
Abstract
Description
Technical Field
[0001] The embodiments of this specification belong to the field of blockchain technology, and more particularly to a method and server for providing smart contract services. Background Art
[0002] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. In the blockchain system, data blocks are combined into a chain data structure in a sequential manner according to time sequence, and a distributed ledger that cannot be tampered with or forged is guaranteed by cryptography. Due to the characteristics of blockchain such as decentralization, information cannot be tampered with, and autonomy, blockchain has also received more and more attention and application. Summary of the invention
[0003] The purpose of the present invention is to provide a solution for providing smart contract services, so that users can use the contract services by calling the service interface.
[0004] A first aspect of the present specification provides a method for providing a smart contract service, which is executed by a server, and the method comprises:
[0005] Receiving a first call request for a first service interface, wherein the server stores a correspondence between the first service interface and a first contract interface of a first contract, and a parameter format of the first contract interface;
[0006] According to the corresponding relationship, obtaining the parameter format of the first contract interface;
[0007] Generate a first transaction that calls the first contract interface based on the first call request, the first contract interface, and the parameter format;
[0008] The first transaction is sent to the blockchain system.
[0009] In one embodiment, the method further comprises:
[0010] Acquiring, based on the first call request, an application identifier of a first application that sends the first call request, wherein the server records authorization information of the first application;
[0011] Acquire authorization information of the first application according to the application identifier;
[0012] Based on the authorization information, it is checked whether the first application has the permission to call the first service interface.
[0013] In one embodiment, the parameter format includes the parameter format of the input parameters of the first contract interface, and the first transaction for calling the first contract interface based on the first call request, the first contract interface and the parameter format includes: generating the input parameters of the first contract interface based on the format of the input parameters and the input parameters of the first service interface.
[0014] In one embodiment, the parameter format includes the parameter format of the output parameters of the first contract interface, and the method further includes: receiving the output parameters of the first contract interface from the blockchain system, parsing the output parameters according to the parameter format of the output parameters, converting the output parameters into output parameters of the first service interface, and returning the output parameters of the first service interface to the first application.
[0015] In one implementation, the first call request includes a first signature of the first application; the method further includes: verifying the first signature using a pre-acquired public key corresponding to the first application.
[0016] In one embodiment, the method further comprises:
[0017] receiving a second call request for a second service interface sent by a tenant device, wherein the second call request includes a template identifier of a first contract template corresponding to the first contract;
[0018] Generate and store the first service interface according to the second call request;
[0019] Based on the template identifier and the pre-stored contract code corresponding to the first contract template, generating a second transaction for deploying the first contract;
[0020] Sending the second transaction to the blockchain system;
[0021] After the first contract is successfully deployed, the first service interface is returned to the tenant device.
[0022] In one embodiment, generating and storing the first service interface according to the second call request includes: generating a contract service instance corresponding to the first contract according to the second call request, the contract service instance including the first service interface;
[0023] The generating of the first transaction for calling the first contract interface based on the first calling request, the first contract interface and the parameter format includes: the contract service instance generating the first transaction for calling the first contract interface based on the first calling request, the first contract interface and the parameter format.
[0024] In one embodiment, the method further comprises:
[0025] receiving an application registration request sent by the tenant device, wherein the application registration request includes an application identifier of the first application;
[0026] Obtaining a public-private key pair corresponding to the application identifier;
[0027] Returning the public-private key pair to the tenant device;
[0028] The public-private key pair is associated with an application identifier of the first application.
[0029] In one embodiment, the method further includes: binding the first service interface to a tenant identifier corresponding to the tenant device;
[0030] Receiving an application authorization request sent by the tenant device, for requesting authorization for the first application to call the first service interface;
[0031] When the tenant's permission verification is passed, authorization information indicating that the first application is authorized to call the first service interface is stored.
[0032] In one embodiment, the method further comprises:
[0033] Receiving a contract template from an operating device, wherein the contract template includes a contract code, contract interface data, and a contract template identifier; and storing the contract template;
[0034] Acquire a second contract interface and a parameter format corresponding to the second contract interface from the contract interface data;
[0035] The second contract interface and the parameter format are recorded in association with the contract template identifier, wherein the first contract interface corresponds to the second contract interface.
[0036] A second aspect of the present specification provides a server, including:
[0037] A receiving unit, configured to receive a first call request for a first service interface, wherein the server stores a correspondence between the first service interface and a first contract interface of a first contract, and a parameter format of the first contract interface;
[0038] An acquiring unit, configured to acquire a parameter format of the first contract interface according to the corresponding relationship;
[0039] a generating unit, configured to generate a first transaction for calling the first contract interface based on the first calling request, the first contract interface and the parameter format;
[0040] A sending unit is used to send the first transaction to the blockchain system.
[0041] A third aspect of the present specification provides a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method described in the first aspect.
[0042] A fourth aspect of the specification provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in the first aspect is implemented.
[0043] The fifth aspect of this specification provides a computer program product, including a computer program / instruction, which implements the steps of the method described in the first aspect when executed by a processor.
[0044] In the embodiments of this specification, operations such as deploying smart contracts and calling smart contracts are encapsulated as service interfaces and provided to applications, so that applications can deploy contracts and call contracts by calling APIs without the need for users to perceive contract codes, contract deployment, etc. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0046] Figure 1 This is a system architecture diagram for providing contract services in the embodiments of this specification;
[0047] Figure 2 This is an architecture diagram of the contract server S1 in the embodiment of this specification;
[0048] Figure 3 A flow chart of a method for storing a contract template in a contract server in an embodiment of this specification;
[0049] Figure 4 This is a flow chart of the method for deploying a contract in an embodiment of this specification;
[0050] Figure 5 This is a flow chart of a method for authorizing a tenant's application in an embodiment of this specification;
[0051] Figure 6 A flowchart of a method for providing contract services in an embodiment of this specification;
[0052] Figure 7This is an architecture diagram of a server in one embodiment of this specification. DETAILED DESCRIPTION
[0053] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.
[0054] In order to more clearly explain the scheme in the embodiments of this specification, the blockchain system is first introduced. The blockchain system may include multiple nodes, and the nodes may be connected to each other. These nodes may store the full amount of ledgers, that is, store the status of all blocks and all accounts. Among them, each node in the blockchain system can generate the same state in the blockchain system by executing the same transaction, and each node in the blockchain system may store the same state database.
[0055] Transactions in the blockchain field can refer to task units executed and recorded in the blockchain system. Transactions usually include a send field (From), a receive field (To), and a data field (Data). Among them, in the case of a transfer transaction, the From field indicates the account address that initiates the transaction (i.e., initiates a transfer task to another account), the To field indicates the account address that receives the transaction (i.e., receives the transfer), and the Data field includes the transfer amount.
[0056] The blockchain system can provide the function of smart contracts. Smart contracts on the blockchain system are contracts that can be triggered and executed by transactions on the blockchain system. Smart contracts can be defined in the form of code. Calling a smart contract in the blockchain system is to initiate a transaction pointing to the smart contract address, so that each node in the blockchain system can run the smart contract code in a distributed manner.
[0057] In the scenario of deploying a contract, for example, Bob sends a transaction containing information about creating a smart contract (i.e., deploying a contract) to the blockchain system. The data field of the transaction includes the code of the contract to be created (such as bytecode or machine code), and the to field of the transaction is empty, indicating that the transaction is used to deploy a contract. After the nodes reach an agreement through the consensus mechanism, the contract address "0x6f8ae93..." of the contract is determined. Each node adds a contract account corresponding to the contract address of the smart contract to the state database, allocates the state storage corresponding to the contract account, and stores the contract code. The hash value of the contract code is saved in the state storage of the contract, so that the contract is successfully created.
[0058] In the scenario of calling a contract, for example, Bob sends a transaction for calling a smart contract to the blockchain system. The from field of the transaction is the address of the account of the transaction initiator (i.e. Bob), the to field is the above-mentioned "0x6f8ae93...", that is, the address of the smart contract being called, and the data field of the transaction includes the method and parameters for calling the smart contract. After the blockchain system reaches a consensus on the transaction, each node in the blockchain system can execute the transaction separately, thereby executing the contract separately, and updating the status database based on the execution of the contract.
[0059] At present, many blockchain businesses need to use smart contracts, but there are certain barriers to the development and use of smart contracts, which is difficult for many developers and businesses that want to use smart contracts. In order to reduce the cost of using smart contracts for users, related technologies provide products such as contract engineering, contract templates, and contract markets. These products provide written smart contract code templates, and users can deploy and use contracts based on code templates, or perform secondary development based on the code, and then deploy and use new contracts. However, these users still need to operate contracts, and need to perceive contract codes, accounts on the blockchain, contract deployment, etc.
[0060] To this end, in the embodiments of this specification, operations such as deploying smart contracts and calling smart contracts are encapsulated as service interfaces (Application Programming Interface, API) and provided to applications. Applications can deploy and call contracts by calling APIs without the need for users to perceive contract codes, contract deployment, etc.
[0061] Figure 1 This is a system architecture diagram for providing contract services in the embodiments of this specification. Figure 1As shown, the system may include a contract server S1, an operation server S2, an application server A1, an application server A2, a tenant device C1, a user device C2, a blockchain system 100, etc. The operation server S2 may provide a contract template to the contract server S1, and the user device (e.g., the tenant device C1 or the user device C2) may instruct the contract server S1 to deploy the contract in the blockchain system based on the contract template by calling an API for deploying the contract (such as API1 or API2 described below). After receiving the API for deploying the contract, the contract server S1 creates multiple APIs (such as API3 described below) for calling multiple contract interfaces (Application Binary Interface, ABI) of the contract, and generates a transaction for deploying the contract, and sends the transaction to the blockchain system 100 to deploy the contract in the blockchain system.
[0062] The above tenant may be used to refer to an enterprise user, which, for example, owns an application server to provide services to users of the application.
[0063] The above ABI interface is a set of rules and structures that define how smart contracts communicate with external callers. The ABI interface includes the function name, input and output parameter format, etc. of the smart contract, so that the code on the blockchain can be correctly accessed and interacted by external programs.
[0064] The above-mentioned API may include the following contents: (1) Interface description, which is used to provide instructions for using the API, including interface description, parameter description, etc.; (2) Endpoint: URL address corresponding to the API service; (3) Method name: the name of the method supported by the endpoint. In the embodiment of this specification, the method corresponding to the method name in the above-mentioned API1 or API2 is used, for example, to generate a transaction for deploying a contract, and send the transaction to the blockchain system to deploy the contract; the method corresponding to the method name in the above-mentioned API3 is used, for example, to generate a transaction for calling a contract, and send the transaction to the blockchain system, return parameters, etc.; (4) Parameters: The parameters may include the input parameters and output parameters of the API, where the input parameters are the parameters passed to the API when the application initiates an API request, and the output parameters are the parameters returned by the API to the application, etc.
[0065] After the contract is deployed, the application server (such as application server A1 or A2) can call the above API corresponding to the ABI, so that the contract server S1 sends a transaction calling the ABI to the blockchain system, thereby realizing the call of the contract.
[0066] Understandably, Figure 1The system shown is merely exemplary and is not intended to limit the system architecture of the embodiments of this specification. For example, each application server can be connected to a gateway, and the service request sent by the application server can be sent to the contract server S1 after being verified by the gateway, thereby further improving the security of the network connection.
[0067] Figure 2 FIG. 1 is an architecture diagram of the contract server S1 in the embodiment of this specification. Figure 2 As shown, the contract server S1 can access services Sv1, contract service Sv2, user management service Sv3, application service Sv4 and other services. Among them, the services in the server usually refer to the background programs or processes running on the server, which provide various network services or business functions. Specifically, the access service Sv1 is used to provide the service interface API to the application and verify the user's login information. The contract service Sv2 provides two services: contract deployment and contract call. Among them, the contract deployment service may include operations such as deploying contracts to the blockchain system, publishing APIs corresponding to contracts, and upgrading contracts. The contract call service may include parsing API parameters, generating transactions for calling contracts based on parameters, sending transactions to the blockchain system, receiving output parameters from the blockchain system, and returning output parameters. The user management server Sv3 includes: recording user identification (user ID) and user password, creating a blockchain account for the user, and recording the public and private key pairing operations of the user's blockchain account. The application service Sv includes operations such as registering applications, authorizing applications, and releasing application authorization. The following is a detailed description of each of the above services with reference to the method flow chart.
[0068] Figure 3 The following is a flow chart of a method for storing a contract template in a contract server in an embodiment of this specification. The method is executed by the contract server.
[0069] like Figure 3 As shown, first, in step S301, the contract server receives the contract template.
[0070] refer to Figure 1 As shown, the contract server S1 can receive a contract template from the operation server S2. The contract template includes a template identifier, a contract code file, and an abi file. The contract code file includes, for example, a contract code in wasm format, and the abi file includes one or more ABIs of the contract. Specifically, the abi file usually includes the following information: function name, type and order of input parameters of the function, type and structure of return value after function execution, etc. The abi file is usually stored in JSON format, which describes how to format and encode data between a smart contract and a program that calls its ABI. The template identifier may include information such as the template name and the template number.
[0071] In one embodiment, the operation server S2 can also parse the contract template, obtain interface information corresponding to the contract template, and send the interface information together with the contract template to the contract server. The interface information may include one or more ABIs included in the contract and the input and output parameter formats of each ABI.
[0072] In step S303, the contract server stores the contract template and the interface information corresponding to the contract template.
[0073] Specifically, the contract server S1 can execute this step through the contract service Sv2, so that the contract service Sv2 can use the contract template and its interface information later.
[0074] After receiving the contract template, the contract server S1 can first perform mandatory item verification to verify whether the contract template includes mandatory items, such as template name, contract code file, abi file, etc. Then, the contract service Sv2 can verify whether the template name is repeated with the existing template name.
[0075] After the above verification is passed, the contract service Sv2 can store the contract code file and abi file in the contract template in the file storage system (such as the Oss storage system), and record the storage address of the above files in association with the contract template name. In the case where the operation server S2 only sends the contract template to the contract server S1, the contract server S1 can parse the abi file in the contract template, extract the interface of the smart contract and the input and output parameter format corresponding to the interface, and record the interface and its input and output parameter format in association with the template identifier of the contract template in the contract resolution table. Afterwards, the contract server S1 can store the contract resolution table in the Mysql database.
[0076] In one embodiment, after generating the above interface information, the contract service Sv2 may cache the interface information and the above storage address in the Oss storage system, and return the interface information to the operation server S2. After confirming that the interface information is correct, the operator instructs the operation server S2 to create a contract template, so that the operation server S2 instructs the contract server S1 to create the contract template. After receiving the creation instruction from the operation server S2, the contract server S1 obtains the interface information from the cache, and stores the interface information and the Oss storage address in the contract parsing table in the Mysql database in association with the template identifier of the contract template. After completing the above storage, the contract service Sv2 may create an API1 for deploying the contract corresponding to the contract template, and publish an introduction to the contract template and the API1, that is, put the contract template on the shelf, so that the tenant or user can obtain the introduction of the contract template and can deploy the contract through API1.
[0077] Figure 4 This is a flow chart of a method for deploying a contract in an embodiment of this specification. The method can be executed by a contract server.
[0078] like Figure 4 As shown, first, in step S401, a contract deployment request is received.
[0079] The tenant or user can first register in the contract server S1 and provide a user ID and password to request the activation of the service. The contract server S1 receives the tenant's user ID and password through the access service Sv1 and provides it to the user management service Sv3. After determining that the user ID does not overlap with an existing user ID, the user management service Sv3 creates a service instance corresponding to the user ID. Among them, a service instance refers to an independent service unit created for a specific user or client request during the service provision process. These service units are usually pre-configured and can be managed and maintained separately as needed, allowing users to run independent, isolated service environments on a shared infrastructure, providing flexibility, scalability and customization. Among them, each service instance is isolated from other instances to a certain extent to ensure the security of operations and the privacy of data.
[0080] As described above, after creating a contract template, the contract service Sv2 provides the tenant or user with an API1 for deploying the contract corresponding to the contract template, and the tenant device C1 or the user device C2 can deploy the contract corresponding to the contract template (hereinafter referred to as contract Contract1) by calling the API1. The method included in the API1 is, for example, the function create(), where the parameters in the brackets of the function are the input parameters to the function.
[0081] In one embodiment, the input parameters to the API 1 may include the contract identifier of the contract that the tenant or user (hereinafter described using the tenant as an example) wishes to create. In this way, the tenant or user can use the contract identifier to uniquely identify the deployed contract without the need to perceive the contract address of the deployed contract.
[0082] In one embodiment, the contract service Sv2 may publish an API2 for deploying contracts corresponding to multiple contract templates. In this case, the input parameters to API2 may include an identifier of the contract template to indicate the contract template corresponding to the deployed contract.
[0083] In step S403, the contract server generates and stores the API3 of the contract.
[0084] Specifically, after the contract server receives the contract deployment request, the user management service Sv3 first creates an on-chain account corresponding to "Tenant1" based on the user ID of the tenant or user login (such as Tenant1). The on-chain account includes the account address, public key and private key, and stores "Tenant1" and its on-chain account in association, and provides the information of the on-chain account to the contract service Sv2.
[0085] At the same time, the contract service Sv2 can create a contract service instance corresponding to the contract template in response to the above contract deployment request, and the contract service instance includes one or more API3 corresponding to one or more ABIs in the contract template. Specifically, the above API3 can be implemented in various forms, including RESTful API, SOAP API, etc.
[0086] The contract service Sv2 generates an interface code corresponding to each API3, which includes the name of the ABI in the corresponding contract template, which is used to indicate the generation of a transaction that calls the ABI and sends the transaction to the blockchain system. The contract service Sv2 can record the status of the current contract deployment step as the status of completing the creation of the contract server instance. In the case where the contract deployment request includes a contract identifier, the contract service Sv2 binds the contract identifier to the contract service instance. In addition, the contract service Sv2 also binds the tenant's user ID "Tenant1" to the contract service instance to indicate that the contract service instance corresponds to the tenant "Tenant1".
[0087] In step S405, the contract server obtains the contract code and generates a transaction for deploying the contract based on the contract code.
[0088] Then, the contract service Sv2 obtains the contract template based on the identifier of the contract template corresponding to API1, or based on the identifier of the contract template in the input parameter of API2. Specifically, the storage address of the contract template stored in association with the contract template identifier can be obtained, and the contract code in the contract template is read through the storage address in the OSS storage system. Afterwards, the contract server Sv2 can generate a transaction Tx1 for deploying the contract. The sending account of the transaction Tx1 is the account address of the on-chain account corresponding to "Tenant1", and the receiving account can be empty to indicate that it is used to deploy the transaction. The data field can include the contract code obtained above, and the signature of the transaction Tx1 is a signature based on the private key of the on-chain account corresponding to "Tenant1".
[0089] In step S407, the contract server sends the transaction to the blockchain system to deploy the contract.
[0090] After generating transaction Tx1, contract service Sv2 sends transaction Tx1 to the blockchain system through the connection between the contract server and the blockchain system (e.g., a blockchain node), so that contract Contract1 is deployed in the blockchain system by executing transaction Tx1. After completing the deployment of contract Contract1, the determined contract address of contract Contract1 is returned to contract service Sv2 in the blockchain system. Contract service Sv2 can store the contract address of contract Contract1 in association with the above-mentioned contract service instance for subsequent calls to the contract Contract1. Contract service Sv2 can also update the status of the deployment step to the status of completing the deployment of the contract in the blockchain system.
[0091] In step S409, the contract server returns the one or more APIs 3 generated above after the contract is successfully deployed.
[0092] After the contract service Sv2 determines from the blockchain system that the contract Contract1 has been deployed successfully, the contract service Sv2 may return the one or more API3s generated above to the tenant device C1. For example, assuming that one of the API3s corresponds to the ABI for transfer in the contract, and the contract function corresponding to the ABI is used to transfer resources between blockchain accounts, the interface description of the API3 may include: Function: used to transfer resources between blockchain accounts corresponding to users; Input parameter format: transfer-out user ID / transfer-in user ID / transfer resource amount. Among them, the input and output parameters of the API3 have a corresponding relationship with the input and output parameters of ABI1. For example, the input parameters of ABI1 may include: the blockchain account corresponding to the transfer-out user ID, the blockchain account corresponding to the transfer-in user ID, the transfer resource amount, etc.
[0093] Tenant device C1 can call these API3 according to the interface description of each API3. Since tenant "Tenant1" is bound to the contract service instance in the above contract service instance, the contract service instance can determine that tenant "Tenant1" has the authority to call these API3 according to the binding.
[0094] After completing the contract deployment and obtaining the API3 corresponding to the contract as described above, the tenant device C1 can also authorize the application belonging to the tenant to use the API3. Figure 5 This is a flow chart of a method for authorizing a tenant's application in an embodiment of this specification, and the method is executed by a contract server.
[0095] like Figure 5 As shown, first, in step S501, the contract server receives an application registration request from a tenant device.
[0096] The application registration request may include an application identifier (application ID) of the application, which is used to request registration of the application in the contract server S1. The application may be, for example, a decentralized application that relies on blockchain technology.
[0097] After the tenant's login verification is passed, the access service Sv1 in the contract server can send the tenant's user ID and application registration request to the application service Sv4.
[0098] In step S503, the contract server obtains the key of the application and returns the key of the application to the tenant device.
[0099] In one embodiment, the application service Sv4 may generate the public key PK1 and the private key SK1 of the application. In another embodiment, the application service Sv4 may obtain the public and private key pair corresponding to the application from another service in the contract server. In another embodiment, the application service Sv4 may obtain the public and private key pair corresponding to the application by calling a service provided by another server.
[0100] Afterwards, the application service Sv4 may associate and store the user ID, application ID, public key PK1, and private key SK1, and return the public key PK1 and private key SK1 to the tenant device C1. Figure 1 In the case where the system shown also includes a gateway of the contract server S1, the application service Sv4 can provide the application ID and the public key PK1 to the gateway to verify the signature of the request sent by the application, thereby further improving network security.
[0101] In one embodiment, the tenant device C1 may actively send a request to the contract server to view the application private key. The application service Sv4 may determine whether the application belongs to the tenant corresponding to the tenant device C1 based on the pre-stored associated user ID and application ID, that is, determine whether the tenant has the permission to view the application private key. If the tenant's permission check is passed, the private key SK1 is returned to the tenant device C1.
[0102] In step S505, the contract server receives an application authorization request from the tenant device.
[0103] After registering the application, the tenant device C1 may send an application authorization request to the contract server to authorize the application to call or use the above API 3. The application authorization request may include the application ID and API 3.
[0104] Before sending an application authorization request to the contract server, the tenant device C1 can send a request to view the application authorization list to the contract server. After receiving the request, the application service Sv4 can read the application authorization list stored in association with the user ID of the tenant, which includes the application ID of the application belonging to the tenant and the authorization information corresponding to each application ID, and return the application authorization list to the tenant device, so that the tenant device can determine the authorization status of each application based on the list.
[0105] In step S507, when the tenant's permission verification is passed, the contract server authorizes the application to call API3.
[0106] After receiving the application authorization request, the contract server first verifies the tenant's login by the access service Sv1. If the verification is successful, the contract service Sv2 verifies whether the tenant has the permission to use API3. If the permission verification is successful, the application service Sv4 records the authorization relationship between the target application ID and API3 in the application authorization list corresponding to the tenant, that is, authorizes the application to call API3.
[0107] In addition, the tenant device can also send an application authorization relationship deletion request to the contract server to delete the authorization for the application. Specifically, if the tenant's permission verification is passed, the contract server can delete the authorization relationship of the target application ID in the application authorization list corresponding to the tenant.
[0108] After completing the above contract deployment and authorization of the application, the application can call the contract in the blockchain system by calling the above API3.
[0109] Figure 6 This is a flow chart of a method for providing contract services in an embodiment of this specification. The method can be executed by a contract server.
[0110] like Figure 6 As shown, in step S601, the contract server receives a call request to API3.
[0111] refer to Figure 1 After receiving API3 from the contract server S1 as described above, the tenant device C1 can send API3 to the application server A1. The tenant device C1 can also send the public key PK1 and private key SK1 of the application obtained above to the application server A1.
[0112] Application server A1 can generate a call request for API3 based on API3. For example, API3 is used to call method1 interface of contract Contract1. Method1 is used to perform preset calculations on the incoming data and then store the processing results. The incoming parameters of method1 include the data to be processed, and the return parameters of method1 include the processing results. Therefore, the endpoint included in API3 is the connection address of contract server S1, the method name is, for example, Method1(), the incoming parameters of Method1() are the data to be processed, and the output parameters are the processing results of the blockchain system on the data. Method1 includes the following operations: generating a transaction to call contract method1, sending the transaction to the blockchain system, receiving the processing results from the blockchain system, and returning the processing results as output parameters to the application that calls API3. The call request to API3 includes, for example, the data data1 to be processed as the incoming parameter of API3.
[0113] Afterwards, the application server A1 sends the generated API3 call request and the signature Sign1 of the call request using the private key SK1 to the contract server S1.
[0114] In one embodiment, when the system includes a gateway, the application server A1 sends a call request and a signature Sign1 to the gateway, and the gateway uses the public key PK1 of the application received in advance from the application service Sv4 to verify the signature Sign1. If the verification passes, the gateway sends the call request, the signature Sign1 and the application ID to the contract server S1.
[0115] In step S603, the contract server obtains the contract interface and parameter format corresponding to API3.
[0116] After the contract server S1 receives the call request for API3, the signature Sign1 and the application ID, first, the application service Sv4 can obtain the public key PK1 corresponding to the application ID, and use the public key PK1 to verify the signature Sign1. If the verification is successful, it is determined whether the application is authorized to call API3 based on the application authorization list. If it is determined that the application is authorized, the application service Sv4 sends the call request for API3 to the contract service instance corresponding to the contract Contract1. The contract service instance first determines whether the current status of the contract template is the shelf status based on the template identifier of the pre-recorded contract template. If it is determined that the current status of the contract template is the shelf status, the interface information corresponding to the template identifier is obtained from the contract resolution table, and the contract ABI interface (for example, ABI1) corresponding to the API3 and its parameter format are obtained from the interface information.
[0117] The contract service instance can also determine the status of the function corresponding to the ABI interface from the blockchain system, such as whether the function exists in the contract, whether the function is disabled, etc., and execute step S605 if the function is included in the contract and is not disabled.
[0118] In step S605, the contract server generates a transaction for calling the contract based on the contract interface and parameter format.
[0119] Specifically, after obtaining the ABI1 interface and parameter format of the contract, the contract service instance also obtains the pre-recorded blockchain account of the tenant to which the contract Contract1 belongs and the account address of the contract Contract1. The contract service instance also converts the format of the input parameter data1 of API3 according to the parameter format of the ABI1 interface to serve as the input parameter of the ABI1 interface.
[0120] The contract service instance can then generate transaction Tx2 that calls the contract's ABI1 interface, where transaction Tx2 uses the blockchain account of the tenant "Tenant1" as the transaction sending account, and the account address of the contract Contract1 as the receiving account. The data field includes the ABI1 interface and the input parameters to the ABI1 interface.
[0121] In one embodiment, when API3 involves updating the resources of the user of the application, the input parameter of API3 also includes the user ID of the application. In the contract server S1, the user management service Sv3 can create a blockchain account of the user, and the user ID and blockchain account of the user are stored in association. Afterwards, the contract service instance also includes the blockchain account of the user as an input parameter in the transaction generated by calling the contract.
[0122] In step 607, the contract server sends the transaction to the blockchain system to call the contract interface.
[0123] Specifically, the contract service instance can send the generated transaction Tx2 to the blockchain system so that the transaction Tx2 is executed in the blockchain system, thereby performing preset processing on the data data1 and obtaining the processing result. After that, the blockchain system can return the processing result to the contract server, so that the contract service instance can return the processing result to the application server A1.
[0124] In the above-mentioned solution for providing contract services provided in the embodiments of this specification, based on the management and analysis of contract templates, users can deploy contracts by calling API services, so that there is no need to perceive contract codes, contract deployment, etc., and the contract server generates an API for calling contracts. Any contract can be converted into a contract service API according to a unified logic, so that users can use the contract service API to call the contract without having to perceive operations such as transaction generation and transaction sending.
[0125] Figure 7 is a diagram of the architecture of a server in one embodiment of this specification, wherein the server is used to execute Figure 3-Figure 6 The method shown in any of the accompanying drawings, wherein the server comprises:
[0126] The receiving unit 71 is used to receive a first call request for a first service interface, wherein the server stores a correspondence between the first service interface and a first contract interface of a first contract, and a parameter format of the first contract interface;
[0127] An acquisition unit 72, configured to acquire a parameter format of the first contract interface according to the corresponding relationship;
[0128] A generating unit 73, configured to generate a first transaction for calling the first contract interface based on the first calling request, the first contract interface and the parameter format;
[0129] The sending unit 74 is used to send the first transaction to the blockchain system.
[0130] In one embodiment of the present specification, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the following Figure 3-Figure 6 The method as shown in any of the accompanying drawings.
[0131] In one embodiment of the present specification, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the following is implemented: Figure 3-Figure 6 The method as shown in any of the accompanying drawings.
[0132] In one embodiment of the present specification, a computer program product is provided, including a computer program / instruction, which is executed by a processor to implement the following Figure 3-Figure 6 The steps of the method shown in any one of the accompanying drawings.
[0133] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0134] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0135] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, the present application does not exclude that with the development of computer technology in the future, the computer that implements the functions of the above embodiments may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0136] Although one or more embodiments of the present specification provide method operation steps as described in the embodiments or flow charts, more or less operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way of executing the order of many steps, and does not represent the only execution order. When the device or terminal product in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "include", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such a process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements. For example, if the words first, second, etc. are used to represent the name, they do not represent any specific order.
[0137] For the convenience of description, the above devices are described in various modules according to their functions. Of course, when implementing one or more of the present specification, the functions of each module can be implemented in the same or more software and / or hardware, or the module implementing the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0138] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0139] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0140] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0141] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0142] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0143] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage, graphene storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0144] It should be understood by those skilled in the art that one or more embodiments of the present specification may be provided as a method, system or computer program product. Therefore, one or more embodiments of the present specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, one or more embodiments of the present specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0145] One or more embodiments of the present specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. One or more embodiments of the present specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0146] Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. In the description of this specification, the description of the reference terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representation of the above terms does not necessarily target the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples without contradiction.
[0147] The above description is only an example of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. For those skilled in the art, one or more embodiments of the present specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification shall be included in the scope of the claims.
Claims
1. A method for providing smart contract services, performed by a server, the method comprising: Receiving a first call request for a first service interface, wherein the server stores a correspondence between the first service interface and a first contract interface of a first contract, and a parameter format of the first contract interface; According to the corresponding relationship, obtaining the parameter format of the first contract interface; Generate a first transaction that calls the first contract interface based on the first call request, the first contract interface, and the parameter format; The first transaction is sent to the blockchain system.
2. The method according to claim 1, further comprising: Acquiring, based on the first call request, an application identifier of a first application that sends the first call request, wherein the server records authorization information of the first application; Acquire authorization information of the first application according to the application identifier; Based on the authorization information, it is checked whether the first application has the permission to call the first service interface.
3. The method according to claim 2, wherein the parameter format comprises a parameter format of an input parameter of the first contract interface, and the generating a first transaction for calling the first contract interface based on the first call request, the first contract interface and the parameter format comprises: Based on the format of the input parameters and the input parameters of the first service interface, the input parameters of the first contract interface are generated.
4. The method according to claim 3, wherein the parameter format comprises a parameter format of an output parameter of the first contract interface, and the method further comprises: receiving output parameters of the first contract interface from the blockchain system, parsing the output parameters according to a parameter format of the output parameters, converting the output parameters into output parameters of the first service interface, and returning the output parameters of the first service interface to the first application.
5. The method according to claim 1, wherein the first call request includes a first signature of the first application; the method further comprises: The first signature is verified using the pre-acquired public key corresponding to the first application.
6. The method according to claim 1, further comprising: receiving a second call request for a second service interface sent by a tenant device, wherein the second call request includes a template identifier of a first contract template corresponding to the first contract; Generate and store the first service interface according to the second call request; Based on the template identifier and the pre-stored contract code corresponding to the first contract template, generating a second transaction for deploying the first contract; Sending the second transaction to the blockchain system; After the first contract is successfully deployed, the first service interface is returned to the tenant device.
7. The method according to claim 6, wherein generating and storing the first service interface according to the second call request comprises: Generate a contract service instance corresponding to the first contract according to the second call request, wherein the contract service instance includes the first service interface; The generating of the first transaction for calling the first contract interface based on the first calling request, the first contract interface and the parameter format includes: the contract service instance generating the first transaction for calling the first contract interface based on the first calling request, the first contract interface and the parameter format.
8. The method according to claim 6, further comprising: receiving an application registration request sent by the tenant device, wherein the application registration request includes an application identifier of the first application; Obtaining a public-private key pair corresponding to the application identifier; Returning the public-private key pair to the tenant device; The public-private key pair is associated with an application identifier of the first application and stored.
9. The method according to claim 8, further comprising: Binding the first service interface to a tenant identifier corresponding to the tenant device; Receiving an application authorization request sent by the tenant device, for requesting authorization for the first application to call the first service interface; When the permission verification of the tenant is passed, authorization information indicating that the first application is authorized to call the first service interface is stored.
10. The method according to claim 1, further comprising: Receiving a contract template from an operating device, wherein the contract template includes a contract code, contract interface data, and a contract template identifier; Storage contract template; Acquire a second contract interface and a parameter format corresponding to the second contract interface from the contract interface data; The second contract interface and the parameter format are recorded in association with the contract template identifier, wherein the first contract interface corresponds to the second contract interface.
11. The method according to claim 10, further comprising: The second service interface is published for use in deploying a contract corresponding to the contract template.
12. A server, comprising: A receiving unit, configured to receive a first call request for a first service interface, wherein the server stores a correspondence between the first service interface and a first contract interface of a first contract, and a parameter format of the first contract interface; An acquiring unit, configured to acquire a parameter format of the first contract interface according to the corresponding relationship; a generating unit, configured to generate a first transaction for calling the first contract interface based on the first calling request, the first contract interface and the parameter format; A sending unit is used to send the first transaction to the blockchain system.
13. A computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 11.
14. A computing device, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method according to any one of claims 1 to 11 is implemented.
