小明今天繼續完成的是用戶檢視賣單交易帳簿的功能:
function getSellOrderBook(string symbolName) view public returns (uint[], uint[]) {
uint8 tokenNameIndex = getSymbolIndexOrThrow(symbolName);
uint[] memory arrPricesSell = new uint[](tokens[tokenNameIndex].amountSellPrices);
uint[] memory arrVolumesSell = new uint[](tokens[tokenNameIndex].amountSellPrices);
uint sellWhilePrice = tokens[tokenNameIndex].curSellPrice;
uint sellCounter = 0;
if (tokens[tokenNameIndex].curSellPrice > 0) {
while (sellWhilePrice <= tokens[tokenNameIndex].highestSellPrice) {
arrPricesSell[sellCounter] = sellWhilePrice;
uint sellVolumeAtPrice = 0;
uint sell_offers_key = 0;
sell_offers_key = tokens[tokenNameIndex].sellBook[sellWhilePrice].offers_key;
while (sell_offers_key <= tokens[tokenNameIndex].sellBook[sellWhilePrice].offers_length) {
sellVolumeAtPrice += tokens[tokenNameIndex].sellBook[sellWhilePrice].offers[sell_offers_key].amount;
sell_offers_key++;
}
arrVolumesSell[sellCounter] = sellVolumeAtPrice;
if (tokens[tokenNameIndex].sellBook[sellWhilePrice].higherPrice == 0) {
break;
}
else {
sellWhilePrice = tokens[tokenNameIndex].sellBook[sellWhilePrice].higherPrice;
}
sellCounter++;
}
}
return (arrPricesSell, arrVolumesSell);
}
本文同時發佈於作者部落格:https://www.bdetw.com/blog
想找區塊鏈人才或想學習區塊鏈知識的夥伴。歡迎參加社群小聚,一起來輕鬆交流、互相學習成長、認識新朋友、發現新機會!
台北區塊鏈社群
https://bitlly.co/Q4dIK
BDE 區塊鏈學院 - 提供專業的區塊鏈培訓與顧問服務。
https://bitlly.co/mbDwX