示例#1
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);
        }
示例#2
0
 public void VerifiyAccountNameWithHipan()
 {
     Assert.IsTrue(BitsharesWallet.IsValidAccountName("argentina-marketing.matt608"));
 }
示例#3
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);
        }