/**asset includes amount and currency symbol*/structasset:fc::reflect_init{// 通過給定的符號名稱以及資產(chǎn)數(shù)量構(gòu)建一個新的資產(chǎn)對象。explicitasset(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源碼分析。staticconstexprint64_t max_amount =(1LL<<62)-1;//資產(chǎn)數(shù)量最大值,取決于int64_t類型的取值范圍。// 檢查資產(chǎn)數(shù)量是否在范圍以內(nèi),是否超過了最大限額。boolis_amount_within_range()const{return-max_amount <= amount && amount <= max_amount;}// 檢查資產(chǎn)對象是否有效,有效資產(chǎn)的數(shù)量應(yīng)該小于等于最大限額同時它的符號名稱也是有效的。boolis_valid()const{returnis_amount_within_range()&& symbol.is_valid();}// 設(shè)置資產(chǎn)的數(shù)量voidset_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)voidprint()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))}voidreflector_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;structextended_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)擁有者};