在根據交易所需求設計了基本的功能介面後,小明今天進一步思考在智能合約中,如何儲存功能中所需要的資料。
//儲存每個用戶錢包地址所對應的以太幣餘額
mapping (address => uint) balanceEthForAddress;
//儲存每個用戶錢包地址所對應的其他代幣餘額
mapping (address => mapping (uint8 => uint)) tokenBalanceForAddress;
//可支援256種代幣
mapping (uint8 => Token) tokens;
struct Token {
address tokenContract;
string symbolName;
mapping (uint => OrderBook) buyBook;
uint curBuyPrice;
uint lowestBuyPrice;
uint amountBuyPrices;
mapping (uint => OrderBook) sellBook;
uint curSellPrice;
uint highestSellPrice;
uint amountSellPrices;
}
struct OrderBook {
uint higherPrice;
uint lowerPrice;
mapping (uint => Offer) offers;
}
struct Offer {
address who;
uint amount;
}
本文同時發佈於作者部落格:https://www.bdetw.com/blog
想找區塊鏈人才或想學習區塊鏈知識的夥伴。歡迎參加社群小聚,一起來輕鬆交流、互相學習成長、認識新朋友、發現新機會!
台北區塊鏈社群
https://bitlly.co/Q4dIK
BDE 區塊鏈學院 - 提供專業的區塊鏈培訓與顧問服務。
https://bitlly.co/mbDwX