日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

EOS 智能合约源代码解读 (3)asset.hpp

發(fā)布時間:2025/3/21 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 EOS 智能合约源代码解读 (3)asset.hpp 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1. 合約中關(guān)于資產(chǎn)的數(shù)據(jù)結(jié)構(gòu)的定義

輸入字符串: “10.0000 CUR”
輸出:amount = 10, symbol(4,“CUR”)

/**asset includes amount and currency symbol*/ struct asset : fc::reflect_init { // 通過給定的符號名稱以及資產(chǎn)數(shù)量構(gòu)建一個新的資產(chǎn)對象。explicit asset(share_type a = 0, symbol id = symbol(CORE_SYMBOL)) :amount(a), sym(id) {eosio_assert( is_amount_within_range(), asset_type_exception, "magnitude of asset amount must be less than 2^62" );eosio_assert( sym.valid(), asset_type_exception, "invalid symbol" );share_type amount; // 資產(chǎn)數(shù)量symbol_type symbol; // 資產(chǎn)符號名稱,詳見以下symbol_type源碼分析。static constexpr int64_t max_amount = (1LL << 62) - 1; //資產(chǎn)數(shù)量最大值,取決于int64_t類型的取值范圍。// 檢查資產(chǎn)數(shù)量是否在范圍以內(nèi),是否超過了最大限額。 bool is_amount_within_range() const { return -max_amount <= amount && amount <= max_amount; }// 檢查資產(chǎn)對象是否有效,有效資產(chǎn)的數(shù)量應(yīng)該小于等于最大限額同時它的符號名稱也是有效的。 bool is_valid() const { return is_amount_within_range() && symbol.is_valid(); }// 設(shè)置資產(chǎn)的數(shù)量void set_amount(int64_t a) {amount = a;eosio_assert(is_amount_within_range(), "magnitude of asset amount must be less than 2^62");}//資產(chǎn)對象的運(yùn)算符重載 ...// 打印資產(chǎn)void print() const{int64_t p = (int64_t)symbol.precision();int64_t p10 = 1;while (p > 0){p10 *= 10;--p;}p = (int64_t)symbol.precision();char fraction[p + 1];fraction[p] = '\0';auto change = amount % p10;for (int64_t i = p - 1; i >= 0; --i){fraction[i] = (change % 10) + '0';change /= 10;}printi(amount / p10);prints(".");prints_l(fraction, uint32_t(p));prints(" ");symbol.print(false);} EOSLIB_SERIALIZE(asset, (amount)(symbol))}void reflector_init()const {eosio_assert( is_amount_within_range(), asset_type_exception, "magnitude of asset amount must be less than 2^62" );eosio_assert( sym.valid(), asset_type_exception, "invalid symbol" );}};//using share_type = int64_t;struct extended_asset { // 默認(rèn)構(gòu)造器,構(gòu)造一個擴(kuò)展資產(chǎn)對象extended_asset(){}// 通過給定的數(shù)量和擴(kuò)展符號構(gòu)造一個擴(kuò)展資產(chǎn)對象。extended_asset( asset a, text_name n ):quantity(a),contract(n){}asset quantity;text_name contract;// 資產(chǎn)擁有者 };

總結(jié)

以上是生活随笔為你收集整理的EOS 智能合约源代码解读 (3)asset.hpp的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。