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