Example #1
0
 public Chain(
     Dictionary <int, Block <T> > blockChain,
     IProofOfWork proofOfWork)
 {
     _proofOfWork = proofOfWork;
     _blockChain  = blockChain;
 }
Example #2
0
 public Miner(ICurrencyBlockchain blockchain, IProofOfWork proofOfWork, IOptions <CoinSettings> coinSettings, ILogger <Miner> logger)
 {
     _blockchain   = blockchain;
     _proofOfWork  = proofOfWork;
     _logger       = logger;
     _coinSettings = coinSettings.Value;
 }
Example #3
0
        public Blockchain(IBlockRepository <Block> blocks, IProofOfWork proofOfWork, IHashProvider hashProvider, ILogger <Blockchain> logger)
        {
            _blocks       = blocks;
            _hashProvider = hashProvider;
            _logger       = logger;
            _proofOfWork  = proofOfWork;

            Init();
        }
Example #4
0
        public Blockchain(IOptions <CoinSettings> coinSettings, ICurrencyBlockRepository blocks, IProofOfWork proofOfWork, ITransactionRepository transactions, IHashProvider hashProvider, JsonSerializerSettings jsonSettings, ILogger <Blockchain> logger)
        {
            _coinSettings = coinSettings.Value;
            _blocks       = blocks;
            _transactions = transactions;
            _hashProvider = hashProvider;
            _logger       = logger;
            _jsonSettings = jsonSettings;
            _proofOfWork  = proofOfWork;

            Init();
        }
Example #5
0
        public Block (T data, string previousHash = "", IProofOfWork proofOfWork = null) {
            _prefix = proofOfWork == null ? string.Empty : proofOfWork.GetPrefix ();
            var rnd = new Random ();
            while (true) {
                var blockData = new Data<T> (rnd.Next (), data, previousHash);
                var result = computeHash(blockData);
 
                if (string.IsNullOrEmpty (_prefix) ||
                    result.Substring (0, _prefix.Length) == _prefix) {
                    _hash = result;
                    _data = blockData;
                    break;
                }
            }
        }
Example #6
0
        public Node(INodeSynchornizator nodeSynchornizator, IProofOfWork proofOfWork,
                    ICryptoUtil cryptoUtil, ITransactionValidator transactionValidator, NodeInfo nodeInfo)
        {
            NodeInfo            = nodeInfo;
            BlockChain          = new ConcurrentDictionary <int, Block>();
            PendingTransactions = new ConcurrentBag <Transaction>();
            MiningJobs          = new ConcurrentDictionary <string, Block>();
            Peers            = new ConcurrentBag <Peer>();
            Difficulty       = 5;
            BlocksInProgress = new ConcurrentDictionary <string, Block>();

            NodeSynchornizator   = nodeSynchornizator;
            TransactionValidator = transactionValidator;
            CryptoUtil           = cryptoUtil;
            ProofOfWork          = proofOfWork;
        }
Example #7
0
 public Miner(IBlockchain blockchain, IProofOfWork proofOfWork, ILogger <Miner> logger)
 {
     _blockchain  = blockchain;
     _proofOfWork = proofOfWork;
     _logger      = logger;
 }
Example #8
0
 public Chain(IProofOfWork proofOfWork = null)
 {
     _proofOfWork = proofOfWork;
 }