Пример #1
0
        public static Block <PolymorphicAction <ActionBase> > MineGenesisBlock(
            IDictionary <string, string> tableSheets,
            GoldDistribution[] goldDistributions,
            PendingActivationState[] pendingActivationStates,
            AdminState adminState,
            AuthorizedMinersState authorizedMinersState = null,
            IImmutableSet <Address> activatedAccounts   = null,
            bool isActivateAdminAddress  = false,
            IEnumerable <string> credits = null,
            int maximumTransactions      = 100,
            PrivateKey privateKey        = null
            )
        {
            if (!tableSheets.TryGetValue(nameof(GameConfigSheet), out var csv))
            {
                throw new KeyNotFoundException(nameof(GameConfigSheet));
            }
            var gameConfigState     = new GameConfigState(csv);
            var redeemCodeListSheet = new RedeemCodeListSheet();

            redeemCodeListSheet.Set(tableSheets[nameof(RedeemCodeListSheet)]);

            if (privateKey is null)
            {
                privateKey = new PrivateKey();
            }

            var ncg = new Currency("NCG", 2, privateKey.ToAddress());

            activatedAccounts = activatedAccounts ?? ImmutableHashSet <Address> .Empty;
            var initialStatesAction = new InitializeStates
                                      (
                rankingState: new RankingState(),
                shopState: new ShopState(),
                tableSheets: (Dictionary <string, string>)tableSheets,
                gameConfigState: gameConfigState,
                redeemCodeState: new RedeemCodeState(redeemCodeListSheet),
                adminAddressState: adminState,
                activatedAccountsState: new ActivatedAccountsState(
                    isActivateAdminAddress
                    ? activatedAccounts.Add(adminState.AdminAddress)
                    : activatedAccounts),
                goldCurrencyState: new GoldCurrencyState(ncg),
                goldDistributions: goldDistributions,
                pendingActivationStates: pendingActivationStates,
                authorizedMinersState: authorizedMinersState,
                creditsState: credits is null ? null : new CreditsState(credits)
                                      );
            var actions = new PolymorphicAction <ActionBase>[]
            {
                initialStatesAction,
            };
            var blockAction = new BlockPolicySource(Log.Logger).GetPolicy(5000000, maximumTransactions).BlockAction;

            return
                (BlockChain <PolymorphicAction <ActionBase> > .MakeGenesisBlock(
                     actions,
                     privateKey : privateKey,
                     blockAction : blockAction));
        }
Пример #2
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);
            }
        }
Пример #3
0
        public override IAccountStateDelta Execute(IActionContext context)
        {
            var states = context.PreviousStates;

            if (context.Rehearsal)
            {
                return(states
                       .SetState(Addresses.RedeemCode, MarkChanged));
            }

            CheckPermission(context);

            var redeem = states.GetRedeemCodeState();
            var sheet  = new RedeemCodeListSheet();

            sheet.Set(redeemCsv);
            redeem.Update(sheet);
            return(states
                   .SetState(Addresses.RedeemCode, redeem.Serialize()));
        }
Пример #4
0
        public void ExecuteThrowSheetRowValidateException()
        {
            var csv   = TableSheetsImporter.ImportSheets()[nameof(RedeemCodeListSheet)];
            var sheet = new RedeemCodeListSheet();

            sheet.Set(csv);

            var state = new State()
                        .SetState(Addresses.RedeemCode, new RedeemCodeState(sheet).Serialize());

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

            Assert.Throws <SheetRowValidateException>(() => action.Execute(new ActionContext
            {
                BlockIndex     = 0,
                PreviousStates = state,
            })
                                                      );
        }
Пример #5
0
        public void Execute()
        {
            var gameConfigState     = new GameConfigState(_sheets[nameof(GameConfigSheet)]);
            var redeemCodeListSheet = new RedeemCodeListSheet();

            redeemCodeListSheet.Set(_sheets[nameof(RedeemCodeListSheet)]);
            var goldDistributionCsvPath = GoldDistributionTest.CreateFixtureCsvFile();
            var goldDistributions       = GoldDistribution.LoadInDescendingEndBlockOrder(goldDistributionCsvPath);
            var minterKey  = new PrivateKey();
            var ncg        = new Currency("NCG", 2, minterKey.ToAddress());
            var nonce      = new byte[] { 0x00, 0x01, 0x02, 0x03 };
            var privateKey = new PrivateKey();

            (ActivationKey activationKey, PendingActivationState pendingActivation) =
                ActivationKey.Create(privateKey, nonce);

            var action = new InitializeStates(
                rankingState: new RankingState(),
                shopState: new ShopState(),
                tableSheets: _sheets,
                gameConfigState: gameConfigState,
                redeemCodeState: new RedeemCodeState(redeemCodeListSheet),
                adminAddressState: new AdminState(
                    new Address("F9A15F870701268Bd7bBeA6502eB15F4997f32f9"),
                    1500000
                    ),
                activatedAccountsState: new ActivatedAccountsState(),
                goldCurrencyState: new GoldCurrencyState(ncg),
                goldDistributions: goldDistributions,
                pendingActivationStates: new[] { pendingActivation }
                );

            var genesisState = action.Execute(new ActionContext()
            {
                BlockIndex     = 0,
                Miner          = default,