solidity mapping of mapping
生活随笔
收集整理的這篇文章主要介紹了
solidity mapping of mapping
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
solidity mapping of mapping,兩層映射,用的時候可以像二維數(shù)組一樣去訪問和修改值,非常方便。
以下代碼示例中的這一句:
mapping(string => mapping(uint => uint)) prices
相當(dāng)于建立了一個price數(shù)據(jù)庫表(只不過存在內(nèi)存中),表結(jié)構(gòu)為:index, date, price, key值為index + date。
pragma solidity ^0.4.21;contract mappingOfMapping{mapping(string => mapping(uint => uint)) prices; // string代表指數(shù)名,一個uint代表收盤日期,第二個uint代表收盤價格 function setPrice(string _index, uint _date, uint _price) public{ // 設(shè)置某指數(shù)某天的收盤價prices[_index][_date] = _price; }function getPrice(string _index,uint _date) public view returns(uint){ // 獲取某指數(shù)某天的收盤價return(prices[_index][_date]);}}?
轉(zhuǎn)載于:https://www.cnblogs.com/huahuayu/p/8624169.html
總結(jié)
以上是生活随笔為你收集整理的solidity mapping of mapping的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何禁止Linux内核的-O2编译选项【
- 下一篇: 《可爱的Python》读书笔记(五)