Stepn/Jogger跑鞋NFT質(zhì)押鑄造合成挖礦項目系統(tǒng)開發(fā)方案設(shè)計/案例解析/源碼程序
那智能合約到底是什么呢?In short,a smart contract is a contract that uses Computer language instead of Legal writing to record terms and is automatically executed by a program.簡換句話說,智能合約就是傳統(tǒng)合約的數(shù)字化版本,跑在區(qū)塊鏈網(wǎng)絡(luò)上,由程序自動執(zhí)行。
智能合約是用計算機語言取代了法律語言記錄條款、由程序自動執(zhí)行的合約。部署在區(qū)塊上的它,也具備了區(qū)塊鏈的數(shù)據(jù)公開透明、不可篡改、永久運行的特點。
區(qū)塊鏈技術(shù)一般用于構(gòu)建交易系統(tǒng),而且要保證交易的信息真實可信,可追蹤且不可篡改。每一次交易的信息被確認后存儲在一個區(qū)塊中,區(qū)塊信息通過散列技術(shù)加密,以保證信息不被篡改。這些區(qū)塊按時間順序構(gòu)成鏈條。每個節(jié)點都保有完整的區(qū)塊鏈信息,個別節(jié)點的信息損壞,不會對區(qū)塊鏈信息產(chǎn)生影響。這種信息記錄方式被稱作分布式賬本。
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes memory path
)external view override{
require(amount0Delta>0||amount1Delta>0);//swaps entirely within 0-liquidity regions are not supported
(address tokenIn,address tokenOut,uint24 fee)=path.decodeFirstPool();
CallbackValidation.verifyCallback(factory,tokenIn,tokenOut,fee);
(bool isExactInput,uint256 amountToPay,uint256 amountReceived)=
amount0Delta>0
?(tokenIn<tokenOut,uint256(amount0Delta),uint256(-amount1Delta))
:(tokenOut<tokenIn,uint256(amount1Delta),uint256(-amount0Delta));
if(isExactInput){
assembly{//這里代碼需要將結(jié)果保存在內(nèi)存中
let ptr:=mload(0x40)//0x40是solidity定義的free memory pointer
mstore(ptr,amountReceived)//將結(jié)果保存起來
revert(ptr,32)//revert掉交易,并將內(nèi)存中的數(shù)據(jù)作為revert data
}
}else{
//if the cache has been populated,ensure that the full output amount has been received
if(amountOutCached!=0)require(amountReceived==amountOutCached);
assembly{
let ptr:=mload(0x40)
mstore(ptr,amountToPay)
revert(ptr,32)
}
}
}