示例#1
0
        public MarketBase(MetaDaemonApi daemon, MarketRow market, BitsharesWallet bitshares, BitcoinWallet bitcoin, string bitsharesAccount)
        {
            m_daemon = daemon;
            m_market = market;

            m_bitshares        = bitshares;
            m_bitcoin          = bitcoin;
            m_bitsharesAccount = bitsharesAccount;
        }
示例#2
0
        public MarketBase(MetaDaemonApi daemon, MarketRow market, BitsharesWallet bitshares, BitcoinWallet bitcoin, string bitsharesAccount)
        {
            m_daemon = daemon;
            m_market = market;

            m_bitshares = bitshares;
            m_bitcoin = bitcoin;
            m_bitsharesAccount = bitsharesAccount;
        }
示例#3
0
        /// <summary>	Constructor. </summary>
        ///
        /// <remarks>	Paul, 17/01/2015. </remarks>
        ///
        /// <param name="bitsharesConfig">		 	The bitshares configuration. </param>
        /// <param name="bitcoinConfig">		 	The bitcoin configuration. </param>
        /// <param name="bitsharesAccount">		 	The bitshares account. </param>
        /// <param name="bitsharesAsset">		 	The bitshares asset. </param>
        /// <param name="bitcoinDespositAddress">	The bitcoin desposit address. </param>
        public DaemonBase(	RpcConfig bitsharesConfig, RpcConfig bitcoinConfig, 
							string bitsharesAccount, string adminUsernames)
        {
            m_bitshares = new BitsharesWallet(bitsharesConfig.m_url, bitsharesConfig.m_rpcUser, bitsharesConfig.m_rpcPassword);
            m_bitcoin = new BitcoinWallet(bitcoinConfig.m_url, bitcoinConfig.m_rpcUser, bitcoinConfig.m_rpcPassword, false);

            m_bitsharesAccount = bitsharesAccount;
            m_adminUsernames = adminUsernames.Split(',');

            m_addressByteType = (byte)(bitcoinConfig.m_useTestnet ? AltCoinAddressTypeBytes.BitcoinTestnet : AltCoinAddressTypeBytes.Bitcoin);
        }
示例#4
0
        /// <summary>	Constructor. </summary>
        ///
        /// <remarks>	Paul, 17/01/2015. </remarks>
        ///
        /// <param name="bitsharesConfig">		    The bitshares configuration. </param>
        /// <param name="bitcoinConfig">		    The bitcoin configuration. </param>
        /// <param name="bitsharesAccount">		    The bitshares account. </param>
        /// <param name="bitsharesAsset">		    The bitshares asset. </param>
        /// <param name="bitcoinDespositAddress">	The bitcoin desposit address. </param>
        public DaemonBase(RpcConfig bitsharesConfig, RpcConfig bitcoinConfig,
                          string bitsharesAccount, string adminUsernames)
        {
            m_bitshares = new BitsharesWallet(bitsharesConfig.m_url, bitsharesConfig.m_rpcUser, bitsharesConfig.m_rpcPassword);
            m_bitcoin   = new BitcoinWallet(bitcoinConfig.m_url, bitcoinConfig.m_rpcUser, bitcoinConfig.m_rpcPassword, false);

            m_bitsharesAccount = bitsharesAccount;
            m_adminUsernames   = adminUsernames.Split(',');

            m_addressByteType = (byte)(bitcoinConfig.m_useTestnet ? AltCoinAddressTypeBytes.BitcoinTestnet : AltCoinAddressTypeBytes.Bitcoin);
        }
示例#5
0
        /// <summary>	Constructor. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="uid">			    The UID. </param>
        /// <param name="base">			    The base. </param>
        /// <param name="quote">		    The quote. </param>
        /// <param name="bitshares">	    The bitshares. </param>
        /// <param name="bitcoin">		    The bitcoin. </param>
        /// <param name="bitsharesAccount">	The bitshares account. </param>
        public InternalMarket(MetaDaemonApi daemon, MarketRow market, BitsharesWallet bitshares, BitcoinWallet bitcoin,
                              string bitsharesAccount, CurrenciesRow bitsharesAsset) :
            base(daemon, market, bitshares, bitcoin, bitsharesAccount)
        {
            m_currency = bitsharesAsset;
            m_flipped  = m_market.GetBase(daemon.m_AllCurrencies) != bitsharesAsset;
            m_asset    = m_bitshares.BlockchainGetAsset(CurrencyHelpers.ToBitsharesSymbol(bitsharesAsset));

            Dictionary <int, ulong> allBitsharesBalances = m_bitshares.WalletAccountBalance(bitsharesAccount)[bitsharesAccount];
            decimal bitcoinBalance = bitcoin.GetBalance();

            ComputeMarketPricesAndLimits(ref m_market, allBitsharesBalances, bitcoinBalance);
        }
示例#6
0
        /// <summary>	Constructor. </summary>
        ///
        /// <remarks>	Paul, 17/01/2015. </remarks>
        ///
        /// <param name="bitsharesConfig">		    The bitshares configuration. </param>
        /// <param name="bitcoinConfig">		    The bitcoin configuration. </param>
        /// <param name="bitsharesAccount">		    The bitshares account. </param>
        /// <param name="bitsharesAsset">		    The bitshares asset. </param>
        /// <param name="bitcoinDespositAddress">	The bitcoin desposit address. </param>
        public DaemonBase(RpcConfig bitsharesConfig, RpcConfig bitcoinConfig,
                          string bitsharesAccount, string bitsharesAsset,
                          string bitcoinDespositAddress)
        {
            m_bitshares = new BitsharesWallet(bitsharesConfig.m_url, bitsharesConfig.m_rpcUser, bitsharesConfig.m_rpcPassword);
            m_bitcoin   = new BitcoinWallet(bitcoinConfig.m_url, bitcoinConfig.m_rpcUser, bitcoinConfig.m_rpcPassword, false);

            m_bitsharesAccount      = bitsharesAccount;
            m_bitsharesAsset        = bitsharesAsset;
            m_bitcoinDespoitAddress = bitcoinDespositAddress;

            m_asset = m_bitshares.BlockchainGetAsset(bitsharesAsset);

            m_addressByteType = (byte)(bitcoinConfig.m_useTestnet ? AltCoinAddressTypeBytes.BitcoinTestnet : AltCoinAddressTypeBytes.Bitcoin);
        }
示例#7
0
        /// <summary>	Constructor. </summary>
        ///
        /// <remarks>	Paul, 17/01/2015. </remarks>
        ///
        /// <param name="bitsharesConfig">		 	The bitshares configuration. </param>
        /// <param name="bitcoinConfig">		 	The bitcoin configuration. </param>
        /// <param name="bitsharesAccount">		 	The bitshares account. </param>
        /// <param name="bitsharesAsset">		 	The bitshares asset. </param>
        /// <param name="bitcoinDespositAddress">	The bitcoin desposit address. </param>
        public DaemonBase(	RpcConfig bitsharesConfig, RpcConfig bitcoinConfig, 
							string bitsharesAccount, string bitsharesAsset,
							string bitcoinDespositAddress)
        {
            m_bitshares = new BitsharesWallet(bitsharesConfig.m_url, bitsharesConfig.m_rpcUser, bitsharesConfig.m_rpcPassword);
            m_bitcoin = new BitcoinWallet(bitcoinConfig.m_url, bitcoinConfig.m_rpcUser, bitcoinConfig.m_rpcPassword, false);

            m_bitsharesAccount = bitsharesAccount;
            m_bitsharesAsset = bitsharesAsset;
            m_bitcoinDespoitAddress = bitcoinDespositAddress;

            m_asset = m_bitshares.BlockchainGetAsset(bitsharesAsset);

            m_addressByteType = (byte)(bitcoinConfig.m_useTestnet ? AltCoinAddressTypeBytes.BitcoinTestnet : AltCoinAddressTypeBytes.Bitcoin);
        }
示例#8
0
 public void VerifiyAccountNameWithHipan()
 {
     Assert.IsTrue(BitsharesWallet.IsValidAccountName("argentina-marketing.matt608"));
 }
示例#9
0
        /// <summary>	Executes the submit address action. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <exception cref="ApiExceptionMessage">	    Thrown when an API exception message error
        ///                                             condition occurs. </exception>
        /// <exception cref="UnexpectedCaseException">	Thrown when an Unexpected Case error condition
        ///                                             occurs. </exception>
        ///
        /// <param name="receivingAddress">	The receiving address. </param>
        /// <param name="orderType">	    Type of the order. </param>
        ///
        /// <returns>	A SubmitAddressResponse. </returns>
        public override SubmitAddressResponse OnSubmitAddress(string receivingAddress, MetaOrderType orderType, uint referralUser)
        {
            SubmitAddressResponse response;

            if (orderType == MetaOrderType.buy)
            {
                string accountName = receivingAddress;
                bool   isPublicKey = BitsharesPubKey.IsValidPublicKey(accountName);

                // check for theoretical validity

                if (!isPublicKey && !BitsharesWallet.IsValidAccountName(accountName))
                {
                    throw new ApiExceptionInvalidAccount(accountName);
                }

                // try and retrieve a previous entry
                SenderToDepositRow senderToDeposit = m_daemon.GetSenderDepositFromReceiver(accountName, m_market.symbol_pair, referralUser);
                if (senderToDeposit == null)
                {
                    // no dice, create a new entry

                    // check for actual validity
                    string rcA;

                    if (!isPublicKey)
                    {
                        BitsharesAccount account = m_bitshares.GetAccount(accountName);
                        if (account == null)
                        {
                            throw new ApiExceptionInvalidAccount(accountName);
                        }

                        rcA = account.name;
                    }
                    else
                    {
                        rcA = accountName;
                    }

                    // generate a new bitcoin address and tie it to this account
                    string depositAdress = m_bitcoin.GetNewAddress();
                    senderToDeposit = m_daemon.InsertSenderToDeposit(rcA, depositAdress, m_market.symbol_pair, referralUser);
                }

                response = new SubmitAddressResponse
                {
                    deposit_address   = senderToDeposit.deposit_address,
                    receiving_address = senderToDeposit.receiving_address
                };
            }
            else if (orderType == MetaOrderType.sell)
            {
                string bitcoinAddress = receivingAddress;

                // validate bitcoin address
                byte[] check = Util.Base58CheckToByteArray(bitcoinAddress);
                if (check == null)
                {
                    throw new ApiExceptionInvalidAddress(bitcoinAddress);
                }

                // try and retrieve a previous entry
                SenderToDepositRow senderToDeposit = m_daemon.GetSenderDepositFromReceiver(bitcoinAddress, m_market.symbol_pair, referralUser);
                if (senderToDeposit == null)
                {
                    // generate a memo field to use instead
                    senderToDeposit = m_daemon.InsertSenderToDeposit(bitcoinAddress, MarketBase.CreateMemo(bitcoinAddress, m_market.symbol_pair, referralUser), m_market.symbol_pair, referralUser);
                }

                response = new SubmitAddressResponse
                {
                    deposit_address   = m_bitsharesAccount,
                    receiving_address = senderToDeposit.receiving_address,
                    memo = senderToDeposit.deposit_address
                };
            }
            else
            {
                throw new UnexpectedCaseException();
            }

            return(response);
        }
示例#10
0
        /// <summary>	Executes the submit address action. </summary>
        ///
        /// <remarks>	Paul, 25/01/2015. </remarks>
        ///
        /// <exception cref="ApiExceptionMessage">		    Thrown when an API exception message error
        ///                                                 condition occurs. </exception>
        /// <exception cref="ApiExceptionMissingParameter">	Thrown when an API exception missing
        ///                                                 parameter error condition occurs. </exception>
        ///
        /// <param name="ctx">      The context. </param>
        /// <param name="dummy">	The dummy. </param>
        ///
        /// <returns>	A Task. </returns>
        Task OnSubmitAddress(RequestContext ctx, IDummy dummy)
        {
            CurrencyTypes fromCurrency     = RestHelpers.GetPostArg <CurrencyTypes, ApiExceptionMissingParameter>(ctx, WebForms.kFromCurrency);
            CurrencyTypes toCurrency       = RestHelpers.GetPostArg <CurrencyTypes, ApiExceptionMissingParameter>(ctx, WebForms.kToCurrency);
            string        receivingAddress = RestHelpers.GetPostArg <string, ApiExceptionMissingParameter>(ctx, WebForms.kReceivingAddress);

            SubmitAddressResponse response;

            if (fromCurrency == CurrencyTypes.BTC && toCurrency == CurrencyTypes.bitBTC)
            {
                string accountName = receivingAddress;

                // try and retrieve a previous entry
                SenderToDepositRow senderToDeposit = m_database.Query <SenderToDepositRow>("SELECT * FROM sender_to_deposit WHERE receiving_address=@s;", accountName).FirstOrDefault();
                if (senderToDeposit == null || !BitsharesWallet.IsValidAccountName(accountName))
                {
                    // no dice, create a new entry

                    // validate bitshares account name
                    try
                    {
                        BitsharesAccount account = m_bitshares.WalletGetAccount(accountName);

                        // generate a new bitcoin address and tie it to this account
                        string depositAdress = m_bitcoin.GetNewAddress();
                        senderToDeposit = InsertSenderToDeposit(account.name, depositAdress);
                    }
                    catch (BitsharesRpcException)
                    {
                        throw new ApiExceptionMessage(accountName + " is not an existing account! Are you sure it is registered?");
                    }
                }

                response = new SubmitAddressResponse {
                    deposit_address = senderToDeposit.deposit_address
                };
            }
            else if (fromCurrency == CurrencyTypes.bitBTC && toCurrency == CurrencyTypes.BTC)
            {
                string bitcoinAddress = receivingAddress;

                // try and retrieve a previous entry
                SenderToDepositRow senderToDeposit = m_database.Query <SenderToDepositRow>("SELECT * FROM sender_to_deposit WHERE receiving_address=@s;", bitcoinAddress).FirstOrDefault();
                if (senderToDeposit == null)
                {
                    // validate bitcoin address
                    byte[] check = Util.Base58CheckToByteArray(bitcoinAddress);
                    if (check == null)
                    {
                        throw new ApiExceptionMessage(bitcoinAddress + " is not a valid bitcoin address!");
                    }

                    // generate a memo field to use instead
                    string start = "meta-";
                    string memo  = start + bitcoinAddress.Substring(0, BitsharesWallet.kBitsharesMaxMemoLength - start.Length);
                    senderToDeposit = InsertSenderToDeposit(bitcoinAddress, memo);
                }

                response = new SubmitAddressResponse {
                    deposit_address = m_bitsharesAccount, memo = senderToDeposit.deposit_address
                };
            }
            else
            {
                throw new ApiExceptionUnsupportedTrade(fromCurrency, toCurrency);
            }

            ctx.Respond <SubmitAddressResponse>(response);

            return(null);
        }