示例#1
0
        public void Execute()
        {
            var adminAddress = new Address("399bddF9F7B6d902ea27037B907B2486C9910730");
            var adminState   = new AdminState(adminAddress, 100);

            var csv = TableSheetsImporter.ImportSheets()[nameof(RedeemCodeListSheet)];

            var action = new AddRedeemCode
            {
                redeemCsv = csv,
            };

            var nextState = action.Execute(new ActionContext
            {
                Signer         = adminAddress,
                BlockIndex     = 0,
                PreviousStates = new State()
                                 .SetState(Addresses.Admin, adminState.Serialize())
                                 .SetState(Addresses.RedeemCode, new RedeemCodeState(new RedeemCodeListSheet()).Serialize()),
            });

            var sheet = new RedeemCodeListSheet();

            sheet.Set(csv);
            var expectedMap = new RedeemCodeState(sheet).Map;
            var redeemState = nextState.GetRedeemCodeState();

            foreach (var(key, reward) in expectedMap)
            {
                Assert.Equal(reward.RewardId, redeemState.Map[key].RewardId);
            }
        }
示例#2
0
        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,
示例#3
0
 protected override void LoadPlainValueInternal(IImmutableDictionary <string, IValue> plainValue)
 {
     RankingState           = new RankingState((Bencodex.Types.Dictionary)plainValue["ranking_state"]);
     ShopState              = new ShopState((Bencodex.Types.Dictionary)plainValue["shop_state"]);
     TableSheetsState       = new TableSheetsState((Bencodex.Types.Dictionary)plainValue["table_sheets_state"]);
     GameConfigState        = new GameConfigState((Bencodex.Types.Dictionary)plainValue["game_config_state"]);
     RedeemCodeState        = new RedeemCodeState((Bencodex.Types.Dictionary)plainValue["redeem_code_state"]);
     AdminAddressState      = new AdminState((Bencodex.Types.Dictionary)plainValue["admin_address_state"]);
     ActivatedAccountsState = new ActivatedAccountsState(
         (Bencodex.Types.Dictionary)plainValue["activated_accounts_state"]
         );
     GoldCurrencyState = new GoldCurrencyState(
         (Bencodex.Types.Dictionary)plainValue["gold_currency_state"]
         );
 }
示例#4
0
        public override IAccountStateDelta Execute(IActionContext context)
        {
            IActionContext ctx              = context;
            var            states           = ctx.PreviousStates;
            var            weeklyArenaState = new WeeklyArenaState(0);

            if (ctx.Rehearsal)
            {
                states = states.SetState(RankingState.Address, MarkChanged);
                states = states.SetState(ShopState.Address, MarkChanged);
                states = states.SetState(TableSheetsState.Address, MarkChanged);
                states = states.SetState(weeklyArenaState.address, MarkChanged);
                states = states.SetState(GameConfigState.Address, MarkChanged);
                states = states.SetState(RedeemCodeState.Address, MarkChanged);
                states = states.SetState(AdminState.Address, MarkChanged);
                states = states.SetState(ActivatedAccountsState.Address, MarkChanged);
                states = states.SetState(GoldCurrencyState.Address, MarkChanged);
                states = states.SetState(Addresses.GoldDistribution, MarkChanged);
                return(states);
            }

            if (ctx.BlockIndex != 0)
            {
                return(states);
            }

            states = states
                     .SetState(weeklyArenaState.address, weeklyArenaState.Serialize())
                     .SetState(RankingState.Address, RankingState.Serialize())
                     .SetState(ShopState.Address, ShopState.Serialize())
                     .SetState(TableSheetsState.Address, TableSheetsState.Serialize())
                     .SetState(GameConfigState.Address, GameConfigState.Serialize())
                     .SetState(RedeemCodeState.Address, RedeemCodeState.Serialize())
                     .SetState(AdminState.Address, AdminAddressState.Serialize())
                     .SetState(ActivatedAccountsState.Address, ActivatedAccountsState.Serialize())
                     .SetState(GoldCurrencyState.Address, GoldCurrencyState.Serialize())
                     .SetState(Addresses.GoldDistribution, GoldDistributions.Select(v => v.Serialize()).Serialize());

            states = states.MintAsset(GoldCurrencyState.Address, GoldCurrencyState.Currency, 1000000000);
            return(states);
        }
示例#5
0
        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,
示例#6
0
        public InitializeStates(
            RankingState rankingState,
            ShopState shopState,
            Dictionary <string, string> tableSheets,
            GameConfigState gameConfigState,
            RedeemCodeState redeemCodeState,
            AdminState adminAddressState,
            ActivatedAccountsState activatedAccountsState,
            GoldCurrencyState goldCurrencyState,
            GoldDistribution[] goldDistributions,
            PendingActivationState[] pendingActivationStates,
            AuthorizedMinersState authorizedMinersState = null,
            CreditsState creditsState = null)
        {
            Ranking           = (Bencodex.Types.Dictionary)rankingState.Serialize();
            Shop              = (Bencodex.Types.Dictionary)shopState.Serialize();
            TableSheets       = tableSheets;
            GameConfig        = (Bencodex.Types.Dictionary)gameConfigState.Serialize();
            RedeemCode        = (Bencodex.Types.Dictionary)redeemCodeState.Serialize();
            AdminAddress      = (Bencodex.Types.Dictionary)adminAddressState.Serialize();
            ActivatedAccounts = (Bencodex.Types.Dictionary)activatedAccountsState.Serialize();
            GoldCurrency      = (Bencodex.Types.Dictionary)goldCurrencyState.Serialize();
            GoldDistributions = new Bencodex.Types.List(
                goldDistributions.Select(d => d.Serialize()).Cast <Bencodex.Types.IValue>()
                );
            PendingActivations = new Bencodex.Types.List(pendingActivationStates.Select(p => p.Serialize()));

            if (!(authorizedMinersState is null))
            {
                AuthorizedMiners = (Bencodex.Types.Dictionary)authorizedMinersState.Serialize();
            }

            if (!(creditsState is null))
            {
                Credits = (Bencodex.Types.Dictionary)creditsState.Serialize();
            }
        }