public BuildinRandomContributorService(RandomContributorConfig config, IRandomNumberGenerator random, IGenericDataStorage storage, ICryptoService cryptoService, IKeySecretManager keySecretManager) { this.random = random; this.storage = storage; this.cryptoService = cryptoService; this.keySecret = keySecretManager.LoadKeySecret(config.PrivateKey); }
public DemoGameRandomService(DemoGameConfig config, IRandomNumberGenerator random, IGenericDataStorage storage, ICryptoService cryptoService, IKeySecretManager keySecretManager) { this.random = random; this.storage = storage; this.cryptoService = cryptoService; this.keySecret = keySecretManager.LoadKeySecret(config.PrivateKey); }
public async Task <Sp8deBlock> Produce(IKeySecret producerKey) { var block = await blockStorage.GetLatestBlock() ?? new Sp8deBlock(); var transactions = await transactionStorage.GetPending(new Random().Next(1, 200)); if (transactions.Count == 0 && DateConverter.UtcNow - block.Timestamp < (60 * 15)) //skip empty blocks { return(null); } block = GenerateNewBlock(transactions, block, producerKey); await blockStorage.Add(block); foreach (var item in transactions) { item.Status = Sp8deTransactionStatus.Confirmed; item.Meta = new TransactionMeta() { BlockId = block.Id }; } await transactionStorage.Update(transactions); return(block); }
public DemoProtocolService(ChaosProtocolConfig config, IRandomNumberGenerator random, IGenericDataStorage storage, ICryptoService cryptoService, IKeySecretManager keySecretManager, IpfsFileStorageService ipfs) { this.random = random; this.storage = storage; this.cryptoService = cryptoService; this.ipfs = ipfs; this.keySecret = keySecretManager.LoadKeySecret(config.ApiSecret); }
public Sp8deBlock GenerateNewBlock(IReadOnlyList <Sp8deTransaction> list, Sp8deBlock prevBlock, IKeySecret producerKey) { var block = new Sp8deBlock() { Id = prevBlock.Id + 1, PreviousHash = prevBlock.Hash, Timestamp = DateConverter.UtcNow, Transactions = list.Select(x => x.Id).ToList(), Signer = producerKey.PublicAddress }; block.TransactionRoot = CalculateTransactionRootHash(list); var blockContent = block.GeteDataForSing(); block.Signature = cryptoService.SignMessage(blockContent, producerKey.PrivateKey); block.Hash = HexConverter.ToHex(cryptoService.CalculateHash(Encoding.UTF8.GetBytes(block.Signature))); return(block); }