├── LICENSE ├── README.md ├── demo ├── App.config ├── DemoClient.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── paket.references ├── paket.dependencies ├── paket.lock └── src ├── BitcoinLib.sln └── BitcoinLib ├── Auxiliary ├── Encoders │ ├── ASCIIEncoder.cs │ ├── DataEncoder.cs │ └── HexEncoder.cs ├── GlobalConstants.cs ├── Hashing.cs └── UnixTime.cs ├── BitcoinLib.csproj ├── CoinParameters ├── Base │ ├── CoinConstants.cs │ ├── CoinParameters.cs │ └── ICoinParameters.cs ├── Bitcoin │ ├── BitcoinConstants.cs │ └── IBitcoinConstants.cs ├── Dallar │ ├── DallarConstants.cs │ └── IDallarConstants.cs ├── Dash │ ├── DashConstants.cs │ └── IDashConstants.cs ├── Dogecoin │ ├── DogecoinConstants.cs │ └── IDogecoinConstants.cs ├── Litecoin │ ├── ILitecoinConstants.cs │ └── LitecoinConstants.cs ├── Mogwaicoin │ ├── IMogwaicoinConstants.cs │ └── MogwaicoinConstants.cs └── Smartcash │ ├── ISmartcashConstants.cs │ └── SmartcashConstants.cs ├── ExceptionHandling ├── RawTransactions │ ├── RawTransactionExcessiveFeeException.cs │ └── RawTransactionInvalidAmountException.cs ├── Rpc │ ├── RpcException.cs │ ├── RpcInternalServerErrorException.cs │ ├── RpcRequestTimeoutException.cs │ └── RpcResponseDeserializationException.cs └── RpcExtenderService │ └── GetAddressBalanceException.cs ├── ExtensionMethods ├── CoinServiceExtensionMethods.cs └── DecimalExtensionMethods.cs ├── RPC ├── Connector │ ├── IRpcConnector.cs │ ├── RawRpcConnector.cs │ └── RpcConnector.cs ├── RequestResponse │ ├── JsonRpcError.cs │ ├── JsonRpcRequest.cs │ └── JsonRpcResponse.cs └── Specifications │ ├── RpcErrorCode.cs │ └── RpcMethods.cs ├── Requests ├── AddNode │ └── NodeAction.cs ├── CreateRawTransaction │ ├── CreateRawTransactionInput.cs │ ├── CreateRawTransactionOutput.cs │ └── CreateRawTransactionRequest.cs └── SignRawTransaction │ ├── SigHashType.cs │ ├── SignRawTransactionInput.cs │ └── SignRawTransactionRequest.cs ├── Responses ├── Bridges │ └── ITransactionResponse.cs ├── CreateMultiSigResponse.cs ├── DecodeRawTransactionResponse.cs ├── DecodeScriptResponse.cs ├── EstimateSmartFeeResponse.cs ├── GetAddedNodeInfoResponse.cs ├── GetBlockResponse.cs ├── GetBlockTemplateResponse.cs ├── GetBlockchainInfoResponse.cs ├── GetChainTipsResponse.cs ├── GetFundRawTransactionResponse.cs ├── GetInfoResponse.cs ├── GetMemPoolInfoResponse.cs ├── GetMiningInfoResponse.cs ├── GetNetTotalsResponse.cs ├── GetNetworkInfoResponse.cs ├── GetPeerInfoResponse.cs ├── GetRawMemPoolResponse.cs ├── GetRawTransactionResponse.cs ├── GetTransactionResponse.cs ├── GetTxOutSetInfoResponse.cs ├── GetWalletInfoResponse.cs ├── ListAddressGroupingsResponse.cs ├── ListReceivedByAccountResponse.cs ├── ListReceivedByAddressResponse.cs ├── ListSinceBlockResponse.cs ├── ListTransactionsResponse.cs ├── ListUnspentResponse.cs ├── SharedComponents │ ├── Vin.cs │ └── Vout.cs ├── SignRawTransactionResponse.cs └── ValidateAddressResponse.cs ├── Services ├── Coins │ ├── Base │ │ └── ICoinService.cs │ ├── Bitcoin │ │ ├── BitcoinService.cs │ │ └── IBitcoinService.cs │ ├── Cryptocoin │ │ ├── CryptocoinService.cs │ │ └── ICryptocoinService.cs │ ├── Dallar │ │ ├── DallarService.cs │ │ └── IDallarService.cs │ ├── Dash │ │ ├── DashService.cs │ │ └── IDashService.cs │ ├── Dogecoin │ │ ├── DogecoinService.cs │ │ └── IDogecoinService.cs │ ├── Litecoin │ │ ├── ILitecoinService.cs │ │ └── LitecoinService.cs │ ├── Mogwaicoin │ │ ├── IMogwaicoinService.cs │ │ └── MogwaicoinService.cs │ ├── Sarcoin │ │ ├── ISarcoinService.cs │ │ └── SarcoinService.cs │ └── Smartcash │ │ ├── ISmartcashService.cs │ │ └── SmartcashService.cs └── RpcServices │ ├── RpcExtenderService │ ├── IRpcExtenderService.cs │ └── RpcExtenderService.cs │ └── RpcService │ ├── IRpcService.cs │ └── RpcService.cs └── paket.references /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 PowerMobile Team 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BitcoinLib 2 | 3 | **.NET Bitcoin & Altcoins library** 4 | 5 | ## Features 6 | 7 | - Compatible with [Bitcoin Core](https://bitcoin.org/en/download) RPC API. 8 | - Strongly-typed structures for complex RPC requests and responses. 9 | - Implicit JSON casting for all RPC messages. 10 | - Extended methods for every-day scenarios where the built-in methods fall short. 11 | - Exposure of all [RPC API's functionality](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list) as well as the extended methods through a single interface. 12 | - Custom RPC exceptions. 13 | - Supports all Bitcoin clones. 14 | - Can operate on unlimited daemons with a single library reference. 15 | - [Bitcoin](http://en.wikipedia.org/wiki/Bitcoin), [Litecoin](http://en.wikipedia.org/wiki/Litecoin), [Dogecoin](http://en.wikipedia.org/wiki/Dogecoin), SmartCash, Dash and other Altcoins included. 16 | - Each coin instance can be fully parametrized at run-time and implement its own constants. 17 | - Demo client included. 18 | - Disconnected raw RPC connector included for quick'n'dirty debugging. 19 | - Handles and relays RPC internal server errors along with their error code. 20 | - Can work without a `.config` file. 21 | - Fully compatible with [Mono](http://www.mono-project.com/). 22 | - [Test Network (testnet)](https://bitcoin.org/en/developer-examples#testnet) and [Regression Test Mode (regtest)](https://bitcoin.org/en/developer-examples#regtest-mode) ready. 23 | - Fully configurable. 24 | 25 | ## Donations 26 | 27 | This library took a significant amount of time and effort to build and requires continuous maintenance in order to keep up with changes introduced with every new Bitcoin-Core release. Keep it up by donating at: [15Nb3RhMd13zp5Pc7yngUon83nFtEZUyBA](bitcoin:15Nb3RhMd13zp5Pc7yngUon83nFtEZUyBA?label=BitcoinLib) 28 | 29 | ## Support 30 | 31 | Premium Support is available by our team of experts at: [info@powermobile.org](mailto:info@powermobile.org). 32 | 33 | ## License 34 | 35 | See [LICENSE](LICENSE). 36 | 37 | ## NuGet packages 38 | 39 | BitcoinLib is available on NuGet: 40 | 41 | * [BitcoinLib](https://www.nuget.org/packages/BitcoinLib/) 42 | 43 | ## Versioning 44 | 45 | From version 1.4.0, BitcoinLib follows [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html). 46 | 47 | ## Building from source 48 | 49 | To build BitcoinLib from source, you will need either the 50 | [.NET Core SDK or Visual Studio](https://www.microsoft.com/net/download/). 51 | 52 | ### Linux-specific 53 | 54 | If you are using Linux you will also need Mono installed 55 | (in order to run Paket). The full install sequence (for Ubuntu) 56 | will be something like [this](https://github.com/powermobileteam/fsharp-hedgehog/pull/153#issuecomment-364325504). 57 | 58 | ### Building & running tests 59 | 60 | With Visual Studio you can build BitcoinLib and run the tests 61 | from inside the IDE, otherwise with the `dotnet` command-line 62 | tool you can execute: 63 | 64 | ```sh 65 | dotnet build src/BitcoinLib.sln 66 | ``` 67 | 68 | The first time you run it, this will use Paket to restore all 69 | the packages, and then build the code. 70 | 71 | ## Instructions for Bitcoin 72 | 73 | - Locate your `bitcoin.conf` file (in Windows it's under: `%AppData%\Roaming\Bitcoin`, if it's not there just go ahead and create it) and add these lines: 74 | ``` 75 | rpcuser = MyRpcUsername 76 | rpcpassword = MyRpcPassword 77 | server=1 78 | txindex=1 79 | ``` 80 | - Edit the `app.config` file in the Console test client to best fit your needs. Make sure you also update the `bitcoin.conf` file when you alter the `Bitcoin_RpcUsername` and `Bitcoin_RpcPassword` parameters. 81 | 82 | ## Instructions for Litecoin and other Bitcoin clones 83 | 84 | - Perform the same steps as those mentioned above for Bitcoin. 85 | - Litecoin configuration file is: `litecoin.conf` under: `%AppData%\Roaming\Litecoin` and its daemon is: `litecoind`. 86 | - Each coin can be initialized by its own interface specification: 87 | - `IBitcoinService BitcoinService = new BitcoinService();` 88 | - `ILitecoinService LitecoinService = new LitecoinService();` 89 | - Any bitcoin clone can be adopted without any further installation steps with the use of the generic `ICryptocoinService`: 90 | - `ICryptocoinService cryptocoinService = new CryptocoinService("daemonUrl", "rpcUsername", "rpcPassword", "walletPassword");` 91 | - Use `(ICryptocoinService).Parameters` to fully configure each coin pointer at run-time. 92 | 93 | ## Configuration 94 | 95 | Sample configuration: 96 | 97 | ```xml 98 |  99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | ``` 119 | -------------------------------------------------------------------------------- /demo/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /demo/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Configuration; 7 | using System.Globalization; 8 | using System.Linq; 9 | using System.Reflection; 10 | using BitcoinLib.Auxiliary; 11 | using BitcoinLib.ExceptionHandling.Rpc; 12 | using BitcoinLib.Responses; 13 | using BitcoinLib.Services.Coins.Base; 14 | using BitcoinLib.Services.Coins.Bitcoin; 15 | 16 | namespace ConsoleClient 17 | { 18 | internal sealed class Program 19 | { 20 | private static readonly ICoinService CoinService = new BitcoinService(useTestnet: true); 21 | 22 | private static void Main() 23 | { 24 | try 25 | { 26 | Console.Write("\n\nConnecting to {0} {1}Net via RPC at {2}...", CoinService.Parameters.CoinLongName, (CoinService.Parameters.UseTestnet ? "Test" : "Main"), CoinService.Parameters.SelectedDaemonUrl); 27 | 28 | // Network difficulty 29 | var networkDifficulty = CoinService.GetDifficulty(); 30 | Console.WriteLine("[OK]\n\n{0} Network Difficulty: {1}", CoinService.Parameters.CoinLongName, networkDifficulty.ToString("#,###", CultureInfo.InvariantCulture)); 31 | 32 | // My balance 33 | var myBalance = CoinService.GetBalance(); 34 | Console.WriteLine("\nMy balance: {0} {1}", myBalance, CoinService.Parameters.CoinShortName); 35 | 36 | // Current block 37 | Console.WriteLine("Current block: {0}", 38 | CoinService.GetBlockCount().ToString("#,#", CultureInfo.InvariantCulture)); 39 | 40 | // Wallet state 41 | Console.WriteLine("Wallet state: {0}", CoinService.IsWalletEncrypted() ? "Encrypted" : "Unencrypted"); 42 | 43 | // Keys and addresses 44 | if (myBalance > 0) 45 | { 46 | // My non-empty addresses 47 | Console.WriteLine("\n\nMy non-empty addresses:"); 48 | 49 | var myNonEmptyAddresses = CoinService.ListReceivedByAddress(); 50 | 51 | foreach (var address in myNonEmptyAddresses) 52 | { 53 | Console.WriteLine("\n--------------------------------------------------"); 54 | Console.WriteLine("Account: " + (string.IsNullOrWhiteSpace(address.Account) ? "(no label)" : address.Account)); 55 | Console.WriteLine("Address: " + address.Address); 56 | Console.WriteLine("Amount: " + address.Amount); 57 | Console.WriteLine("Confirmations: " + address.Confirmations); 58 | Console.WriteLine("--------------------------------------------------"); 59 | } 60 | 61 | // My private keys 62 | if (bool.Parse(ConfigurationManager.AppSettings["ExtractMyPrivateKeys"]) && myNonEmptyAddresses.Count > 0 && CoinService.IsWalletEncrypted()) 63 | { 64 | const short secondsToUnlockTheWallet = 30; 65 | 66 | Console.Write("\nWill now unlock the wallet for " + secondsToUnlockTheWallet + ((secondsToUnlockTheWallet > 1) ? " seconds" : " second") + "..."); 67 | CoinService.WalletPassphrase(CoinService.Parameters.WalletPassword, secondsToUnlockTheWallet); 68 | Console.WriteLine("[OK]\n\nMy private keys for non-empty addresses:\n"); 69 | 70 | foreach (var address in myNonEmptyAddresses) 71 | { 72 | Console.WriteLine("Private Key for address " + address.Address + ": " + CoinService.DumpPrivKey(address.Address)); 73 | } 74 | 75 | Console.Write("\nLocking wallet..."); 76 | CoinService.WalletLock(); 77 | Console.WriteLine("[OK]"); 78 | } 79 | 80 | // My transactions 81 | Console.WriteLine("\n\nMy transactions: "); 82 | var myTransactions = CoinService.ListTransactions(null, int.MaxValue, 0); 83 | 84 | foreach (var transaction in myTransactions) 85 | { 86 | Console.WriteLine("\n---------------------------------------------------------------------------"); 87 | Console.WriteLine("Account: " + (string.IsNullOrWhiteSpace(transaction.Account) ? "(no label)" : transaction.Account)); 88 | Console.WriteLine("Address: " + transaction.Address); 89 | Console.WriteLine("Category: " + transaction.Category); 90 | Console.WriteLine("Amount: " + transaction.Amount); 91 | Console.WriteLine("Fee: " + transaction.Fee); 92 | Console.WriteLine("Confirmations: " + transaction.Confirmations); 93 | Console.WriteLine("BlockHash: " + transaction.BlockHash); 94 | Console.WriteLine("BlockIndex: " + transaction.BlockIndex); 95 | Console.WriteLine("BlockTime: " + transaction.BlockTime + " - " + UnixTime.UnixTimeToDateTime(transaction.BlockTime)); 96 | Console.WriteLine("TxId: " + transaction.TxId); 97 | Console.WriteLine("Time: " + transaction.Time + " - " + UnixTime.UnixTimeToDateTime(transaction.Time)); 98 | Console.WriteLine("TimeReceived: " + transaction.TimeReceived + " - " + UnixTime.UnixTimeToDateTime(transaction.TimeReceived)); 99 | 100 | if (!string.IsNullOrWhiteSpace(transaction.Comment)) 101 | { 102 | Console.WriteLine("Comment: " + transaction.Comment); 103 | } 104 | 105 | if (!string.IsNullOrWhiteSpace(transaction.OtherAccount)) 106 | { 107 | Console.WriteLine("Other Account: " + transaction.OtherAccount); 108 | } 109 | 110 | if (transaction.WalletConflicts != null && transaction.WalletConflicts.Any()) 111 | { 112 | Console.Write("Conflicted Transactions: "); 113 | 114 | foreach (var conflictedTxId in transaction.WalletConflicts) 115 | { 116 | Console.Write(conflictedTxId + " "); 117 | } 118 | 119 | Console.WriteLine(); 120 | } 121 | 122 | Console.WriteLine("---------------------------------------------------------------------------"); 123 | } 124 | 125 | // Transaction Details 126 | Console.WriteLine("\n\nMy transactions' details:"); 127 | foreach (var transaction in myTransactions) 128 | { 129 | // Move transactions don't have a txId, which this logic fails for 130 | if (transaction.Category == "move") 131 | { 132 | continue; 133 | } 134 | 135 | var localWalletTransaction = CoinService.GetTransaction(transaction.TxId); 136 | IEnumerable localWalletTrasactionProperties = localWalletTransaction.GetType().GetProperties(); 137 | IList localWalletTransactionDetailsList = localWalletTransaction.Details.ToList(); 138 | 139 | Console.WriteLine("\nTransaction\n-----------"); 140 | 141 | foreach (var propertyInfo in localWalletTrasactionProperties) 142 | { 143 | var propertyInfoName = propertyInfo.Name; 144 | 145 | if (propertyInfoName != "Details" && propertyInfoName != "WalletConflicts") 146 | { 147 | Console.WriteLine(propertyInfoName + ": " + propertyInfo.GetValue(localWalletTransaction, null)); 148 | } 149 | } 150 | 151 | foreach (var details in localWalletTransactionDetailsList) 152 | { 153 | IEnumerable detailsProperties = details.GetType().GetProperties(); 154 | Console.WriteLine("\nTransaction details " + (localWalletTransactionDetailsList.IndexOf(details) + 1) + " of total " + localWalletTransactionDetailsList.Count + "\n--------------------------------"); 155 | 156 | foreach (var propertyInfo in detailsProperties) 157 | { 158 | Console.WriteLine(propertyInfo.Name + ": " + propertyInfo.GetValue(details, null)); 159 | } 160 | } 161 | } 162 | 163 | // Unspent transactions 164 | Console.WriteLine("\nMy unspent transactions:"); 165 | var unspentList = CoinService.ListUnspent(); 166 | 167 | foreach (var unspentResponse in unspentList) 168 | { 169 | IEnumerable detailsProperties = unspentResponse.GetType().GetProperties(); 170 | 171 | Console.WriteLine("\nUnspent transaction " + (unspentList.IndexOf(unspentResponse) + 1) + " of " + unspentList.Count + "\n--------------------------------"); 172 | 173 | foreach (var propertyInfo in detailsProperties) 174 | { 175 | Console.WriteLine(propertyInfo.Name + " : " + propertyInfo.GetValue(unspentResponse, null)); 176 | } 177 | } 178 | } 179 | 180 | Console.ReadLine(); 181 | } 182 | catch (RpcInternalServerErrorException exception) 183 | { 184 | var errorCode = 0; 185 | var errorMessage = string.Empty; 186 | 187 | if (exception.RpcErrorCode.GetHashCode() != 0) 188 | { 189 | errorCode = exception.RpcErrorCode.GetHashCode(); 190 | errorMessage = exception.RpcErrorCode.ToString(); 191 | } 192 | 193 | Console.WriteLine("[Failed] {0} {1} {2}", exception.Message, errorCode != 0 ? "Error code: " + errorCode : string.Empty, !string.IsNullOrWhiteSpace(errorMessage) ? errorMessage : string.Empty); 194 | } 195 | catch (Exception exception) 196 | { 197 | Console.WriteLine("[Failed]\n\nPlease check your configuration and make sure that the daemon is up and running and that it is synchronized. \n\nException: " + exception); 198 | } 199 | } 200 | } 201 | } -------------------------------------------------------------------------------- /demo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | 11 | [assembly: AssemblyTitle("ConsoleClient")] 12 | [assembly: AssemblyDescription("Demo Console Client for BitcoinLib")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyCompany("George Kimionis")] 15 | [assembly: AssemblyProduct("ConsoleClient")] 16 | [assembly: AssemblyCopyright("Copyright © 2014")] 17 | [assembly: AssemblyTrademark("")] 18 | [assembly: AssemblyCulture("")] 19 | 20 | // Setting ComVisible to false makes the types in this assembly not visible 21 | // to COM components. If you need to access a type in this assembly from 22 | // COM, set the ComVisible attribute to true on that type. 23 | 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | 28 | [assembly: Guid("567159bb-15c6-461a-a22c-18eecd3ba894")] 29 | 30 | // Version information for an assembly consists of the following four values: 31 | // 32 | // Major Version 33 | // Minor Version 34 | // Build Number 35 | // Revision 36 | // 37 | // You can specify all the values or you can default the Build and Revision Numbers 38 | // by using the '*' as shown below: 39 | // [assembly: AssemblyVersion("1.0.*")] 40 | 41 | [assembly: AssemblyVersion("1.6.0.0")] 42 | [assembly: AssemblyFileVersion("1.6.0.0")] -------------------------------------------------------------------------------- /demo/paket.references: -------------------------------------------------------------------------------- 1 | Newtonsoft.Json -------------------------------------------------------------------------------- /paket.dependencies: -------------------------------------------------------------------------------- 1 | source https://api.nuget.org/v3/index.json 2 | nuget FAKE 3 | nuget NuGet.CommandLine 4 | nuget System.Configuration.ConfigurationManager 5 | nuget Newtonsoft.Json 6 | -------------------------------------------------------------------------------- /src/BitcoinLib.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{8C09BFEC-8BFA-42B3-88B2-47F5010CA418}" 7 | ProjectSection(SolutionItems) = preProject 8 | ..\paket.dependencies = ..\paket.dependencies 9 | EndProjectSection 10 | EndProject 11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitcoinLib", "BitcoinLib\BitcoinLib.csproj", "{B853E315-7103-4CBA-8873-D5202019F267}" 12 | EndProject 13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoClient", "..\demo\DemoClient.csproj", "{56F54485-7B42-4E41-95D3-1998EA614695}" 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {B853E315-7103-4CBA-8873-D5202019F267}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {B853E315-7103-4CBA-8873-D5202019F267}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {B853E315-7103-4CBA-8873-D5202019F267}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {B853E315-7103-4CBA-8873-D5202019F267}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {56F54485-7B42-4E41-95D3-1998EA614695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {56F54485-7B42-4E41-95D3-1998EA614695}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {56F54485-7B42-4E41-95D3-1998EA614695}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {56F54485-7B42-4E41-95D3-1998EA614695}.Release|Any CPU.Build.0 = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(SolutionProperties) = preSolution 31 | HideSolutionNode = FALSE 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /src/BitcoinLib/Auxiliary/Encoders/ASCIIEncoder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Linq; 5 | 6 | namespace BitcoinLib.Auxiliary.Encoders 7 | { 8 | public class ASCIIEncoder : DataEncoder 9 | { 10 | public override byte[] DecodeData(string encoded) 11 | { 12 | return string.IsNullOrEmpty(encoded) ? new byte[0] : encoded.ToCharArray().Select(o => (byte) o).ToArray(); 13 | } 14 | 15 | public override string EncodeData(byte[] data, int offset, int count) 16 | { 17 | return new string(data.Skip(offset).Take(count).Select(o => (char) o).ToArray()).Replace("\0", ""); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Auxiliary/Encoders/DataEncoder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Auxiliary.Encoders 5 | { 6 | public abstract class DataEncoder 7 | { 8 | internal DataEncoder() 9 | { 10 | } 11 | 12 | // char.IsWhiteSpace fits well but it match other whitespaces 13 | // characters too and also works for unicode characters. 14 | public static bool IsSpace(char c) 15 | { 16 | return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r'; 17 | } 18 | 19 | public string EncodeData(byte[] data) 20 | { 21 | return EncodeData(data, 0, data.Length); 22 | } 23 | 24 | public abstract string EncodeData(byte[] data, int offset, int count); 25 | 26 | public abstract byte[] DecodeData(string encoded); 27 | } 28 | 29 | public static class Encoders 30 | { 31 | private static readonly ASCIIEncoder _ASCII = new ASCIIEncoder(); 32 | 33 | private static readonly HexEncoder _Hex = new HexEncoder(); 34 | 35 | public static DataEncoder ASCII => _ASCII; 36 | 37 | public static DataEncoder Hex => _Hex; 38 | } 39 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Auxiliary/Encoders/HexEncoder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | using System.Linq; 6 | 7 | namespace BitcoinLib.Auxiliary.Encoders 8 | { 9 | public class HexEncoder : DataEncoder 10 | { 11 | private static readonly string[] HexTbl = Enumerable.Range(0, 256).Select(v => v.ToString("x2")).ToArray(); 12 | 13 | private static readonly int[] HexValueArray; 14 | 15 | static HexEncoder() 16 | { 17 | var hexDigits = new[] 18 | { 19 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 20 | 'A', 'B', 'C', 'D', 'E', 'F' 21 | }; 22 | var hexValues = new byte[] 23 | { 24 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 25 | 10, 11, 12, 13, 14, 15 26 | }; 27 | 28 | var max = hexDigits.Max(); 29 | HexValueArray = new int[max + 1]; 30 | for (var i = 0; i < HexValueArray.Length; i++) 31 | { 32 | var idx = Array.IndexOf(hexDigits, (char) i); 33 | var value = -1; 34 | if (idx != -1) 35 | value = hexValues[idx]; 36 | HexValueArray[i] = value; 37 | } 38 | } 39 | 40 | public bool Space { get; set; } 41 | 42 | public override string EncodeData(byte[] data, int offset, int count) 43 | { 44 | if (data == null) 45 | throw new ArgumentNullException(nameof(data)); 46 | 47 | var pos = 0; 48 | var spaces = (Space ? Math.Max((count - 1), 0) : 0); 49 | var s = new char[2 * count + spaces]; 50 | for (var i = offset; i < offset + count; i++) 51 | { 52 | if (Space && i != 0) 53 | s[pos++] = ' '; 54 | var c = HexTbl[data[i]]; 55 | s[pos++] = c[0]; 56 | s[pos++] = c[1]; 57 | } 58 | return new string(s); 59 | } 60 | 61 | public override byte[] DecodeData(string encoded) 62 | { 63 | if (encoded == null) 64 | throw new ArgumentNullException(nameof(encoded)); 65 | if (encoded.Length % 2 == 1) 66 | throw new FormatException("Invalid Hex String"); 67 | 68 | var result = new byte[encoded.Length / 2]; 69 | for (int i = 0, j = 0; i < encoded.Length; i += 2, j++) 70 | { 71 | var a = IsDigit(encoded[i]); 72 | var b = IsDigit(encoded[i + 1]); 73 | if (a == -1 || b == -1) 74 | throw new FormatException("Invalid Hex String"); 75 | result[j] = (byte) (((uint) a << 4) | (uint) b); 76 | } 77 | return result; 78 | } 79 | 80 | public bool IsValid(string str) 81 | { 82 | return str.ToCharArray().All(c => IsDigit(c) != -1) && str.Length % 2 == 0; 83 | } 84 | 85 | public static int IsDigit(char c) 86 | { 87 | return c + 1 <= HexValueArray.Length 88 | ? HexValueArray[c] 89 | : -1; 90 | } 91 | 92 | public static bool IsWellFormed(string str) 93 | { 94 | try 95 | { 96 | Encoders.Hex.DecodeData(str); 97 | return true; 98 | } 99 | catch (FormatException) 100 | { 101 | return false; 102 | } 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Auxiliary/GlobalConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Auxiliary 5 | { 6 | public static class GlobalConstants 7 | { 8 | public const ushort MillisecondsInASecond = 1000; 9 | public const ushort MinutesInADay = 1440; 10 | } 11 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Auxiliary/Hashing.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Linq; 5 | using System.Security.Cryptography; 6 | using System.Text; 7 | 8 | namespace BitcoinLib.Auxiliary 9 | { 10 | public class Hashing 11 | { 12 | public static string GetSha256(string text) 13 | { 14 | return new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(text)).Aggregate(string.Empty, (current, x) => current + $"{x:x2}"); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Auxiliary/UnixTime.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | 6 | namespace BitcoinLib.Auxiliary 7 | { 8 | public static class UnixTime 9 | { 10 | private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0); 11 | 12 | public static DateTime UnixTimeToDateTime(double unixTimeStamp) 13 | { 14 | return Epoch.AddSeconds(unixTimeStamp).ToUniversalTime(); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/BitcoinLib/BitcoinLib.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard20;net461 5 | BitcoinLib 6 | The most complete, up-to-date, battle-tested library and RPC wrapper for Bitcoin, Litecoin, Dogecoin and other Bitcoin clones in .NET. 7 | © George Kimionis 2018 8 | 1.9.0.0 9 | 1.9.0.0 10 | George Kimionis 11 | https://github.com/GeorgeKimionis/BitcoinLib/blob/master/LICENSE 12 | https://github.com/GeorgeKimionis/BitcoinLib 13 | c#;dotnet;bitcoin 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Base/CoinConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | 6 | namespace BitcoinLib.CoinParameters.Base 7 | { 8 | public abstract class CoinConstants where T : CoinConstants, new() 9 | { 10 | private static readonly Lazy Lazy = new Lazy(() => new T()); 11 | public static T Instance => Lazy.Value; 12 | } 13 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Base/CoinParameters.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | using System.Configuration; 6 | using System.Diagnostics; 7 | using BitcoinLib.Auxiliary; 8 | using BitcoinLib.Services.Coins.Base; 9 | using BitcoinLib.Services.Coins.Bitcoin; 10 | using BitcoinLib.Services.Coins.Cryptocoin; 11 | using BitcoinLib.Services.Coins.Dallar; 12 | using BitcoinLib.Services.Coins.Dash; 13 | using BitcoinLib.Services.Coins.Dogecoin; 14 | using BitcoinLib.Services.Coins.Litecoin; 15 | using BitcoinLib.Services.Coins.Mogwaicoin; 16 | using BitcoinLib.Services.Coins.Sarcoin; 17 | using BitcoinLib.Services.Coins.Smartcash; 18 | 19 | namespace BitcoinLib.Services 20 | { 21 | public partial class CoinService 22 | { 23 | public CoinParameters Parameters { get; } 24 | 25 | public class CoinParameters 26 | { 27 | #region Constructor 28 | 29 | public CoinParameters(ICoinService coinService, 30 | string daemonUrl, 31 | string rpcUsername, 32 | string rpcPassword, 33 | string walletPassword, 34 | short rpcRequestTimeoutInSeconds) 35 | { 36 | if (!string.IsNullOrWhiteSpace(daemonUrl)) 37 | { 38 | DaemonUrl = daemonUrl; 39 | UseTestnet = false; // this will force the CoinParameters.SelectedDaemonUrl dynamic property to automatically pick the daemonUrl defined above 40 | IgnoreConfigFiles = true; 41 | RpcUsername = rpcUsername; 42 | RpcPassword = rpcPassword; 43 | WalletPassword = walletPassword; 44 | } 45 | 46 | if (rpcRequestTimeoutInSeconds > 0) 47 | { 48 | RpcRequestTimeoutInSeconds = rpcRequestTimeoutInSeconds; 49 | } 50 | else 51 | { 52 | short rpcRequestTimeoutTryParse = 0; 53 | 54 | if (short.TryParse(ConfigurationManager.AppSettings.Get("RpcRequestTimeoutInSeconds"), out rpcRequestTimeoutTryParse)) 55 | { 56 | RpcRequestTimeoutInSeconds = rpcRequestTimeoutTryParse; 57 | } 58 | } 59 | 60 | if (IgnoreConfigFiles && (string.IsNullOrWhiteSpace(DaemonUrl) || string.IsNullOrWhiteSpace(RpcUsername) || string.IsNullOrWhiteSpace(RpcPassword))) 61 | { 62 | throw new Exception($"One or more required parameters, as defined in {GetType().Name}, were not found in the configuration file!"); 63 | } 64 | 65 | if (IgnoreConfigFiles && Debugger.IsAttached && string.IsNullOrWhiteSpace(WalletPassword)) 66 | { 67 | Console.ForegroundColor = ConsoleColor.Yellow; 68 | Console.WriteLine("[WARNING] The wallet password is either null or empty"); 69 | Console.ResetColor(); 70 | } 71 | 72 | #region Bitcoin 73 | 74 | if (coinService is BitcoinService) 75 | { 76 | if (!IgnoreConfigFiles) 77 | { 78 | DaemonUrl = ConfigurationManager.AppSettings.Get("Bitcoin_DaemonUrl"); 79 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Bitcoin_DaemonUrl_Testnet"); 80 | RpcUsername = ConfigurationManager.AppSettings.Get("Bitcoin_RpcUsername"); 81 | RpcPassword = ConfigurationManager.AppSettings.Get("Bitcoin_RpcPassword"); 82 | WalletPassword = ConfigurationManager.AppSettings.Get("Bitcoin_WalletPassword"); 83 | } 84 | 85 | CoinShortName = "BTC"; 86 | CoinLongName = "Bitcoin"; 87 | IsoCurrencyCode = "XBT"; 88 | 89 | TransactionSizeBytesContributedByEachInput = 148; 90 | TransactionSizeBytesContributedByEachOutput = 34; 91 | TransactionSizeFixedExtraSizeInBytes = 10; 92 | 93 | FreeTransactionMaximumSizeInBytes = 1000; 94 | FreeTransactionMinimumOutputAmountInCoins = 0.01M; 95 | FreeTransactionMinimumPriority = 57600000; 96 | FeePerThousandBytesInCoins = 0.0001M; 97 | MinimumTransactionFeeInCoins = 0.0001M; 98 | MinimumNonDustTransactionAmountInCoins = 0.0000543M; 99 | 100 | TotalCoinSupplyInCoins = 21000000; 101 | EstimatedBlockGenerationTimeInMinutes = 10; 102 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000; 103 | 104 | BaseUnitName = "Satoshi"; 105 | BaseUnitsPerCoin = 100000000; 106 | CoinsPerBaseUnit = 0.00000001M; 107 | } 108 | 109 | #endregion 110 | 111 | #region Litecoin 112 | 113 | else if (coinService is LitecoinService) 114 | { 115 | if (!IgnoreConfigFiles) 116 | { 117 | DaemonUrl = ConfigurationManager.AppSettings.Get("Litecoin_DaemonUrl"); 118 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Litecoin_DaemonUrl_Testnet"); 119 | RpcUsername = ConfigurationManager.AppSettings.Get("Litecoin_RpcUsername"); 120 | RpcPassword = ConfigurationManager.AppSettings.Get("Litecoin_RpcPassword"); 121 | WalletPassword = ConfigurationManager.AppSettings.Get("Litecoin_WalletPassword"); 122 | } 123 | 124 | CoinShortName = "LTC"; 125 | CoinLongName = "Litecoin"; 126 | IsoCurrencyCode = "XLT"; 127 | 128 | TransactionSizeBytesContributedByEachInput = 148; 129 | TransactionSizeBytesContributedByEachOutput = 34; 130 | TransactionSizeFixedExtraSizeInBytes = 10; 131 | 132 | FreeTransactionMaximumSizeInBytes = 5000; 133 | FreeTransactionMinimumOutputAmountInCoins = 0.001M; 134 | FreeTransactionMinimumPriority = 230400000; 135 | FeePerThousandBytesInCoins = 0.001M; 136 | MinimumTransactionFeeInCoins = 0.001M; 137 | MinimumNonDustTransactionAmountInCoins = 0.001M; 138 | 139 | TotalCoinSupplyInCoins = 84000000; 140 | EstimatedBlockGenerationTimeInMinutes = 2.5; 141 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000; 142 | BlockMaximumSizeInBytes = 250000; 143 | 144 | BaseUnitName = "Litetoshi"; 145 | BaseUnitsPerCoin = 100000000; 146 | CoinsPerBaseUnit = 0.00000001M; 147 | } 148 | 149 | #endregion 150 | 151 | #region Dogecoin 152 | 153 | else if (coinService is DogecoinService) 154 | { 155 | if (!IgnoreConfigFiles) 156 | { 157 | DaemonUrl = ConfigurationManager.AppSettings.Get("Dogecoin_DaemonUrl"); 158 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Dogecoin_DaemonUrl_Testnet"); 159 | RpcUsername = ConfigurationManager.AppSettings.Get("Dogecoin_RpcUsername"); 160 | RpcPassword = ConfigurationManager.AppSettings.Get("Dogecoin_RpcPassword"); 161 | WalletPassword = ConfigurationManager.AppSettings.Get("Dogecoin_WalletPassword"); 162 | } 163 | 164 | CoinShortName = "Doge"; 165 | CoinLongName = "Dogecoin"; 166 | IsoCurrencyCode = "XDG"; 167 | TransactionSizeBytesContributedByEachInput = 148; 168 | TransactionSizeBytesContributedByEachOutput = 34; 169 | TransactionSizeFixedExtraSizeInBytes = 10; 170 | FreeTransactionMaximumSizeInBytes = 1; // free txs are not supported from v.1.8+ 171 | FreeTransactionMinimumOutputAmountInCoins = 1; 172 | FreeTransactionMinimumPriority = 230400000; 173 | FeePerThousandBytesInCoins = 1; 174 | MinimumTransactionFeeInCoins = 1; 175 | MinimumNonDustTransactionAmountInCoins = 0.1M; 176 | TotalCoinSupplyInCoins = 100000000000; 177 | EstimatedBlockGenerationTimeInMinutes = 1; 178 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000; 179 | BlockMaximumSizeInBytes = 500000; 180 | BaseUnitName = "Koinu"; 181 | BaseUnitsPerCoin = 100000000; 182 | CoinsPerBaseUnit = 0.00000001M; 183 | } 184 | 185 | #endregion 186 | 187 | #region Sarcoin 188 | 189 | else if (coinService is SarcoinService) 190 | { 191 | if (!IgnoreConfigFiles) 192 | { 193 | DaemonUrl = ConfigurationManager.AppSettings.Get("Sarcoin_DaemonUrl"); 194 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Sarcoin_DaemonUrl_Testnet"); 195 | RpcUsername = ConfigurationManager.AppSettings.Get("Sarcoin_RpcUsername"); 196 | RpcPassword = ConfigurationManager.AppSettings.Get("Sarcoin_RpcPassword"); 197 | WalletPassword = ConfigurationManager.AppSettings.Get("Sarcoin_WalletPassword"); 198 | } 199 | 200 | CoinShortName = "SAR"; 201 | CoinLongName = "Sarcoin"; 202 | IsoCurrencyCode = "SAR"; 203 | 204 | TransactionSizeBytesContributedByEachInput = 148; 205 | TransactionSizeBytesContributedByEachOutput = 34; 206 | TransactionSizeFixedExtraSizeInBytes = 10; 207 | 208 | FreeTransactionMaximumSizeInBytes = 0; 209 | FreeTransactionMinimumOutputAmountInCoins = 0; 210 | FreeTransactionMinimumPriority = 0; 211 | FeePerThousandBytesInCoins = 0.00001M; 212 | MinimumTransactionFeeInCoins = 0.00001M; 213 | MinimumNonDustTransactionAmountInCoins = 0.00001M; 214 | 215 | TotalCoinSupplyInCoins = 2000000000; 216 | EstimatedBlockGenerationTimeInMinutes = 1.5; 217 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000; 218 | 219 | BaseUnitName = "Satoshi"; 220 | BaseUnitsPerCoin = 100000000; 221 | CoinsPerBaseUnit = 0.00000001M; 222 | } 223 | 224 | #endregion 225 | 226 | #region Dash 227 | 228 | else if (coinService is DashService) 229 | { 230 | if (!IgnoreConfigFiles) 231 | { 232 | DaemonUrl = ConfigurationManager.AppSettings.Get("Dash_DaemonUrl"); 233 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Dash_DaemonUrl_Testnet"); 234 | RpcUsername = ConfigurationManager.AppSettings.Get("Dash_RpcUsername"); 235 | RpcPassword = ConfigurationManager.AppSettings.Get("Dash_RpcPassword"); 236 | WalletPassword = ConfigurationManager.AppSettings.Get("Dash_WalletPassword"); 237 | } 238 | 239 | CoinShortName = "DASH"; 240 | CoinLongName = "Dash"; 241 | IsoCurrencyCode = "DASH"; 242 | 243 | TransactionSizeBytesContributedByEachInput = 148; 244 | TransactionSizeBytesContributedByEachOutput = 34; 245 | TransactionSizeFixedExtraSizeInBytes = 10; 246 | 247 | FreeTransactionMaximumSizeInBytes = 1000; 248 | FreeTransactionMinimumOutputAmountInCoins = 0.0001M; 249 | FreeTransactionMinimumPriority = 57600000; 250 | FeePerThousandBytesInCoins = 0.0001M; 251 | MinimumTransactionFeeInCoins = 0.001M; 252 | MinimumNonDustTransactionAmountInCoins = 0.0000543M; 253 | 254 | TotalCoinSupplyInCoins = 18900000; 255 | EstimatedBlockGenerationTimeInMinutes = 2.7; 256 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000; 257 | 258 | BaseUnitName = "Duff"; 259 | BaseUnitsPerCoin = 100000000; 260 | CoinsPerBaseUnit = 0.00000001M; 261 | } 262 | 263 | #endregion 264 | 265 | #region Mogwai 266 | else if (coinService is MogwaicoinService) 267 | { 268 | if (!IgnoreConfigFiles) 269 | { 270 | DaemonUrl = ConfigurationManager.AppSettings.Get("Mogwaicoin_DaemonUrl"); 271 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Mogwaicoin_DaemonUrl_Testnet"); 272 | RpcUsername = ConfigurationManager.AppSettings.Get("Mogwaicoin_RpcUsername"); 273 | RpcPassword = ConfigurationManager.AppSettings.Get("Mogwaicoin_RpcPassword"); 274 | WalletPassword = ConfigurationManager.AppSettings.Get("Mogwaicoin_WalletPassword"); 275 | } 276 | CoinShortName = "Mogwaicoin"; 277 | CoinLongName = "Mogwaicoin"; 278 | IsoCurrencyCode = "MOG"; 279 | TransactionSizeBytesContributedByEachInput = 148; 280 | TransactionSizeBytesContributedByEachOutput = 34; 281 | TransactionSizeFixedExtraSizeInBytes = 10; 282 | FreeTransactionMaximumSizeInBytes = 1000; 283 | FreeTransactionMinimumOutputAmountInCoins = 0.0001M; 284 | FreeTransactionMinimumPriority = 57600000; 285 | FeePerThousandBytesInCoins = 0.0001M; 286 | MinimumTransactionFeeInCoins = 0.001M; 287 | MinimumNonDustTransactionAmountInCoins = 0.0000543M; 288 | TotalCoinSupplyInCoins = 50000000; 289 | EstimatedBlockGenerationTimeInMinutes = 2.0; 290 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000; 291 | BaseUnitName = "Puff"; 292 | BaseUnitsPerCoin = 100000000; 293 | CoinsPerBaseUnit = 0.00000001M; 294 | } 295 | #endregion 296 | 297 | #region Smartcash 298 | 299 | else if (coinService is SmartcashService) 300 | { 301 | if (!IgnoreConfigFiles) 302 | { 303 | DaemonUrl = ConfigurationManager.AppSettings.Get("Smartcash_DaemonUrl"); 304 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Smartcash_DaemonUrl_Testnet"); 305 | RpcUsername = ConfigurationManager.AppSettings.Get("Smartcash_RpcUsername"); 306 | RpcPassword = ConfigurationManager.AppSettings.Get("Smartcash_RpcPassword"); 307 | WalletPassword = ConfigurationManager.AppSettings.Get("Smartcash_WalletPassword"); 308 | } 309 | 310 | CoinShortName = "SMART"; 311 | CoinLongName = "Smartcash"; 312 | IsoCurrencyCode = "SMART"; 313 | 314 | TransactionSizeBytesContributedByEachInput = 148; 315 | TransactionSizeBytesContributedByEachOutput = 34; 316 | TransactionSizeFixedExtraSizeInBytes = 10; 317 | 318 | FreeTransactionMaximumSizeInBytes = 0; // free txs are not supported 319 | FreeTransactionMinimumOutputAmountInCoins = 0; 320 | FreeTransactionMinimumPriority = 0; 321 | FeePerThousandBytesInCoins = 0.0001M; 322 | MinimumTransactionFeeInCoins = 0.001M; 323 | MinimumNonDustTransactionAmountInCoins = 0.00001M; 324 | 325 | TotalCoinSupplyInCoins = 5000000000; 326 | EstimatedBlockGenerationTimeInMinutes = 0.916667; 327 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000; 328 | 329 | BaseUnitName = "Smartoshi"; 330 | BaseUnitsPerCoin = 100000000; 331 | CoinsPerBaseUnit = 0.00000001M; 332 | } 333 | 334 | #endregion 335 | 336 | #region Dallar 337 | 338 | else if (coinService is DallarService) 339 | { 340 | if (!IgnoreConfigFiles) 341 | { 342 | DaemonUrl = ConfigurationManager.AppSettings.Get("Dallar_DaemonUrl"); 343 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Dallar_DaemonUrl_Testnet"); 344 | RpcUsername = ConfigurationManager.AppSettings.Get("Dallar_RpcUsername"); 345 | RpcPassword = ConfigurationManager.AppSettings.Get("Dallar_RpcPassword"); 346 | WalletPassword = ConfigurationManager.AppSettings.Get("Dallar_WalletPassword"); 347 | } 348 | 349 | CoinShortName = "DAL"; 350 | CoinLongName = "Dallar"; 351 | IsoCurrencyCode = "DAL"; 352 | 353 | TransactionSizeBytesContributedByEachInput = 148; 354 | TransactionSizeBytesContributedByEachOutput = 34; 355 | TransactionSizeFixedExtraSizeInBytes = 10; 356 | 357 | FreeTransactionMaximumSizeInBytes = 1000; 358 | FreeTransactionMinimumOutputAmountInCoins = 0.001M; 359 | FreeTransactionMinimumPriority = 230400000; 360 | FeePerThousandBytesInCoins = 0.001M; 361 | MinimumTransactionFeeInCoins = 0.0001M; 362 | MinimumNonDustTransactionAmountInCoins = 0.001M; 363 | 364 | TotalCoinSupplyInCoins = 80000000; 365 | EstimatedBlockGenerationTimeInMinutes = 1.0; 366 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000; 367 | BlockMaximumSizeInBytes = 750000; 368 | 369 | BaseUnitName = "Allar"; 370 | BaseUnitsPerCoin = 100000000; 371 | CoinsPerBaseUnit = 0.00000001M; 372 | } 373 | 374 | #endregion 375 | 376 | #region Agnostic coin (cryptocoin) 377 | 378 | else if (coinService is CryptocoinService) 379 | { 380 | CoinShortName = "XXX"; 381 | CoinLongName = "Generic Cryptocoin Template"; 382 | IsoCurrencyCode = "XXX"; 383 | 384 | // Note: The rest of the parameters will have to be defined at run-time 385 | } 386 | 387 | #endregion 388 | 389 | #region Uknown coin exception 390 | 391 | else 392 | { 393 | throw new Exception("Unknown coin!"); 394 | } 395 | 396 | #endregion 397 | 398 | #region Invalid configuration / Missing parameters 399 | 400 | if (RpcRequestTimeoutInSeconds <= 0) 401 | { 402 | throw new Exception("RpcRequestTimeoutInSeconds must be greater than zero"); 403 | } 404 | 405 | if (string.IsNullOrWhiteSpace(DaemonUrl) 406 | || string.IsNullOrWhiteSpace(RpcUsername) 407 | || string.IsNullOrWhiteSpace(RpcPassword)) 408 | { 409 | throw new Exception($"One or more required parameters, as defined in {GetType().Name}, were not found in the configuration file!"); 410 | } 411 | 412 | #endregion 413 | } 414 | 415 | #endregion 416 | 417 | public string BaseUnitName { get; set; } 418 | public uint BaseUnitsPerCoin { get; set; } 419 | public int BlocksHighestPriorityTransactionsReservedSizeInBytes { get; set; } 420 | public int BlockMaximumSizeInBytes { get; set; } 421 | public string CoinShortName { get; set; } 422 | public string CoinLongName { get; set; } 423 | public decimal CoinsPerBaseUnit { get; set; } 424 | public string DaemonUrl { private get; set; } 425 | public string DaemonUrlTestnet { private get; set; } 426 | public double EstimatedBlockGenerationTimeInMinutes { get; set; } 427 | public int ExpectedNumberOfBlocksGeneratedPerDay => (int) EstimatedBlockGenerationTimeInMinutes * GlobalConstants.MinutesInADay; 428 | public decimal FeePerThousandBytesInCoins { get; set; } 429 | public short FreeTransactionMaximumSizeInBytes { get; set; } 430 | public decimal FreeTransactionMinimumOutputAmountInCoins { get; set; } 431 | public int FreeTransactionMinimumPriority { get; set; } 432 | public bool IgnoreConfigFiles { get; } 433 | public string IsoCurrencyCode { get; set; } 434 | public decimal MinimumNonDustTransactionAmountInCoins { get; set; } 435 | public decimal MinimumTransactionFeeInCoins { get; set; } 436 | public decimal OneBaseUnitInCoins => CoinsPerBaseUnit; 437 | public uint OneCoinInBaseUnits => BaseUnitsPerCoin; 438 | public string RpcPassword { get; set; } 439 | public short RpcRequestTimeoutInSeconds { get; set; } 440 | public string RpcUsername { get; set; } 441 | public string SelectedDaemonUrl => !UseTestnet ? DaemonUrl : DaemonUrlTestnet; 442 | public ulong TotalCoinSupplyInCoins { get; set; } 443 | public int TransactionSizeBytesContributedByEachInput { get; set; } 444 | public int TransactionSizeBytesContributedByEachOutput { get; set; } 445 | public int TransactionSizeFixedExtraSizeInBytes { get; set; } 446 | public bool UseTestnet { get; set; } 447 | public string WalletPassword { get; set; } 448 | } 449 | } 450 | } 451 | -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Base/ICoinParameters.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.Services; 5 | 6 | namespace BitcoinLib.CoinParameters.Base 7 | { 8 | public interface ICoinParameters 9 | { 10 | CoinService.CoinParameters Parameters { get; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Bitcoin/BitcoinConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Base; 5 | 6 | namespace BitcoinLib.CoinParameters.Bitcoin 7 | { 8 | public static class BitcoinConstants 9 | { 10 | public sealed class Constants : CoinConstants 11 | { 12 | public readonly int OneBitcoinInSatoshis = 100000000; 13 | public readonly decimal OneSatoshiInBTC = 0.00000001M; 14 | public readonly int SatoshisPerBitcoin = 100000000; 15 | public readonly string Symbol = "฿"; 16 | 17 | #region Custom constructor example - commented out on purpose 18 | 19 | //private static readonly Lazy Lazy = new Lazy(() => new Constants()); 20 | 21 | //public static Constants Instance 22 | //{ 23 | // get 24 | // { 25 | // return Lazy.Value; 26 | // } 27 | //} 28 | 29 | //private Constants() 30 | //{ 31 | // // custom logic here 32 | //} 33 | 34 | #endregion 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Bitcoin/IBitcoinConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.CoinParameters.Bitcoin 5 | { 6 | public interface IBitcoinConstants 7 | { 8 | BitcoinConstants.Constants Constants { get; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Dallar/DallarConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Base; 5 | 6 | namespace BitcoinLib.CoinParameters.Dallar 7 | { 8 | public static class DallarConstants 9 | { 10 | public sealed class Constants : CoinConstants 11 | { 12 | public readonly ushort CoinReleaseReduceEveryXInBlocks = 10080; 13 | public readonly ushort DifficultyIncreasesEveryXInBlocks = 6; 14 | public readonly uint OneDallarInAllars = 100000000; 15 | public readonly decimal OneAllarInDAL = 0.00000001M; 16 | public readonly decimal OneMicroDallarInDAL = 0.000001M; 17 | public readonly decimal OneMilliDallarInDAL = 0.001M; 18 | public readonly string Symbol = "D"; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Dallar/IDallarConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.CoinParameters.Dallar 5 | { 6 | public interface IDallarConstants 7 | { 8 | DallarConstants.Constants Constants { get; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Dash/DashConstants.cs: -------------------------------------------------------------------------------- 1 | using BitcoinLib.CoinParameters.Base; 2 | 3 | namespace BitcoinLib.CoinParameters.Dash 4 | { 5 | public static class DashConstants 6 | { 7 | public sealed class Constants : CoinConstants 8 | { 9 | public readonly ushort CoinReleaseHalfsEveryXInYears = 7; 10 | public readonly ushort DifficultyIncreasesEveryXInBlocks = 34560; 11 | public readonly uint OneDashInDuffs = 100000000; 12 | public readonly decimal OneDuffInDash = 0.00000001M; 13 | public readonly decimal OneMicrodashInDash = 0.000001M; 14 | public readonly decimal OneMillidashInDash = 0.001M; 15 | public readonly string Symbol = "DASH"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Dash/IDashConstants.cs: -------------------------------------------------------------------------------- 1 | namespace BitcoinLib.CoinParameters.Dash 2 | { 3 | public interface IDashConstants 4 | { 5 | DashConstants.Constants Constants { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Dogecoin/DogecoinConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Base; 5 | 6 | namespace BitcoinLib.CoinParameters.Dogecoin 7 | { 8 | public static class DogecoinConstants 9 | { 10 | public sealed class Constants : CoinConstants 11 | { 12 | public readonly ushort CoinReleaseHalfsEveryXInYears = 4; 13 | public readonly ushort DifficultyIncreasesEveryXInBlocks = 2016; 14 | public readonly uint OneDogecoinInKoinus = 100000000; 15 | public readonly decimal OneKoinuInXDG = 0.00000001M; 16 | public readonly decimal OneMicrocoinInXDG = 0.000001M; 17 | public readonly decimal OneMillicoinInXDG = 0.001M; 18 | public readonly string Symbol = "Ð"; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Dogecoin/IDogecoinConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.CoinParameters.Dogecoin 5 | { 6 | public interface IDogecoinConstants 7 | { 8 | DogecoinConstants.Constants Constants { get; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Litecoin/ILitecoinConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.CoinParameters.Litecoin 5 | { 6 | public interface ILitecoinConstants 7 | { 8 | LitecoinConstants.Constants Constants { get; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Litecoin/LitecoinConstants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Base; 5 | 6 | namespace BitcoinLib.CoinParameters.Litecoin 7 | { 8 | public static class LitecoinConstants 9 | { 10 | public sealed class Constants : CoinConstants 11 | { 12 | public readonly ushort CoinReleaseHalfsEveryXInYears = 4; 13 | public readonly ushort DifficultyIncreasesEveryXInBlocks = 2016; 14 | public readonly uint OneLitecoinInLitetoshis = 100000000; 15 | public readonly decimal OneLitetoshiInLTC = 0.00000001M; 16 | public readonly decimal OneMicrocoinInLTC = 0.000001M; 17 | public readonly decimal OneMillicoinInLTC = 0.001M; 18 | public readonly string Symbol = "Ł"; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Mogwaicoin/IMogwaicoinConstants.cs: -------------------------------------------------------------------------------- 1 | namespace BitcoinLib.CoinParameters.Mogwaicoin 2 | { 3 | public interface IMogwaicoinConstants 4 | { 5 | MogwaicoinConstants.Constants Constants { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Mogwaicoin/MogwaicoinConstants.cs: -------------------------------------------------------------------------------- 1 | using BitcoinLib.CoinParameters.Base; 2 | 3 | namespace BitcoinLib.CoinParameters.Mogwaicoin 4 | { 5 | public static class MogwaicoinConstants 6 | { 7 | public sealed class Constants : CoinConstants 8 | { 9 | public readonly ushort CoinReleaseHalfsEveryXInYears = 7; 10 | public readonly ushort DifficultyIncreasesEveryXInBlocks = 34560; 11 | public readonly uint OneDashInDuffs = 100000000; 12 | public readonly decimal OneDuffInDash = 0.00000001M; 13 | public readonly decimal OneMicrodashInDash = 0.000001M; 14 | public readonly decimal OneMillidashInDash = 0.001M; 15 | public readonly string Symbol = "MOG"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Smartcash/ISmartcashConstants.cs: -------------------------------------------------------------------------------- 1 | namespace BitcoinLib.CoinParameters.Smartcash 2 | { 3 | public interface ISmartcashConstants 4 | { 5 | SmartcashConstants.Constants Constants { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/BitcoinLib/CoinParameters/Smartcash/SmartcashConstants.cs: -------------------------------------------------------------------------------- 1 | using BitcoinLib.CoinParameters.Base; 2 | 3 | namespace BitcoinLib.CoinParameters.Smartcash 4 | { 5 | public static class SmartcashConstants 6 | { 7 | public sealed class Constants : CoinConstants 8 | { 9 | public readonly ushort CoinReleaseHalfsEveryXInYears = 4; 10 | public readonly ushort DifficultyIncreasesEveryXInBlocks = 2016; 11 | public readonly uint OneSmartInSmartoshis = 100000000; 12 | public readonly decimal OneSmartoshisInSmart = 0.00000001M; 13 | public readonly decimal OneMicrosmartInSmart = 0.000001M; 14 | public readonly decimal OneMillismartInSmart = 0.001M; 15 | public readonly string Symbol = "SMART"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/BitcoinLib/ExceptionHandling/RawTransactions/RawTransactionExcessiveFeeException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | 6 | namespace BitcoinLib.ExceptionHandling.RawTransactions 7 | { 8 | [Serializable] 9 | public class RawTransactionExcessiveFeeException : Exception 10 | { 11 | public RawTransactionExcessiveFeeException() : base("Fee in raw transaction is greater than specified amount.") 12 | { 13 | } 14 | 15 | public RawTransactionExcessiveFeeException(decimal maxSpecifiedFee) : base($"Fee in raw transaction is greater than specified amount of {maxSpecifiedFee}.") 16 | { 17 | } 18 | 19 | public RawTransactionExcessiveFeeException(decimal actualFee, decimal maxSpecifiedFee) : base($"Fee of {actualFee} in raw transaction is greater than specified amount of {maxSpecifiedFee}.") 20 | { 21 | } 22 | 23 | public RawTransactionExcessiveFeeException(string message) : base(message) 24 | { 25 | } 26 | 27 | public RawTransactionExcessiveFeeException(string message, Exception innerException) : base(message, innerException) 28 | { 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/BitcoinLib/ExceptionHandling/RawTransactions/RawTransactionInvalidAmountException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | 6 | namespace BitcoinLib.ExceptionHandling.RawTransactions 7 | { 8 | [Serializable] 9 | public class RawTransactionInvalidAmountException : Exception 10 | { 11 | public RawTransactionInvalidAmountException() : base("Raw Transaction amount is invalid.") 12 | { 13 | } 14 | 15 | public RawTransactionInvalidAmountException(string message) : base(message) 16 | { 17 | } 18 | 19 | public RawTransactionInvalidAmountException(string message, Exception innerException) : base(message, innerException) 20 | { 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/BitcoinLib/ExceptionHandling/Rpc/RpcException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | 6 | namespace BitcoinLib.ExceptionHandling.Rpc 7 | { 8 | [Serializable] 9 | public class RpcException : Exception 10 | { 11 | public RpcException() 12 | { 13 | } 14 | 15 | public RpcException(string customMessage) : base(customMessage) 16 | { 17 | } 18 | 19 | public RpcException(string customMessage, Exception exception) : base(customMessage, exception) 20 | { 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/BitcoinLib/ExceptionHandling/Rpc/RpcInternalServerErrorException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | using System.Runtime.Serialization; 6 | using BitcoinLib.RPC.Specifications; 7 | 8 | namespace BitcoinLib.ExceptionHandling.Rpc 9 | { 10 | [Serializable] 11 | public class RpcInternalServerErrorException : Exception 12 | { 13 | public RpcInternalServerErrorException() 14 | { 15 | } 16 | 17 | public RpcInternalServerErrorException(string customMessage) : base(customMessage) 18 | { 19 | } 20 | 21 | public RpcInternalServerErrorException(string customMessage, Exception exception) : base(customMessage, exception) 22 | { 23 | } 24 | 25 | public RpcErrorCode? RpcErrorCode { get; set; } 26 | 27 | public override void GetObjectData(SerializationInfo info, StreamingContext context) 28 | { 29 | if (info == null) 30 | { 31 | throw new ArgumentNullException("info"); 32 | } 33 | 34 | info.AddValue("RpcErrorCode", RpcErrorCode, typeof(RpcErrorCode)); 35 | base.GetObjectData(info, context); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/BitcoinLib/ExceptionHandling/Rpc/RpcRequestTimeoutException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | 6 | namespace BitcoinLib.ExceptionHandling.Rpc 7 | { 8 | [Serializable] 9 | public class RpcRequestTimeoutException : Exception 10 | { 11 | public RpcRequestTimeoutException() 12 | { 13 | } 14 | 15 | public RpcRequestTimeoutException(string customMessage) : base(customMessage) 16 | { 17 | } 18 | 19 | public RpcRequestTimeoutException(string customMessage, Exception exception) : base(customMessage, exception) 20 | { 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/BitcoinLib/ExceptionHandling/Rpc/RpcResponseDeserializationException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | 6 | namespace BitcoinLib.ExceptionHandling.Rpc 7 | { 8 | [Serializable] 9 | public class RpcResponseDeserializationException : Exception 10 | { 11 | public RpcResponseDeserializationException() 12 | { 13 | } 14 | 15 | public RpcResponseDeserializationException(string customMessage) : base(customMessage) 16 | { 17 | } 18 | 19 | public RpcResponseDeserializationException(string customMessage, Exception exception) : base(customMessage, exception) 20 | { 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/BitcoinLib/ExceptionHandling/RpcExtenderService/GetAddressBalanceException.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | 6 | namespace BitcoinLib.ExceptionHandling.RpcExtenderService 7 | { 8 | [Serializable] 9 | public class GetAddressBalanceException : Exception 10 | { 11 | public GetAddressBalanceException() 12 | { 13 | } 14 | 15 | public GetAddressBalanceException(string customMessage) : base(customMessage) 16 | { 17 | } 18 | 19 | public GetAddressBalanceException(string customMessage, Exception exception) : base(customMessage, exception) 20 | { 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/BitcoinLib/ExtensionMethods/CoinServiceExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.Services.Coins.Base; 5 | 6 | namespace BitcoinLib.ExtensionMethods 7 | { 8 | public static class CoinServiceExtensionMethods 9 | { 10 | public static void SwitchNetworks(this ICoinService coinService) 11 | { 12 | coinService.Parameters.UseTestnet = !coinService.Parameters.UseTestnet; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/BitcoinLib/ExtensionMethods/DecimalExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | 6 | namespace BitcoinLib.ExtensionMethods 7 | { 8 | public static class DecimalExtensionMethods 9 | { 10 | public static ushort GetNumberOfDecimalPlaces(this decimal number) 11 | { 12 | return BitConverter.GetBytes(decimal.GetBits(number)[3])[2]; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/BitcoinLib/RPC/Connector/IRpcConnector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.RPC.Specifications; 5 | 6 | namespace BitcoinLib.RPC.Connector 7 | { 8 | public interface IRpcConnector 9 | { 10 | T MakeRequest(RpcMethods method, params object[] parameters); 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/RPC/Connector/RawRpcConnector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | using System.IO; 6 | using System.Net; 7 | using System.Text; 8 | using BitcoinLib.Services.Coins.Base; 9 | 10 | namespace BitcoinLib.RPC.Connector 11 | { 12 | // This class is disconnected from the core logic and its sole purpose is to serve as a quick and dirty means of debugging 13 | public static class RawRpcConnector 14 | { 15 | // Usage example: String networkDifficultyJsonResult = RawRpcConnector.MakeRequest("{\"method\":\"getdifficulty\",\"params\":[],\"id\":1}", "http://127.0.0.1:8332/", "MyRpcUsername", "MyRpcPassword"); 16 | public static string MakeRequest(string jsonRequest, string daemonUrl, string rpcUsername, string rpcPassword) 17 | { 18 | try 19 | { 20 | var tempCookies = new CookieContainer(); 21 | var encoding = new ASCIIEncoding(); 22 | var byteData = encoding.GetBytes(jsonRequest); 23 | var postReq = (HttpWebRequest) WebRequest.Create(daemonUrl); 24 | postReq.Credentials = new NetworkCredential(rpcUsername, rpcPassword); 25 | postReq.Method = "POST"; 26 | postReq.KeepAlive = true; 27 | postReq.CookieContainer = tempCookies; 28 | postReq.ContentType = "application/json"; 29 | postReq.ContentLength = byteData.Length; 30 | var postreqstream = postReq.GetRequestStream(); 31 | postreqstream.Write(byteData, 0, byteData.Length); 32 | postreqstream.Close(); 33 | var postresponse = (HttpWebResponse) postReq.GetResponse(); 34 | var postreqreader = new StreamReader(postresponse.GetResponseStream()); 35 | return postreqreader.ReadToEnd(); 36 | } 37 | catch (Exception exception) 38 | { 39 | return exception.ToString(); 40 | } 41 | } 42 | 43 | // Usage example: String networkDifficultyJsonResult = RawRpcConnector.MakeRequest("{\"method\":\"getdifficulty\",\"params\":[],\"id\":1}", new BitcoinService()); 44 | public static string MakeRequest(string jsonRequest, ICoinService coinService) 45 | { 46 | return MakeRequest(jsonRequest, coinService.Parameters.SelectedDaemonUrl, coinService.Parameters.RpcUsername, coinService.Parameters.RpcPassword); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/BitcoinLib/RPC/Connector/RpcConnector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Net; 8 | using System.Text; 9 | using BitcoinLib.Auxiliary; 10 | using BitcoinLib.ExceptionHandling.Rpc; 11 | using BitcoinLib.RPC.RequestResponse; 12 | using BitcoinLib.RPC.Specifications; 13 | using BitcoinLib.Services.Coins.Base; 14 | using Newtonsoft.Json; 15 | 16 | namespace BitcoinLib.RPC.Connector 17 | { 18 | public sealed class RpcConnector : IRpcConnector 19 | { 20 | private readonly ICoinService _coinService; 21 | 22 | public RpcConnector(ICoinService coinService) 23 | { 24 | _coinService = coinService; 25 | } 26 | 27 | public T MakeRequest(RpcMethods rpcMethod, params object[] parameters) 28 | { 29 | var jsonRpcRequest = new JsonRpcRequest(1, rpcMethod.ToString(), parameters); 30 | var webRequest = (HttpWebRequest) WebRequest.Create(_coinService.Parameters.SelectedDaemonUrl); 31 | SetBasicAuthHeader(webRequest, _coinService.Parameters.RpcUsername, _coinService.Parameters.RpcPassword); 32 | webRequest.Credentials = new NetworkCredential(_coinService.Parameters.RpcUsername, _coinService.Parameters.RpcPassword); 33 | webRequest.ContentType = "application/json-rpc"; 34 | webRequest.Method = "POST"; 35 | webRequest.Proxy = null; 36 | webRequest.Timeout = _coinService.Parameters.RpcRequestTimeoutInSeconds * GlobalConstants.MillisecondsInASecond; 37 | var byteArray = jsonRpcRequest.GetBytes(); 38 | webRequest.ContentLength = jsonRpcRequest.GetBytes().Length; 39 | 40 | try 41 | { 42 | using (var dataStream = webRequest.GetRequestStream()) 43 | { 44 | dataStream.Write(byteArray, 0, byteArray.Length); 45 | dataStream.Dispose(); 46 | } 47 | } 48 | catch (Exception exception) 49 | { 50 | throw new RpcException("There was a problem sending the request to the wallet", exception); 51 | } 52 | 53 | try 54 | { 55 | string json; 56 | 57 | using (var webResponse = webRequest.GetResponse()) 58 | { 59 | using (var stream = webResponse.GetResponseStream()) 60 | { 61 | using (var reader = new StreamReader(stream)) 62 | { 63 | var result = reader.ReadToEnd(); 64 | reader.Dispose(); 65 | json = result; 66 | } 67 | } 68 | } 69 | 70 | var rpcResponse = JsonConvert.DeserializeObject>(json); 71 | return rpcResponse.Result; 72 | } 73 | catch (WebException webException) 74 | { 75 | #region RPC Internal Server Error (with an Error Code) 76 | 77 | var webResponse = webException.Response as HttpWebResponse; 78 | 79 | if (webResponse != null) 80 | { 81 | switch (webResponse.StatusCode) 82 | { 83 | case HttpStatusCode.InternalServerError: 84 | { 85 | using (var stream = webResponse.GetResponseStream()) 86 | { 87 | if (stream == null) 88 | { 89 | throw new RpcException("The RPC request was either not understood by the server or there was a problem executing the request", webException); 90 | } 91 | 92 | using (var reader = new StreamReader(stream)) 93 | { 94 | var result = reader.ReadToEnd(); 95 | reader.Dispose(); 96 | 97 | try 98 | { 99 | var jsonRpcResponseObject = JsonConvert.DeserializeObject>(result); 100 | 101 | var internalServerErrorException = new RpcInternalServerErrorException(jsonRpcResponseObject.Error.Message, webException) 102 | { 103 | RpcErrorCode = jsonRpcResponseObject.Error.Code 104 | }; 105 | 106 | throw internalServerErrorException; 107 | } 108 | catch (JsonException) 109 | { 110 | throw new RpcException(result, webException); 111 | } 112 | } 113 | } 114 | } 115 | 116 | default: 117 | throw new RpcException("The RPC request was either not understood by the server or there was a problem executing the request", webException); 118 | } 119 | } 120 | 121 | #endregion 122 | 123 | #region RPC Time-Out 124 | 125 | if (webException.Message == "The operation has timed out") 126 | { 127 | throw new RpcRequestTimeoutException(webException.Message); 128 | } 129 | 130 | #endregion 131 | 132 | throw new RpcException("An unknown web exception occured while trying to read the JSON response", webException); 133 | } 134 | catch (JsonException jsonException) 135 | { 136 | throw new RpcResponseDeserializationException("There was a problem deserializing the response from the wallet", jsonException); 137 | } 138 | catch (ProtocolViolationException protocolViolationException) 139 | { 140 | throw new RpcException("Unable to connect to the server", protocolViolationException); 141 | } 142 | catch (Exception exception) 143 | { 144 | var queryParameters = jsonRpcRequest.Parameters.Cast().Aggregate(string.Empty, (current, parameter) => current + (parameter + " ")); 145 | throw new Exception($"A problem was encountered while calling MakeRpcRequest() for: {jsonRpcRequest.Method} with parameters: {queryParameters}. \nException: {exception.Message}"); 146 | } 147 | } 148 | 149 | private static void SetBasicAuthHeader(WebRequest webRequest, string username, string password) 150 | { 151 | var authInfo = username + ":" + password; 152 | authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); 153 | webRequest.Headers["Authorization"] = "Basic " + authInfo; 154 | } 155 | } 156 | } -------------------------------------------------------------------------------- /src/BitcoinLib/RPC/RequestResponse/JsonRpcError.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.RPC.Specifications; 5 | using Newtonsoft.Json; 6 | 7 | namespace BitcoinLib.RPC.RequestResponse 8 | { 9 | public class JsonRpcError 10 | { 11 | [JsonProperty(PropertyName = "code")] 12 | public RpcErrorCode Code { get; set; } 13 | 14 | [JsonProperty(PropertyName = "message")] 15 | public string Message { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/BitcoinLib/RPC/RequestResponse/JsonRpcRequest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using Newtonsoft.Json; 8 | 9 | namespace BitcoinLib.RPC.RequestResponse 10 | { 11 | public class JsonRpcRequest 12 | { 13 | public JsonRpcRequest(int id, string method, params object[] parameters) 14 | { 15 | Id = id; 16 | Method = method; 17 | Parameters = parameters?.ToList() ?? new List(); 18 | } 19 | 20 | [JsonProperty(PropertyName = "method", Order = 0)] 21 | public string Method { get; set; } 22 | 23 | [JsonProperty(PropertyName = "params", Order = 1)] 24 | public IList Parameters { get; set; } 25 | 26 | [JsonProperty(PropertyName = "id", Order = 2)] 27 | public int Id { get; set; } 28 | 29 | public byte[] GetBytes() 30 | { 31 | var json = JsonConvert.SerializeObject(this); 32 | return Encoding.UTF8.GetBytes(json); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/BitcoinLib/RPC/RequestResponse/JsonRpcResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using Newtonsoft.Json; 5 | 6 | namespace BitcoinLib.RPC.RequestResponse 7 | { 8 | public class JsonRpcResponse 9 | { 10 | [JsonProperty(PropertyName = "result", Order = 0)] 11 | public T Result { get; set; } 12 | 13 | [JsonProperty(PropertyName = "id", Order = 1)] 14 | public int Id { get; set; } 15 | 16 | [JsonProperty(PropertyName = "error", Order = 2)] 17 | public JsonRpcError Error { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /src/BitcoinLib/RPC/Specifications/RpcErrorCode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.RPC.Specifications 5 | { 6 | // As of: https://github.com/bitcoin/bitcoin/blob/master/src/rpcprotocol.h 7 | // Note: Do not alter enum members' capitalization 8 | // Note: It's alright if the enum is not complete (for altcoins etc), the plain rpc error code number will be used instead in RpcInternalServerErrorException() 9 | public enum RpcErrorCode 10 | { 11 | //! Standard JSON-RPC 2.0 errors 12 | RPC_INVALID_REQUEST = -32600, 13 | RPC_METHOD_NOT_FOUND = -32601, 14 | RPC_INVALID_PARAMS = -32602, 15 | RPC_INTERNAL_ERROR = -32603, 16 | RPC_PARSE_ERROR = -32700, 17 | 18 | //! General application defined errors 19 | RPC_MISC_ERROR = -1, //! std::exception thrown in command handling 20 | RPC_FORBIDDEN_BY_SAFE_MODE = -2, //! Server is in safe mode, and command is not allowed in safe mode 21 | RPC_TYPE_ERROR = -3, //! Unexpected type was passed as parameter 22 | RPC_INVALID_ADDRESS_OR_KEY = -5, //! Invalid address or key 23 | RPC_OUT_OF_MEMORY = -7, //! Ran out of memory during operation 24 | RPC_INVALID_PARAMETER = -8, //! Invalid, missing or duplicate parameter 25 | RPC_DATABASE_ERROR = -20, //! Database error 26 | RPC_DESERIALIZATION_ERROR = -22, //! Error parsing or validating structure in raw format 27 | RPC_VERIFY_ERROR = -25, //! General error during transaction or block submission 28 | RPC_VERIFY_REJECTED = -26, //! Transaction or block was rejected by network rules 29 | RPC_VERIFY_ALREADY_IN_CHAIN = -27, //! Transaction already in chain 30 | RPC_IN_WARMUP = -28, //! Client still warming up 31 | 32 | //! Aliases for backward compatibility 33 | RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR, 34 | RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED, 35 | RPC_TRANSACTION_ALREADY_IN_CHAIN = RPC_VERIFY_ALREADY_IN_CHAIN, 36 | 37 | //! P2P client errors 38 | RPC_CLIENT_NOT_CONNECTED = -9, //! Bitcoin is not connected 39 | RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //! Still downloading initial blocks 40 | RPC_CLIENT_NODE_ALREADY_ADDED = -23, //! Node is already added 41 | RPC_CLIENT_NODE_NOT_ADDED = -24, //! Node has not been added before 42 | 43 | //! Wallet errors 44 | RPC_WALLET_ERROR = -4, //! Unspecified problem with wallet (key not found etc.) 45 | RPC_WALLET_INSUFFICIENT_FUNDS = -6, //! Not enough funds in wallet or account 46 | RPC_WALLET_INVALID_ACCOUNT_NAME = -11, //! Invalid account name 47 | RPC_WALLET_KEYPOOL_RAN_OUT = -12, //! Keypool ran out, call keypoolrefill first 48 | RPC_WALLET_UNLOCK_NEEDED = -13, //! Enter the wallet passphrase with walletpassphrase first 49 | RPC_WALLET_PASSPHRASE_INCORRECT = -14, //! The wallet passphrase entered was incorrect 50 | RPC_WALLET_WRONG_ENC_STATE = -15, //! Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.) 51 | RPC_WALLET_ENCRYPTION_FAILED = -16, //! Failed to encrypt the wallet 52 | RPC_WALLET_ALREADY_UNLOCKED = -17, //! Wallet is already unlocked 53 | } 54 | } -------------------------------------------------------------------------------- /src/BitcoinLib/RPC/Specifications/RpcMethods.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.RPC.Specifications 5 | { 6 | // Note: Do not alter the capitalization of the enum members as they are being cast as-is to the RPC server 7 | public enum RpcMethods 8 | { 9 | //== Blockchain == 10 | getbestblockhash, 11 | getblock, 12 | getblockchaininfo, 13 | getblockcount, 14 | getblockhash, 15 | getblockheader, 16 | getchaintips, 17 | getdifficulty, 18 | getmempoolinfo, 19 | getrawmempool, 20 | gettxout, 21 | gettxoutproof, 22 | gettxoutsetinfo, 23 | verifychain, 24 | verifytxoutproof, 25 | 26 | //== Control == 27 | getinfo, 28 | help, 29 | stop, 30 | 31 | //== Generating == 32 | generate, 33 | getgenerate, 34 | setgenerate, 35 | 36 | //== Mining == 37 | getblocktemplate, 38 | getmininginfo, 39 | getnetworkhashps, 40 | prioritisetransaction, 41 | submitblock, 42 | 43 | //== Network == 44 | addnode, 45 | clearbanned, 46 | disconnectnode, 47 | getaddednodeinfo, 48 | getconnectioncount, 49 | getnettotals, 50 | getnetworkinfo, 51 | getpeerinfo, 52 | listbanned, 53 | ping, 54 | setban, 55 | 56 | //== Rawtransactions == 57 | createrawtransaction, 58 | decoderawtransaction, 59 | decodescript, 60 | fundrawtransaction, 61 | getrawtransaction, 62 | sendrawtransaction, 63 | signrawtransaction, 64 | sighashtype, 65 | 66 | //== Util == 67 | createmultisig, 68 | estimatefee, 69 | estimatepriority, 70 | estimatesmartfee, 71 | estimatesmartpriority, 72 | validateaddress, 73 | mirroraddress, 74 | verifymessage, 75 | 76 | //== Wallet == 77 | abandontransaction, 78 | addmultisigaddress, 79 | addwitnessaddress, 80 | backupwallet, 81 | dumpprivkey, 82 | dumpwallet, 83 | getaccount, 84 | getaccountaddress, 85 | getaddressesbyaccount, 86 | getbalance, 87 | getnewaddress, 88 | getrawchangeaddress, 89 | getreceivedbyaccount, 90 | getreceivedbyaddress, 91 | gettransaction, 92 | getunconfirmedbalance, 93 | getwalletinfo, 94 | importaddress, 95 | importprivkey, 96 | importpubkey, 97 | importwallet, 98 | keypoolrefill, 99 | listaccounts, 100 | listaddressgroupings, 101 | listlockunspent, 102 | listreceivedbyaccount, 103 | listreceivedbyaddress, 104 | listsinceblock, 105 | listtransactions, 106 | listmirrtransactions, 107 | listunspent, 108 | lockunspent, 109 | move, 110 | sendfrom, 111 | sendmany, 112 | sendtoaddress, 113 | setaccount, 114 | settxfee, 115 | signmessage, 116 | walletlock, 117 | walletpassphrase, 118 | walletpassphrasechange 119 | } 120 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Requests/AddNode/NodeAction.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Requests.AddNode 5 | { 6 | // Note: Do not alter the capitalization of the enum members as they are being cast as-is to the RPC server 7 | public enum NodeAction 8 | { 9 | add, 10 | remove, 11 | onetry 12 | } 13 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Requests/CreateRawTransaction/CreateRawTransactionInput.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using Newtonsoft.Json; 5 | 6 | namespace BitcoinLib.Requests.CreateRawTransaction 7 | { 8 | public class CreateRawTransactionInput 9 | { 10 | [JsonProperty("txid")] 11 | public string TxId { get; set; } 12 | 13 | [JsonProperty("vout")] 14 | public int Vout { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Requests/CreateRawTransaction/CreateRawTransactionOutput.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Requests.CreateRawTransaction 5 | { 6 | public class CreateRawTransactionOutput 7 | { 8 | public string Address { get; set; } 9 | public decimal Amount { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Requests/CreateRawTransaction/CreateRawTransactionRequest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | namespace BitcoinLib.Requests.CreateRawTransaction 8 | { 9 | public class CreateRawTransactionRequest 10 | { 11 | public CreateRawTransactionRequest() 12 | { 13 | Inputs = new List(); 14 | Outputs = new Dictionary(); 15 | } 16 | 17 | public CreateRawTransactionRequest(IList inputs, IDictionary outputs) : this() 18 | { 19 | Inputs = inputs; 20 | Outputs = outputs; 21 | } 22 | 23 | public IList Inputs { get; } 24 | public IDictionary Outputs { get; } 25 | 26 | public void AddInput(CreateRawTransactionInput input) 27 | { 28 | Inputs.Add(input); 29 | } 30 | 31 | public void AddOutput(CreateRawTransactionOutput output) 32 | { 33 | Outputs.Add(output.Address, output.Amount); 34 | } 35 | 36 | public void AddInput(string txId, int vout) 37 | { 38 | Inputs.Add(new CreateRawTransactionInput 39 | { 40 | TxId = txId, 41 | Vout = vout 42 | }); 43 | } 44 | 45 | public void AddOutput(string address, decimal amount) 46 | { 47 | Outputs.Add(address, amount); 48 | } 49 | 50 | public bool RemoveInput(CreateRawTransactionInput input) 51 | { 52 | return Inputs.Contains(input) && Inputs.Remove(input); 53 | } 54 | 55 | public bool RemoveOutput(CreateRawTransactionOutput output) 56 | { 57 | return RemoveOutput(output.Address, output.Amount); 58 | } 59 | 60 | public bool RemoveInput(string txId, int vout) 61 | { 62 | var input = Inputs.FirstOrDefault(x => x.TxId == txId && x.Vout == vout); 63 | return input != null && Inputs.Remove(input); 64 | } 65 | 66 | public bool RemoveOutput(string address, decimal amount) 67 | { 68 | var outputToBeRemoved = new KeyValuePair(address, amount); 69 | return Outputs.Contains>(outputToBeRemoved) && Outputs.Remove(outputToBeRemoved); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Requests/SignRawTransaction/SigHashType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Requests.SignRawTransaction 5 | { 6 | public static class SigHashType 7 | { 8 | public const string All = "ALL"; 9 | public const string None = "NONE"; 10 | public const string Single = "SINGLE"; 11 | public const string AllAnyoneCanPay = "ALL|ANYONECANPAY"; 12 | public const string NoneAnyoneCanPay = "NONE|ANYONECANPAY"; 13 | public const string SingleAnyoneCanPay = "SINGLE|ANYONECANPAY"; 14 | public const string AllForkId = "ALL|FORKID"; 15 | public const string NoneForkId = "NONE|FORKID"; 16 | public const string SingleForkId = "SINGLE|FORKID"; 17 | public const string ALlForkIdAnyoneCanPay = "ALL|FORKID|ANYONECANPAY"; 18 | public const string NoneForkIdAnyoneCanPay = "NONE|FORKID|ANYONECANPAY"; 19 | public const string SingleForkIdAnyoneCanPay = "SINGLE|FORKID|ANYONECANPAY"; 20 | } 21 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Requests/SignRawTransaction/SignRawTransactionInput.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using Newtonsoft.Json; 5 | 6 | namespace BitcoinLib.Requests.SignRawTransaction 7 | { 8 | public class SignRawTransactionInput 9 | { 10 | [JsonProperty(PropertyName = "txid", Order = 0)] 11 | public string TxId { get; set; } 12 | 13 | [JsonProperty(PropertyName = "vout", Order = 1)] 14 | public int Vout { get; set; } 15 | 16 | [JsonProperty(PropertyName = "scriptPubKey", Order = 2)] 17 | public string ScriptPubKey { get; set; } 18 | 19 | [JsonProperty(PropertyName = "redeemScript", Order = 3)] 20 | public string RedeemScript { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Requests/SignRawTransaction/SignRawTransactionRequest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Requests.SignRawTransaction 7 | { 8 | public class SignRawTransactionRequest 9 | { 10 | public SignRawTransactionRequest(string rawTransactionHex, string sigHashType = "ALL") 11 | { 12 | RawTransactionHex = rawTransactionHex; 13 | Inputs = new List(); 14 | PrivateKeys = new List(); 15 | SigHashType = sigHashType; 16 | } 17 | 18 | public string RawTransactionHex { get; set; } 19 | public List Inputs { get; set; } 20 | public List PrivateKeys { get; set; } 21 | public string SigHashType { get; set; } 22 | 23 | public void AddInput(string txId, int vout, string scriptPubKey, string redeemScript) 24 | { 25 | Inputs.Add(new SignRawTransactionInput 26 | { 27 | TxId = txId, 28 | Vout = vout, 29 | ScriptPubKey = scriptPubKey, 30 | RedeemScript = redeemScript 31 | }); 32 | } 33 | 34 | public void AddInput(SignRawTransactionInput signRawTransactionInput) 35 | { 36 | Inputs.Add(signRawTransactionInput); 37 | } 38 | 39 | public void AddKey(string privateKey) 40 | { 41 | PrivateKeys.Add(privateKey); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/Bridges/ITransactionResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses.Bridges 5 | { 6 | // Note: This serves as a common interface for the cases that a strongly-typed response is required while it is not yet clear whether the transaction in question is in-wallet or not 7 | // A practical example is the bridging of GetTransaction(), DecodeRawTransaction() and GetRawTransaction() 8 | public interface ITransactionResponse 9 | { 10 | string TxId { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/CreateMultiSigResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class CreateMultiSigResponse 7 | { 8 | public string Address { get; set; } 9 | public string RedeemScript { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/DecodeRawTransactionResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | using BitcoinLib.Responses.Bridges; 6 | using BitcoinLib.Responses.SharedComponents; 7 | 8 | namespace BitcoinLib.Responses 9 | { 10 | public class DecodeRawTransactionResponse : ITransactionResponse 11 | { 12 | public string Version { get; set; } 13 | public string LockTime { get; set; } 14 | public List Vin { get; set; } 15 | public List Vout { get; set; } 16 | public string TxId { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/DecodeScriptResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class DecodeScriptResponse 7 | { 8 | public string Asm { get; set; } 9 | public string P2SH { get; set; } 10 | public string Type { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/EstimateSmartFeeResponse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace BitcoinLib.Responses 4 | { 5 | public class EstimateSmartFeeResponse 6 | { 7 | public decimal? FeeRate { get; set; } 8 | public uint? Blocks { get; set; } 9 | public IList Errors { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetAddedNodeInfoResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Responses 7 | { 8 | public class GetAddedNodeInfoResponse 9 | { 10 | public string AddedNode { get; set; } 11 | public bool Connected { get; set; } 12 | public List Addresses { get; set; } 13 | } 14 | 15 | public class NodeAddress 16 | { 17 | public string Address { get; set; } 18 | public bool Connected { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetBlockResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Responses 7 | { 8 | public class GetBlockResponse 9 | { 10 | public GetBlockResponse() 11 | { 12 | Tx = new List(); 13 | } 14 | 15 | public List Tx { get; set; } 16 | public string Hash { get; set; } 17 | public int Confirmations { get; set; } 18 | public int Size { get; set; } 19 | public int Height { get; set; } 20 | public int Version { get; set; } 21 | public string MerkleRoot { get; set; } 22 | public double Difficulty { get; set; } 23 | public string ChainWork { get; set; } 24 | public string PreviousBlockHash { get; set; } 25 | public string NextBlockHash { get; set; } 26 | public string Bits { get; set; } 27 | public int Time { get; set; } 28 | public string Nonce { get; set; } 29 | } 30 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetBlockTemplateResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Responses 7 | { 8 | public class GetBlockTemplateResponse 9 | { 10 | public int Version { get; set; } 11 | public string PreviousBlockHash { get; set; } 12 | public List Transactions { get; set; } 13 | public GetBlockTemplateCoinbaseAux CoinbaseAux { get; set; } 14 | public long CoinbaseValue { get; set; } 15 | public string Target { get; set; } 16 | public int MinTime { get; set; } 17 | public List Mutable { get; set; } 18 | public string NonceRange { get; set; } 19 | public int SigopLimit { get; set; } 20 | public int SizeLimit { get; set; } 21 | public uint CurTime { get; set; } 22 | public string Bits { get; set; } 23 | public int Height { get; set; } 24 | } 25 | 26 | public class GetBlockTemplateCoinbaseAux 27 | { 28 | public string Flags { get; set; } 29 | } 30 | 31 | public class GetBlockTemplateTransaction 32 | { 33 | public string Data { get; set; } 34 | public string Hash { get; set; } 35 | public List Depends { get; set; } 36 | public int Fee { get; set; } 37 | public int Sigops { get; set; } 38 | } 39 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetBlockchainInfoResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class GetBlockchainInfoResponse 7 | { 8 | public string Chain { get; set; } 9 | public ulong Blocks { get; set; } 10 | public ulong Headers { get; set; } 11 | public string BestBlockHash { get; set; } 12 | public double Difficulty { get; set; } 13 | public double VerificationProgress { get; set; } 14 | public string ChainWork { get; set; } 15 | public bool Pruned { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetChainTipsResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class GetChainTipsResponse 7 | { 8 | public uint Height { get; set; } 9 | public string Hash { get; set; } 10 | public int BranchLen { get; set; } 11 | public string Status { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetFundRawTransactionResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BitcoinLib.Responses 6 | { 7 | public class GetFundRawTransactionResponse 8 | { 9 | public string Hex { get; set; } 10 | public decimal Fee { get; set; } 11 | public int ChangePos { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetInfoResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using Newtonsoft.Json; 5 | 6 | namespace BitcoinLib.Responses 7 | { 8 | public class GetInfoResponse 9 | { 10 | public string Version { get; set; } 11 | public string ProtocolVersion { get; set; } 12 | public string WalletVersion { get; set; } 13 | public decimal Balance { get; set; } 14 | public double Blocks { get; set; } 15 | public double TimeOffset { get; set; } 16 | public double Connections { get; set; } 17 | public string Proxy { get; set; } 18 | public double Difficulty { get; set; } 19 | public bool Testnet { get; set; } 20 | public double KeyPoolEldest { get; set; } 21 | public double KeyPoolSize { get; set; } 22 | 23 | [JsonProperty("unlocked_until")] 24 | public ulong UnlockedUntil { get; set; } 25 | 26 | public decimal PayTxFee { get; set; } 27 | public decimal RelayTxFee { get; set; } 28 | public string Errors { get; set; } 29 | } 30 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetMemPoolInfoResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class GetMemPoolInfoResponse 7 | { 8 | public uint Size { get; set; } 9 | public ulong Bytes { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetMiningInfoResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class GetMiningInfoResponse 7 | { 8 | public int Blocks { get; set; } 9 | public int CurrentBockSize { get; set; } 10 | public int CurrentBlockTx { get; set; } 11 | public double Difficulty { get; set; } 12 | public string Errors { get; set; } 13 | public int GenProcLimit { get; set; } 14 | public long NetworkHashPS { get; set; } 15 | public int PooledTx { get; set; } 16 | public bool Testnet { get; set; } 17 | public string Chain { get; set; } 18 | public bool Generate { get; set; } 19 | public long HashesPerSec { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetNetTotalsResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class GetNetTotalsResponse 7 | { 8 | public ulong TotalBytesRecv { get; set; } 9 | public ulong TotalBytesSent { get; set; } 10 | public ulong TimeMillis { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetNetworkInfoResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Responses 7 | { 8 | public class GetNetworkInfoResponse 9 | { 10 | public uint Version { get; set; } 11 | public string Subversion { get; set; } 12 | public uint ProtocolVersion { get; set; } 13 | public string LocalServices { get; set; } 14 | public int TimeOffset { get; set; } 15 | public uint Connections { get; set; } 16 | public IList Networks { get; set; } 17 | public decimal RelayFee { get; set; } 18 | public IList LocalAddresses { get; set; } 19 | } 20 | 21 | public class LocalAddress 22 | { 23 | public string Address { get; set; } 24 | public ushort Port { get; set; } 25 | public int Score { get; set; } 26 | } 27 | 28 | public class Network 29 | { 30 | public string Name { get; set; } 31 | public bool Limited { get; set; } 32 | public bool Reachable { get; set; } 33 | public string Proxy { get; set; } 34 | } 35 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetPeerInfoResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | using Newtonsoft.Json; 6 | 7 | namespace BitcoinLib.Responses 8 | { 9 | public class GetPeerInfoResponse 10 | { 11 | public uint Id { get; set; } 12 | public string Addr { get; set; } 13 | public string AddrLocal { get; set; } 14 | public string Services { get; set; } 15 | public int LastSend { get; set; } 16 | public int LastRecv { get; set; } 17 | public int BytesSent { get; set; } 18 | public int BytesRecv { get; set; } 19 | public int ConnTime { get; set; } 20 | public double PingTime { get; set; } 21 | public double Version { get; set; } 22 | public string SubVer { get; set; } 23 | public bool Inbound { get; set; } 24 | public int StartingHeight { get; set; } 25 | public int BanScore { get; set; } 26 | 27 | [JsonProperty("synced_headers")] 28 | public int SyncedHeaders { get; set; } 29 | 30 | [JsonProperty("synced_blocks")] 31 | public int SyncedBlocks { get; set; } 32 | 33 | public IList InFlight { get; set; } 34 | public bool WhiteListed { get; set; } 35 | } 36 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetRawMemPoolResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Responses 7 | { 8 | public class GetRawMemPoolResponse 9 | { 10 | public GetRawMemPoolResponse() 11 | { 12 | TxIds = new List(); 13 | VerboseResponses = new List(); 14 | } 15 | 16 | public IList TxIds { get; set; } 17 | public bool IsVerbose { get; set; } 18 | public IList VerboseResponses { get; set; } 19 | } 20 | 21 | public class GetRawMemPoolVerboseResponse 22 | { 23 | public GetRawMemPoolVerboseResponse() 24 | { 25 | Depends = new List(); 26 | } 27 | 28 | public string TxId { get; set; } 29 | public int? Size { get; set; } 30 | public decimal? Fee { get; set; } 31 | public int? Time { get; set; } 32 | public int? Height { get; set; } 33 | public double? StartingPriority { get; set; } 34 | public double? CurrentPriority { get; set; } 35 | public IList Depends { get; set; } 36 | } 37 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetRawTransactionResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | using BitcoinLib.Responses.Bridges; 6 | using BitcoinLib.Responses.SharedComponents; 7 | 8 | namespace BitcoinLib.Responses 9 | { 10 | public class GetRawTransactionResponse : ITransactionResponse 11 | { 12 | public string Hex { get; set; } 13 | public long Version { get; set; } 14 | public uint LockTime { get; set; } 15 | public List Vin { get; set; } 16 | public List Vout { get; set; } 17 | public string BlockHash { get; set; } 18 | public int Confirmations { get; set; } 19 | public uint Time { get; set; } 20 | public uint BlockTime { get; set; } 21 | public string TxId { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetTransactionResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | using BitcoinLib.Responses.Bridges; 6 | 7 | namespace BitcoinLib.Responses 8 | { 9 | // Note: Local wallet transactions only 10 | public class GetTransactionResponse : ITransactionResponse 11 | { 12 | public decimal Amount { get; set; } 13 | public decimal Fee { get; set; } 14 | public string BlockHash { get; set; } 15 | public int BlockIndex { get; set; } 16 | public int BlockTime { get; set; } 17 | public int Confirmations { get; set; } 18 | public List Details { get; set; } 19 | public string Hex { get; set; } 20 | public int Time { get; set; } 21 | public int TimeReceived { get; set; } 22 | public List WalletConflicts { get; set; } 23 | public string TxId { get; set; } 24 | } 25 | 26 | public class GetTransactionResponseDetails 27 | { 28 | public string Account { get; set; } 29 | public string Address { get; set; } 30 | public decimal Amount { get; set; } 31 | public string Label { get; set; } 32 | public decimal Fee { get; set; } 33 | public int Vout { get; set; } 34 | public string Category { get; set; } 35 | } 36 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetTxOutSetInfoResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class GetTxOutSetInfoResponse 7 | { 8 | public int Height { get; set; } 9 | public string BestBlock { get; set; } 10 | public int Transactions { get; set; } 11 | public int TxOuts { get; set; } 12 | public int BytesSerialized { get; set; } 13 | public string HashSerialized { get; set; } 14 | public double TotalAmount { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/GetWalletInfoResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using Newtonsoft.Json; 5 | 6 | namespace BitcoinLib.Responses 7 | { 8 | public class GetWalletInfoResponse 9 | { 10 | public string WalletVersion { get; set; } 11 | public decimal Balance { get; set; } 12 | 13 | [JsonProperty("unconfirmed_balance")] 14 | public decimal UnconfirmedBalance { get; set; } 15 | 16 | [JsonProperty("immature_balance")] 17 | public decimal ImmatureBalance { get; set; } 18 | 19 | public ulong TxCount { get; set; } 20 | public double KeyPoolOldest { get; set; } 21 | 22 | [JsonProperty("unlocked_until")] 23 | public ulong UnlockedUntil { get; set; } 24 | 25 | public ulong KeyPoolSize { get; set; } 26 | } 27 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/ListAddressGroupingsResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class ListAddressGroupingsResponse 7 | { 8 | public string Address { get; set; } 9 | public decimal Balance { get; set; } 10 | public string Account { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/ListReceivedByAccountResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class ListReceivedByAccountResponse 7 | { 8 | public string Account { get; set; } 9 | public double Amount { get; set; } 10 | public int Confirmations { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/ListReceivedByAddressResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Responses 7 | { 8 | public class ListReceivedByAddressResponse 9 | { 10 | public string Account { get; set; } 11 | public string Address { get; set; } 12 | public decimal Amount { get; set; } 13 | public int Confirmations { get; set; } 14 | public List TxIds { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/ListSinceBlockResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Responses 7 | { 8 | public class ListSinceBlockResponse 9 | { 10 | public List Transactions { get; set; } 11 | public string Lastblock { get; set; } 12 | } 13 | 14 | public class TransactionSinceBlock 15 | { 16 | public string Account { get; set; } 17 | public string Address { get; set; } 18 | public string Category { get; set; } 19 | public decimal Amount { get; set; } 20 | public int Vout { get; set; } 21 | public decimal Fee { get; set; } 22 | public int Confirmations { get; set; } 23 | public string BlockHash { get; set; } 24 | public long BlockIndex { get; set; } 25 | public int BlockTime { get; set; } 26 | public string TxId { get; set; } 27 | public List WalletConflicts { get; set; } 28 | public int Time { get; set; } 29 | public int TimeReceived { get; set; } 30 | public string Comment { get; set; } 31 | public string To { get; set; } 32 | public bool InvolvesWatchonly { get; set; } 33 | } 34 | 35 | // Note: Do not alter the capitalization of the enum members 36 | public enum TransactionSinceBlockCategory 37 | { 38 | send, 39 | receive, 40 | generate, 41 | immature 42 | } 43 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/ListTransactionsResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Responses 7 | { 8 | public class ListTransactionsResponse 9 | { 10 | public string Account { get; set; } 11 | public string Address { get; set; } 12 | public string Category { get; set; } 13 | public decimal Amount { get; set; } 14 | public string Label { get; set; } 15 | public int Vout { get; set; } 16 | public decimal Fee { get; set; } 17 | public int Confirmations { get; set; } 18 | public string BlockHash { get; set; } 19 | public double BlockIndex { get; set; } 20 | public double BlockTime { get; set; } 21 | public string TxId { get; set; } 22 | public List WalletConflicts { get; set; } 23 | public double Time { get; set; } 24 | public double TimeReceived { get; set; } 25 | public string Comment { get; set; } 26 | public string OtherAccount { get; set; } 27 | public bool InvolvesWatchonly { get; set; } 28 | } 29 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/ListUnspentResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class ListUnspentResponse 7 | { 8 | public string TxId { get; set; } 9 | public int Vout { get; set; } 10 | public string Address { get; set; } 11 | public string Account { get; set; } 12 | public string ScriptPubKey { get; set; } 13 | public decimal Amount { get; set; } 14 | public int Confirmations { get; set; } 15 | public bool Spendable { get; set; } 16 | 17 | public override string ToString() 18 | { 19 | return $"Account: {Account}, Address: {Address}, Amount: {Amount}, Confirmations: {Confirmations}"; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/SharedComponents/Vin.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses.SharedComponents 5 | { 6 | public class Vin 7 | { 8 | public string TxId { get; set; } 9 | public string Vout { get; set; } 10 | public ScriptSig ScriptSig { get; set; } 11 | public string CoinBase { get; set; } 12 | public string Sequence { get; set; } 13 | } 14 | 15 | public class ScriptSig 16 | { 17 | public string Asm { get; set; } 18 | public string Hex { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/SharedComponents/Vout.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Responses.SharedComponents 7 | { 8 | public class Vout 9 | { 10 | public decimal Value { get; set; } 11 | public int N { get; set; } 12 | public ScriptPubKey ScriptPubKey { get; set; } 13 | } 14 | 15 | public class ScriptPubKey 16 | { 17 | public string Asm { get; set; } 18 | public string Hex { get; set; } 19 | public int ReqSigs { get; set; } 20 | public string Type { get; set; } 21 | public List Addresses { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/SignRawTransactionResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class SignRawTransactionResponse 7 | { 8 | public string Hex { get; set; } 9 | public bool Complete { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Responses/ValidateAddressResponse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Responses 5 | { 6 | public class ValidateAddressResponse 7 | { 8 | public bool IsValid { get; set; } 9 | public string Address { get; set; } 10 | public bool IsMine { get; set; } 11 | public bool IsScript { get; set; } 12 | public string PubKey { get; set; } 13 | public bool IsCompressed { get; set; } 14 | public string Account { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Base/ICoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Base; 5 | using BitcoinLib.Services.RpcServices.RpcExtenderService; 6 | using BitcoinLib.Services.RpcServices.RpcService; 7 | 8 | namespace BitcoinLib.Services.Coins.Base 9 | { 10 | public interface ICoinService : IRpcService, IRpcExtenderService, ICoinParameters 11 | { 12 | } 13 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Bitcoin/BitcoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Bitcoin; 5 | 6 | namespace BitcoinLib.Services.Coins.Bitcoin 7 | { 8 | public class BitcoinService : CoinService, IBitcoinService 9 | { 10 | public BitcoinService(bool useTestnet = false) : base(useTestnet) 11 | { 12 | } 13 | 14 | public BitcoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword) 15 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword) 16 | { 17 | } 18 | 19 | public BitcoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, short rpcRequestTimeoutInSeconds) 20 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds) 21 | { 22 | } 23 | 24 | public BitcoinConstants.Constants Constants => BitcoinConstants.Constants.Instance; 25 | } 26 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Bitcoin/IBitcoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Bitcoin; 5 | using BitcoinLib.Services.Coins.Base; 6 | 7 | namespace BitcoinLib.Services.Coins.Bitcoin 8 | { 9 | public interface IBitcoinService : ICoinService, IBitcoinConstants 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Cryptocoin/CryptocoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Services.Coins.Cryptocoin 5 | { 6 | public class CryptocoinService : CoinService, ICryptocoinService 7 | { 8 | public CryptocoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword) 9 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword) 10 | { 11 | } 12 | 13 | public CryptocoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, short rpcRequestTimeoutInSeconds) 14 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds) 15 | { 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Cryptocoin/ICryptocoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.Services.Coins.Base; 5 | 6 | namespace BitcoinLib.Services.Coins.Cryptocoin 7 | { 8 | public interface ICryptocoinService : ICoinService 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Dallar/DallarService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Dallar; 5 | using BitcoinLib.Requests.CreateRawTransaction; 6 | using BitcoinLib.Responses; 7 | using BitcoinLib.RPC.Specifications; 8 | 9 | namespace BitcoinLib.Services.Coins.Dallar 10 | { 11 | public class DallarService : CoinService, IDallarService 12 | { 13 | public DallarService(bool useTestnet = false) : base(useTestnet) 14 | { 15 | } 16 | 17 | public DallarService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword = null) 18 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword) 19 | { 20 | } 21 | 22 | public DallarService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, short rpcRequestTimeoutInSeconds) 23 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds) 24 | { 25 | } 26 | 27 | public DallarConstants.Constants Constants => DallarConstants.Constants.Instance; 28 | 29 | public GetFundRawTransactionResponse GetFundRawTransaction(string rawTransactionHex) 30 | { 31 | return _rpcConnector.MakeRequest(RpcMethods.fundrawtransaction, rawTransactionHex); 32 | } 33 | 34 | public decimal GetEstimateFeeForSendToAddress(string Address, decimal Amount) 35 | { 36 | var txRequest = new CreateRawTransactionRequest(); 37 | txRequest.AddOutput(Address, Amount); 38 | return GetFundRawTransaction(CreateRawTransaction(txRequest)).Fee; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Dallar/IDallarService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Dallar; 5 | using BitcoinLib.Responses; 6 | using BitcoinLib.Services.Coins.Base; 7 | 8 | namespace BitcoinLib.Services.Coins.Dallar 9 | { 10 | public interface IDallarService : ICoinService, IDallarConstants 11 | { 12 | GetFundRawTransactionResponse GetFundRawTransaction(string rawTransactionHex); 13 | decimal GetEstimateFeeForSendToAddress(string Address, decimal Amount); 14 | } 15 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Dash/DashService.cs: -------------------------------------------------------------------------------- 1 | using BitcoinLib.CoinParameters.Dash; 2 | using BitcoinLib.RPC.Specifications; 3 | 4 | namespace BitcoinLib.Services.Coins.Dash 5 | { 6 | public class DashService : CoinService, IDashService 7 | { 8 | public DashService(bool useTestnet = false) : base(useTestnet) 9 | { 10 | } 11 | 12 | public DashService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword) 13 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword) 14 | { 15 | } 16 | 17 | public DashService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, 18 | short rpcRequestTimeoutInSeconds) 19 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds) 20 | { 21 | } 22 | 23 | /// 24 | public string SendToAddress(string dashAddress, decimal amount, string comment = null, string commentTo = null, 25 | bool subtractFeeFromAmount = false, bool useInstantSend = false, bool usePrivateSend = false) 26 | { 27 | return _rpcConnector.MakeRequest(RpcMethods.sendtoaddress, dashAddress, amount, comment, commentTo, 28 | subtractFeeFromAmount, useInstantSend, usePrivateSend); 29 | } 30 | 31 | public DashConstants.Constants Constants => DashConstants.Constants.Instance; 32 | } 33 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Dash/IDashService.cs: -------------------------------------------------------------------------------- 1 | using BitcoinLib.CoinParameters.Dash; 2 | using BitcoinLib.Services.Coins.Base; 3 | 4 | namespace BitcoinLib.Services.Coins.Dash 5 | { 6 | public interface IDashService : ICoinService, IDashConstants 7 | { 8 | /// 9 | /// Send an amount to a given address. 10 | /// 11 | /// The dash address to send to. 12 | /// The amount in DASH to send. eg 0.1. 13 | /// 14 | /// A comment used to store what the transaction is for. This is not part of the transaction, 15 | /// just kept in your wallet. 16 | /// 17 | /// 18 | /// A comment to store the name of the person or organization to which you're sending the 19 | /// transaction. This is not part of the transaction, just kept in your wallet. 20 | /// 21 | /// 22 | /// The fee will be deducted from the amount being sent. The recipient will receive 23 | /// less amount of Dash than you enter in the amount field. 24 | /// 25 | /// Send this transaction as InstantSend. 26 | /// Use anonymized funds only. 27 | /// The transaction id. 28 | string SendToAddress(string dashAddress, decimal amount, string comment = null, 29 | string commentTo = null, bool subtractFeeFromAmount = false, bool useInstantSend = false, 30 | bool usePrivateSend = false); 31 | } 32 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Dogecoin/DogecoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Dogecoin; 5 | 6 | namespace BitcoinLib.Services.Coins.Dogecoin 7 | { 8 | public class DogecoinService : CoinService, IDogecoinService 9 | { 10 | public DogecoinService(bool useTestnet = false) : base(useTestnet) 11 | { 12 | } 13 | 14 | public DogecoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword) 15 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword) 16 | { 17 | } 18 | 19 | public DogecoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, short rpcRequestTimeoutInSeconds) 20 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds) 21 | { 22 | } 23 | 24 | public DogecoinConstants.Constants Constants => DogecoinConstants.Constants.Instance; 25 | } 26 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Dogecoin/IDogecoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Dogecoin; 5 | using BitcoinLib.Services.Coins.Base; 6 | 7 | namespace BitcoinLib.Services.Coins.Dogecoin 8 | { 9 | public interface IDogecoinService : ICoinService, IDogecoinConstants 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Litecoin/ILitecoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Litecoin; 5 | using BitcoinLib.Services.Coins.Base; 6 | 7 | namespace BitcoinLib.Services.Coins.Litecoin 8 | { 9 | public interface ILitecoinService : ICoinService, ILitecoinConstants 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Litecoin/LitecoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Litecoin; 5 | 6 | namespace BitcoinLib.Services.Coins.Litecoin 7 | { 8 | public class LitecoinService : CoinService, ILitecoinService 9 | { 10 | public LitecoinService(bool useTestnet = false) : base(useTestnet) 11 | { 12 | } 13 | 14 | public LitecoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword = null) 15 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword) 16 | { 17 | } 18 | 19 | public LitecoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, short rpcRequestTimeoutInSeconds) 20 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds) 21 | { 22 | } 23 | 24 | public LitecoinConstants.Constants Constants => LitecoinConstants.Constants.Instance; 25 | } 26 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Mogwaicoin/IMogwaicoinService.cs: -------------------------------------------------------------------------------- 1 | using BitcoinLib.CoinParameters.Mogwaicoin; 2 | using BitcoinLib.Services.Coins.Base; 3 | using System.Collections.Generic; 4 | 5 | namespace BitcoinLib.Services.Coins.Mogwaicoin 6 | { 7 | public interface IMogwaicoinService : ICoinService, IMogwaicoinConstants 8 | { 9 | /// 10 | /// Send an amount to a given address. 11 | /// 12 | /// The mogwai address to send to. 13 | /// The amount in MOG to send. eg 0.1. 14 | /// 15 | /// A comment used to store what the transaction is for. This is not part of the transaction, 16 | /// just kept in your wallet. 17 | /// 18 | /// 19 | /// A comment to store the name of the person or organization to which you're sending the 20 | /// transaction. This is not part of the transaction, just kept in your wallet. 21 | /// 22 | /// 23 | /// The fee will be deducted from the amount being sent. The recipient will receive 24 | /// less amount of Dash than you enter in the amount field. 25 | /// 26 | /// Send this transaction as InstantSend. 27 | /// Use anonymized funds only. 28 | /// The transaction id. 29 | string SendToAddress(string dashAddress, decimal amount, string comment = null, 30 | string commentTo = null, bool subtractFeeFromAmount = false, bool useInstantSend = false, 31 | bool usePrivateSend = false); 32 | 33 | /// 34 | /// Get MirrorAddress 35 | /// 36 | /// The mogwai address to send to. 37 | /// 38 | MirrorAddressResponse MirrorAddress(string mogwaiAddress); 39 | 40 | /// 41 | /// Get transactions sent to MirrorAddress 42 | /// 43 | /// The mogwai address to send to. 44 | /// 45 | List ListMirrorTransactions(string mogwaiAddress); 46 | } 47 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Mogwaicoin/MogwaicoinService.cs: -------------------------------------------------------------------------------- 1 | using BitcoinLib.CoinParameters.Mogwaicoin; 2 | using BitcoinLib.Responses; 3 | using BitcoinLib.RPC.Specifications; 4 | using System.Collections.Generic; 5 | 6 | namespace BitcoinLib.Services.Coins.Mogwaicoin 7 | { 8 | public class MogwaicoinService : CoinService, IMogwaicoinService 9 | { 10 | public MogwaicoinService(bool useTestnet = false) : base(useTestnet) 11 | { 12 | } 13 | 14 | public MogwaicoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword) 15 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword) 16 | { 17 | } 18 | 19 | public MogwaicoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, 20 | short rpcRequestTimeoutInSeconds) 21 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds) 22 | { 23 | } 24 | 25 | /// 26 | public string SendToAddress(string mogwaiAddress, decimal amount, string comment = null, string commentTo = null, 27 | bool subtractFeeFromAmount = false, bool useInstantSend = false, bool usePrivateSend = false) 28 | { 29 | return _rpcConnector.MakeRequest(RpcMethods.sendtoaddress, mogwaiAddress, amount, comment, commentTo, 30 | subtractFeeFromAmount, useInstantSend, usePrivateSend); 31 | } 32 | 33 | public MirrorAddressResponse MirrorAddress(string mogwaiAddress) 34 | { 35 | return _rpcConnector.MakeRequest(RpcMethods.mirroraddress, mogwaiAddress); 36 | } 37 | 38 | public List ListMirrorTransactions(string mogwaiAddress) 39 | { 40 | return _rpcConnector.MakeRequest>(RpcMethods.listmirrtransactions, mogwaiAddress); 41 | } 42 | 43 | public MogwaicoinConstants.Constants Constants => MogwaicoinConstants.Constants.Instance; 44 | } 45 | 46 | public class MirrorAddressResponse 47 | { 48 | public bool IsValid { get; set; } 49 | public string Address { get; set; } 50 | public bool IsMine { get; set; } 51 | public bool IsScript { get; set; } 52 | public string PubKey { get; set; } 53 | public bool IsCompressed { get; set; } 54 | public string MirKey { get; set; } 55 | public bool MirKeyValid { get; set; } 56 | public bool IsMirAddrValid { get; set; } 57 | public string MirAddress { get; set; } 58 | } 59 | 60 | public class ListMirrorTransactionsResponse 61 | { 62 | public string Address { get; set; } 63 | public string Category { get; set; } 64 | public decimal Amount { get; set; } 65 | public int Vout { get; set; } 66 | public decimal Fee { get; set; } 67 | public int Confirmations { get; set; } 68 | public bool Instantlock { get; set; } 69 | public bool Generated { get; set; } 70 | public bool Trusted { get; set; } 71 | public string BlockHash { get; set; } 72 | public double BlockIndex { get; set; } 73 | public double BlockTime { get; set; } 74 | public string TxId { get; set; } 75 | public double Time { get; set; } 76 | public double TimeReceived { get; set; } 77 | public bool Abandoned { get; set; } 78 | } 79 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Sarcoin/ISarcoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.Services.Coins.Base; 5 | 6 | namespace BitcoinLib.Services.Coins.Sarcoin 7 | { 8 | public interface ISarcoinService : ICoinService 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Sarcoin/SarcoinService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | namespace BitcoinLib.Services.Coins.Sarcoin 5 | { 6 | public class SarcoinService : CoinService, ISarcoinService 7 | { 8 | public SarcoinService(bool useTestnet = false) : base(useTestnet) 9 | { 10 | } 11 | 12 | public SarcoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword) 13 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword) 14 | { 15 | } 16 | 17 | public SarcoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, short rpcRequestTimeoutInSeconds) 18 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds) 19 | { 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Smartcash/ISmartcashService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Smartcash; 5 | using BitcoinLib.Services.Coins.Base; 6 | 7 | namespace BitcoinLib.Services.Coins.Smartcash 8 | { 9 | public interface ISmartcashService : ICoinService, ISmartcashConstants 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/Coins/Smartcash/SmartcashService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using BitcoinLib.CoinParameters.Smartcash; 5 | 6 | namespace BitcoinLib.Services.Coins.Smartcash 7 | { 8 | public class SmartcashService : CoinService, ISmartcashService 9 | { 10 | public SmartcashService(bool useTestnet = false) : base(useTestnet) 11 | { 12 | } 13 | 14 | public SmartcashService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword = null) 15 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword) 16 | { 17 | } 18 | 19 | public SmartcashService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, short rpcRequestTimeoutInSeconds) 20 | : base(daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds) 21 | { 22 | } 23 | 24 | public SmartcashConstants.Constants Constants => SmartcashConstants.Constants.Instance; 25 | } 26 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/RpcServices/RpcExtenderService/IRpcExtenderService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | using BitcoinLib.Requests.CreateRawTransaction; 6 | using BitcoinLib.Responses; 7 | 8 | namespace BitcoinLib.Services.RpcServices.RpcExtenderService 9 | { 10 | public interface IRpcExtenderService 11 | { 12 | decimal GetAddressBalance(string inWalletAddress, int minConf = 0, bool validateAddressBeforeProcessing = true); 13 | decimal GetMinimumNonZeroTransactionFeeEstimate(short numberOfInputs = 1, short numberOfOutputs = 1); 14 | Dictionary GetMyPublicAndPrivateKeyPairs(); 15 | DecodeRawTransactionResponse GetPublicTransaction(string txId); 16 | decimal GetTransactionFee(CreateRawTransactionRequest createRawTransactionRequest, bool checkIfTransactionQualifiesForFreeRelay = true, bool enforceMinimumTransactionFeePolicy = true); 17 | decimal GetTransactionPriority(CreateRawTransactionRequest createRawTransactionRequest); 18 | decimal GetTransactionPriority(IList transactionInputs, int numberOfOutputs); 19 | string GetTransactionSenderAddress(string txId); 20 | int GetTransactionSizeInBytes(CreateRawTransactionRequest createRawTransactionRequest); 21 | int GetTransactionSizeInBytes(int numberOfInputs, int numberOfOutputs); 22 | GetRawTransactionResponse GetRawTxFromImmutableTxId(string rigidTxId, int listTransactionsCount = int.MaxValue, int listTransactionsFrom = 0, bool getRawTransactionVersbose = true, bool rigidTxIdIsSha256 = false); 23 | string GetImmutableTxId(string txId, bool getSha256Hash = false); 24 | bool IsInWalletTransaction(string txId); 25 | bool IsTransactionFree(CreateRawTransactionRequest createRawTransactionRequest); 26 | bool IsTransactionFree(IList transactionInputs, int numberOfOutputs, decimal minimumAmountAmongOutputs); 27 | bool IsWalletEncrypted(); 28 | } 29 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/RpcServices/RpcExtenderService/RpcExtenderService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Globalization; 7 | using System.Linq; 8 | using BitcoinLib.Auxiliary; 9 | using BitcoinLib.ExceptionHandling.RpcExtenderService; 10 | using BitcoinLib.ExtensionMethods; 11 | using BitcoinLib.Requests.CreateRawTransaction; 12 | using BitcoinLib.Responses; 13 | using BitcoinLib.RPC.Specifications; 14 | using BitcoinLib.Services.Coins.Base; 15 | 16 | namespace BitcoinLib.Services 17 | { 18 | public partial class CoinService 19 | { 20 | // Note: This will return funky results if the address in question along with its private key have been used to create a multisig address with unspent funds 21 | public decimal GetAddressBalance(string inWalletAddress, int minConf, bool validateAddressBeforeProcessing) 22 | { 23 | if (validateAddressBeforeProcessing) 24 | { 25 | var validateAddressResponse = ValidateAddress(inWalletAddress); 26 | 27 | if (!validateAddressResponse.IsValid) 28 | { 29 | throw new GetAddressBalanceException($"Address {inWalletAddress} is invalid!"); 30 | } 31 | 32 | if (!validateAddressResponse.IsMine) 33 | { 34 | throw new GetAddressBalanceException($"Address {inWalletAddress} is not an in-wallet address!"); 35 | } 36 | } 37 | 38 | var listUnspentResponses = ListUnspent(minConf, 9999999, new List 39 | { 40 | inWalletAddress 41 | }); 42 | 43 | return listUnspentResponses.Any() ? listUnspentResponses.Sum(x => x.Amount) : 0; 44 | } 45 | 46 | public string GetImmutableTxId(string txId, bool getSha256Hash) 47 | { 48 | var response = GetRawTransaction(txId, 1); 49 | var text = response.Vin.First().TxId + "|" + response.Vin.First().Vout + "|" + response.Vout.First().Value; 50 | return getSha256Hash ? Hashing.GetSha256(text) : text; 51 | } 52 | 53 | // Get a rough estimate on fees for non-free txs, depending on the total number of tx inputs and outputs 54 | [Obsolete("Please don't use this method to calculate tx fees, its purpose is to provide a rough estimate only")] 55 | public decimal GetMinimumNonZeroTransactionFeeEstimate(short numberOfInputs = 1, short numberOfOutputs = 1) 56 | { 57 | var rawTransactionRequest = new CreateRawTransactionRequest(new List(numberOfInputs), new Dictionary(numberOfOutputs)); 58 | 59 | for (short i = 0; i < numberOfInputs; i++) 60 | { 61 | rawTransactionRequest.AddInput(new CreateRawTransactionInput 62 | { 63 | TxId = "dummyTxId" + i.ToString(CultureInfo.InvariantCulture), Vout = i 64 | }); 65 | } 66 | 67 | for (short i = 0; i < numberOfOutputs; i++) 68 | { 69 | rawTransactionRequest.AddOutput(new CreateRawTransactionOutput 70 | { 71 | Address = "dummyAddress" + i.ToString(CultureInfo.InvariantCulture), Amount = i + 1 72 | }); 73 | } 74 | 75 | return GetTransactionFee(rawTransactionRequest, false, true); 76 | } 77 | 78 | public Dictionary GetMyPublicAndPrivateKeyPairs() 79 | { 80 | const short secondsToUnlockTheWallet = 30; 81 | var keyPairs = new Dictionary(); 82 | WalletPassphrase(Parameters.WalletPassword, secondsToUnlockTheWallet); 83 | var myAddresses = (this as ICoinService).ListReceivedByAddress(0, true); 84 | 85 | foreach (var listReceivedByAddressResponse in myAddresses) 86 | { 87 | var validateAddressResponse = ValidateAddress(listReceivedByAddressResponse.Address); 88 | 89 | if (validateAddressResponse.IsMine && validateAddressResponse.IsValid && !validateAddressResponse.IsScript) 90 | { 91 | var privateKey = DumpPrivKey(listReceivedByAddressResponse.Address); 92 | keyPairs.Add(validateAddressResponse.PubKey, privateKey); 93 | } 94 | } 95 | 96 | WalletLock(); 97 | return keyPairs; 98 | } 99 | 100 | // Note: As RPC's gettransaction works only for in-wallet transactions this had to be extended so it will work for every single transaction. 101 | public DecodeRawTransactionResponse GetPublicTransaction(string txId) 102 | { 103 | var rawTransaction = GetRawTransaction(txId, 0).Hex; 104 | return DecodeRawTransaction(rawTransaction); 105 | } 106 | 107 | [Obsolete("Please use EstimateFee() instead. You can however keep on using this method until the network fully adjusts to the new rules on fee calculation")] 108 | public decimal GetTransactionFee(CreateRawTransactionRequest transaction, bool checkIfTransactionQualifiesForFreeRelay, bool enforceMinimumTransactionFeePolicy) 109 | { 110 | if (checkIfTransactionQualifiesForFreeRelay && IsTransactionFree(transaction)) 111 | { 112 | return 0; 113 | } 114 | 115 | decimal transactionSizeInBytes = GetTransactionSizeInBytes(transaction); 116 | var transactionFee = ((transactionSizeInBytes / Parameters.FreeTransactionMaximumSizeInBytes) + (transactionSizeInBytes % Parameters.FreeTransactionMaximumSizeInBytes == 0 ? 0 : 1)) * Parameters.FeePerThousandBytesInCoins; 117 | 118 | if (transactionFee.GetNumberOfDecimalPlaces() > Parameters.CoinsPerBaseUnit.GetNumberOfDecimalPlaces()) 119 | { 120 | transactionFee = decimal.Round(transactionFee, Parameters.CoinsPerBaseUnit.GetNumberOfDecimalPlaces(), MidpointRounding.AwayFromZero); 121 | } 122 | 123 | if (enforceMinimumTransactionFeePolicy && Parameters.MinimumTransactionFeeInCoins != 0 && transactionFee < Parameters.MinimumTransactionFeeInCoins) 124 | { 125 | transactionFee = Parameters.MinimumTransactionFeeInCoins; 126 | } 127 | 128 | return transactionFee; 129 | } 130 | 131 | public GetRawTransactionResponse GetRawTxFromImmutableTxId(string rigidTxId, int listTransactionsCount, int listTransactionsFrom, bool getRawTransactionVersbose, bool rigidTxIdIsSha256) 132 | { 133 | var allTransactions = (this as ICoinService).ListTransactions("*", listTransactionsCount, listTransactionsFrom); 134 | 135 | return (from listTransactionsResponse in allTransactions 136 | where rigidTxId == GetImmutableTxId(listTransactionsResponse.TxId, rigidTxIdIsSha256) 137 | select GetRawTransaction(listTransactionsResponse.TxId, getRawTransactionVersbose ? 1 : 0)).FirstOrDefault(); 138 | } 139 | 140 | public decimal GetTransactionPriority(CreateRawTransactionRequest transaction) 141 | { 142 | if (transaction.Inputs.Count == 0) 143 | { 144 | return 0; 145 | } 146 | 147 | var unspentInputs = (this as ICoinService).ListUnspent(0).ToList(); 148 | var sumOfInputsValueInBaseUnitsMultipliedByTheirAge = transaction.Inputs.Select(input => unspentInputs.First(x => x.TxId == input.TxId)).Select(unspentResponse => (unspentResponse.Amount * Parameters.OneCoinInBaseUnits) * unspentResponse.Confirmations).Sum(); 149 | return sumOfInputsValueInBaseUnitsMultipliedByTheirAge / GetTransactionSizeInBytes(transaction); 150 | } 151 | 152 | public decimal GetTransactionPriority(IList transactionInputs, int numberOfOutputs) 153 | { 154 | if (transactionInputs.Count == 0) 155 | { 156 | return 0; 157 | } 158 | 159 | return transactionInputs.Sum(input => input.Amount * Parameters.OneCoinInBaseUnits * input.Confirmations) / GetTransactionSizeInBytes(transactionInputs.Count, numberOfOutputs); 160 | } 161 | 162 | // Note: Be careful when using GetTransactionSenderAddress() as it just gives you an address owned by someone who previously controlled the transaction's outputs 163 | // which might not actually be the sender (e.g. for e-wallets) and who may not intend to receive anything there in the first place. 164 | [Obsolete("Please don't use this method in production enviroment, it's for testing purposes only")] 165 | public string GetTransactionSenderAddress(string txId) 166 | { 167 | var rawTransaction = GetRawTransaction(txId, 0).Hex; 168 | var decodedRawTransaction = DecodeRawTransaction(rawTransaction); 169 | var transactionInputs = decodedRawTransaction.Vin; 170 | var rawTransactionHex = GetRawTransaction(transactionInputs[0].TxId, 0).Hex; 171 | var inputDecodedRawTransaction = DecodeRawTransaction(rawTransactionHex); 172 | var vouts = inputDecodedRawTransaction.Vout; 173 | return vouts[0].ScriptPubKey.Addresses[0]; 174 | } 175 | 176 | public int GetTransactionSizeInBytes(CreateRawTransactionRequest transaction) 177 | { 178 | return GetTransactionSizeInBytes(transaction.Inputs.Count, transaction.Outputs.Count); 179 | } 180 | 181 | public int GetTransactionSizeInBytes(int numberOfInputs, int numberOfOutputs) 182 | { 183 | return numberOfInputs * Parameters.TransactionSizeBytesContributedByEachInput 184 | + numberOfOutputs * Parameters.TransactionSizeBytesContributedByEachOutput 185 | + Parameters.TransactionSizeFixedExtraSizeInBytes 186 | + numberOfInputs; 187 | } 188 | 189 | public bool IsInWalletTransaction(string txId) 190 | { 191 | // Note: This might not be efficient if iterated, consider caching ListTransactions' results. 192 | return (this as ICoinService).ListTransactions(null, int.MaxValue).Any(listTransactionsResponse => listTransactionsResponse.TxId == txId); 193 | } 194 | 195 | public bool IsTransactionFree(CreateRawTransactionRequest transaction) 196 | { 197 | return transaction.Outputs.Any(x => x.Value < Parameters.FreeTransactionMinimumOutputAmountInCoins) 198 | && GetTransactionSizeInBytes(transaction) < Parameters.FreeTransactionMaximumSizeInBytes 199 | && GetTransactionPriority(transaction) > Parameters.FreeTransactionMinimumPriority; 200 | } 201 | 202 | public bool IsTransactionFree(IList transactionInputs, int numberOfOutputs, decimal minimumAmountAmongOutputs) 203 | { 204 | return minimumAmountAmongOutputs < Parameters.FreeTransactionMinimumOutputAmountInCoins 205 | && GetTransactionSizeInBytes(transactionInputs.Count, numberOfOutputs) < Parameters.FreeTransactionMaximumSizeInBytes 206 | && GetTransactionPriority(transactionInputs, numberOfOutputs) > Parameters.FreeTransactionMinimumPriority; 207 | } 208 | 209 | public bool IsWalletEncrypted() 210 | { 211 | return !Help(RpcMethods.walletlock.ToString()).Contains("unknown command"); 212 | } 213 | } 214 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/RpcServices/RpcService/IRpcService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System.Collections.Generic; 5 | using BitcoinLib.Requests.AddNode; 6 | using BitcoinLib.Requests.CreateRawTransaction; 7 | using BitcoinLib.Requests.SignRawTransaction; 8 | using BitcoinLib.Responses; 9 | 10 | namespace BitcoinLib.Services.RpcServices.RpcService 11 | { 12 | public interface IRpcService 13 | { 14 | #region Blockchain 15 | 16 | string GetBestBlockHash(); 17 | GetBlockResponse GetBlock(string hash, bool verbose = true); 18 | GetBlockchainInfoResponse GetBlockchainInfo(); 19 | uint GetBlockCount(); 20 | string GetBlockHash(long index); 21 | // getblockheader 22 | // getchaintips 23 | double GetDifficulty(); 24 | List GetChainTips(); 25 | GetMemPoolInfoResponse GetMemPoolInfo(); 26 | GetRawMemPoolResponse GetRawMemPool(bool verbose = false); 27 | GetTransactionResponse GetTxOut(string txId, int n, bool includeMemPool = true); 28 | // gettxoutproof["txid",...] ( blockhash ) 29 | GetTxOutSetInfoResponse GetTxOutSetInfo(); 30 | bool VerifyChain(ushort checkLevel = 3, uint numBlocks = 288); // Note: numBlocks: 0 => ALL 31 | 32 | #endregion 33 | 34 | #region Control 35 | 36 | GetInfoResponse GetInfo(); 37 | string Help(string command = null); 38 | string Stop(); 39 | 40 | #endregion 41 | 42 | #region Generating 43 | 44 | // generate numblocks 45 | bool GetGenerate(); 46 | string SetGenerate(bool generate, short generatingProcessorsLimit); 47 | 48 | #endregion 49 | 50 | #region Mining 51 | 52 | GetBlockTemplateResponse GetBlockTemplate(params object[] parameters); 53 | GetMiningInfoResponse GetMiningInfo(); 54 | ulong GetNetworkHashPs(uint blocks = 120, long height = -1); 55 | bool PrioritiseTransaction(string txId, decimal priorityDelta, decimal feeDelta); 56 | string SubmitBlock(string hexData, params object[] parameters); 57 | 58 | #endregion 59 | 60 | #region Network 61 | 62 | void AddNode(string node, NodeAction action); 63 | // clearbanned 64 | // disconnectnode 65 | GetAddedNodeInfoResponse GetAddedNodeInfo(string dns, string node = null); 66 | int GetConnectionCount(); 67 | GetNetTotalsResponse GetNetTotals(); 68 | GetNetworkInfoResponse GetNetworkInfo(); 69 | List GetPeerInfo(); 70 | // listbanned 71 | void Ping(); 72 | // setban 73 | 74 | #endregion 75 | 76 | #region Rawtransactions 77 | 78 | string CreateRawTransaction(CreateRawTransactionRequest rawTransaction); 79 | DecodeRawTransactionResponse DecodeRawTransaction(string rawTransactionHexString); 80 | DecodeScriptResponse DecodeScript(string hexString); 81 | // fundrawtransaction 82 | GetRawTransactionResponse GetRawTransaction(string txId, int verbose = 0); 83 | string SendRawTransaction(string rawTransactionHexString, bool? allowHighFees = false); 84 | SignRawTransactionResponse SignRawTransaction(SignRawTransactionRequest signRawTransactionRequest); 85 | 86 | #endregion 87 | 88 | #region Util 89 | 90 | CreateMultiSigResponse CreateMultiSig(int nRquired, List publicKeys); 91 | decimal EstimateFee(ushort nBlocks); 92 | EstimateSmartFeeResponse EstimateSmartFee(ushort nBlocks); 93 | decimal EstimatePriority(ushort nBlocks); 94 | // estimatesmartfee 95 | // estimatesmartpriority 96 | ValidateAddressResponse ValidateAddress(string bitcoinAddress); 97 | bool VerifyMessage(string bitcoinAddress, string signature, string message); 98 | 99 | #endregion 100 | 101 | #region Wallet 102 | 103 | // abandontransaction 104 | string AddMultiSigAddress(int nRquired, List publicKeys, string account = null); 105 | string AddWitnessAddress(string address); 106 | void BackupWallet(string destination); 107 | string DumpPrivKey(string bitcoinAddress); 108 | void DumpWallet(string filename); 109 | string GetAccount(string bitcoinAddress); 110 | string GetAccountAddress(string account); 111 | List GetAddressesByAccount(string account); 112 | decimal GetBalance(string account = null, int minConf = 1, bool? includeWatchonly = null); 113 | string GetNewAddress(string account = ""); 114 | string GetRawChangeAddress(); 115 | decimal GetReceivedByAccount(string account, int minConf = 1); 116 | decimal GetReceivedByAddress(string bitcoinAddress, int minConf = 1); 117 | GetTransactionResponse GetTransaction(string txId, bool? includeWatchonly = null); 118 | decimal GetUnconfirmedBalance(); 119 | GetWalletInfoResponse GetWalletInfo(); 120 | void ImportAddress(string address, string label = null, bool rescan = true); 121 | string ImportPrivKey(string privateKey, string label = null, bool rescan = true); 122 | // importpubkey 123 | void ImportWallet(string filename); 124 | string KeyPoolRefill(uint newSize = 100); 125 | Dictionary ListAccounts(int minConf = 1, bool? includeWatchonly = null); 126 | List> ListAddressGroupings(); 127 | string ListLockUnspent(); 128 | List ListReceivedByAccount(int minConf = 1, bool includeEmpty = false, bool? includeWatchonly = null); 129 | List ListReceivedByAddress(int minConf = 1, bool includeEmpty = false, bool? includeWatchonly = null); 130 | ListSinceBlockResponse ListSinceBlock(string blockHash = null, int targetConfirmations = 1, bool? includeWatchonly = null); 131 | List ListTransactions(string account = null, int count = 10, int from = 0, bool? includeWatchonly = null); 132 | List ListUnspent(int minConf = 1, int maxConf = 9999999, List addresses = null); 133 | bool LockUnspent(bool unlock, IList listUnspentResponses); 134 | bool Move(string fromAccount, string toAccount, decimal amount, int minConf = 1, string comment = ""); 135 | string SendFrom(string fromAccount, string toBitcoinAddress, decimal amount, int minConf = 1, string comment = null, string commentTo = null); 136 | string SendMany(string fromAccount, Dictionary toBitcoinAddress, int minConf = 1, string comment = null); 137 | string SendToAddress(string bitcoinAddress, decimal amount, string comment = null, string commentTo = null, bool subtractFeeFromAmount = false); 138 | string SetAccount(string bitcoinAddress, string account); 139 | string SetTxFee(decimal amount); 140 | string SignMessage(string bitcoinAddress, string message); 141 | string WalletLock(); 142 | string WalletPassphrase(string passphrase, int timeoutInSeconds); 143 | string WalletPassphraseChange(string oldPassphrase, string newPassphrase); 144 | 145 | #endregion 146 | } 147 | } -------------------------------------------------------------------------------- /src/BitcoinLib/Services/RpcServices/RpcService/RpcService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 - 2016 George Kimionis 2 | // See the accompanying file LICENSE for the Software License Aggrement 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using BitcoinLib.Requests.AddNode; 8 | using BitcoinLib.Requests.CreateRawTransaction; 9 | using BitcoinLib.Requests.SignRawTransaction; 10 | using BitcoinLib.Responses; 11 | using BitcoinLib.RPC.Connector; 12 | using BitcoinLib.RPC.Specifications; 13 | using BitcoinLib.Services.Coins.Base; 14 | using Newtonsoft.Json.Linq; 15 | 16 | namespace BitcoinLib.Services 17 | { 18 | // Implementation of API calls list, as found at: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list (note: this list is often out-of-date so call "help" in your bitcoin-cli to get the latest signatures) 19 | public partial class CoinService : ICoinService 20 | { 21 | protected readonly IRpcConnector _rpcConnector; 22 | 23 | public CoinService() 24 | { 25 | _rpcConnector = new RpcConnector(this); 26 | Parameters = new CoinParameters(this, null, null, null, null, 0); 27 | } 28 | 29 | public CoinService(bool useTestnet) : this() 30 | { 31 | Parameters.UseTestnet = useTestnet; 32 | } 33 | 34 | public CoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword) 35 | { 36 | _rpcConnector = new RpcConnector(this); 37 | Parameters = new CoinParameters(this, daemonUrl, rpcUsername, rpcPassword, walletPassword, 0); 38 | } 39 | 40 | // this provides support for cases where *.config files are not an option 41 | public CoinService(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword, short rpcRequestTimeoutInSeconds) 42 | { 43 | _rpcConnector = new RpcConnector(this); 44 | Parameters = new CoinParameters(this, daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds); 45 | } 46 | 47 | public string AddMultiSigAddress(int nRquired, List publicKeys, string account) 48 | { 49 | return account != null 50 | ? _rpcConnector.MakeRequest(RpcMethods.addmultisigaddress, nRquired, publicKeys, account) 51 | : _rpcConnector.MakeRequest(RpcMethods.addmultisigaddress, nRquired, publicKeys); 52 | } 53 | 54 | public void AddNode(string node, NodeAction action) 55 | { 56 | _rpcConnector.MakeRequest(RpcMethods.addnode, node, action.ToString()); 57 | } 58 | 59 | public string AddWitnessAddress(string address) 60 | { 61 | return _rpcConnector.MakeRequest(RpcMethods.addwitnessaddress, address); 62 | } 63 | 64 | public void BackupWallet(string destination) 65 | { 66 | _rpcConnector.MakeRequest(RpcMethods.backupwallet, destination); 67 | } 68 | 69 | public CreateMultiSigResponse CreateMultiSig(int nRquired, List publicKeys) 70 | { 71 | return _rpcConnector.MakeRequest(RpcMethods.createmultisig, nRquired, publicKeys); 72 | } 73 | 74 | public string CreateRawTransaction(CreateRawTransactionRequest rawTransaction) 75 | { 76 | return _rpcConnector.MakeRequest(RpcMethods.createrawtransaction, rawTransaction.Inputs, rawTransaction.Outputs); 77 | } 78 | 79 | public DecodeRawTransactionResponse DecodeRawTransaction(string rawTransactionHexString) 80 | { 81 | return _rpcConnector.MakeRequest(RpcMethods.decoderawtransaction, rawTransactionHexString); 82 | } 83 | 84 | public DecodeScriptResponse DecodeScript(string hexString) 85 | { 86 | return _rpcConnector.MakeRequest(RpcMethods.decodescript, hexString); 87 | } 88 | 89 | public string DumpPrivKey(string bitcoinAddress) 90 | { 91 | return _rpcConnector.MakeRequest(RpcMethods.dumpprivkey, bitcoinAddress); 92 | } 93 | 94 | public void DumpWallet(string filename) 95 | { 96 | _rpcConnector.MakeRequest(RpcMethods.dumpwallet, filename); 97 | } 98 | 99 | public decimal EstimateFee(ushort nBlocks) 100 | { 101 | return _rpcConnector.MakeRequest(RpcMethods.estimatefee, nBlocks); 102 | } 103 | 104 | public EstimateSmartFeeResponse EstimateSmartFee(ushort nBlocks) 105 | { 106 | return _rpcConnector.MakeRequest(RpcMethods.estimatesmartfee, nBlocks); 107 | } 108 | 109 | public decimal EstimatePriority(ushort nBlocks) 110 | { 111 | return _rpcConnector.MakeRequest(RpcMethods.estimatepriority, nBlocks); 112 | } 113 | 114 | public string GetAccount(string bitcoinAddress) 115 | { 116 | return _rpcConnector.MakeRequest(RpcMethods.getaccount, bitcoinAddress); 117 | } 118 | 119 | public string GetAccountAddress(string account) 120 | { 121 | return _rpcConnector.MakeRequest(RpcMethods.getaccountaddress, account); 122 | } 123 | 124 | public GetAddedNodeInfoResponse GetAddedNodeInfo(string dns, string node) 125 | { 126 | return string.IsNullOrWhiteSpace(node) 127 | ? _rpcConnector.MakeRequest(RpcMethods.getaddednodeinfo, dns) 128 | : _rpcConnector.MakeRequest(RpcMethods.getaddednodeinfo, dns, node); 129 | } 130 | 131 | public List GetAddressesByAccount(string account) 132 | { 133 | return _rpcConnector.MakeRequest>(RpcMethods.getaddressesbyaccount, account); 134 | } 135 | 136 | public decimal GetBalance(string account, int minConf, bool? includeWatchonly) 137 | { 138 | return includeWatchonly == null 139 | ? _rpcConnector.MakeRequest(RpcMethods.getbalance, (string.IsNullOrWhiteSpace(account) ? "*" : account), minConf) 140 | : _rpcConnector.MakeRequest(RpcMethods.getbalance, (string.IsNullOrWhiteSpace(account) ? "*" : account), minConf, includeWatchonly); 141 | } 142 | 143 | public string GetBestBlockHash() 144 | { 145 | return _rpcConnector.MakeRequest(RpcMethods.getbestblockhash); 146 | } 147 | 148 | public GetBlockResponse GetBlock(string hash, bool verbose) 149 | { 150 | return _rpcConnector.MakeRequest(RpcMethods.getblock, hash, verbose); 151 | } 152 | 153 | public GetBlockchainInfoResponse GetBlockchainInfo() 154 | { 155 | return _rpcConnector.MakeRequest(RpcMethods.getblockchaininfo); 156 | } 157 | 158 | public uint GetBlockCount() 159 | { 160 | return _rpcConnector.MakeRequest(RpcMethods.getblockcount); 161 | } 162 | 163 | public string GetBlockHash(long index) 164 | { 165 | return _rpcConnector.MakeRequest(RpcMethods.getblockhash, index); 166 | } 167 | 168 | public GetBlockTemplateResponse GetBlockTemplate(params object[] parameters) 169 | { 170 | return parameters == null 171 | ? _rpcConnector.MakeRequest(RpcMethods.getblocktemplate) 172 | : _rpcConnector.MakeRequest(RpcMethods.getblocktemplate, parameters); 173 | } 174 | 175 | public List GetChainTips() 176 | { 177 | return _rpcConnector.MakeRequest>(RpcMethods.getchaintips); 178 | } 179 | 180 | public int GetConnectionCount() 181 | { 182 | return _rpcConnector.MakeRequest(RpcMethods.getconnectioncount); 183 | } 184 | 185 | public double GetDifficulty() 186 | { 187 | return _rpcConnector.MakeRequest(RpcMethods.getdifficulty); 188 | } 189 | 190 | public bool GetGenerate() 191 | { 192 | return _rpcConnector.MakeRequest(RpcMethods.getgenerate); 193 | } 194 | 195 | [Obsolete("Please use calls: GetWalletInfo(), GetBlockchainInfo() and GetNetworkInfo() instead")] 196 | public GetInfoResponse GetInfo() 197 | { 198 | return _rpcConnector.MakeRequest(RpcMethods.getinfo); 199 | } 200 | 201 | public GetMemPoolInfoResponse GetMemPoolInfo() 202 | { 203 | return _rpcConnector.MakeRequest(RpcMethods.getmempoolinfo); 204 | } 205 | 206 | public GetMiningInfoResponse GetMiningInfo() 207 | { 208 | return _rpcConnector.MakeRequest(RpcMethods.getmininginfo); 209 | } 210 | 211 | public GetNetTotalsResponse GetNetTotals() 212 | { 213 | return _rpcConnector.MakeRequest(RpcMethods.getnettotals); 214 | } 215 | 216 | public ulong GetNetworkHashPs(uint blocks, long height) 217 | { 218 | return _rpcConnector.MakeRequest(RpcMethods.getnetworkhashps); 219 | } 220 | 221 | public GetNetworkInfoResponse GetNetworkInfo() 222 | { 223 | return _rpcConnector.MakeRequest(RpcMethods.getnetworkinfo); 224 | } 225 | 226 | public string GetNewAddress(string account) 227 | { 228 | return string.IsNullOrWhiteSpace(account) 229 | ? _rpcConnector.MakeRequest(RpcMethods.getnewaddress) 230 | : _rpcConnector.MakeRequest(RpcMethods.getnewaddress, account); 231 | } 232 | 233 | public List GetPeerInfo() 234 | { 235 | return _rpcConnector.MakeRequest>(RpcMethods.getpeerinfo); 236 | } 237 | 238 | public GetRawMemPoolResponse GetRawMemPool(bool verbose) 239 | { 240 | var getRawMemPoolResponse = new GetRawMemPoolResponse 241 | { 242 | IsVerbose = verbose 243 | }; 244 | 245 | var rpcResponse = _rpcConnector.MakeRequest(RpcMethods.getrawmempool, verbose); 246 | 247 | if (!verbose) 248 | { 249 | var rpcResponseAsArray = (JArray) rpcResponse; 250 | 251 | foreach (string txId in rpcResponseAsArray) 252 | { 253 | getRawMemPoolResponse.TxIds.Add(txId); 254 | } 255 | 256 | return getRawMemPoolResponse; 257 | } 258 | 259 | IList> rpcResponseAsKvp = (new EnumerableQuery>(((JObject) (rpcResponse)))).ToList(); 260 | IList children = JObject.Parse(rpcResponse.ToString()).Children().ToList(); 261 | 262 | for (var i = 0; i < children.Count(); i++) 263 | { 264 | var getRawMemPoolVerboseResponse = new GetRawMemPoolVerboseResponse 265 | { 266 | TxId = rpcResponseAsKvp[i].Key 267 | }; 268 | 269 | getRawMemPoolResponse.TxIds.Add(getRawMemPoolVerboseResponse.TxId); 270 | 271 | foreach (var property in children[i].SelectMany(grandChild => grandChild.OfType())) 272 | { 273 | switch (property.Name) 274 | { 275 | case "currentpriority": 276 | 277 | double currentPriority; 278 | 279 | if (double.TryParse(property.Value.ToString(), out currentPriority)) 280 | { 281 | getRawMemPoolVerboseResponse.CurrentPriority = currentPriority; 282 | } 283 | 284 | break; 285 | 286 | case "depends": 287 | 288 | foreach (var jToken in property.Value) 289 | { 290 | getRawMemPoolVerboseResponse.Depends.Add(jToken.Value()); 291 | } 292 | 293 | break; 294 | 295 | case "fee": 296 | 297 | decimal fee; 298 | 299 | if (decimal.TryParse(property.Value.ToString(), out fee)) 300 | { 301 | getRawMemPoolVerboseResponse.Fee = fee; 302 | } 303 | 304 | break; 305 | 306 | case "height": 307 | 308 | int height; 309 | 310 | if (int.TryParse(property.Value.ToString(), out height)) 311 | { 312 | getRawMemPoolVerboseResponse.Height = height; 313 | } 314 | 315 | break; 316 | 317 | case "size": 318 | 319 | int size; 320 | 321 | if (int.TryParse(property.Value.ToString(), out size)) 322 | { 323 | getRawMemPoolVerboseResponse.Size = size; 324 | } 325 | 326 | break; 327 | 328 | case "startingpriority": 329 | 330 | double startingPriority; 331 | 332 | if (double.TryParse(property.Value.ToString(), out startingPriority)) 333 | { 334 | getRawMemPoolVerboseResponse.StartingPriority = startingPriority; 335 | } 336 | 337 | break; 338 | 339 | case "time": 340 | 341 | int time; 342 | 343 | if (int.TryParse(property.Value.ToString(), out time)) 344 | { 345 | getRawMemPoolVerboseResponse.Time = time; 346 | } 347 | 348 | break; 349 | 350 | default: 351 | 352 | throw new Exception("Unkown property: " + property.Name + " in GetRawMemPool()"); 353 | } 354 | } 355 | getRawMemPoolResponse.VerboseResponses.Add(getRawMemPoolVerboseResponse); 356 | } 357 | return getRawMemPoolResponse; 358 | } 359 | 360 | public string GetRawChangeAddress() 361 | { 362 | return _rpcConnector.MakeRequest(RpcMethods.getrawchangeaddress); 363 | } 364 | 365 | public GetRawTransactionResponse GetRawTransaction(string txId, int verbose) 366 | { 367 | if (verbose == 0) 368 | { 369 | return new GetRawTransactionResponse 370 | { 371 | Hex = _rpcConnector.MakeRequest(RpcMethods.getrawtransaction, txId, verbose) 372 | }; 373 | } 374 | 375 | if (verbose == 1) 376 | { 377 | return _rpcConnector.MakeRequest(RpcMethods.getrawtransaction, txId, verbose); 378 | } 379 | 380 | throw new Exception("Invalid verbose value: " + verbose + " in GetRawTransaction()!"); 381 | } 382 | 383 | public decimal GetReceivedByAccount(string account, int minConf) 384 | { 385 | return _rpcConnector.MakeRequest(RpcMethods.getreceivedbyaccount, account, minConf); 386 | } 387 | 388 | public decimal GetReceivedByAddress(string bitcoinAddress, int minConf) 389 | { 390 | return _rpcConnector.MakeRequest(RpcMethods.getreceivedbyaddress, bitcoinAddress, minConf); 391 | } 392 | 393 | public GetTransactionResponse GetTransaction(string txId, bool? includeWatchonly) 394 | { 395 | return includeWatchonly == null 396 | ? _rpcConnector.MakeRequest(RpcMethods.gettransaction, txId) 397 | : _rpcConnector.MakeRequest(RpcMethods.gettransaction, txId, includeWatchonly); 398 | } 399 | 400 | public GetTransactionResponse GetTxOut(string txId, int n, bool includeMemPool) 401 | { 402 | return _rpcConnector.MakeRequest(RpcMethods.gettxout, txId, n, includeMemPool); 403 | } 404 | 405 | public GetTxOutSetInfoResponse GetTxOutSetInfo() 406 | { 407 | return _rpcConnector.MakeRequest(RpcMethods.gettxoutsetinfo); 408 | } 409 | 410 | public decimal GetUnconfirmedBalance() 411 | { 412 | return _rpcConnector.MakeRequest(RpcMethods.getunconfirmedbalance); 413 | } 414 | 415 | public GetWalletInfoResponse GetWalletInfo() 416 | { 417 | return _rpcConnector.MakeRequest(RpcMethods.getwalletinfo); 418 | } 419 | 420 | public string Help(string command) 421 | { 422 | return string.IsNullOrWhiteSpace(command) 423 | ? _rpcConnector.MakeRequest(RpcMethods.help) 424 | : _rpcConnector.MakeRequest(RpcMethods.help, command); 425 | } 426 | 427 | public void ImportAddress(string address, string label, bool rescan) 428 | { 429 | _rpcConnector.MakeRequest(RpcMethods.importaddress, address, label, rescan); 430 | } 431 | 432 | public string ImportPrivKey(string privateKey, string label, bool rescan) 433 | { 434 | return _rpcConnector.MakeRequest(RpcMethods.importprivkey, privateKey, label, rescan); 435 | } 436 | 437 | public void ImportWallet(string filename) 438 | { 439 | _rpcConnector.MakeRequest(RpcMethods.importwallet, filename); 440 | } 441 | 442 | public string KeyPoolRefill(uint newSize) 443 | { 444 | return _rpcConnector.MakeRequest(RpcMethods.keypoolrefill, newSize); 445 | } 446 | 447 | public Dictionary ListAccounts(int minConf, bool? includeWatchonly) 448 | { 449 | return includeWatchonly == null 450 | ? _rpcConnector.MakeRequest>(RpcMethods.listaccounts, minConf) 451 | : _rpcConnector.MakeRequest>(RpcMethods.listaccounts, minConf, includeWatchonly); 452 | } 453 | 454 | public List> ListAddressGroupings() 455 | { 456 | var unstructuredResponse = _rpcConnector.MakeRequest>>>(RpcMethods.listaddressgroupings); 457 | var structuredResponse = new List>(unstructuredResponse.Count); 458 | 459 | for (var i = 0; i < unstructuredResponse.Count; i++) 460 | { 461 | for (var j = 0; j < unstructuredResponse[i].Count; j++) 462 | { 463 | if (unstructuredResponse[i][j].Count > 1) 464 | { 465 | var response = new ListAddressGroupingsResponse 466 | { 467 | Address = unstructuredResponse[i][j][0].ToString() 468 | }; 469 | 470 | decimal balance; 471 | if (decimal.TryParse(unstructuredResponse[i][j][1].ToString(), out balance)) 472 | { 473 | response.Balance = balance; 474 | } 475 | 476 | if (unstructuredResponse[i][j].Count > 2) 477 | { 478 | response.Account = unstructuredResponse[i][j][2].ToString(); 479 | } 480 | 481 | if (structuredResponse.Count < i + 1) 482 | { 483 | structuredResponse.Add(new List()); 484 | } 485 | 486 | structuredResponse[i].Add(response); 487 | } 488 | } 489 | } 490 | return structuredResponse; 491 | } 492 | 493 | public string ListLockUnspent() 494 | { 495 | return _rpcConnector.MakeRequest(RpcMethods.listlockunspent); 496 | } 497 | 498 | public List ListReceivedByAccount(int minConf, bool includeEmpty, bool? includeWatchonly) 499 | { 500 | return includeWatchonly == null 501 | ? _rpcConnector.MakeRequest>(RpcMethods.listreceivedbyaccount, minConf, includeEmpty) 502 | : _rpcConnector.MakeRequest>(RpcMethods.listreceivedbyaccount, minConf, includeEmpty, includeWatchonly); 503 | } 504 | 505 | public List ListReceivedByAddress(int minConf, bool includeEmpty, bool? includeWatchonly) 506 | { 507 | return includeWatchonly == null 508 | ? _rpcConnector.MakeRequest>(RpcMethods.listreceivedbyaddress, minConf, includeEmpty) 509 | : _rpcConnector.MakeRequest>(RpcMethods.listreceivedbyaddress, minConf, includeEmpty, includeWatchonly); 510 | } 511 | 512 | public ListSinceBlockResponse ListSinceBlock(string blockHash, int targetConfirmations, bool? includeWatchonly) 513 | { 514 | return includeWatchonly == null 515 | ? _rpcConnector.MakeRequest(RpcMethods.listsinceblock, (string.IsNullOrWhiteSpace(blockHash) ? "*" : blockHash), targetConfirmations) 516 | : _rpcConnector.MakeRequest(RpcMethods.listsinceblock, (string.IsNullOrWhiteSpace(blockHash) ? "*" : blockHash), targetConfirmations, includeWatchonly); 517 | } 518 | 519 | public List ListTransactions(string account, int count, int from, bool? includeWatchonly) 520 | { 521 | return includeWatchonly == null 522 | ? _rpcConnector.MakeRequest>(RpcMethods.listtransactions, (string.IsNullOrWhiteSpace(account) ? "*" : account), count, from) 523 | : _rpcConnector.MakeRequest>(RpcMethods.listtransactions, (string.IsNullOrWhiteSpace(account) ? "*" : account), count, from, includeWatchonly); 524 | } 525 | 526 | public List ListUnspent(int minConf, int maxConf, List addresses) 527 | { 528 | return _rpcConnector.MakeRequest>(RpcMethods.listunspent, minConf, maxConf, (addresses ?? new List())); 529 | } 530 | 531 | public bool LockUnspent(bool unlock, IList listUnspentResponses) 532 | { 533 | IList transactions = new List(); 534 | 535 | foreach (var listUnspentResponse in listUnspentResponses) 536 | { 537 | transactions.Add(new 538 | { 539 | txid = listUnspentResponse.TxId, vout = listUnspentResponse.Vout 540 | }); 541 | } 542 | 543 | return _rpcConnector.MakeRequest(RpcMethods.lockunspent, unlock, transactions.ToArray()); 544 | } 545 | 546 | public bool Move(string fromAccount, string toAccount, decimal amount, int minConf, string comment) 547 | { 548 | return _rpcConnector.MakeRequest(RpcMethods.move, fromAccount, toAccount, amount, minConf, comment); 549 | } 550 | 551 | public void Ping() 552 | { 553 | _rpcConnector.MakeRequest(RpcMethods.ping); 554 | } 555 | 556 | public bool PrioritiseTransaction(string txId, decimal priorityDelta, decimal feeDelta) 557 | { 558 | return _rpcConnector.MakeRequest(RpcMethods.prioritisetransaction, txId, priorityDelta, feeDelta); 559 | } 560 | 561 | public string SendFrom(string fromAccount, string toBitcoinAddress, decimal amount, int minConf, string comment, string commentTo) 562 | { 563 | return _rpcConnector.MakeRequest(RpcMethods.sendfrom, fromAccount, toBitcoinAddress, amount, minConf, comment, commentTo); 564 | } 565 | 566 | public string SendMany(string fromAccount, Dictionary toBitcoinAddress, int minConf, string comment) 567 | { 568 | return _rpcConnector.MakeRequest(RpcMethods.sendmany, fromAccount, toBitcoinAddress, minConf, comment); 569 | } 570 | 571 | public string SendRawTransaction(string rawTransactionHexString, bool? allowHighFees) 572 | { 573 | return allowHighFees == null 574 | ? _rpcConnector.MakeRequest(RpcMethods.sendrawtransaction, rawTransactionHexString) 575 | : _rpcConnector.MakeRequest(RpcMethods.sendrawtransaction, rawTransactionHexString, allowHighFees); 576 | } 577 | 578 | public string SendToAddress(string bitcoinAddress, decimal amount, string comment, string commentTo, bool subtractFeeFromAmount) 579 | { 580 | return _rpcConnector.MakeRequest(RpcMethods.sendtoaddress, bitcoinAddress, amount, comment, commentTo, subtractFeeFromAmount); 581 | } 582 | 583 | public string SetAccount(string bitcoinAddress, string account) 584 | { 585 | return _rpcConnector.MakeRequest(RpcMethods.setaccount, bitcoinAddress, account); 586 | } 587 | 588 | public string SetGenerate(bool generate, short generatingProcessorsLimit) 589 | { 590 | return _rpcConnector.MakeRequest(RpcMethods.setgenerate, generate, generatingProcessorsLimit); 591 | } 592 | 593 | public string SetTxFee(decimal amount) 594 | { 595 | return _rpcConnector.MakeRequest(RpcMethods.settxfee, amount); 596 | } 597 | 598 | public string SignMessage(string bitcoinAddress, string message) 599 | { 600 | return _rpcConnector.MakeRequest(RpcMethods.signmessage, bitcoinAddress, message); 601 | } 602 | 603 | public SignRawTransactionResponse SignRawTransaction(SignRawTransactionRequest request) 604 | { 605 | #region default values 606 | 607 | if (request.Inputs.Count == 0) 608 | { 609 | request.Inputs = null; 610 | } 611 | 612 | if (string.IsNullOrWhiteSpace(request.SigHashType)) 613 | { 614 | request.SigHashType = SigHashType.All; 615 | } 616 | 617 | if (request.PrivateKeys.Count == 0) 618 | { 619 | request.PrivateKeys = null; 620 | } 621 | 622 | #endregion 623 | 624 | return _rpcConnector.MakeRequest(RpcMethods.signrawtransaction, request.RawTransactionHex, request.Inputs, request.PrivateKeys, request.SigHashType); 625 | } 626 | 627 | public string Stop() 628 | { 629 | return _rpcConnector.MakeRequest(RpcMethods.stop); 630 | } 631 | 632 | public string SubmitBlock(string hexData, params object[] parameters) 633 | { 634 | return parameters == null 635 | ? _rpcConnector.MakeRequest(RpcMethods.submitblock, hexData) 636 | : _rpcConnector.MakeRequest(RpcMethods.submitblock, hexData, parameters); 637 | } 638 | 639 | public ValidateAddressResponse ValidateAddress(string bitcoinAddress) 640 | { 641 | return _rpcConnector.MakeRequest(RpcMethods.validateaddress, bitcoinAddress); 642 | } 643 | 644 | public bool VerifyChain(ushort checkLevel, uint numBlocks) 645 | { 646 | return _rpcConnector.MakeRequest(RpcMethods.verifychain, checkLevel, numBlocks); 647 | } 648 | 649 | public bool VerifyMessage(string bitcoinAddress, string signature, string message) 650 | { 651 | return _rpcConnector.MakeRequest(RpcMethods.verifymessage, bitcoinAddress, signature, message); 652 | } 653 | 654 | public string WalletLock() 655 | { 656 | return _rpcConnector.MakeRequest(RpcMethods.walletlock); 657 | } 658 | 659 | public string WalletPassphrase(string passphrase, int timeoutInSeconds) 660 | { 661 | return _rpcConnector.MakeRequest(RpcMethods.walletpassphrase, passphrase, timeoutInSeconds); 662 | } 663 | 664 | public string WalletPassphraseChange(string oldPassphrase, string newPassphrase) 665 | { 666 | return _rpcConnector.MakeRequest(RpcMethods.walletpassphrasechange, oldPassphrase, newPassphrase); 667 | } 668 | 669 | public override string ToString() 670 | { 671 | return Parameters.CoinLongName; 672 | } 673 | } 674 | } 675 | -------------------------------------------------------------------------------- /src/BitcoinLib/paket.references: -------------------------------------------------------------------------------- 1 | System.Configuration.ConfigurationManager 2 | Newtonsoft.Json --------------------------------------------------------------------------------