Plasma是通过创建区块链的“树”来提高可扩展性的另一种方式,主链是树的根,而“子”区块链尽可能少地与更高级别的链互动。例如Loom的PlasmaChain和OmigeGO Plasma。
加密存储(Encrypted storage):使用密码学对数据进行数学加密和解密,包括静态(即存储在特定的计算机上)和动态(即从一台计算机传输到另一台)。例如静态指的是存储加密,动态指的是传输加密(HTTPS就是一种传输加密)
状态机是由状态寄存器和组合逻辑电路构成的,能够根据控制信号按照预先设定的状态进行状态转移,是协调相关信号动作、完成特定操作的控制中心。区块链可以理解为一种被实例化为创世状态的状态机,并且有非常严格的规则(即共识)来定义该状态如何转换。
//如果tokenA,tokenB的流动池不存在,就创建流动池
if(IUniswapV2Factory(factory).getPair(tokenA,tokenB)==address(0)){
IUniswapV2Factory(factory).createPair(tokenA,tokenB);
}
//获取tokenA,tokenB的目前库存数量
(uint reserveA,uint reserveB)=UniswapV2Library.getReserves(factory,tokenA,tokenB);
if(reserveA==0&&reserveB==0){
//如果库存数量为0,也就是新建tokenA,tokenB的流动池,那么实际添加的amountA,amountB就是amountADesired和amountBDesired
(amountA,amountB)=(amountADesired,amountBDesired);
}else{
//reserveA*reserveB/amountADesired,算出实际要添加的tokenB数量amountBOptimal
uint amountBOptimal=UniswapV2Library.quote(amountADesired,reserveA,reserveB);
if(amountBOptimal<=amountBDesired){
//如果amountBMin<=amountBOptimal<=amountBDesired,amountA和amountB就是amountADesired和amountBOptimal
require(amountBOptimal>=amountBMin,'UniswapV2Router:INSUFFICIENT_B_AMOUNT');
(amountA,amountB)=(amountADesired,amountBOptimal);
}else{
//reserveA*reserveB/amountBDesired,算出实际要添加的tokenA数量amountAOptimal
uint amountAOptimal=UniswapV2Library.quote(amountBDesired,reserveB,reserveA);
//如果amountAMin<=amountAOptimal<=amountADesired,amountA和amountB就是amountAOptimal和amountBDesired
assert(amountAOptimal<=amountADesired);
require(amountAOptimal>=amountAMin,'UniswapV2Router:INSUFFICIENT_A_AMOUNT');
(amountA,amountB)=(amountAOptimal,amountBDesired);
}
}
}
function _addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin
)internal virtual returns(uint amountA,uint amountB){
if(IUniswapV2Factory(factory).getPair(tokenA,tokenB)==address(0)){
IUniswapV2Factory(factory).createPair(tokenA,tokenB);
}
(uint reserveA,uint reserveB)=UniswapV2Library.getReserves(factory,tokenA,tokenB);
if(reserveA==0&&reserveB==0){
(amountA,amountB)=(amountADesired,amountBDesired);
}else{
uint amountBOptimal=UniswapV2Library.quote(amountADesired,reserveA,reserveB);
if(amountBOptimal<=amountBDesired){
require(amountBOptimal>=amountBMin,'UniswapV2Router:INSUFFICIENT_B_AMOUNT');
(amountA,amountB)=(amountADesired,amountBOptimal);
}else{
uint amountAOptimal=UniswapV2Library.quote(amountBDesired,reserveB,reserveA);
assert(amountAOptimal<=amountADesired);
require(amountAOptimal>=amountAMin,'UniswapV2Router:INSUFFICIENT_A_AMOUNT');
(amountA,amountB)=(amountAOptimal,amountBDesired);
}
}
}