예제 #1
0
        public RpcConnector(ICoinService coinService)
        {
            _coinService = coinService;
            lock (locker)
            {
                if (!clients.ContainsKey(_coinService.Parameters.SelectedDaemonUrl))
                {
                    HttpClientHandler hch = new HttpClientHandler();
                    hch.Proxy    = null;
                    hch.UseProxy = false;
                    client       = new HttpClient(hch);
                    clients.Add(_coinService.Parameters.SelectedDaemonUrl, client);
                }
                else
                {
                    client = clients[_coinService.Parameters.SelectedDaemonUrl];
                }
            }
            var sb = new StringBuilder();

            sb.Append(_coinService.Parameters.RpcUsername);
            sb.Append(":");
            sb.Append(_coinService.Parameters.RpcPassword);
            var authenticationBytes = Encoding.ASCII.GetBytes(sb.ToString());

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                                                                                       Convert.ToBase64String(authenticationBytes));
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }
        private void tscbWallets_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <WalletSettings> wallets = Utils.GetWalletSettings();

            foreach (WalletSettings wallet in wallets)
            {
                if (wallet.walletName == tscbWallets.ComboBox.Text)
                {
                    // this is the wallet we want to use.
                    try
                    {
                        xayaCoinService = new XAYAService(wallet.daemonUrl,
                                                          wallet.rpcUsername,
                                                          wallet.rpcPassword,
                                                          wallet.walletPassword,
                                                          wallet.rpcRequestTimeoutInSeconds);
                        this.Text = tscbWallets.Text + " wallet balance: " + string.Format("{0:0,0.00000000}", xayaCoinService.GetBalance()).ToString();
                    }
                    catch
                    {
                        this.Text = "Failed to load default wallet.";
                        MessageBox.Show("Failed to load default wallet. \r\n\r\nMake corrections in settings & try again. \r\n\r\n(Probably username & password are wrong or blank.)");
                    }
                }
            }
        }
예제 #3
0
        public ActorService(IOnionServiceClient onionService, IWalletService walletService, ICoinService coinService, IConfiguration configuration, ILogger logger, IUnitOfWork unitOfWork)
        {
            this.onionService  = onionService;
            this.walletService = walletService;
            this.coinService   = coinService;
            this.logger        = logger;
            this.unitOfWork    = unitOfWork;

            Client = onionService.OnionEnabled.Equals(1) ?
                     new Client(configuration, logger, new DotNetTor.SocksPort.SocksPortHandler(onionService.SocksHost, onionService.SocksPort)) :
                     new Client(configuration, logger);

            Sessions = new ConcurrentDictionary <Guid, Session>();
            machine  = new StateMachine <State, Trigger>(State.New);

            verifyTrigger            = machine.SetTriggerParameters <Guid>(Trigger.Verify);
            unlockTrigger            = machine.SetTriggerParameters <Guid>(Trigger.Unlock);
            burnTrigger              = machine.SetTriggerParameters <Guid>(Trigger.Torch);
            commitReceiverTrigger    = machine.SetTriggerParameters <Guid>(Trigger.Commit);
            redemptionKeyTrigger     = machine.SetTriggerParameters <Guid>(Trigger.PrepareRedemptionKey);
            publicKeyAgreementTrgger = machine.SetTriggerParameters <Guid>(Trigger.PublicKeyAgreement);
            paymentTrgger            = machine.SetTriggerParameters <Guid>(Trigger.PaymentAgreement);
            reversedTrgger           = machine.SetTriggerParameters <Guid>(Trigger.RollBack);

            Configure();

            // Test().GetAwaiter().GetResult();
        }
예제 #4
0
        // Includes a couple ways to get the config. Should be done differently in a real app.
        // The rpcPassword should be fixed for your own wallet.
        private void Form1_Load(object sender, EventArgs e)
        {
            // This is to just be able to close the wallet and not have to do any reconfig.
            // That is, we'll always have the correct password even across restarts.
            CookieReader cookie = new CookieReader();

            Console.WriteLine("Username = "******"Userpassword = "******"XAYA_DaemonUrl"]; //  + "/wallet/game.dat";
            rpcUsername                = cookie.Username;                                    //  ConfigurationManager.AppSettings["XAYA_RpcUsername"]; //
            rpcPassword                = cookie.Userpassword;                                //  ConfigurationManager.AppSettings["XAYA_RpcPassword"]; //
            walletPassword             = ConfigurationManager.AppSettings["XAYA_WalletPassword"];
            rpcRequestTimeoutInSeconds = 60;

            //daemonUrl = "http://localhost:8396/wallet/game.dat";
            //rpcUsername = "******";
            //rpcPassword = "******";
            //walletPassword = "******";
            //rpcRequestTimeoutInSeconds = 60;

            xayaCoinService = new XAYAService(daemonUrl, rpcUsername, rpcPassword, walletPassword, rpcRequestTimeoutInSeconds);

            this.Text = xayaCoinService.GetBlockCount().ToString();

            foreach (var v in xayaCoinService.GetPeerInfo())
            {
                Console.WriteLine(v.Version);
            }
        }
예제 #5
0
 public GetCoinPriceCommandHandler(IMapper mapper,
                                   ILogger <GetCoinPriceCommandHandler> logger, ICoinService coinService, ICoinRepository coinRepository)
 {
     _mapper         = mapper;
     _logger         = logger;
     _coinService    = coinService;
     _coinRepository = coinRepository;
 }
예제 #6
0
        public MyMnsForm(ICoinService SetCoinService)
        {
            CoinService = SetCoinService;

            InitializeComponent();

            updateMnCoinfig();
        }
 public CoinsController(ICoinService coinService, ICountryService countryService,
                        ICollectorValueService collectorValueService, IMapper mapper)
 {
     _coinService           = coinService;
     _countryService        = countryService;
     _collectorValueService = collectorValueService;
     _mapper = mapper;
 }
 public CustomerController(
     IProductService productService,
     ICoinService coinService,
     ICustomerService customerService)
 {
     _productService  = productService;
     _coinService     = coinService;
     _customerService = customerService;
 }
예제 #9
0
 public CoinController
 (
     IMapper mapper,
     ICoinService coinService
 )
 {
     this._mapper      = mapper;
     this._coinService = coinService;
 }
 public AdminController(
     IProductService productService,
     ICoinService coinService,
     IAdminService adminService)
 {
     _productService = productService;
     _coinService    = coinService;
     _adminService   = adminService;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public LitecoinClientService()
        {
            bool useLitecoinTestNet = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("LtcUseTestNet"));

            _litecoinService = new LitecoinService(useTestnet: useLitecoinTestNet);

            StartTimer();
            Log.Debug(string.Format("Litecoin Timer Started"));
        }
예제 #12
0
        public WalletPrintCommand(IServiceProvider serviceProvider)
        {
            actorService  = serviceProvider.GetService <IActorService>();
            walletService = serviceProvider.GetService <IWalletService>();
            coinService   = serviceProvider.GetService <ICoinService>();
            console       = serviceProvider.GetService <IConsole>();
            logger        = serviceProvider.GetService <ILogger>();

            actorService.MessagePump += ActorService_MessagePump;
        }
예제 #13
0
        public void InitializeTests()
        {
            // HttpContext
            HttpContext.Current = MockHelper.FakeHttpContext();

            // SessionHelper
            SessionHelper.ClearAll();

            _sut = new CoinService();
        }
예제 #14
0
        private CreateRawTransactionRequest createNewRawTransactionRequest(ICoinService coinService, decimal sendAmount, string toAddress, string changeAddress)
        {
            var listUnspent = coinService.ListUnspent().OrderBy(utxo => utxo.Amount);

            //TODO: Read from appdata cloudchains config
            decimal minimumFee    = coinService.Parameters.MinimumTransactionFeeInCoins;
            decimal calculatedFee = 0;
            decimal sum           = 0;

            var utxos = listUnspent.TakeWhile(x =>
            {
                var temp = sum;
                sum     += x.Amount;
                return(temp < sendAmount);
            }).ToList();

            var rawTransactionRequest = new CreateRawTransactionRequest();

            foreach (var utxo in utxos)
            {
                rawTransactionRequest.AddInput(new CreateRawTransactionInput
                {
                    TxId = utxo.TxId,
                    Vout = utxo.Vout
                });
            }

            var inputSum = utxos.Sum(utxo => utxo.Amount);

            if (inputSum > sendAmount)
            {
                rawTransactionRequest.AddOutput(new CreateRawTransactionOutput
                {
                    Address = toAddress,
                    Amount  = sendAmount
                });

                calculatedFee = calculateFee(coinService, rawTransactionRequest.Inputs.Count(), 2);
                rawTransactionRequest.AddOutput(new CreateRawTransactionOutput
                {
                    Address = changeAddress,
                    Amount  = inputSum - sendAmount - (calculatedFee <= minimumFee ? minimumFee : calculatedFee)
                });
            }
            else
            {
                rawTransactionRequest.AddOutput(new CreateRawTransactionOutput
                {
                    Address = toAddress,
                    Amount  = sendAmount - calculateFee(coinService, rawTransactionRequest.Inputs.Count(), 1)
                });
            }
            return(rawTransactionRequest);
        }
예제 #15
0
        public EncryptWalletForm(ICoinService SetCoinService)
        {
            CoinService = SetCoinService;

            InitializeComponent();

            if (!CoinService.IsWalletEncrypted())
            {
                passwordOld.Hide();
                label1.Hide();
            }
        }
예제 #16
0
        public ActorService(IOnionServiceClient onionService, IWalletService walletService, ICoinService coinService, IConfiguration configuration, ILogger logger)
        {
            this.onionService  = onionService;
            this.walletService = walletService;
            this.coinService   = coinService;
            this.logger        = logger;

            client = onionService.OnionEnabled.Equals(1) ?
                     new Client(logger, new DotNetTor.SocksPort.SocksPortHandler(onionService.SocksHost, onionService.SocksPort)) :
                     new Client(logger);

            apiRestSection = configuration.GetSection(Constant.ApiGateway);
        }
        public VendingMachine(ICoinService coinService, IProductService productService)
        {
            if (coinService == null)
            {
                throw new ArgumentNullException("coinService parameter is null");
            }
            if (productService == null)
            {
                throw new ArgumentNullException("productService parameter is null");
            }

            _coinService    = coinService;
            _productService = productService;
        }
예제 #18
0
        private decimal calculateFee(ICoinService coinSvc, int numInputs, int numOutputs)
        {
            decimal relayFee = 10M;

            return
                (coinSvc.Parameters.CoinsPerBaseUnit *
                 (relayFee *
                  (
                      coinSvc.Parameters.TransactionSizeBytesContributedByEachInput * numInputs
                      +
                      coinSvc.Parameters.TransactionSizeBytesContributedByEachOutput * numOutputs
                  )
                 ));
        }
예제 #19
0
        public AsyncRpcConnector(ICoinService coinService)
        {
            _coinService = coinService;
            _httpClient  = new Lazy <HttpClient>(() =>
            {
                var httpClient = new HttpClient(new RpcClientHandler(coinService.Parameters));

                var authInfo = $"{coinService.Parameters.RpcUsername}:{coinService.Parameters.RpcPassword}";
                authInfo     = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));

                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authInfo);

                return(httpClient);
            });
        }
예제 #20
0
        public RPCNodeIntegration(Settings settings, IContextFactory contextFactory, FatalErrorNotifier fatalNotifier)
        {
            var daemonUrl   = settings.ConfigReader.GetOrDefault <string>("daemonUrl", "http://127.0.0.1:23521/");
            var rpcUsername = settings.ConfigReader.GetOrDefault <string>("rpcUsername", "user");
            var rpcPassword = settings.ConfigReader.GetOrDefault <string>("rpcPassword", "pass");
            var rpcRequestTimeoutInSeconds = settings.ConfigReader.GetOrDefault <short>("rpcTimeout", 20);

            this.walletPassword = settings.ConfigReader.GetOrDefault <string>("walletPassword", "walletpass");

            this.coinService    = new BitcoinService(daemonUrl, rpcUsername, rpcPassword, this.walletPassword, rpcRequestTimeoutInSeconds);
            this.contextFactory = contextFactory;
            this.settings       = settings;
            this.cancellation   = new CancellationTokenSource();
            this.logger         = LogManager.GetCurrentClassLogger();
            this.fatalNotifier  = fatalNotifier;
        }
        public RPCNodeIntegration(Settings settings, IContextFactory contextFactory)
        {
            // To run stratis daemon that supports RPC use "dotnet exec ...\netcoreapp2.1\Stratis.StratisD.dll -rpcuser=user -rpcpassword=4815162342 -rpcport=23521 -server=1"
            var daemonUrl   = settings.ConfigReader.GetOrDefault <string>("daemonUrl", "http://127.0.0.1:23521/");
            var rpcUsername = settings.ConfigReader.GetOrDefault <string>("rpcUsername", "user");
            var rpcPassword = settings.ConfigReader.GetOrDefault <string>("rpcPassword", "4815162342");
            var rpcRequestTimeoutInSeconds = settings.ConfigReader.GetOrDefault <short>("rpcTimeout", 20);

            this.walletPassword = settings.ConfigReader.GetOrDefault <string>("walletPassword", "4815162342");

            this.coinService    = new BitcoinService(daemonUrl, rpcUsername, rpcPassword, this.walletPassword, rpcRequestTimeoutInSeconds);
            this.contextFactory = contextFactory;
            this.settings       = settings;
            this.cancellation   = new CancellationTokenSource();
            this.logger         = LogManager.GetCurrentClassLogger();
        }
예제 #22
0
            public CoinParameters(ICoinService coinService,
                                  string daemonUrl,
                                  string rpcUsername,
                                  string rpcPassword,
                                  string walletPassword,
                                  short rpcRequestTimeoutInSeconds)
            {
                if (!string.IsNullOrWhiteSpace(daemonUrl))
                {
                    DaemonUrl         = daemonUrl;
                    UseTestnet        = false; //  this will force the CoinParameters.SelectedDaemonUrl dynamic property to automatically pick the daemonUrl defined above
                    IgnoreConfigFiles = true;
                    RpcUsername       = rpcUsername;
                    RpcPassword       = rpcPassword;
                    WalletPassword    = walletPassword;
                }

                if (rpcRequestTimeoutInSeconds > 0)
                {
                    RpcRequestTimeoutInSeconds = rpcRequestTimeoutInSeconds;
                }
                else
                {
                    short rpcRequestTimeoutTryParse = 0;

                    if (short.TryParse(ConfigurationManager.AppSettings.Get("RpcRequestTimeoutInSeconds"), out rpcRequestTimeoutTryParse))
                    {
                        RpcRequestTimeoutInSeconds = rpcRequestTimeoutTryParse;
                    }
                }

                if (IgnoreConfigFiles && (string.IsNullOrWhiteSpace(DaemonUrl) || string.IsNullOrWhiteSpace(RpcUsername) || string.IsNullOrWhiteSpace(RpcPassword)))
                {
                    throw new Exception($"One or more required parameters, as defined in {GetType().Name}, were not found in the configuration file!");
                }

                if (IgnoreConfigFiles && Debugger.IsAttached && string.IsNullOrWhiteSpace(WalletPassword))
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("[WARNING] The wallet password is either null or empty");
                    Console.ResetColor();
                }
            }
예제 #23
0
 public RpcConnector(ICoinService coinService)
 {
     _coinService = coinService;
 }
예제 #24
0
 //  Usage example:  String networkDifficultyJsonResult = RawRpcConnector.MakeRequest("{\"method\":\"getdifficulty\",\"params\":[],\"id\":1}", new BitcoinService());
 public async static Task <string> MakeRequest(string jsonRequest, ICoinService coinService)
 {
     return(await MakeRequest(jsonRequest, coinService.Parameters.SelectedDaemonUrl, coinService.Parameters.RpcUsername, coinService.Parameters.RpcPassword));
 }
예제 #25
0
 public CoinController(ICoinService coinService)
 {
     _coinService = coinService;
 }
 public CoinCreationDtoValidator(ICoinService service, IMapper mapper)
     : base(service, mapper)
 {
 }
 public static void SwitchNetworks(this ICoinService coinService)
 {
     coinService.Parameters.UseTestnet = !coinService.Parameters.UseTestnet;
 }
예제 #28
0
            public CoinParameters(ICoinService coinService,
                string daemonUrl,
                string rpcUsername,
                string rpcPassword,
                string walletPassword,
                short rpcRequestTimeoutInSeconds)
            {
                var appSettings = new ConfigurationBuilder().AddJsonFile("config.json").Build().GetSection("AppSettings");

                if (!string.IsNullOrWhiteSpace(daemonUrl))
                {
                    DaemonUrl = daemonUrl;
                    UseTestnet = false; //  this will force the CoinParameters.SelectedDaemonUrl dynamic property to automatically pick the daemonUrl defined above
                    IgnoreConfigFiles = true;
                    RpcUsername = rpcUsername;
                    RpcPassword = rpcPassword;
                    WalletPassword = walletPassword;
                }

                if (rpcRequestTimeoutInSeconds > 0)
                {
                    RpcRequestTimeoutInSeconds = rpcRequestTimeoutInSeconds;
                }
                else
                {
                    short rpcRequestTimeoutTryParse = 0;

                    if (short.TryParse(appSettings.GetSection("RpcRequestTimeoutInSeconds").Value, out rpcRequestTimeoutTryParse))
                    {
                        RpcRequestTimeoutInSeconds = rpcRequestTimeoutTryParse;
                    }
                }

                if (IgnoreConfigFiles && (string.IsNullOrWhiteSpace(DaemonUrl) || string.IsNullOrWhiteSpace(RpcUsername) || string.IsNullOrWhiteSpace(RpcPassword)))
                {
                    throw new Exception($"One or more required parameters, as defined in {GetType().Name}, were not found in the configuration file!");
                }

                if (IgnoreConfigFiles && Debugger.IsAttached && string.IsNullOrWhiteSpace(WalletPassword))
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("[WARNING] The wallet password is either null or empty");
                    Console.ResetColor();
                }

                #region Bitcoin

                if (coinService is BitcoinService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl = appSettings.GetSection("Bitcoin_DaemonUrl").Value;
                        DaemonUrlTestnet = appSettings.GetSection("Bitcoin_DaemonUrl_Testnet").Value;
                        RpcUsername = appSettings.GetSection("Bitcoin_RpcUsername").Value;
                        RpcPassword = appSettings.GetSection("Bitcoin_RpcPassword").Value;
                        WalletPassword = appSettings.GetSection("Bitcoin_WalletPassword").Value;
                    }

                    CoinShortName = "BTC";
                    CoinLongName = "Bitcoin";
                    IsoCurrencyCode = "XBT";

                    TransactionSizeBytesContributedByEachInput = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes = 10;

                    FreeTransactionMaximumSizeInBytes = 1000;
                    FreeTransactionMinimumOutputAmountInCoins = 0.01M;
                    FreeTransactionMinimumPriority = 57600000;
                    FeePerThousandBytesInCoins = 0.0001M;
                    MinimumTransactionFeeInCoins = 0.0001M;
                    MinimumNonDustTransactionAmountInCoins = 0.0000543M;

                    TotalCoinSupplyInCoins = 21000000;
                    EstimatedBlockGenerationTimeInMinutes = 10;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;

                    BaseUnitName = "Satoshi";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }

                #endregion

                #region Litecoin

                else if (coinService is LitecoinService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl = appSettings.GetSection("Litecoin_DaemonUrl").Value;
                        DaemonUrlTestnet = appSettings.GetSection("Litecoin_DaemonUrl_Testnet").Value;
                        RpcUsername = appSettings.GetSection("Litecoin_RpcUsername").Value;
                        RpcPassword = appSettings.GetSection("Litecoin_RpcPassword").Value;
                        WalletPassword = appSettings.GetSection("Litecoin_WalletPassword").Value;
                    }

                    CoinShortName = "LTC";
                    CoinLongName = "Litecoin";
                    IsoCurrencyCode = "XLT";

                    TransactionSizeBytesContributedByEachInput = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes = 10;

                    FreeTransactionMaximumSizeInBytes = 5000;
                    FreeTransactionMinimumOutputAmountInCoins = 0.001M;
                    FreeTransactionMinimumPriority = 230400000;
                    FeePerThousandBytesInCoins = 0.001M;
                    MinimumTransactionFeeInCoins = 0.001M;
                    MinimumNonDustTransactionAmountInCoins = 0.001M;

                    TotalCoinSupplyInCoins = 84000000;
                    EstimatedBlockGenerationTimeInMinutes = 2.5;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000;
                    BlockMaximumSizeInBytes = 250000;

                    BaseUnitName = "Litetoshi";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }

                #endregion

                #region Dogecoin

                else if (coinService is DogecoinService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl = appSettings.GetSection("Dogecoin_DaemonUrl").Value;
                        DaemonUrlTestnet = appSettings.GetSection("Dogecoin_DaemonUrl_Testnet").Value;
                        RpcUsername = appSettings.GetSection("Dogecoin_RpcUsername").Value;
                        RpcPassword = appSettings.GetSection("Dogecoin_RpcPassword").Value;
                        WalletPassword = appSettings.GetSection("Dogecoin_WalletPassword").Value;
                    }

                    CoinShortName = "Doge";
                    CoinLongName = "Dogecoin";
                    IsoCurrencyCode = "XDG";
                    TransactionSizeBytesContributedByEachInput = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes = 10;
                    FreeTransactionMaximumSizeInBytes = 1; // free txs are not supported from v.1.8+
                    FreeTransactionMinimumOutputAmountInCoins = 1;
                    FreeTransactionMinimumPriority = 230400000;
                    FeePerThousandBytesInCoins = 1;
                    MinimumTransactionFeeInCoins = 1;
                    MinimumNonDustTransactionAmountInCoins = 0.1M;
                    TotalCoinSupplyInCoins = 100000000000;
                    EstimatedBlockGenerationTimeInMinutes = 1;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000;
                    BlockMaximumSizeInBytes = 500000;
                    BaseUnitName = "Koinu";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }

                #endregion

                #region Sarcoin

                else if (coinService is SarcoinService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl = appSettings.GetSection("Sarcoin_DaemonUrl").Value;
                        DaemonUrlTestnet = appSettings.GetSection("Sarcoin_DaemonUrl_Testnet").Value;
                        RpcUsername = appSettings.GetSection("Sarcoin_RpcUsername").Value;
                        RpcPassword = appSettings.GetSection("Sarcoin_RpcPassword").Value;
                        WalletPassword = appSettings.GetSection("Sarcoin_WalletPassword").Value;
                    }

                    CoinShortName = "SAR";
                    CoinLongName = "Sarcoin";
                    IsoCurrencyCode = "SAR";

                    TransactionSizeBytesContributedByEachInput = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes = 10;

                    FreeTransactionMaximumSizeInBytes = 0;
                    FreeTransactionMinimumOutputAmountInCoins = 0;
                    FreeTransactionMinimumPriority = 0;
                    FeePerThousandBytesInCoins = 0.00001M;
                    MinimumTransactionFeeInCoins = 0.00001M;
                    MinimumNonDustTransactionAmountInCoins = 0.00001M;

                    TotalCoinSupplyInCoins = 2000000000;
                    EstimatedBlockGenerationTimeInMinutes = 1.5;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;

                    BaseUnitName = "Satoshi";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }

                #endregion

                #region Agnostic coin (cryptocoin)

                else if (coinService is CryptocoinService)
                {
                    CoinShortName = "XXX";
                    CoinLongName = "Generic Cryptocoin Template";
                    IsoCurrencyCode = "XXX";

                    //  Note: The rest of the parameters will have to be defined at run-time
                }

                #endregion

                #region Uknown coin exception

                else
                {
                    throw new Exception("Unknown coin!");
                }

                #endregion

                #region Invalid configuration / Missing parameters

                if (RpcRequestTimeoutInSeconds <= 0)
                {
                    throw new Exception("RpcRequestTimeoutInSeconds must be greater than zero");
                }

                if (string.IsNullOrWhiteSpace(DaemonUrl)
                    || string.IsNullOrWhiteSpace(RpcUsername)
                    || string.IsNullOrWhiteSpace(RpcPassword))
                {
                    throw new Exception($"One or more required parameters, as defined in {GetType().Name}, were not found in the configuration file!");
                }

                #endregion
            }
예제 #29
0
 public void Setup()
 {
     _coinService    = new CoinService();
     _vendingMachine = new VendMachine(_coinService);
 }
예제 #30
0
 //  Usage example:  String networkDifficultyJsonResult = RawRpcConnector.MakeRequest("{\"method\":\"getdifficulty\",\"params\":[],\"id\":1}", new BitcoinService());
 public static String MakeRequest(String jsonRequest, ICoinService coinService)
 {
     return MakeRequest(jsonRequest, coinService.Parameters.SelectedDaemonUrl, coinService.Parameters.RpcUsername, coinService.Parameters.RpcPassword);
 }
예제 #31
0
            public CoinParameters(ICoinService coinService,
                                  string daemonUrl,
                                  string rpcUsername,
                                  string rpcPassword,
                                  string walletPassword,
                                  short rpcRequestTimeoutInSeconds)
            {
                if (!string.IsNullOrWhiteSpace(daemonUrl))
                {
                    DaemonUrl         = daemonUrl;
                    UseTestnet        = false; //  this will force the CoinParameters.SelectedDaemonUrl dynamic property to automatically pick the daemonUrl defined above
                    IgnoreConfigFiles = true;
                    RpcUsername       = rpcUsername;
                    RpcPassword       = rpcPassword;
                    WalletPassword    = walletPassword;
                }

                if (rpcRequestTimeoutInSeconds > 0)
                {
                    RpcRequestTimeoutInSeconds = rpcRequestTimeoutInSeconds;
                }
                else
                {
                    short rpcRequestTimeoutTryParse = 0;

                    if (short.TryParse(ConfigurationManager.AppSettings.Get("RpcRequestTimeoutInSeconds"), out rpcRequestTimeoutTryParse))
                    {
                        RpcRequestTimeoutInSeconds = rpcRequestTimeoutTryParse;
                    }
                }

                if (IgnoreConfigFiles && (string.IsNullOrWhiteSpace(DaemonUrl) || string.IsNullOrWhiteSpace(RpcUsername) || string.IsNullOrWhiteSpace(RpcPassword)))
                {
                    throw new Exception($"One or more required parameters, as defined in {GetType().Name}, were not found in the configuration file!");
                }

                if (IgnoreConfigFiles && Debugger.IsAttached && string.IsNullOrWhiteSpace(WalletPassword))
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("[WARNING] The wallet password is either null or empty");
                    Console.ResetColor();
                }

                #region Bitcoin

                if (coinService is BitcoinService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl        = ConfigurationManager.AppSettings.Get("Bitcoin_DaemonUrl");
                        DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Bitcoin_DaemonUrl_Testnet");
                        RpcUsername      = ConfigurationManager.AppSettings.Get("Bitcoin_RpcUsername");
                        RpcPassword      = ConfigurationManager.AppSettings.Get("Bitcoin_RpcPassword");
                        WalletPassword   = ConfigurationManager.AppSettings.Get("Bitcoin_WalletPassword");
                    }

                    CoinShortName   = "BTC";
                    CoinLongName    = "Bitcoin";
                    IsoCurrencyCode = "XBT";

                    TransactionSizeBytesContributedByEachInput  = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes        = 10;

                    FreeTransactionMaximumSizeInBytes         = 1000;
                    FreeTransactionMinimumOutputAmountInCoins = 0.01M;
                    FreeTransactionMinimumPriority            = 57600000;
                    FeePerThousandBytesInCoins             = 0.0001M;
                    MinimumTransactionFeeInCoins           = 0.0001M;
                    MinimumNonDustTransactionAmountInCoins = 0.0000543M;

                    TotalCoinSupplyInCoins = 21000000;
                    EstimatedBlockGenerationTimeInMinutes = 10;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;

                    BaseUnitName     = "Satoshi";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }

                #endregion

                #region Litecoin

                else if (coinService is LitecoinService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl        = ConfigurationManager.AppSettings.Get("Litecoin_DaemonUrl");
                        DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Litecoin_DaemonUrl_Testnet");
                        RpcUsername      = ConfigurationManager.AppSettings.Get("Litecoin_RpcUsername");
                        RpcPassword      = ConfigurationManager.AppSettings.Get("Litecoin_RpcPassword");
                        WalletPassword   = ConfigurationManager.AppSettings.Get("Litecoin_WalletPassword");
                    }

                    CoinShortName   = "LTC";
                    CoinLongName    = "Litecoin";
                    IsoCurrencyCode = "XLT";

                    TransactionSizeBytesContributedByEachInput  = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes        = 10;

                    FreeTransactionMaximumSizeInBytes         = 5000;
                    FreeTransactionMinimumOutputAmountInCoins = 0.001M;
                    FreeTransactionMinimumPriority            = 230400000;
                    FeePerThousandBytesInCoins             = 0.001M;
                    MinimumTransactionFeeInCoins           = 0.001M;
                    MinimumNonDustTransactionAmountInCoins = 0.001M;

                    TotalCoinSupplyInCoins = 84000000;
                    EstimatedBlockGenerationTimeInMinutes = 2.5;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000;
                    BlockMaximumSizeInBytes = 250000;

                    BaseUnitName     = "Litetoshi";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }

                #endregion

                #region Dogecoin

                else if (coinService is DogecoinService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl        = ConfigurationManager.AppSettings.Get("Dogecoin_DaemonUrl");
                        DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Dogecoin_DaemonUrl_Testnet");
                        RpcUsername      = ConfigurationManager.AppSettings.Get("Dogecoin_RpcUsername");
                        RpcPassword      = ConfigurationManager.AppSettings.Get("Dogecoin_RpcPassword");
                        WalletPassword   = ConfigurationManager.AppSettings.Get("Dogecoin_WalletPassword");
                    }

                    CoinShortName   = "Doge";
                    CoinLongName    = "Dogecoin";
                    IsoCurrencyCode = "XDG";
                    TransactionSizeBytesContributedByEachInput  = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes        = 10;
                    FreeTransactionMaximumSizeInBytes           = 1; // free txs are not supported from v.1.8+
                    FreeTransactionMinimumOutputAmountInCoins   = 1;
                    FreeTransactionMinimumPriority         = 230400000;
                    FeePerThousandBytesInCoins             = 1;
                    MinimumTransactionFeeInCoins           = 1;
                    MinimumNonDustTransactionAmountInCoins = 0.1M;
                    TotalCoinSupplyInCoins = 100000000000;
                    EstimatedBlockGenerationTimeInMinutes = 1;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000;
                    BlockMaximumSizeInBytes = 500000;
                    BaseUnitName            = "Koinu";
                    BaseUnitsPerCoin        = 100000000;
                    CoinsPerBaseUnit        = 0.00000001M;
                }

                #endregion

                #region Sarcoin

                else if (coinService is SarcoinService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl        = ConfigurationManager.AppSettings.Get("Sarcoin_DaemonUrl");
                        DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Sarcoin_DaemonUrl_Testnet");
                        RpcUsername      = ConfigurationManager.AppSettings.Get("Sarcoin_RpcUsername");
                        RpcPassword      = ConfigurationManager.AppSettings.Get("Sarcoin_RpcPassword");
                        WalletPassword   = ConfigurationManager.AppSettings.Get("Sarcoin_WalletPassword");
                    }

                    CoinShortName   = "SAR";
                    CoinLongName    = "Sarcoin";
                    IsoCurrencyCode = "SAR";

                    TransactionSizeBytesContributedByEachInput  = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes        = 10;

                    FreeTransactionMaximumSizeInBytes         = 0;
                    FreeTransactionMinimumOutputAmountInCoins = 0;
                    FreeTransactionMinimumPriority            = 0;
                    FeePerThousandBytesInCoins             = 0.00001M;
                    MinimumTransactionFeeInCoins           = 0.00001M;
                    MinimumNonDustTransactionAmountInCoins = 0.00001M;

                    TotalCoinSupplyInCoins = 2000000000;
                    EstimatedBlockGenerationTimeInMinutes = 1.5;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;

                    BaseUnitName     = "Satoshi";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }

                #endregion

                #region Dash

                else if (coinService is DashService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl        = ConfigurationManager.AppSettings.Get("Dash_DaemonUrl");
                        DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Dash_DaemonUrl_Testnet");
                        RpcUsername      = ConfigurationManager.AppSettings.Get("Dash_RpcUsername");
                        RpcPassword      = ConfigurationManager.AppSettings.Get("Dash_RpcPassword");
                        WalletPassword   = ConfigurationManager.AppSettings.Get("Dash_WalletPassword");
                    }

                    CoinShortName   = "DASH";
                    CoinLongName    = "Dash";
                    IsoCurrencyCode = "DASH";

                    TransactionSizeBytesContributedByEachInput  = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes        = 10;

                    FreeTransactionMaximumSizeInBytes         = 1000;
                    FreeTransactionMinimumOutputAmountInCoins = 0.0001M;
                    FreeTransactionMinimumPriority            = 57600000;
                    FeePerThousandBytesInCoins             = 0.0001M;
                    MinimumTransactionFeeInCoins           = 0.001M;
                    MinimumNonDustTransactionAmountInCoins = 0.0000543M;

                    TotalCoinSupplyInCoins = 18900000;
                    EstimatedBlockGenerationTimeInMinutes = 2.7;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;

                    BaseUnitName     = "Duff";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }

                #endregion

                #region Smartcash

                else if (coinService is SmartcashService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl        = ConfigurationManager.AppSettings.Get("Smartcash_DaemonUrl");
                        DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Smartcash_DaemonUrl_Testnet");
                        RpcUsername      = ConfigurationManager.AppSettings.Get("Smartcash_RpcUsername");
                        RpcPassword      = ConfigurationManager.AppSettings.Get("Smartcash_RpcPassword");
                        WalletPassword   = ConfigurationManager.AppSettings.Get("Smartcash_WalletPassword");
                    }

                    CoinShortName   = "SMART";
                    CoinLongName    = "Smartcash";
                    IsoCurrencyCode = "SMART";

                    TransactionSizeBytesContributedByEachInput  = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes        = 10;

                    FreeTransactionMaximumSizeInBytes         = 0; // free txs are not supported
                    FreeTransactionMinimumOutputAmountInCoins = 0;
                    FreeTransactionMinimumPriority            = 0;
                    FeePerThousandBytesInCoins             = 0.0001M;
                    MinimumTransactionFeeInCoins           = 0.001M;
                    MinimumNonDustTransactionAmountInCoins = 0.00001M;

                    TotalCoinSupplyInCoins = 5000000000;
                    EstimatedBlockGenerationTimeInMinutes = 0.916667;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;

                    BaseUnitName     = "Smartoshi";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }

                #endregion

                #region Dallar

                else if (coinService is DallarService)
                {
                    if (!IgnoreConfigFiles)
                    {
                        DaemonUrl        = ConfigurationManager.AppSettings.Get("Dallar_DaemonUrl");
                        DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Dallar_DaemonUrl_Testnet");
                        RpcUsername      = ConfigurationManager.AppSettings.Get("Dallar_RpcUsername");
                        RpcPassword      = ConfigurationManager.AppSettings.Get("Dallar_RpcPassword");
                        WalletPassword   = ConfigurationManager.AppSettings.Get("Dallar_WalletPassword");
                    }

                    CoinShortName   = "DAL";
                    CoinLongName    = "Dallar";
                    IsoCurrencyCode = "DAL";

                    TransactionSizeBytesContributedByEachInput  = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes        = 10;

                    FreeTransactionMaximumSizeInBytes         = 1000;
                    FreeTransactionMinimumOutputAmountInCoins = 0.001M;
                    FreeTransactionMinimumPriority            = 230400000;
                    FeePerThousandBytesInCoins             = 0.001M;
                    MinimumTransactionFeeInCoins           = 0.0001M;
                    MinimumNonDustTransactionAmountInCoins = 0.001M;

                    TotalCoinSupplyInCoins = 80000000;
                    EstimatedBlockGenerationTimeInMinutes = 1.0;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000;
                    BlockMaximumSizeInBytes = 750000;

                    BaseUnitName     = "Allar";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }

                #endregion

                #region Agnostic coin (cryptocoin)

                else if (coinService is CryptocoinService)
                {
                    CoinShortName   = "XXX";
                    CoinLongName    = "Generic Cryptocoin Template";
                    IsoCurrencyCode = "XXX";

                    //  Note: The rest of the parameters will have to be defined at run-time
                }

                #endregion

                #region Uknown coin exception

                else
                {
                    throw new Exception("Unknown coin!");
                }

                #endregion

                #region Invalid configuration / Missing parameters

                if (RpcRequestTimeoutInSeconds <= 0)
                {
                    throw new Exception("RpcRequestTimeoutInSeconds must be greater than zero");
                }

                if (string.IsNullOrWhiteSpace(DaemonUrl) ||
                    string.IsNullOrWhiteSpace(RpcUsername) ||
                    string.IsNullOrWhiteSpace(RpcPassword))
                {
                    throw new Exception($"One or more required parameters, as defined in {GetType().Name}, were not found in the configuration file!");
                }

                #endregion
            }
예제 #32
0
 public static void ConnectToRpc(string daemonUrl, string rpcUsername, string rpcPassword, string walletPassword)
 {
     bitcoin_Logger = new responseTip.Helpers.Logger();
     bitcoin_Logger.SetPath("C:\\Users\\GereG\\Source\\Repos\\ResponseTip\\responseTip");
     CoinService = new BitcoinService(daemonUrl, rpcUsername, rpcPassword, walletPassword);
 }
예제 #33
0
 public RestRequestClient(ICoinService coinService)
 {
     _coinService = coinService;
 }
예제 #34
0
            public CoinParameters(ICoinService coinService)
                : this()
            {
                if (coinService is BitcoinService)
                {
                    DaemonUrl = ConfigurationManager.AppSettings.Get("Bitcoin_DaemonUrl");
                    DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Bitcoin_DaemonUrl_Testnet");
                    RpcUsername = ConfigurationManager.AppSettings.Get("Bitcoin_RpcUsername");
                    RpcPassword = ConfigurationManager.AppSettings.Get("Bitcoin_RpcPassword");
                    WalletPassword = ConfigurationManager.AppSettings.Get("Bitcoin_WalletPassword");

                    CoinShortName = "BTC";
                    CoinLongName = "Bitcoin";
                    IsoCurrencyCode = "XBT";

                    TransactionSizeBytesContributedByEachInput = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes = 10;

                    FreeTransactionMaximumSizeInBytes = 1000;
                    FreeTransactionMinimumOutputAmountInCoins = 0.01M;
                    FreeTransactionMinimumPriority = 57600000;
                    FeePerThousandBytesInCoins = 0.0001M;
                    MinimumTransactionFeeInCoins = 0.0001M;
                    MinimumNonDustTransactionAmountInCoins = 0.0000543M;

                    TotalCoinSupplyInCoins = 21000000;
                    EstimatedBlockGenerationTimeInMinutes = 10;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 50000;

                    BaseUnitName = "Satoshi";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }
                else if (coinService is LitecoinService)
                {
                    DaemonUrl = ConfigurationManager.AppSettings.Get("Litecoin_DaemonUrl");
                    DaemonUrlTestnet = ConfigurationManager.AppSettings.Get("Litecoin_DaemonUrl_Testnet");
                    RpcUsername = ConfigurationManager.AppSettings.Get("Litecoin_RpcUsername");
                    RpcPassword = ConfigurationManager.AppSettings.Get("Litecoin_RpcPassword");
                    WalletPassword = ConfigurationManager.AppSettings.Get("Litecoin_WalletPassword");

                    CoinShortName = "LTC";
                    CoinLongName = "Litecoin";
                    IsoCurrencyCode = "XLT";

                    TransactionSizeBytesContributedByEachInput = 148;
                    TransactionSizeBytesContributedByEachOutput = 34;
                    TransactionSizeFixedExtraSizeInBytes = 10;

                    FreeTransactionMaximumSizeInBytes = 5000;
                    FreeTransactionMinimumOutputAmountInCoins = 0.001M;
                    FreeTransactionMinimumPriority = 230400000;
                    FeePerThousandBytesInCoins = 0.001M;
                    MinimumTransactionFeeInCoins = 0.001M;
                    MinimumNonDustTransactionAmountInCoins = 0.001M;

                    TotalCoinSupplyInCoins = 84000000;
                    EstimatedBlockGenerationTimeInMinutes = 2.5;
                    BlocksHighestPriorityTransactionsReservedSizeInBytes = 16000;
                    BlockMaximumSizeInBytes = 250000;

                    BaseUnitName = "Litetoshi";
                    BaseUnitsPerCoin = 100000000;
                    CoinsPerBaseUnit = 0.00000001M;
                }
                else if (coinService is CryptocoinService)
                {
                    CoinShortName = "XXX";
                    CoinLongName = "Generic Cryptocoin Template";
                    IsoCurrencyCode = "XXX";

                    //  Note: The rest of the parameters will have to be defined at run-time
                }
                else
                {
                    throw new Exception("Unknown coin!");
                }
            }