CN116880857B - Intelligent contract generation method and system of cross-region block chain engine - Google Patents

Intelligent contract generation method and system of cross-region block chain engine Download PDF

Info

Publication number
CN116880857B
CN116880857B CN202311146776.XA CN202311146776A CN116880857B CN 116880857 B CN116880857 B CN 116880857B CN 202311146776 A CN202311146776 A CN 202311146776A CN 116880857 B CN116880857 B CN 116880857B
Authority
CN
China
Prior art keywords
intelligent contract
interface
business
engine
blockchain
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202311146776.XA
Other languages
Chinese (zh)
Other versions
CN116880857A (en
Inventor
于明亮
王刚
李劲松
云雄
郭宗宝
刘禄荣
彭跟耀
赵玉霞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Travelsky Technology Co Ltd
Original Assignee
China Travelsky Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Travelsky Technology Co Ltd filed Critical China Travelsky Technology Co Ltd
Priority to CN202311146776.XA priority Critical patent/CN116880857B/en
Publication of CN116880857A publication Critical patent/CN116880857A/en
Application granted granted Critical
Publication of CN116880857B publication Critical patent/CN116880857B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Business, Economics & Management (AREA)
  • Finance (AREA)
  • Accounting & Taxation (AREA)
  • Development Economics (AREA)
  • Economics (AREA)
  • Marketing (AREA)
  • Strategic Management (AREA)
  • Technology Law (AREA)
  • General Business, Economics & Management (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention provides an intelligent contract generation method and system of a cross-region block chain engine. The method comprises the following steps: receiving a business intelligence contract; obtaining an implementation dependent package of a target blockchain engine in a plurality of blockchain engines; according to the compiling instruction and the realization dependency package, compiling the business intelligent contract to generate an intelligent contract deployment package matched with the target blockchain engine; and deploying the intelligent contract deployment package on the target blockchain engine for operation. According to the intelligent contract of the business, the compiling instruction and the realization dependent package of the target blockchain engine, the intelligent contract deployment package matched with the target blockchain engine is obtained, and the deployment package is deployed on the target blockchain engine to operate, so that an intelligent contract developer can focus on the realization of the business more, specific blockchain engine details are not needed to be concerned, and the intelligent contract deployment package has the advantages of saving cost and improving efficiency.

Description

Intelligent contract generation method and system of cross-region block chain engine
Technical Field
The invention relates to the technical field of blockchain, in particular to an intelligent contract generation method and system of a cross-region blockchain engine.
Background
A federation chain is a blockchain with rights control and admission control that is commonly managed by multiple organizations or organizations, peer-to-peer recording of transaction data, and only joining organizations and their members can access the ledger. Because the alliance chain has authority and admission control, the alliance chain is widely applied to enterprises and organizations. In a blockchain, business logic code is commonly referred to as a smart contract. Smart contracts are a type of code that runs on a blockchain network that programmatically defines and executes transactions that automatically execute rules and conditions set in the contract. Different alliance chains have own design ideas and architecture systems, and have differences in respective implementation levels. For example, the blockchain open source bottom software platform and the open source enterprise-level license distributed account book platform both have respective intelligent contract interface constraints and cannot be compatible with each other. If a user needs to use both federation chains at the same time, then smart contracts need to be developed separately to accommodate the different federation chains.
The development mode for the single alliance chain intelligent contract has the defects of high time cost and low adaptability.
Disclosure of Invention
The invention aims to solve the technical problem of providing an intelligent contract generation method and system of a cross-region block chain engine, so as to solve the problems of high time cost and low adaptability of a development mode of an intelligent contract aiming at a single alliance chain.
In order to solve the technical problems, the technical scheme of the invention is as follows:
an intelligent contract generation method of a cross-region block chain engine, comprising:
receiving a business intelligent contract, wherein the business intelligent contract is generated according to a general abstract layer intelligent contract interface and a general intelligent contract dependent package submitted by a user;
obtaining an implementation dependent package of a target blockchain engine in a plurality of blockchain engines;
according to the compiling instruction and the realization dependency package, compiling the business intelligent contract to generate an intelligent contract deployment package matched with the target blockchain engine;
and deploying the intelligent contract deployment package on the target blockchain engine for operation.
Further, the generic abstraction layer intelligent contract interface includes: an intelligent contract business interface and an intelligent contract access context interface; the smart contract business interface and the smart contract access context interface each have: unified smart contract request response data format, unified block information format, unified transactor initiator data format, and unified transaction format.
Further, the smart contract business interface includes: initializing an interface, upgrading the interface and calling the interface;
the smart contract access context interface includes: the system comprises a reading and writing interface of an account book, an operation interface of historical data, an information inquiry interface of a transaction initiator and a block information analysis interface.
Further, obtaining an implementation dependent package of a target blockchain engine of the plurality of blockchain engines includes:
a blockchain engine name and a corresponding deployment package name of a target blockchain engine of the plurality of blockchain engines are obtained.
Further, according to the compiling instruction and the implementation dependent package, compiling the business intelligent contract to generate an intelligent contract deployment package matched with the target blockchain engine, including:
and compiling the business codes of the business intelligent contracts according to the names of the target blockchain engines, the names of the corresponding deployment packages and the compiling parameters in the compiling instructions to generate intelligent contract deployment packages matched with the target blockchain engines.
Further, according to the name of the target blockchain engine, the name of the corresponding deployment package and the compiling parameters in the compiling instruction, compiling the service codes of the service intelligent contracts to generate intelligent contract deployment packages matched with the target blockchain engine, including:
and if the target blockchain is an open-source blockchain engine, compiling the service codes of the service intelligent contracts according to the compiling parameters of the open-source blockchain engine to obtain an intelligent contract deployment package.
Further, deploying the intelligent contract deployment package to the target blockchain engine operation includes:
and deploying the intelligent contract deployment package on an open-source blockchain engine through a blockchain serving platform to run.
According to another aspect of the present invention, there is provided an intelligent contract generation system of a cross-region block chain engine, including:
the receiving module is used for receiving a business intelligent contract which is generated according to a general abstract layer intelligent contract interface and a general intelligent contract dependent package submitted by a user;
the acquisition module is used for acquiring an implementation dependent package of a target blockchain engine in the multiple blockchain engines;
the processing module is used for compiling the business intelligent contracts according to the compiling instruction and the implementation dependent package to generate an intelligent contract deployment package matched with the target blockchain engine;
and the deployment module is used for deploying the intelligent contract deployment package to the target blockchain engine for operation.
The scheme of the invention at least comprises the following beneficial effects:
according to the scheme, the intelligent contract deployment package matched with the target blockchain engine is obtained according to the business intelligent contract, the compiling instruction and the implementation dependent package of the target blockchain engine, and the deployment package is deployed on the target blockchain engine to operate, so that an intelligent contract developer can focus on the implementation of the business without concern about specific blockchain engine details, and the intelligent contract deployment package has the advantages of saving cost and improving efficiency.
Drawings
FIG. 1 is a step diagram of a method of intelligent contract generation across blockchain engines in accordance with embodiments of the invention;
FIG. 2 is a schematic diagram of a unified smart contract implementation in one embodiment of the invention;
FIG. 3 is a diagram of the steps in the use of a unified smart contract implementation architecture in one embodiment of the invention;
FIG. 4 is a schematic diagram of an intelligent contract generation system for a cross-blockchain engine in an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
As shown in fig. 1, an embodiment of the present invention proposes an intelligent contract generation method of a cross-region block chain engine, including the following steps:
s1, receiving a business intelligent contract, wherein the business intelligent contract is generated according to a general abstract layer intelligent contract interface and a general intelligent contract dependent package submitted by a user;
s2, obtaining an implementation dependent package of a target blockchain engine in a plurality of blockchain engines;
s3, compiling the business intelligent contracts according to compiling instructions and the implementation dependent packages to generate intelligent contract deployment packages matched with the target blockchain engine;
s4, deploying the intelligent contract deployment package on the target blockchain engine for operation.
According to the scheme provided by the embodiment of the invention, the intelligent contract deployment package matched with the target blockchain engine is obtained according to the business intelligent contracts, the compiling instructions and the implementation dependent package of the target blockchain engine, and the deployment package is deployed on the target blockchain engine to run, so that an intelligent contract developer can focus on the implementation of the business, specific blockchain engine details are not needed to be concerned, and the method has the advantages of saving cost and improving efficiency.
In specific implementation, the business intelligence contract only needs to realize three interfaces of the universal interface: initializing an interface, upgrading the interface and calling the interface. By defining the universal interface, the implementation class of the business intelligent contract can be ensured to be implemented according to a specified method so as to meet the initialization, upgrading and calling requirements of the business intelligent contract. Meanwhile, the realization class of the business intelligent contract can be switched and expanded conveniently through the polymorphism of the interface so as to adapt to different business scenes and requirements. The intelligent contract developer uses the machine language package to provide interactive package writing business intelligent contracts with the running environment, and the business intelligent contracts are used for operating an account book, such as data storage, source tracing, transaction submitter information acquisition and the like. The user can operate data such as account book according to business requirements.
A specific embodiment of a business intelligence contract is: importing and running environment interaction packages and the like, wherein the packages provide functions of hash, encryption algorithm calculation, transaction submission and the like. And defining a structure body for realizing the functions of the business intelligence contract. Three interfaces through a universal interface: the system comprises an initialization interface, an upgrade interface and a calling interface, wherein the initialization interface, the upgrade interface and the calling interface call an initialization function when a business intelligent contract is deployed, call an upgrade function when the business intelligent contract is upgraded, and execute corresponding logic according to different call function names.
In an optional embodiment of the present invention, in S1, the generic abstraction layer intelligent contract interface includes: an intelligent contract business interface and an intelligent contract access context interface; the smart contract business interface and the smart contract access context interface each have: unified smart contract request response data format, unified block information format, unified transactor initiator data format, and unified transaction format.
In specific implementation, the intelligent contract service interface includes: initializing an interface, upgrading the interface and calling the interface;
the smart contract access context interface includes: the system comprises a reading and writing interface of an account book, an operation interface of historical data, an information inquiry interface of a transaction initiator and a block information analysis interface.
The generic abstraction layer smart contract interface is a standardized interface for interacting and communicating with different smart contracts. Generic abstraction layer smart contract interfaces provide a generic way for users to write smart contracts on different blockchain platforms and to perform cross-chain operations and interoperability on these platforms. The generic smart contract dependency package contains the core functions of the smart contract such as encryption algorithms, unified interaction data formats, contract deployment and invocation, etc. The business intelligent contracts are generated according to the universal abstract layer intelligent contract interfaces and universal intelligent contract dependent packages submitted by users, so that the finally obtained intelligent contract deployment packages can be deployed in the blockchain network, and switching of different blockchain engines is realized.
According to the generic abstraction layer intelligent contract interface, a user can write business intelligent contracts conforming to the interface specification. These business intelligence contracts can use tools and libraries provided in generic intelligence contract-dependent packages to implement core functions of the intelligent contracts, such as ledger administration, log output, event triggering, and rights control, among others. However, the specific implementation of the business intelligence contract may vary depending on the blockchain business system, not just relying on generic abstract layer intelligence contract interfaces and generic intelligence contract dependency packages, but also using tools and libraries provided by a particular platform or framework.
The certificate cryptography system, the type and the certificate related interfaces used by different alliance chain engines are different, and the identity verification and the access control of the alliance chain engines are based on a key system and mainly comprise a symmetric encryption algorithm, an asymmetric encryption algorithm, a digital signature, a hash algorithm and a cryptographic security protocol. The account book data formats of the alliance chain engines are different, so that the supported interfaces are also different; the intelligent contracts are managed differently than the lifecycle, so are the interfaces of the intelligent contracts. But collect these two kinds of blockchain engines and include certificate structure data of the cryptology system of the certificate, include the intelligent contract operation logic data such as the data format of the account book and data interface of the account book, etc., and abstract and draw, get the business interface of the general intelligent contract and intelligent contract to visit the context interface, such as the unified intelligent contract requests and responds to the data format, the unified block information format, unified transactor sponsor data format and unified transaction format, for the follow-up intelligent contract deployment package that is matched with target blockchain engine is based.
Here, the smart contract dependency package may be generated by the following process:
compiling and starting a block chain framework node; setting an environment variable of the blockchain framework node;
starting a block chain framework node according to the environment variable; creating a contract account on a blockchain framework node; creating a contract project based on the contract account; compiling the contract engineering to obtain the intelligent contract dependent package.
In an alternative embodiment of the present invention, S2 includes:
a blockchain engine name and a corresponding deployment package name of a target blockchain engine of the plurality of blockchain engines are obtained.
The blockchain engine name and the corresponding deployment package name of each blockchain engine are different, and the blockchain engine name and the corresponding deployment package name of the target blockchain engine are obtained in order to generate an intelligent contract deployment package matched with the target blockchain engine. If the blockchain engine name of the blockchain open source underlying software platform is chainaker, the corresponding deployment package can be obtained from an official website or an official package release management platform to obtain the dependency package and related configuration files.
In an alternative embodiment of the present invention, S3 includes:
and compiling the business codes of the business intelligent contracts according to the names of the target blockchain engines, the names of the corresponding deployment packages and the compiling parameters in the compiling instructions to generate intelligent contract deployment packages matched with the target blockchain engines.
Different blockchain engines may have different compilation parameters such as debug mode, performance optimization, security configuration, plug-in support, etc. The specific set-up and manner of use of these compilation parameters may vary from one blockchain engine to another. And generating an intelligent contract deployment package according to compiling parameters corresponding to the target blockchain engine name, and ensuring the accuracy and the effectiveness of the deployment package in operation.
In an optional embodiment S3 of the present invention, if the target blockchain is an open-source blockchain engine, according to compiling parameters of the open-source blockchain engine, compiling the service codes of the service intelligent contract to obtain an intelligent contract deployment package.
When compiling the business codes of the business intelligent contracts, the compiler is preferably selected, and particularly, the corresponding compiler or interpreter is selected according to the programming language of the business codes. The block chain open source bottom layer software platform and the open source enterprise level license distributed ledger platform can both write logic codes by using the Go language, so that when the business codes are compiled, a compiler or an interpreter corresponding to the Go language can be selected. Then, compiling parameters are set, for example, the compiling parameters of the blockchain open source underlying software platform may include a debug mode, performance optimization, security configuration, plug-in support and the like, and the compiling parameters of the open source enterprise-level license distributed ledger platform may include a compiling mode, a debug mode, supported machine programming language, security configuration, network configuration and the like. And then executing the compiling command, and executing the corresponding compiling command to process the business codes by using a compiler corresponding to the Go language. And then processing compiling errors, wherein if errors occur in the compiling process, error information needs to be carefully checked and corrected, and common compiling errors comprise grammar errors, type errors, dependency errors and the like. And finally, generating an intelligent contract deployment package.
In an alternative embodiment of the present invention, S4 includes:
and deploying the intelligent contract deployment package on an open-source blockchain engine through a blockchain serving platform to run.
In implementation, the intelligent contract deployment package can be deployed on a blockchain platform through the blockchain service platform to run.
In specific implementation, the intelligent contract deployment package can be issued to the blockchain service platform for deployment, so that users can realize cost-free switching among different alliance chain engines, and the ledger book and the certificate system are synchronously adapted, so that the blockchain engine switching can be performed without perception.
As shown in fig. 2, taking Chainmaker (long-ampere chain) and Fabric Hyperledger (a federated chain engine) as an example, the implementation of a unified smart contract in the embodiment of the present invention includes:
generic smart contract SDK interface (a set of programming interfaces for interacting with smart contracts, providing a series of methods and functions for connecting, deploying, invoking and querying smart contracts, using which a user can connect to a blockchain network, deploy and invoke smart contracts, and interact data and event listening with smart contracts) according to his own needs: and the interface abstract layer provides a unified intelligent contract implementation and access interface for an upper layer. The intelligent contract interface is mainly arranged in two directions, and the interface must be realized by an upper-layer business intelligent contract; and secondly, the intelligent contract accesses a context interface to provide interfaces such as reading and writing of an account book, operation of historical data, information inquiry of a transaction initiator, block information analysis and the like. The unified intelligent contract request response data format is provided, and the data format which meets the service requirements better is provided for the upper intelligent contract without difference; the block information format is unified, complex bottom block information definitions of two engines are shielded, and a data format which is more friendly and easy to use for business intelligent contracts is provided; unifying the data format of the transactor initiator, defining transactor information instead of directly providing transactor certificate information of the bottom layer, and shielding the different certificate formats of the bottom layer; unified transaction format, shielding complex underlying transaction data format, providing easy-to-use transaction data format.
Chainmaker general intelligent contract implementation: the Chainmaker chain implementation of the generic intelligent contract SDK interface layer.
Hyperledger general intelligent contract implementation: fabric Hyperledger chain implementation of generic intelligent contract SDK interface layer.
Compiling a tool chain: the intelligent contract deployment package is mainly composed of a compiling tool for compiling intelligent contract deployment packages of different blockchain engines, and a blockchain engine starting code management tool for providing different chain starting codes according to different engines and starting parameters, wherein the management tool is used for automatically generating the starting codes relied on by the engines.
As shown in fig. 3, the steps of using the unified smart contract implementation architecture include:
installing a tool chain;
creating a business intelligent contract golang project, and adding dependencies such as a general intelligent contract SDK package;
writing a block chain service code to realize an intelligent contract interface defined by an SDK;
specifying the type of the bottom chain, and operating a compiling tool chain to produce a deployment package;
the deployment package is published to BaaS (blockchain service platform) or other blockchain environments for deployment.
An example of a specific implementation of the above embodiment of the present invention is as follows:
based on Golang language, the core layer provides a generic intelligent contract SDK interface and data format definition.
Intelligent contract interfaces, business intelligent contracts must implement defined interfaces, defined as follows:
type Contract interface {
is invoked for initializing the intelligent contract of the// Init
Init(stub ContractStub) *Response
Is invoked when a/(Upgrade) Smart contract is upgraded
Upgrade(stub ContractStub) *Response
Intelligent contract call distributor
Invoke(stub ContractStub) *Response
}
All smart contract responses conform to this format:
type Response struct {
whether/intelligent contract service call was successful
Success bool `json:"success"`
Information at the time of failure
Message string `json:"message"`
Traffic custom error code
Code int `json:"code"`
Data for response to/service
Data any `json:"data"`
}
Transaction initiator format:
data of// Committer transaction submitter
type Committer struct {
Information promulgator
Issuer string
Name//
CommonName string
Organization unit
OrgType string
Organization of// submitter attribution
Org string
Public key of// submitter
PublicKey crypto.PublicKey
}
Transaction data format:
transaction information
type Transaction struct {
Key string `json:"key"`
TxId string `json:"tx_id"`
Timestamp string `json:"timestamp"`
Value []byte `json:"value"`
}
Ledger operation interface:
type ContractStub interface {
obtaining current request function by using/(and GetFunction)
GetFunction() string
Parameters of the/(GetArgs get request function
GetArgs() map[string][]byte
Data for a given key value is queried from a state database by the// GetState
GetState(key string) ([]byte, error)
Writing data of a given key value into a state database by a// PutState
PutState(key string, value []byte) error
Obtaining transaction submitters by/(GetCommitter)
GetCommitter() (*Committer, error)
The// GetHistory queries historical transaction data for a given key value from the ledger
GetHistory(key string) ([]*Transaction, error)
Return log object for/(log)
Logger() Logger
}
A specific Fabric Hyperledger federated chain ContractStub interface implementation example is as follows:
type fabricStub struct {
stub shim2.ChaincodeStubInterface
logger shim.Logger
}
func newStub(stub shim2.ChaincodeStubInterface) shim.ContractStub {
return &fabricStub{
stub: stub,
logger: &fabricLogger{level: shim.LogLevelAll},
}
}
func (fabric *fabricStub) GetFunction() string {
fn, _ := fabric.stub.GetFunctionAndParameters()
return fn
}
func (fabric *fabricStub) GetArgs() map[string][]byte {
args := fabric.stub.GetArgs()
if len(args) == 0 {
return map[string][]byte{}
}
data := make(map[string][]byte)
_ = json.Unmarshal(args[0], data)
return data
}
func (fabric *fabricStub) GetState(key string) ([]byte, error) {
return fabric.stub.GetState(key)
}
func (fabric *fabricStub) PutState(key string, value []byte) error {
return fabric.stub.PutState(key, value)
}
func (fabric *fabricStub) GetSender() (*shim.Sender, error) {
clientId, err := cid.New(fabric.stub)
if err != nil {
return nil, err
}
cert, err := clientId.GetX509Certificate()
if err != nil {
return nil, err
}
committer := &shim.Sender{
Name: cert.Subject.CommonName,
Type: "",
OrgName: strings.Join(cert.Subject.Organization, ","),
PublicKey: cert.PublicKey,
}
return committer, nil
}
func (fabric *fabricStub) GetHistory(key string) ([]*shim.Transaction, error) {
iter, err := fabric.stub.GetHistoryForKey(key)
if err != nil {
return nil, err
}
defer iter.Close()
trans := make([]*shim.Transaction, 0)
for iter.HasNext() {
tran, err0 := iter.Next()
if err0 != nil {
return nil, err
}
trans = append(trans, &shim.Transaction{
Key: key,
TxId: tran.TxId,
Timestamp: tran.Timestamp.String(),
Value: tran.Value,
})
}
return trans, nil
}
func (fabric *fabricStub) Logger() shim.Logger {
return fabric.logger
}
type fabricLogger struct {
level shim.LogLevel
}
func (f *fabricLogger) SetLevel(level shim.LogLevel) {
f.level = level
}
func (f *fabricLogger) Debug(fmt string, args ...any) {
if f.level > shim.LogLevelDebug {
return
}
log.Printf(fmt, args...)
}
func (f *fabricLogger) Info(fmt string, args ...any) {
if f.level > shim.LogLevelInfo {
return
}
log.Printf(fmt, args...)
}
func (f *fabricLogger) Warn(fmt string, args ...any) {
if f.level > shim.LogLevelWarn {
return
}
log.Printf(fmt, args...)
}
func (f *fabricLogger) Error(fmt string, args ...any) {
if f.level > shim.LogLevelError {
return
}
log.Printf(fmt, args...)
}
an example of a specific ChainMaker alliance chain ContractStub interface implementation is as follows:
type chainmakerStub struct {
method string
logger shim.Logger
}
func newStub(method string) *chainmakerStub {
return &chainmakerStub{
method: method,
logger: &chainmakerLogger{level: shim.LogLevelInfo},
}
}
func (c *chainmakerStub) GetFunction() string {
return c.method
}
func (c *chainmakerStub) GetArgs() map[string][]byte {
return sdk.Instance.GetArgs()
}
func (c *chainmakerStub) GetState(key string) ([]byte, error) {
val, err := sdk.Instance.GetStateFromKeyByte(key)
if err != nil {
return nil, err
}
if val == nil {
return nil, errors.New("key not exits")
}
return val, nil
}
func (c *chainmakerStub) PutState(key string, value []byte) error {
return sdk.Instance.PutStateFromKeyByte(key, value)
}
func (c *chainmakerStub) GetSender() (*shim.Sender, error) {
org, _ := sdk.Instance.GetSenderOrgId()
role, _ := sdk.Instance.GetSenderRole()
pk, _ := sdk.Instance.GetSenderPk()
origin, _ := sdk.Instance.Origin()
return &shim.Sender{
Name: origin,
Type: role,
OrgName: org,
PublicKey: pk,
}, nil
}
func (c *chainmakerStub) GetHistory(key string) ([]*shim.Transaction, error) {
rs, err := sdk.Instance.NewHistoryKvIterForKey(key, "")
if err != nil {
return nil, err
}
trans := make([]*shim.Transaction, 0)
for rs.HasNext() {
km, err0 := rs.Next()
if err0 != nil {
return nil, err0
}
trans = append(trans, &shim.Transaction{
Key: km.Key,
TxId: km.TxId,
Timestamp: km.Timestamp,
Value: km.Value,
})
}
return trans, nil
}
func (c *chainmakerStub) Logger() shim.Logger {
return c.logger
}
type chainmakerLogger struct {
level shim.LogLevel
}
func (dl chainmakerLogger) SetLevel(level shim.LogLevel) {
dl.level = level
}
func (dl chainmakerLogger) Debug(fmt string, args ...any) {
if dl.level > shim.LogLevelDebug {
return
}
sdk.Instance.Debugf(fmt, args...)
}
func (dl chainmakerLogger) Info(fmt string, args ...any) {
if dl.level > shim.LogLevelInfo {
return
}
sdk.Instance.Infof(fmt, args...)
}
func (dl chainmakerLogger) Warn(fmt string, args ...any) {
if dl.level > shim.LogLevelWarn {
return
}
sdk.Instance.Warnf(fmt, args...)
}
func (dl chainmakerLogger) Error(fmt string, args ...any) {
if dl.level > shim.LogLevelError {
return
}
sdk.Instance.Errorf(fmt, args...)
}
the smart contract developer uses the conteractStub interface provided by the shim package for operating the ledger, such as saving data, tracing data, obtaining transaction submitter information, and the like. The user can operate data such as account book according to business requirements.
The smart contract developer gets a return response in a unified format through the OkResponse and NokResponse interfaces. Using the compilation tool chain the first parameter is a blockchain engine name, such as chainaker and fabric, and the second parameter is a deployment package name, a deployment package is generated that can be deployed directly into the blockchain network.
In the above use examples of the present invention, it is shown how the complexity of blockchain smart contracts, blockchain information and certificate information are masked, and a unified smart contract interface and various data format definitions are provided for the upper layer. This advantageously allows the smart contract developer to focus more on the implementation of the business without concern for specific blockchain engine details.
Meanwhile, the BaaS platform generally supports various blockchains, the intelligent contract based on the scheme can be switched by a blockchain engine without cost, the account book and the certificate system are synchronously adapted, and the blockchain engine can be switched without perception. Whether Chainmaker, fabric Hyperledger, or other blockchain, the blockchain engine can be freely switched by adding an implementation layer, and intelligent contract unified implementation specifications adapting to the multi-blockchain engine are provided.
Referring to fig. 4, an embodiment of the present invention provides an intelligent contract generation system of a cross-region block chain engine, including:
the receiving module is used for receiving a business intelligent contract which is generated according to a general abstract layer intelligent contract interface and a general intelligent contract dependent package submitted by a user;
the acquisition module is used for acquiring an implementation dependent package of a target blockchain engine in the multiple blockchain engines;
the processing module is used for compiling the business intelligent contracts according to the compiling instruction and the implementation dependent package to generate an intelligent contract deployment package matched with the target blockchain engine;
and the deployment module is used for deploying the intelligent contract deployment package to the target blockchain engine for operation.
According to the scheme provided by the embodiment of the invention, the intelligent contract deployment package matched with the target blockchain engine is obtained according to the business intelligent contracts, the compiling instructions and the implementation dependent package of the target blockchain engine, and the deployment package is deployed on the target blockchain engine to run, so that an intelligent contract developer can focus on the implementation of the business, specific blockchain engine details are not needed to be concerned, and the method has the advantages of saving cost and improving efficiency.
In specific implementation, the business intelligence contract only needs to realize three interfaces of the universal interface: initializing an interface, upgrading the interface and calling the interface. By defining the universal interface, the implementation class of the business intelligent contract can be ensured to be implemented according to a specified method so as to meet the initialization, upgrading and calling requirements of the business intelligent contract. Meanwhile, the realization class of the business intelligent contract can be switched and expanded conveniently through the polymorphism of the interface so as to adapt to different business scenes and requirements. The intelligent contract developer uses the machine language package to provide interactive package writing business intelligent contracts with the running environment, and the business intelligent contracts are used for operating an account book, such as data storage, source tracing, transaction submitter information acquisition and the like. The user can operate data such as account book according to business requirements.
A specific embodiment of a business intelligence contract is: importing and running environment interaction packages and the like, wherein the packages provide functions of hash, encryption algorithm calculation, transaction submission and the like. And defining a structure body for realizing the functions of the business intelligence contract. Three interfaces through a universal interface: the system comprises an initialization interface, an upgrade interface and a calling interface, wherein the initialization interface, the upgrade interface and the calling interface call an initialization function when a business intelligent contract is deployed, call an upgrade function when the business intelligent contract is upgraded, and execute corresponding logic according to different call function names.
In an alternative embodiment of the present invention, the generic abstraction layer smart contract interface includes: an intelligent contract business interface and an intelligent contract access context interface; the smart contract business interface and the smart contract access context interface each have: unified smart contract request response data format, unified block information format, unified transactor initiator data format, and unified transaction format.
In specific implementation, the intelligent contract service interface includes: initializing an interface, upgrading the interface and calling the interface;
the smart contract access context interface includes: the system comprises a reading and writing interface of an account book, an operation interface of historical data, an information inquiry interface of a transaction initiator and a block information analysis interface.
In an alternative embodiment of the present invention, the obtaining module is specifically configured to:
a blockchain engine name and a corresponding deployment package name of a target blockchain engine of the plurality of blockchain engines are obtained.
The blockchain engine name and the corresponding deployment package name of each blockchain engine are different, and the blockchain engine name and the corresponding deployment package name of the target blockchain engine are obtained in order to generate an intelligent contract deployment package matched with the target blockchain engine.
In an alternative embodiment of the present invention, the processing module is specifically configured to:
and compiling the business codes of the business intelligent contracts according to the names of the target blockchain engines, the names of the corresponding deployment packages and the compiling parameters in the compiling instructions to generate intelligent contract deployment packages matched with the target blockchain engines.
Different blockchain engines may have different compilation parameters such as debug mode, performance optimization, security configuration, plug-in support, etc. The specific set-up and manner of use of these compilation parameters may vary from one blockchain engine to another. And generating an intelligent contract deployment package according to compiling parameters corresponding to the target blockchain engine name, and ensuring the accuracy and the effectiveness of the deployment package in operation.
In an alternative embodiment of the present invention, the processing module is specifically configured to:
and if the target blockchain is an open-source blockchain engine, compiling the service codes of the service intelligent contracts according to the compiling parameters of the open-source blockchain engine to obtain an intelligent contract deployment package.
When compiling the business codes of the business intelligent contracts, the compiler is preferably selected, and particularly, the corresponding compiler or interpreter is selected according to the programming language of the business codes. The block chain open source bottom layer software platform and the open source enterprise level license distributed ledger platform can both write logic codes by using the Go language, so that when the business codes are compiled, a compiler or an interpreter corresponding to the Go language can be selected. Then, compiling parameters are set, for example, the compiling parameters of the blockchain open source underlying software platform may include a debug mode, performance optimization, security configuration, plug-in support and the like, and the compiling parameters of the open source enterprise-level license distributed ledger platform may include a compiling mode, a debug mode, supported machine programming language, security configuration, network configuration and the like. And then executing the compiling command, and executing the corresponding compiling command to process the business codes by using a compiler corresponding to the Go language. And then processing compiling errors, wherein if errors occur in the compiling process, error information needs to be carefully checked and corrected, and common compiling errors comprise grammar errors, type errors, dependency errors and the like. And finally, generating an intelligent contract deployment package.
In an alternative embodiment of the present invention, the deployment module is specifically configured to:
and deploying the intelligent contract deployment package on an open-source blockchain engine through a blockchain serving platform to run.
And the intelligent contract deployment package is issued to the blockchain service platform for deployment, so that users can realize cost-free switching among different alliance chain engines, and the ledger and the certificate system are synchronously adapted, so that the blockchain engine switching can be performed without perception.
An embodiment of the present invention provides a computing device, including: a processor, a memory storing a computer program which, when executed by the processor, performs a method as in any of the above embodiments.
Embodiments of the present invention provide a computer readable storage medium having instructions stored thereon which, when run on a computer, cause the computer to perform a method as in any of the above embodiments.
The intelligent contract generation method and the intelligent contract generation system of the cross-blockchain engine unify the intelligent contract implementation of a plurality of blockchain engines, shield the complexity of blockchain intelligent contracts, blockchain information and certificate information, and provide unified intelligent contract interfaces and various data format definitions for an upper layer. The intelligent contract developer can be focused on the realization of the business without concern for specific blockchain engine details. Meanwhile, the blockchain serving platform generally supports various blockchains, and the intelligent contract generation method and the system of the cross-blockchain engine can switch the blockchain engine without cost, synchronously adapt to an account book and a certificate system and switch the blockchain engine without perception.
Whether the blockchain is an open source bottom software platform, or an enterprise-level license distributed ledger platform of a time-open source, or other blockchains, the blockchain engines can be freely switched by adding an implementation layer.
While the foregoing is directed to the preferred embodiments of the present invention, it will be appreciated by those skilled in the art that various modifications and adaptations can be made without departing from the principles of the present invention, and such modifications and adaptations are intended to be comprehended within the scope of the present invention.

Claims (8)

1. An intelligent contract generation method of a cross-region block chain engine, comprising the following steps:
receiving a business intelligent contract, wherein the business intelligent contract is generated according to a general abstract layer intelligent contract interface and a general intelligent contract dependent package submitted by a user;
obtaining an implementation dependent package of a target blockchain engine in a plurality of blockchain engines;
according to the compiling instruction and the realization dependency package, compiling the business intelligent contract to generate an intelligent contract deployment package matched with the target blockchain engine;
deploying the intelligent contract deployment package to the target blockchain engine for operation;
wherein the generic abstraction layer intelligent contract interface comprises: an intelligent contract business interface and an intelligent contract access context interface; the smart contract business interface and the smart contract access context interface each have: unified smart contract request response data format, unified block information format, unified transactor initiator data format, and unified transaction format;
the intelligent contract service interface includes: initializing an interface, upgrading the interface and calling the interface;
the smart contract access context interface includes: the system comprises a reading and writing interface of an account book, an operation interface of historical data, an information inquiry interface of a transaction initiator and a block information analysis interface.
2. The method of claim 1, wherein obtaining an implementation dependent package of a target blockchain engine of the plurality of blockchain engines comprises:
a blockchain engine name and a corresponding deployment package name of a target blockchain engine of the plurality of blockchain engines are obtained.
3. The method for generating intelligent contracts for a cross-partition blockchain engine according to claim 2, wherein compiling the business intelligent contracts according to compiling instructions and the implementation dependent packages to generate intelligent contract deployment packages matched with the target blockchain engine comprises:
and compiling the business codes of the business intelligent contracts according to the names of the target blockchain engines, the names of the corresponding deployment packages and the compiling parameters in the compiling instructions to generate intelligent contract deployment packages matched with the target blockchain engines.
4. The method for generating intelligent contracts for a cross-regional blockchain engine according to claim 3, wherein compiling the business codes of the business intelligent contracts according to the names of the target blockchain engines, the names of the corresponding deployment packages and the compiling parameters in the compiling instructions to generate intelligent contract deployment packages matched with the target blockchain engines comprises the following steps:
and if the target blockchain is an open-source blockchain engine, compiling the service codes of the service intelligent contracts according to the compiling parameters of the open-source blockchain engine to obtain an intelligent contract deployment package.
5. The method of claim 4, wherein deploying the intelligent contract deployment package to the target blockchain engine operation comprises:
and deploying the intelligent contract deployment package on an open-source blockchain engine through a blockchain serving platform to run.
6. An intelligent contract generation system for a cross-block chain engine, comprising:
the receiving module is used for receiving a business intelligent contract which is generated according to a general abstract layer intelligent contract interface and a general intelligent contract dependent package submitted by a user;
the acquisition module is used for acquiring an implementation dependent package of a target blockchain engine in the multiple blockchain engines;
the processing module is used for compiling the business intelligent contracts according to the compiling instruction and the implementation dependent package to generate an intelligent contract deployment package matched with the target blockchain engine;
the deployment module is used for deploying the intelligent contract deployment package to the target blockchain engine for operation;
wherein the generic abstraction layer intelligent contract interface comprises: an intelligent contract business interface and an intelligent contract access context interface; the smart contract business interface and the smart contract access context interface each have: unified smart contract request response data format, unified block information format, unified transactor initiator data format, and unified transaction format;
the intelligent contract service interface includes: initializing an interface, upgrading the interface and calling the interface;
the smart contract access context interface includes: the system comprises a reading and writing interface of an account book, an operation interface of historical data, an information inquiry interface of a transaction initiator and a block information analysis interface.
7. A computing device, comprising: a processor, a memory storing a computer program which, when executed by the processor, performs the method of any one of claims 1 to 5.
8. A computer readable storage medium having stored thereon instructions which, when run on a computer, cause the computer to perform the method of any of claims 1 to 5.
CN202311146776.XA 2023-09-07 2023-09-07 Intelligent contract generation method and system of cross-region block chain engine Active CN116880857B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311146776.XA CN116880857B (en) 2023-09-07 2023-09-07 Intelligent contract generation method and system of cross-region block chain engine

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311146776.XA CN116880857B (en) 2023-09-07 2023-09-07 Intelligent contract generation method and system of cross-region block chain engine

Publications (2)

Publication Number Publication Date
CN116880857A CN116880857A (en) 2023-10-13
CN116880857B true CN116880857B (en) 2024-01-26

Family

ID=88260888

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311146776.XA Active CN116880857B (en) 2023-09-07 2023-09-07 Intelligent contract generation method and system of cross-region block chain engine

Country Status (1)

Country Link
CN (1) CN116880857B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108876610A (en) * 2018-05-31 2018-11-23 深圳市零度智控科技有限公司 Intelligent contract implementation method, user equipment, storage medium and device
CN112565369A (en) * 2020-11-27 2021-03-26 北京京东拓先科技有限公司 Intelligent contract implementation method, application service node, storage medium and system
CN112688934A (en) * 2020-12-21 2021-04-20 杭州云象网络技术有限公司 Contract calling method and system based on intelligent gateway and contract engine
CN114297119A (en) * 2021-12-30 2022-04-08 北京百度网讯科技有限公司 Intelligent contract execution method, device, equipment and storage medium
CN115022312A (en) * 2022-03-30 2022-09-06 中国信息通信研究院 Method and device for realizing multiple intelligent contract engines, electronic equipment and storage medium
WO2023287969A1 (en) * 2021-07-14 2023-01-19 Strong Force TX Portfolio 2018, LLC Systems and methods with integrated gaming engines and smart contracts

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108876610A (en) * 2018-05-31 2018-11-23 深圳市零度智控科技有限公司 Intelligent contract implementation method, user equipment, storage medium and device
CN112565369A (en) * 2020-11-27 2021-03-26 北京京东拓先科技有限公司 Intelligent contract implementation method, application service node, storage medium and system
CN112688934A (en) * 2020-12-21 2021-04-20 杭州云象网络技术有限公司 Contract calling method and system based on intelligent gateway and contract engine
WO2023287969A1 (en) * 2021-07-14 2023-01-19 Strong Force TX Portfolio 2018, LLC Systems and methods with integrated gaming engines and smart contracts
CN114297119A (en) * 2021-12-30 2022-04-08 北京百度网讯科技有限公司 Intelligent contract execution method, device, equipment and storage medium
CN115022312A (en) * 2022-03-30 2022-09-06 中国信息通信研究院 Method and device for realizing multiple intelligent contract engines, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN116880857A (en) 2023-10-13

Similar Documents

Publication Publication Date Title
CN107147704B (en) block chain-oriented universal service middleware system
US5675804A (en) System and method for enabling a compiled computer program to invoke an interpretive computer program
Sullivan et al. Modular aspect-oriented design with XPIs
US8078357B1 (en) Application-independent and component-isolated system and system of systems framework
US20140372968A1 (en) Software modeling framework
Shao Certified software
US10310828B2 (en) System and method for providing and executing a domain-specific language for cloud services infrastructure
CN101393528B (en) Method and system for determining instance object conversion order in dynamic update of software
WO2002001349A2 (en) System and method for coordination-centric design of software systems
US20050108684A1 (en) Method and system for generating an application object repository from application framework metadata
CN109032631A (en) Application program service packs acquisition methods, device, computer equipment and storage medium
Lapadula et al. Using formal methods to develop WS-BPEL applications
Kamburjan et al. Behavioral contracts for cooperative scheduling
Kraemer et al. Aligning UML 2.0 state machines and temporal logic for the efficient execution of services
Lascu et al. Automatic deployment of component-based applications
CN116880857B (en) Intelligent contract generation method and system of cross-region block chain engine
Fortier et al. Dyninka: a FaaS framework for distributed dataflow applications
EP3005087A1 (en) Declarative configuration elements
Pelliccione et al. An architectural approach to the correct and automatic assembly of evolving component-based systems
CN113626644A (en) Method and device for converting formats of business process data
Herzner et al. Model-based development of distributed embedded real-time systems with the decos tool-chain
Greci et al. A framework for contract-policy matching based on symbolic simulations for securing mobile device application
Bernardeschi et al. Verifying data secure flow in AUTOSAR models
Yahya et al. An aspect-oriented approach to enforce security properties in business processes
CN115630090B (en) Task state conversion system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant