This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 312
Can generate blocks through RPC #220
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Stratis.Bitcoin.Miner; | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Stratis.Bitcoin.Wallet; | ||
using NBitcoin; | ||
|
||
namespace Stratis.Bitcoin.RPC.Controllers | ||
{ | ||
public class WalletRPCController : BaseRPCController | ||
{ | ||
public class UsedWallet | ||
{ | ||
public string WalletName | ||
{ | ||
get; set; | ||
} | ||
public HdAccount Account | ||
{ | ||
get; | ||
set; | ||
} | ||
} | ||
public WalletRPCController(IServiceProvider serviceProvider, IWalletManager walletManager) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI PowMining should be in the DI as well (after we fix the registration issue) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an optional dependency though, is there better way to express ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes hmmm, not without design changes. |
||
{ | ||
this.WalletManager = walletManager; | ||
this.serviceProvider = serviceProvider; | ||
} | ||
|
||
IServiceProvider serviceProvider; | ||
|
||
public IWalletManager WalletManager | ||
{ | ||
get; set; | ||
} | ||
|
||
[ActionName("generate")] | ||
public List<uint256> Generate(int nBlock) | ||
{ | ||
var mining = serviceProvider.GetRequiredService<PowMining>(); | ||
var wallet = GetWallet(); | ||
var address = this.WalletManager.GetUnusedAddress(wallet.WalletName, wallet.Account.Name); | ||
return mining.GenerateBlocks(new ReserveScript(address.Pubkey), (ulong)nBlock, int.MaxValue); | ||
} | ||
|
||
private UsedWallet GetWallet() | ||
{ | ||
var w = this.WalletManager.GetWallets().FirstOrDefault(); | ||
if(w == null) | ||
throw new RPCServerException(NBitcoin.RPC.RPCErrorCode.RPC_INVALID_REQUEST, "No wallet found"); | ||
var account = this.WalletManager.GetAccounts(w).FirstOrDefault(); | ||
return new UsedWallet() | ||
{ | ||
Account = account, | ||
WalletName = w | ||
}; | ||
} | ||
|
||
private string GetAccountName() | ||
{ | ||
return this.WalletManager.GetAccounts(GetWalletName()).FirstOrDefault().Name; | ||
} | ||
|
||
private string GetWalletName() | ||
{ | ||
return this.WalletManager.GetWallets().FirstOrDefault(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using NBitcoin.RPC; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Stratis.Bitcoin.RPC | ||
{ | ||
public class RPCServerException : Exception | ||
{ | ||
public RPCServerException(RPCErrorCode errorCode, string message) : base(message) | ||
{ | ||
this.ErrorCode = errorCode; | ||
} | ||
|
||
public RPCErrorCode ErrorCode | ||
{ | ||
get; set; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use the ChainState on this.FullNode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have ChainState in IFullNode