示例#1
0
        public IEnumerator <object> GetEnumerator()
        {
            var data = new List <object>
            {
                Id.ToString("x"),
                BitConverter.GetBytes(BlockTemplate.Version).ToHexString(),
                PreviousBlockHashReversed,
                null,
                new byte[32].ToHexString(),
                NTime.HexToByteArray().ReverseBuffer().ToHexString(),
                EncodedDifficulty.HexToByteArray().ReverseBuffer().ToHexString(),
                CleanJobs
            };

            return(data.GetEnumerator());
        }
示例#2
0
        /// <summary>
        /// Creates a new instance of JobNotification.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="algorithm"></param>
        /// <param name="blockTemplate"></param>
        /// <param name="generationTransaction"></param>
        public Job(UInt64 id, IHashAlgorithm algorithm, IBlockTemplate blockTemplate, IGenerationTransaction generationTransaction)
        {
            // init the values.
            Id                        = id;
            HashAlgorithm             = algorithm;
            BlockTemplate             = blockTemplate;
            Height                    = blockTemplate.Height;
            GenerationTransaction     = generationTransaction;
            PreviousBlockHash         = blockTemplate.PreviousBlockHash.HexToByteArray().ToHexString();
            PreviousBlockHashReversed = blockTemplate.PreviousBlockHash.HexToByteArray().ReverseByteOrder().ToHexString();
            CoinbaseInitial           = generationTransaction.Initial.ToHexString();
            CoinbaseFinal             = generationTransaction.Final.ToHexString();
            CreationTime              = TimeHelpers.NowInUnixTimestamp();
            EdgeBits                  = blockTemplate.EdgeBits;

            _shares = new List <UInt64>();

            // calculate the merkle tree
            var hashes = BlockTemplate.Transactions.Slice(1, BlockTemplate.Transactions.Length).GetHashList();

            hashes.AddRange(BlockTemplate.Invites.GetHashList());
            hashes.AddRange(BlockTemplate.Referrals.GetHashList());

            MerkleTree = new MerkleTree(hashes);

            // set version
            Version = BitConverter.GetBytes(blockTemplate.Version.BigEndian()).ToHexString();

            // set the encoded difficulty (bits)
            EncodedDifficulty = blockTemplate.Bits;

            // set the target
            Target = string.IsNullOrEmpty(blockTemplate.Target)
                ? EncodedDifficulty.BigIntFromBitsHex()
                : BigInteger.Parse(blockTemplate.Target, NumberStyles.HexNumber);

            // set the block diff
            Difficulty = ((double)new BigRational(AlgorithmManager.Diff1, Target));

            // set the ntime
            NTime = BitConverter.GetBytes(blockTemplate.CurTime.BigEndian()).ToHexString();
        }
示例#3
0
        /// <summary>
        /// Creates a new instance of JobNotification.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="algorithm"></param>
        /// <param name="blockTemplate"></param>
        /// <param name="generationTransaction"></param>
        public Job(UInt64 id, IHashAlgorithm algorithm, IBlockTemplate blockTemplate, IGenerationTransaction generationTransaction)
        {
            // init the values.
            Id                    = id;
            HashAlgorithm         = algorithm;
            BlockTemplate         = blockTemplate;
            Height                = blockTemplate.Height;
            HeightHex             = BitConverter.GetBytes(blockTemplate.Height.BigEndian()).ToHexString();
            GenerationTransaction = generationTransaction;
            _shares               = new List <UInt64>();

            PreviousBlockHash         = blockTemplate.PreviousBlockHash.HexToByteArray().ToHexString();
            PreviousBlockHashReversed = blockTemplate.PreviousBlockHash.HexToByteArray().ReverseByteOrder().ToHexString();
            CoinbaseInitial           = generationTransaction.Initial.ToHexString();
            CoinbaseFinal             = generationTransaction.Final.ToHexString();

            AccountRootHash         = blockTemplate.AccountRootHash.HexToByteArray().ToHexString();
            AccountRootHashReversed = blockTemplate.AccountRootHash.HexToByteArray().ReverseByteOrder().ToHexString();
            // calculate the merkle tree
            MerkleTree = new MerkleTree(BlockTemplate.Transactions.GetHashList());

            // set version
            Version = BitConverter.GetBytes(blockTemplate.Version.BigEndian()).ToHexString();

            // set the encoded difficulty (bits)
            EncodedDifficulty = blockTemplate.Bits;

            // set the target
            Target = string.IsNullOrEmpty(blockTemplate.Target)
                ? EncodedDifficulty.BigIntFromBitsHex()
                : BigInteger.Parse(blockTemplate.Target, NumberStyles.HexNumber);

            TargetString = blockTemplate.Target;
            // set the block diff
            Difficulty = ((double)new BigRational(Algorithms.Diff1, Target));

            // set the ntime
            nTime = BitConverter.GetBytes(blockTemplate.CurTime.BigEndian()).ToHexString();
        }