public void Execute(bool backward) { var privateKey = new PrivateKey(); PublicKey publicKey = privateKey.PublicKey; var prevRedeemCodesState = new RedeemCodeState(new Dictionary <PublicKey, Reward>() { [publicKey] = new Reward(1), }); var gameConfigState = new GameConfigState(); var agentState = new AgentState(_agentAddress); agentState.avatarAddresses[0] = _avatarAddress; var avatarState = new AvatarState( _avatarAddress, _agentAddress, 1, _tableSheets.GetAvatarSheets(), gameConfigState, default ); var goldState = new GoldCurrencyState(new Currency("NCG", 2, minter: null)); var initialState = new State() .SetState(_agentAddress, agentState.Serialize()) .SetState(RedeemCodeState.Address, prevRedeemCodesState.Serialize()) .SetState(GoldCurrencyState.Address, goldState.Serialize()) .MintAsset(GoldCurrencyState.Address, goldState.Currency * 100000000); if (backward) { initialState = initialState.SetState(_avatarAddress, avatarState.Serialize()); } else { initialState = initialState .SetState(_avatarAddress.Derive(LegacyInventoryKey), avatarState.inventory.Serialize()) .SetState(_avatarAddress.Derive(LegacyWorldInformationKey), avatarState.worldInformation.Serialize()) .SetState(_avatarAddress.Derive(LegacyQuestListKey), avatarState.questList.Serialize()) .SetState(_avatarAddress, avatarState.SerializeV2()); } foreach (var(key, value) in _sheets) { initialState = initialState.SetState( Addresses.TableSheet.Derive(key), value.Serialize() ); } var redeemCode = new RedeemCode( ByteUtil.Hex(privateKey.ByteArray), _avatarAddress ); IAccountStateDelta nextState = redeemCode.Execute(new ActionContext() { BlockIndex = 1, Miner = default,
public async Task <List <GenerateOutPutDto> > GenerateCode(CodeInputDto input) { var result = new List <GenerateOutPutDto>(); try { var createdDate = DateTime.Now; var codes = await _context.RedeemCodes.Select(x => x.Code).ToListAsync(); var type = await _context.ProductTypes.FindAsync(input.TypeId); type.GeneratedCount += input.Count; _context.Entry(type).State = EntityState.Modified; if (input.Count > 0) { for (int i = 0; i < input.Count; i++) { var redeemCode = new RedeemCode() { TypeId = input.TypeId, Code = CodeService.GenerateNewCode(codes), Status = Domain.Enums.Status.NotActivated, CreatedDate = createdDate, CreatedUserId = input.UserId }; _context.RedeemCodes.Add(redeemCode); } } await _context.SaveChangesAsync(); var _result = await _context.RedeemCodes.Where(x => !x.VirtualDeleted && x.CreatedDate.Value == createdDate).ToListAsync(); var __result = _result.Select(x => new GenerateOutPutDto() { Code = x.Code, Id = x.Id, CreatedDate = x.CreatedDate.Value.ToString(), CreatedDateTime = x.CreatedDate.Value, ProductType = x.ProductType.Name }); return(__result.ToList()); } catch (Exception ex) { return(result); } }
public void Execute() { var privateKey = new PrivateKey(); PublicKey publicKey = privateKey.PublicKey; var prevRedeemCodesState = new RedeemCodeState(new Dictionary <PublicKey, Reward>() { [publicKey] = new Reward(1), }); var gameConfigState = new GameConfigState(); var agentState = new AgentState(_agentAddress); agentState.avatarAddresses[0] = _avatarAddress; var avatarState = new AvatarState( _avatarAddress, _agentAddress, 1, _tableSheets, gameConfigState ); var goldState = new GoldCurrencyState(new Currency("NCG", 2, minter: null)); var initialState = new State() .SetState(_agentAddress, agentState.Serialize()) .SetState(_avatarAddress, avatarState.Serialize()) .SetState(TableSheetsState.Address, _tableSheetsState.Serialize()) .SetState(RedeemCodeState.Address, prevRedeemCodesState.Serialize()) .SetState(GoldCurrencyState.Address, goldState.Serialize()) .MintAsset(GoldCurrencyState.Address, goldState.Currency * 100000000); var redeemCode = new RedeemCode( ByteUtil.Hex(privateKey.ByteArray), _avatarAddress ); IAccountStateDelta nextState = redeemCode.Execute(new ActionContext() { BlockIndex = 1, Miner = default,