public WalkToBlockState(GridActor user, MiningRequest request, LilLogger logger) : base(user, 100, 1) { this.request = request; this.logger = logger; logger.Log("Initialized a WalkToBlockState with request " + request); Debug.Assert(this.request != null); }
public MiningJob(GridActor actor, MiningRequest request, LilLogger logger) { Debug.Assert(request != null); this.logger = logger; Debug.Log("Started a mining job"); machine = new StateMachine(new WalkToBlockState(actor, request, logger)); }
public MineBlockState(GridActor user, MiningRequest request, LilLogger logger) { this.user = user; this.request = request; this.logger = logger; logger.Log("Entering MineBlockState with request " + request); }
public MineBlockState(GridActor user, IGenericSaveData saveData, LilLogger logger) : base(((SaveData)saveData).parent) { this.user = user; SaveData save = saveData as SaveData; this.request = save.request; logger.Log("Loading MineBlockState with request " + request); }
private void calling_generate() { var request = new MiningRequest() { BlockCount = 1 }; this.send_api_post_request(GenerateUri, request); }
public WalkToBlockState(GridActor user, IGenericSaveData saveData, LilLogger logger) : base(user, ((SaveData)saveData).parent) { this.logger = logger; SaveData save = saveData as SaveData; this.request = save.request; logger.Log("Loaded a WalkToBlockState with request " + request); Debug.Assert(this.request != null); }
public IActionResult Generate([FromBody] MiningRequest request) { Guard.NotNull(request, nameof(request)); try { if (this.network.Consensus.IsProofOfStake && this.consensusManager.Tip.Height > this.network.Consensus.LastPOWBlock) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed", string.Format(LastPowBlockExceededMessage, this.network.Consensus.LastPOWBlock))); } if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } var blockCount = request.BlockCount; if (blockCount <= 0) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, "Invalid request", "The number of blocks to mine must be higher than zero.")); } this.logger.LogDebug("({0}:{1})", nameof(request.BlockCount), blockCount); var accountReference = GetAccount(); var address = this.walletManager.GetUnusedAddress(accountReference); var generateBlocksModel = new GenerateBlocksModel { Blocks = this.powMining.GenerateBlocks( new ReserveScript(new BitcoinWitPubKeyAddress(address.Bech32Address, this.network) .ScriptPubKey), (ulong)blockCount, int.MaxValue) }; this.logger.LogTrace("(-):*.{0}={1}", "Generated block count", generateBlocksModel.Blocks.Count); return(Json(generateBlocksModel)); } catch (Exception e) { this.logger.LogError(ExceptionOccurredMessage, e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult Generate([FromBody] MiningRequest request) { Guard.NotNull(request, nameof(request)); try { if (!this.ModelState.IsValid) { IEnumerable <string> errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } int blockCount = request.BlockCount; if (blockCount <= 0) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, "Invalid request", "The number of blocks to mine must be higher than zero.")); } this.logger.LogTrace("({0}:{1})", nameof(request.BlockCount), blockCount); WalletAccountReference accountReference = this.GetAccount(); HdAddress address = this.walletManager.GetUnusedAddress(accountReference); var generateBlocksModel = new GenerateBlocksModel { Blocks = this.powMining.GenerateBlocks(new ReserveScript(address.Pubkey), (ulong)blockCount, int.MaxValue) }; this.logger.LogTrace("(-):*.{0}={1}", "Generated block count", generateBlocksModel.Blocks.Count); return(this.Json(generateBlocksModel)); } catch (Exception e) { this.logger.LogError(ExceptionOccurredMessage, e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }