The Conflux public chain adopts a lightweight consensus algorithm based on Block DAG implementation, which adopts a transaction sorting method based on DAG structure, namely Unconfirmed Transaction DAG (U-DAG), to sort and confirm the transactions of each block in the public chain.
At the same time, Conflux public chain also uses a confirmation method based on T-G consensus algorithm, which is similar to the PBFT algorithm and can quickly reach consensus. Conflux public chain has also implemented a payment channel technology based on lightning network, which can achieve second level consensus confirmation.
The construction of a public chain can be divided into the following steps:
The first step is to select a suitable blockchain framework. The commonly used blockchain frameworks currently include Ethereum, Hyperledger Fabric, EOS, etc. Each framework has its own advantages and disadvantages, and needs to be selected based on its own needs and technical level.
The second step is to design a consensus algorithm for the public chain. Consensus algorithm is one of the core technologies of public chain, which can affect the security, efficiency, and degree of decentralization of public chain. Commonly used consensus algorithms include PoW, PoS, DPoS, etc., which need to be selected and designed based on actual situations.
The third step is to develop the core functions of the public chain. The core functions of the public chain include currency issuance, smart contracts, etc. Currency issuance can be carried out through mining or pre mining, and smart contracts can be developed using languages such as Solidity and Java.
Step 4: Test the functionality and performance of the public chain. After the development of the public chain is completed, functional and performance testing is required to ensure the safety, stability, and reliability of the public chain.
...
//检查交易是否过期
ensure(deadline){
//计算实际添加的amountToken,amountETH
(amountToken,amountETH)=_addLiquidity(
token,
WETH,
amountTokenDesired,
msg.value,
amountTokenMin,
amountETHMin
);
//获取token,WETH的流动池地址
address pair=UniswapV2Library.pairFor(factory,token,WETH);
//向用户向流动池发送数量为amountToken的token
TransferHelper.safeTransferFrom(token,msg.sender,pair,amountToken);
//Router将用户发送的ETH置换成WETH
IWETH(WETH).deposit{value:amountETH}();
//Router向流动池发送数量为amountETH的WETH
assert(IWETH(WETH).transfer(pair,amountETH));
//流动池向to地址发送数量为liquidity的LP
liquidity=IUniswapV2Pair(pair).mint(to);
//如果用户发送的ETH>amountETH,Router就向用户返还多余的ETH
if(msg.value>amountETH)TransferHelper.safeTransferETH(msg.sender,msg.value-amountETH);
}