区块链是什么?一句话,它是一种特殊的分布式数据库。首先,区块链的主要作用是储存信息。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.区块链的世界里面,没有中心节点,每个节点都是平等的,都保存着整个数据库。你可以向任何一个节点,写入/读取数据,因为所有节点最后都会同步,保证区块链一致。
struct TokenInfo{
string symbol;//e.g.,"ETH","ADX"
address tokenAddr;//ERC20 token address
uint64 scaleFactor;//<original token amount>=<scaleFactor>x<DEx amountE8>/1e8
uint minDeposit;//mininum deposit(original token amount)allowed for this token
}
struct TraderInfo{
address withdrawAddr;
uint8 feeRebatePercent;//range:[0,100]
}
struct TokenAccount{
uint64 balanceE8;//available amount for trading
uint64 pendingWithdrawE8;//the amount to be transferred out from this contract to the trader
}
struct Order{
uint32 pairId;//<cashId>(16)<stockId>(16)
uint8 action;//0 means BUY;1 means SELL
uint8 ioc;//0 means a regular order;1 means an immediate-or-cancel(IOC)order
uint64 priceE8;
uint64 amountE8;
uint64 expireTimeSec;
}
struct Deposit{
address traderAddr;
uint16 tokenCode;
uint64 pendingAmountE8;//amount to be confirmed for trading purpose
}
struct DealInfo{
uint16 stockCode;//stock token code
uint16 cashCode;//cash token code
uint64 stockDealAmountE8;
uint64 cashDealAmountE8;
}
struct ExeStatus{
uint64 logicTimeSec;//logic timestamp for checking order expiration
uint64 lastOperationIndex;//index of the last executed operation
}
uint constant MAX_UINT256=2**256-1;
uint16 constant MAX_FEE_RATE_E4=60;//upper limit of fee rate is 0.6%(60/1e4)
//<original ETH amount in Wei>=<DEx amountE8>*<ETH_SCALE_FACTOR>/1e8
uint64 constant ETH_SCALE_FACTOR=10**18;
uint8 constant ACTIVE=0;
uint8 constant CLOSED=2;
bytes32 constant HASHTYPES=
keccak256('string title','address market_address','uint64 nonce','uint64 expire_time_sec',
'uint64 amount_e8','uint64 price_e8','uint8 immediate_or_cancel','uint8 action',
'uint16 cash_token_code','uint16 stock_token_code');
address public admin;//admin address,and it cannot be changed
mapping(uint16=>TokenInfo)public tokens;//mapping of token code to token information
uint8 public marketStatus;//market status:0-Active;1-Suspended;2-Closed
uint16 public makerFeeRateE4;//maker fee rate(10*4)
uint16 public takerFeeRateE4;//taker fee rate(10*4)
uint16 public withdrawFeeRateE4;//withdraw fee rate(10*4)
uint64 public lastDepositIndex;//index of the last deposit operation
ExeStatus public exeStatus;//status of operation execution
mapping(address=>TraderInfo)public traders;//mapping of trade address to trader information
mapping(uint176=>TokenAccount)public accounts;//mapping of trader token key to its account information
mapping(uint224=>Order)public orders;//mapping of order key to order information
mapping(uint64=>Deposit)public deposits;//mapping of deposit index to deposit information