示例#1
0
        private Block <PolymorphicAction <ActionBase> > MakeGenesisBlock(
            Address adminAddress,
            IImmutableSet <Address> activatedAddresses,
            AuthorizedMinersState authorizedMinersState = null,
            DateTimeOffset?timestamp = null,
            PendingActivationState[] pendingActivations = null
            )
        {
            if (pendingActivations is null)
            {
                var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 };
                (ActivationKey activationKey, PendingActivationState pendingActivation) =
                    ActivationKey.Create(_privateKey, nonce);
                pendingActivations = new[] { pendingActivation };
            }

            var sheets = TableSheetsImporter.ImportSheets();

            return(BlockHelper.MineGenesisBlock(
                       sheets,
                       new GoldDistribution[0],
                       pendingActivations,
                       new AdminState(adminAddress, 1500000),
                       authorizedMinersState: authorizedMinersState,
                       activatedAccounts: activatedAddresses,
                       isActivateAdminAddress: false,
                       credits: null,
                       privateKey: _privateKey,
                       timestamp: timestamp ?? DateTimeOffset.MinValue));
        }
示例#2
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));
        }
示例#3
0
        public void Create(
            [Option("private-key", new[] { 'p' }, Description = "Hex encoded private key for gensis block")]
            string privateKeyHex,
            [Option('g', Description = "/path/to/nekoyume-unity/nekoyume/Assets/AddressableAssets/TableCSV")]
            string gameConfigDir,
            [Option('d', Description = "/path/to/nekoyume-unity/nekoyume/Assets/StreamingAssets/GoldDistribution.csv")]
            string goldDistributedPath,
            [Option('a', Description = "Number of activation keys to generate")]
            uint activationKeyCount,
            [Option("adminStateConfig", Description = "Config path to create AdminState")]
            string adminStateConfigPath,
            [Option("activatedAccountsList", Description = "List of accounts to be activated")]
            string activatedAccountsListPath = null,
            [Option('m', Description = "Config path to create AuthorizedMinersState")]
            string authorizedMinerConfigPath = null,
            [Option('c', Description = "Path of a plain text file containing names for credits.")]
            string creditsPath = null
            )
        {
            Dictionary <string, string> tableSheets = Utils.ImportSheets(gameConfigDir);

            Utils.CreateActivationKey(
                out List <PendingActivationState> pendingActivationStates,
                out List <ActivationKey> activationKeys,
                activationKeyCount);
            GoldDistribution[] goldDistributions = GoldDistribution
                                                   .LoadInDescendingEndBlockOrder(goldDistributedPath);

            AdminState adminState = Utils.GetAdminState(adminStateConfigPath);

            AuthorizedMinersState authorizedMinersState = null;

            if (!(authorizedMinerConfigPath is null))
            {
                authorizedMinersState = Utils.GetAuthorizedMinersState(authorizedMinerConfigPath);
            }

            var activatedAccounts = activatedAccountsListPath is null
                ? ImmutableHashSet <Address> .Empty
                : Utils.GetActivatedAccounts(activatedAccountsListPath);

            Block <PolymorphicAction <ActionBase> > block = BlockHelper.MineGenesisBlock(
                tableSheets,
                goldDistributions,
                pendingActivationStates.ToArray(),
                adminState,
                authorizedMinersState: authorizedMinersState,
                activatedAccounts: activatedAccounts,
                isActivateAdminAddress: activationKeyCount != 0,
                credits: creditsPath is null ? null : File.ReadLines(creditsPath),
                privateKey: new PrivateKey(ByteUtil.ParseHex(privateKeyHex))
                );

            ExportBlock(block, "genesis-block");
            ExportKeys(activationKeys, "keys.txt");
        }
示例#4
0
        public void Serialize()
        {
            var miners = GetNewMiners();
            var state  = new AuthorizedMinersState(
                miners: miners,
                interval: 50,
                validUntil: 1000
                );

            var serialized   = (Dictionary)state.Serialize();
            var deserialized = new AuthorizedMinersState(serialized);

            Assert.Equal(miners, deserialized.Miners);
            Assert.Equal(50, deserialized.Interval);
            Assert.Equal(1000, deserialized.ValidUntil);
        }
示例#5
0
        private Block<PolymorphicAction<ActionBase>> MakeGenesisBlock(
            Address adminAddress,
            IImmutableSet<Address> activatedAddresses,
            AuthorizedMinersState authorizedMinersState = null,
            DateTimeOffset? timestamp = null,
            PendingActivationState[] pendingActivations = null
        )
        {
            if (pendingActivations is null)
            {
                var nonce = new byte[] { 0x00, 0x01, 0x02, 0x03 };
                var privateKey = new PrivateKey();
                (ActivationKey activationKey, PendingActivationState pendingActivation) =
                    ActivationKey.Create(privateKey, nonce);
                pendingActivations = new[] { pendingActivation };
            }

            return BlockChain<PolymorphicAction<ActionBase>>.MakeGenesisBlock(
                    new PolymorphicAction<ActionBase>[]
                    {
                        new InitializeStates(
                            rankingState: new RankingState(),
                            shopState: new ShopState(),
                            tableSheets: TableSheetsImporter.ImportSheets(),
                            gameConfigState: new GameConfigState(),
                            redeemCodeState: new RedeemCodeState(Dictionary.Empty
                                .Add("address", RedeemCodeState.Address.Serialize())
                                .Add("map", Dictionary.Empty)
                            ),
                            adminAddressState: new AdminState(adminAddress, 1500000),
                            activatedAccountsState: new ActivatedAccountsState(activatedAddresses),
                            goldCurrencyState: new GoldCurrencyState(
                                new Currency("NCG", 2, minter: null)
                            ),
                            goldDistributions: new GoldDistribution[0],
                            pendingActivationStates: pendingActivations,
                            authorizedMinersState: authorizedMinersState
                        ),
                    },
                    timestamp: timestamp ?? DateTimeOffset.MinValue
                );
        }
示例#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();
            }
        }