public void SubmitValidBitsharesAccountTwoMarkets() { string contentA = SubmitValidBitsharesAccount(m_defaultSymbolPair); string contentB = SubmitValidBitsharesAccount(m_alternateMarket); SubmitAddressResponse A = JsonSerializer.DeserializeFromString <SubmitAddressResponse>(contentA); SubmitAddressResponse B = JsonSerializer.DeserializeFromString <SubmitAddressResponse>(contentB); A.deposit_address.Should().Not.Be.EqualTo(B.deposit_address); contentA.Should().Not.Be.EqualTo(contentB); }
public void SubmitValidBitcoinAddressTwoMarkets() { string contentA = SubmitValidBitcoinAddress(m_defaultSymbolPair); string contentB = SubmitValidBitcoinAddress(m_alternateMarket); SubmitAddressResponse A = JsonSerializer.DeserializeFromString <SubmitAddressResponse>(contentA); SubmitAddressResponse B = JsonSerializer.DeserializeFromString <SubmitAddressResponse>(contentB); A.memo.Should().Not.Be.EqualTo(B.memo); contentA.Should().Not.Be.EqualTo(contentB); }
/// <summary> Executes the submit address action. </summary> /// /// <remarks> Paul, 19/02/2015. </remarks> /// /// <param name="ctx"> The context. </param> /// <param name="dummy"> The dummy. </param> /// /// <returns> A Task. </returns> async Task OnSubmitAddress(RequestContext ctx, IDummy dummy) { // intercept the response and stick it in the site database so we can handle forwarding future queries string symbolPair = RestHelpers.GetPostArg <string, ApiExceptionMissingParameter>(ctx, WebForms.kSymbolPair); uint referralUser = RestHelpers.GetPostArg <uint>(ctx, WebForms.kReferralId); string receivingAddress = RestHelpers.GetPostArg <string, ApiExceptionMissingParameter>(ctx, WebForms.kReceivingAddress); // do this at the site level, because we need to prevent this from occuring across nodes if (dummy.m_database.IsAnyDepositAddress(receivingAddress)) { throw new ApiExceptionInvalidAddress("<internal deposit address>"); } // forward the post on string response = await ForwardPostSpecific(ctx, dummy); if (response != null) { // get the juicy data out SubmitAddressResponse data = JsonSerializer.DeserializeFromString <SubmitAddressResponse>(response); // pull the market out of the request MarketRow m = dummy.m_database.GetMarket(symbolPair); // stick it in the master database dummy.m_database.InsertSenderToDeposit(data.receiving_address, data.deposit_address, m.symbol_pair, referralUser, true); if (referralUser > 0) { // track referrals string depositAddress; if (data.memo != null) { depositAddress = data.memo; } else { depositAddress = data.deposit_address; } dummy.m_database.InsertReferralAddress(depositAddress, referralUser); } } }
/// <summary> Executes the submit address action. </summary> /// /// <remarks> Paul, 05/02/2015. </remarks> /// /// <exception cref="ApiExceptionUnknownMarket"> Thrown when an API exception unknown market /// error condition occurs. </exception> /// /// <param name="ctx"> The context. </param> /// <param name="dummy"> The dummy. </param> /// /// <returns> A Task. </returns> Task OnSubmitAddress(RequestContext ctx, IDummyDaemon dummy) { if (m_suspended) { throw new ApiExceptionNetworkAlert(); } else { string symbolPair = RestHelpers.GetPostArg <string, ApiExceptionMissingParameter>(ctx, WebForms.kSymbolPair); string receivingAddress = RestHelpers.GetPostArg <string, ApiExceptionMissingParameter>(ctx, WebForms.kReceivingAddress); MetaOrderType orderType = RestHelpers.GetPostArg <MetaOrderType, ApiExceptionMissingParameter>(ctx, WebForms.kOrderType); uint referralUser = RestHelpers.GetPostArg <uint>(ctx, WebForms.kReferralId); if (!m_marketHandlers.ContainsKey(symbolPair)) { throw new ApiExceptionUnknownMarket(symbolPair); } // prevent our own deposit addresses from being used as receiving addresses if (m_dataAccess.GetSenderDepositFromDeposit(receivingAddress, symbolPair, referralUser) != null) { throw new ApiExceptionInvalidAddress("<internal deposit address>"); } else if (m_bitsharesAccount == receivingAddress) { throw new ApiExceptionInvalidAccount(m_bitsharesAccount); } // get the handler for this market MarketBase market = m_marketHandlers[symbolPair]; // get the response and send it SubmitAddressResponse response = market.OnSubmitAddress(receivingAddress, orderType, referralUser); //ctx.Respond<SubmitAddressResponse>(response); m_api.SendCorsResponse <SubmitAddressResponse>(ctx, response); } return(null); }
/// <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); }
/// <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; }