Ejemplo n.º 1
0
        public static BigInteger Hash(LotteryTicket lt)
        {
            var serialized = JsonConvert.SerializeObject(lt);
            var hash       = Cryptography.GenericHashNoKey(serialized).ToList();

            return(new BigInteger(1, hash.ToArray()));
        }
Ejemplo n.º 2
0
        public async Task <SignedLotteryTicket> GenerateSignedLotteryTicket(ulong round)
        {
            var ticket     = LotteryTicket.Generate(round);
            var serialized = JsonConvert.SerializeObject(ticket);
            var hash       = Cryptography.GenericHashNoKey(serialized);

            var signedResponse = await OnionServiceClient.SignHashAsync(hash);

            var signedTicket = new SignedLotteryTicket()
            {
                Hash = hash, PublicKey = signedResponse.PublicKey, Signature = signedResponse.Signature
            };

            return(signedTicket);
        }
Ejemplo n.º 3
0
        public static LotteryTicket GenerateValidTarget(ulong round)
        {
            LotteryTicket lotteryTicket = null;
            object        ticketLock    = new object();

            Parallel.For(
                0,
                Environment.ProcessorCount,
                new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            },
                (i, state) => {
                LotteryTicket lt = null;
                BigInteger hash  = BigInteger.Zero;
                int ct           = 1;

                do
                {
                    lt   = Generate(round);
                    hash = Hash(lt);
                    ct   = hash.CompareTo(PoWTarget);
                } while (ct == 1);

                lock (ticketLock)
                {
                    if (lotteryTicket == null)
                    {
                        lotteryTicket = lt;
                    }

                    state.Stop();
                }
            });

            return(lotteryTicket);
        }