System and method for implementing native contract on blockchain
A computer-implemented method for implementing native contract on blockchain comprises: obtaining combined bytecode associated with a blockchain contract, wherein the combined bytecode comprises an indicator representing a type of the blockchain contract; determining the type of the blockchain contract based at least on the indicator; and executing the blockchain contract based on the determined type of the blockchain contract.
1. A computer-implemented method for implementing blockchain contracts, comprising:
obtaining combined bytecode associated with a blockchain contract, wherein:
source code of the blockchain contract is written in one of a plurality of different high-level programming languages,
a first portion of the combined bytecode representing a type of the blockchain contract indicates the one high-level programming language among the different high-level programming languages,
the type of the blockchain contract comprises native contract type or Solidity contract type,
the native contract type indicates that the one high-level programming language is different from Solidity, and
the Solidity contract type indicates that the one high-level programming language is Solidity;
determining the one high-level programming language based at least on the first portion of the combined bytecode; and
executing the blockchain contract in a blockchain virtual machine matching the one high-level programming language.
2. The method of claim 1 , wherein:
the combined bytecode is low-level machine code; and
at least a part of the combined bytecode is compiled from the source code of the blockchain contract.
3. The method of claim 1 , wherein determining the one high-level programming language based at least on the first portion of the combined bytecode comprises:
determining if the blockchain contract is a Solidity contract or a native contract written in a high-level programming language other than Solidity.
4. The method of claim 1 , wherein:
a second portion of the combined bytecode comprises a dynamic library file in bytecode compiled from the source code of the blockchain contract.
5. The method of claim 4 , wherein executing the blockchain contract in the blockchain virtual machine matching the one high-level programming language comprises:
triggering the blockchain virtual machine to execute the dynamic library file.
6. The method of claim 4 , wherein executing the blockchain contract in the blockchain virtual machine matching the one high-level programming language comprises:
creating a child process to execute the blockchain contract.
7. The method of claim 6 , wherein creating the child process to execute the blockchain contract comprises:
creating an executable file; and
spawning the child process to launch the executable file to execute the dynamic library file.
8. The method of claim 6 , wherein:
the child process and the blockchain virtual machine communicate via socket or shared memory.
9. The method of claim 4 , wherein executing the blockchain contract in the blockchain virtual machine matching the one high-level programming language comprises:
launching a docker container to execute the blockchain contract.
10. The method of claim 9 , wherein launching the docker container to execute the blockchain contract comprises:
creating the docker container; and
launching the docker container to execute the dynamic library file.
11. The method of claim 9 , wherein:
the docker container and the blockchain virtual machine communicate via socket.
12. A non-transitory computer-readable storage medium configured with instructions executable by one or more processors to cause the one or more processors to perform operations comprising:
obtaining combined bytecode associated with a blockchain contract, wherein:
source code of the blockchain contract is written in one of a plurality of different high-level programming languages,
a first portion of the combined bytecode representing a type of the blockchain contract indicates the one high-level programming language among the different high-level programming languages,
the type of the blockchain contract comprises native contract type or Solidity contract type,
the native contract type indicates that the one high-level programming language is different from Solidity, and
the Solidity contract type indicates that the one high-level programming language is Solidity;
determining the one high-level programming language based at least on the first portion of the combined bytecode; and
executing the blockchain contract in a blockchain virtual machine matching the one high-level programming language.
13. The storage medium of claim 12 , wherein:
the combined bytecode is low-level machine code; and
at least a part of the combined bytecode is compiled from the source code of the blockchain contract.
14. The storage medium of claim 12 , wherein determining the one high-level programming language based at least on the first portion of the combined bytecode comprises:
determining if the blockchain contract is a Solidity contract or a native contract written in a high-level programming language other than Solidity.
15. The storage medium of claim 12 , wherein:
a second portion of the combined bytecode comprises a dynamic library file in bytecode compiled from the source code of the blockchain contract.
16. The storage medium of claim 15 , wherein executing the blockchain contract in the blockchain virtual machine matching the one high-level programming language comprises:
triggering the blockchain virtual machine to execute the dynamic library file.
17. The storage medium of claim 15 , wherein executing the blockchain contract in the blockchain virtual machine matching the one high-level programming language comprises:
creating a child process to execute the blockchain contract.
18. The storage medium of claim 17 , wherein creating the child process to execute the blockchain contract comprises:
creating an executable file; and
spawning the child process to launch the executable file to execute the dynamic library file.
19. The storage medium of claim 15 , wherein executing the blockchain contract in the blockchain virtual machine matching the one high-level programming language comprises:
launching a docker container to execute the blockchain contract.
20. A system comprising one or more processors and one or more non-transitory computer-readable memories coupled to the one or more processors and configured with instructions executable by the one or more processors to cause the system to perform operations comprising:
obtaining combined bytecode associated with a blockchain contract, wherein:
source code of the blockchain contract is written in one of a plurality of different high-level programming languages,
a first portion of the combined bytecode representing a type of the blockchain contract indicates the one high-level programming language among the different high-level programming languages,
the type of the blockchain contract comprises native contract type or Solidity contract type,
the native contract type indicates that the one high-level programming language is different from Solidity, and
the Solidity contract type indicates that the one high-level programming language is Solidity;
determining the one high-level programming language based at least on the first portion of the combined bytecode; and
executing the blockchain contract in a blockchain virtual machine matching the one high-level programming language.