コード例 #1
0
 public static KittyCatContractDataModel ToContractDataModel(this Blockchain.Models.Contracts.KittyResponseModel source)
 {
     return(source == null
         ? default(KittyCatContractDataModel)
         : new KittyCatContractDataModel
     {
         BirthTime = source.BirthTime.ToString(16),
         CooldownIndex = source.CooldownIndex,
         Genes = source.Genes.ToString(16),
         IsGestating = source.IsGestating,
         Generation = source.Generation,
         IsReady = source.IsReady,
         MatronId = source.MatronId,
         NextActionAt = source.NextActionAt.ToString(16),
         SireId = source.SireId,
         SiringWithId = source.SiringWithId
     });
 }
        /// <summary>
        /// Writes kitty to underlying state dictionary
        /// </summary>
        /// <param name="id">The kitties identifier.</param>
        /// <param name="kitty">The raw <see cref="Blockchain.Models.Contracts.KittyResponseModel"/> returned from the blockchain.</param>
        /// <returns>The persisted <see cref="KittyCatContractDataModel"/>.</returns>
        private async Task <KittyCatContractDataModel> WriteKittyToState(long id, Blockchain.Models.Contracts.KittyResponseModel kitty)
        {
            var ret     = kitty.ToContractDataModel();
            var kitties = await GetKittyDictionaryAsync();

            var tx = StateManager.CreateTransaction();

            try
            {
                // Update dictionary then commit tx and return
                await kitties.SetAsync(tx, id, new Timestamped <KittyCatContractDataModel>(ret));

                await tx.CommitAsync();
            }
            finally
            {
                tx?.Dispose();
            }
            return(ret);
        }