/// <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); }