/// <summary>
        /// Генерация генезис блока
        /// </summary>
        public static Dictionary <string, Block> GenerateBlockchainGenesis(KeyPair keyPair)
        {
            var outEntry = new OutEntry()
            {
                RecipientHash = keyPair.PublicKey,
                Value         = 100
            };

            var genesisBlock = new Block()
            {
                Id           = 0,
                Hash         = genesisHash,
                Nonce        = 0,
                PreviousHash = null,
                Timestamp    = DateTime.Now,
                Transaction  = new Transaction()
                {
                    Id         = 0,
                    Signature  = EccService.Sign(genesisHash, keyPair.PrivateKey, keyPair.PublicKey),
                    Timestamp  = DateTime.Now,
                    InEntries  = null,
                    OutEntries = new List <OutEntry>()
                    {
                        outEntry
                    }
                }
            };

            var blockchain = new Dictionary <string, Block>()
            {
                { HexConvert.FromBytes(genesisHash), genesisBlock }
            };

            return(blockchain);
        }
Exemplo n.º 2
0
        public static KeyPair LoadFrom(string path)
        {
            var keyContent = File.ReadAllText(path);
            var keyPair    = JsonConvert.DeserializeObject <KeyPair>(keyContent);

            if (!EccService.TestKey(keyPair.PrivateKey, keyPair.PublicKey))
            {
                throw new InvalidDataException("Collapsed keypair.");
            }

            return(keyPair);
        }