コード例 #1
0
ファイル: Program.cs プロジェクト: nsaccon/PromiseBlockChain
        static void Main(string[] args)
        {
            UserKeys keys = new UserKeys();

            Console.WriteLine("Public Key: " + keys.PublicKey);
            Console.WriteLine("Private Key: " + keys.PrivateKey + "\n\n");

            BlockChain chain = new BlockChain();

            Console.WriteLine("BlockChain Created. \n\n");

            Promise promise = new Promise("Any To Address", keys.PublicKey, "I promise to learn how blockchain works");

            Console.WriteLine("Promise Created.");

            EthECKey userPrivateKey = UserKeys.GetEthECKeyFromPrivateKey(keys.PrivateKey);

            promise.SignPromise(userPrivateKey);
            Console.WriteLine("Promise Signed.\n\n");


            Block block = new Block(DateTime.Now.ToString(), promise, chain.GetLatestBlock().Hash);

            Console.WriteLine("Block created.\n\n");
            chain.AddBlock(block);
            Console.WriteLine("Block added to chain.\n\n");

            Console.WriteLine("Is the chain valid?: " + chain.IsChainValid());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: nsaccon/PromiseBlockChain
        public void SignPromise(EthECKey signingKey)
        {
            if (UserKeys.GetPublicKeyString(signingKey) != FromAddress)
            {
                throw new Exception("You cannot sign someone else's transaction.");
            }
            string promiseHash = CalculateHash();

            byte[] msgBytes = Encoding.UTF8.GetBytes(promiseHash);
            byte[] msgHash  = new Sha3Keccack().CalculateHash(msgBytes);
            Signature = signingKey.SignAndCalculateV(msgHash);
        }