合約交易/秒合約/永續(xù)合約/合約跟單/交易所系統(tǒng)開發(fā)成熟案例/需求方案/搭建項目/源碼
區(qū)塊鏈是什么?一句話,它是一種特殊的分布式數(shù)據(jù)庫。首先,區(qū)塊鏈的主要作用是儲存信息。Any information that needs to be saved can be written to or read from the blockchain,so it is a database.
Secondly,anyone can set up a server,join the blockchain network,and become a node.區(qū)塊鏈的世界里面,沒有中心節(jié)點,每個節(jié)點都是平等的,都保存著整個數(shù)據(jù)庫。你可以向任何一個節(jié)點,寫入/讀取數(shù)據(jù),因為所有節(jié)點最后都會同步,保證區(qū)塊鏈一致。
event DeployMarketEvent();
event ChangeMarketStatusEvent(uint8 status);
event SetTokenInfoEvent(uint16 tokenCode,string symbol,address tokenAddr,uint64 scaleFactor,uint minDeposit);
event SetWithdrawAddrEvent(address trader,address withdrawAddr);
event DepositEvent(address trader,uint16 tokenCode,string symbol,uint64 amountE8,uint64 depositIndex);
event WithdrawEvent(address trader,uint16 tokenCode,string symbol,uint64 amountE8,uint64 lastOpIndex);
event TransferFeeEvent(uint16 tokenCode,uint64 amountE8,address toAddr);
//`balanceE8`is the total balance after this deposit confirmation
event ConfirmDepositEvent(address trader,uint16 tokenCode,uint64 balanceE8);
//`amountE8`is the post-fee initiated withdraw amount
//`pendingWithdrawE8`is the total pending withdraw amount after this withdraw initiation
event InitiateWithdrawEvent(address trader,uint16 tokenCode,uint64 amountE8,uint64 pendingWithdrawE8);
event MatchOrdersEvent(address trader1,uint64 nonce1,address trader2,uint64 nonce2);
event HardCancelOrderEvent(address trader,uint64 nonce);
event SetFeeRatesEvent(uint16 makerFeeRateE4,uint16 takerFeeRateE4,uint16 withdrawFeeRateE4);
event SetFeeRebatePercentEvent(address trader,uint8 feeRebatePercent);
function Dex2(address admin_)public{
admin=admin_;
setTokenInfo(0/*tokenCode*/,"ETH",0/*tokenAddr*/,ETH_SCALE_FACTOR,0/*minDeposit*/);
emit DeployMarketEvent();
}
function()external{
revert();
}
//Change the market status of DEX.
function changeMarketStatus(uint8 status_)external{
if(msg.sender!=admin)revert();
if(marketStatus==CLOSED)revert();//closed is forever
marketStatus=status_;
emit ChangeMarketStatusEvent(status_);
}
//Each trader can specify a withdraw address(but cannot change it later).Once a trader's
//withdraw address is set,following withdrawals of this trader will go to the withdraw address
//instead of the trader's address.
function setWithdrawAddr(address withdrawAddr)external{
if(withdrawAddr==0)revert();
if(traders[msg.sender].withdrawAddr!=0)revert();//cannot change withdrawAddr once set
traders[msg.sender].withdrawAddr=withdrawAddr;
emit SetWithdrawAddrEvent(msg.sender,withdrawAddr);
}
//Deposit ETH from msg.sender for the given trader.
function depositEth(address traderAddr)external payable{
if(marketStatus!=ACTIVE)revert();
if(traderAddr==0)revert();
if(msg.value<tokens[0].minDeposit)revert();
if(msg.data.length!=4+32)revert();//length condition of param count
uint64 pendingAmountE8=uint64(msg.value/(ETH_SCALE_FACTOR/10**8));//msg.value is in Wei
if(pendingAmountE8==0)revert();
uint64 depositIndex=++lastDepositIndex;
setDeposits(depositIndex,traderAddr,0,pendingAmountE8);
emit DepositEvent(traderAddr,0,"ETH",pendingAmountE8,depositIndex);
}
//Deposit token(other than ETH)from msg.sender for a specified trader.