/// <summary> Gets bitshares address from bitcoin deposit. </summary> /// /// <remarks> Paul, 25/01/2015. </remarks> /// /// <param name="t"> The TransactionSinceBlock to process. </param> /// /// <returns> The bitshares address from bitcoin deposit. </returns> protected override AddressOrAccountName GetBitsharesAddressFromBitcoinDeposit(TransactionSinceBlock t) { // look up the deposit address in our map of sender->deposit SenderToDepositRow senderToDeposit = GetSenderDepositFromDeposit(t.Address); if (senderToDeposit != null) { return new AddressOrAccountName { m_text = senderToDeposit.receiving_address, m_isAddress = false }; } else { return null; } }
/// <summary> Refund bitcoin deposit. </summary> /// /// <remarks> Paul, 15/01/2015. </remarks> /// /// <param name="t"> The TransactionSinceBlock to process. </param> protected virtual void RefundBitcoinDeposit(TransactionSinceBlock t, string notes) { MarkTransactionAsRefundedStart(t.TxId); // get public key out of transaction string firstPubKey = GetAllPubkeysFromBitcoinTransaction(t.TxId).First(); PublicKey pk = new PublicKey(firstPubKey, m_addressByteType); // refund deposit string sentTxid = m_bitcoin.SendToAddress(pk.AddressBase58, t.Amount); // mark as such MarkTransactionAsRefundedEnd(t.TxId, sentTxid, t.Amount, DaemonTransactionType.bitcoinRefund, notes); }
/// <summary> Compute and send the correct amount of bitassets to the depositor /// given the deposit transaction </summary> /// /// <remarks> Paul, 22/12/2014. </remarks> /// /// <param name="t"> The TransactionSinceBlock to process. </param> /// /// <returns> A BitsharesTransactionResponse. </returns> protected virtual BitsharesTransactionResponse SendBitAssetsToDepositor(TransactionSinceBlock t) { // make sure failures after this point do not result in repeated sending MarkBitcoinDespositAsCreditedStart(t.TxId); if (t.Amount > m_bitcoinDepositLimit) { throw new RefundBitcoinException("Over " + Numeric.Format2Dps(m_bitcoinDepositLimit) + " BTC!"); } AddressOrAccountName bitsharesAddress = GetBitsharesAddressFromBitcoinDeposit(t); BitsharesTransactionResponse bitsharesTrx; decimal amount = (1 / m_askPrice) * t.Amount; if (bitsharesAddress.m_isAddress) { bitsharesTrx = m_bitshares.WalletTransferToAddress(amount, m_asset.symbol, m_bitsharesAccount, bitsharesAddress.m_text); } else { bitsharesTrx = m_bitshares.WalletTransfer(amount, m_asset.symbol, m_bitsharesAccount, bitsharesAddress.m_text); } MarkBitcoinDespositAsCreditedEnd(t.TxId, bitsharesTrx.record_id, amount); return bitsharesTrx; }
/// <summary> Take the given transaction, pull out the first input and get the public key, /// turn that into a bitshares address </summary> /// /// <remarks> Paul, 22/12/2014. </remarks> /// /// <param name="t"> The TransactionSinceBlock to process. </param> /// /// <returns> The bitshares address from bitcoin deposit. </returns> protected virtual AddressOrAccountName GetBitsharesAddressFromBitcoinDeposit(TransactionSinceBlock t) { IEnumerable<string> allPubKeys = GetAllPubkeysFromBitcoinTransaction(t.TxId); // this is probably ok to leave out because if the user imports their whole wallet, they will likely // have all the PKs they need since bitcoin pregenerates 100 or so of them. worst case the user // can re-import their wallet into bitshares to get access to missing transcations /*if (allPubKeys.Distinct().Count() > 1) { // can't handle more than one sender case throw new MultiplePublicKeysException(); }*/ string publicKey = allPubKeys.First(); BitsharesPubKey btsPk = BitsharesPubKey.FromBitcoinHex(publicKey, m_addressByteType); return new AddressOrAccountName { m_text = btsPk.m_Address, m_isAddress = true }; }
/// <summary> Sends a bit assets to depositor. </summary> /// /// <remarks> Paul, 05/02/2015. </remarks> /// /// <exception cref="RefundBitcoinException"> Thrown when a Refund Bitcoin error condition /// occurs. </exception> /// /// <param name="t"> The TransactionSinceBlock to process. </param> /// <param name="asset"> The asset. </param> /// /// <returns> A BitsharesTransactionResponse. </returns> protected BitsharesTransactionResponse SendBitAssetsToDepositor(TransactionSinceBlock t, BitsharesAsset asset, SenderToDepositRow s2d, MetaOrderType orderType) { // make sure failures after this point do not result in repeated sending m_daemon.MarkDespositAsCreditedStart(t.TxId, s2d.deposit_address, m_market.symbol_pair, orderType, MetaOrderStatus.processing, TransactionPolicy.REPLACE); if (t.Amount > m_market.ask_max) { throw new RefundBitcoinException("Over " + Numeric.SerialisedDecimal(m_market.ask_max) + " " + asset.symbol + "!"); } string bitsharesAccount = s2d.receiving_address; decimal bitAssetAmountNoFee; if (m_flipped) { // they're sending us BTC, not bitAssets because the market is flipped, this is // equivelent to the opposite order type, so we have to use bid here bitAssetAmountNoFee = t.Amount * m_market.bid; } else { bitAssetAmountNoFee = t.Amount / m_market.ask; } // when buying, the fee is charged in bitAssets, // the amount recorded in the transaction is the amount of bitAssets purchased sans fee bitAssetAmountNoFee = asset.Truncate(bitAssetAmountNoFee); decimal fee = (m_market.ask_fee_percent / 100) * bitAssetAmountNoFee; decimal amountAsset = bitAssetAmountNoFee - fee; amountAsset = asset.Truncate(amountAsset); BitsharesTransactionResponse bitsharesTrx = SendBitAssets(amountAsset, asset, bitsharesAccount, "mX: " + orderType + " " + asset.symbol); m_daemon.MarkDespositAsCreditedEnd(t.TxId, bitsharesTrx.record_id, MetaOrderStatus.completed, bitAssetAmountNoFee, m_market.ask, fee); return bitsharesTrx; }
/// <summary> Refund bitcoin deposit. </summary> /// /// <remarks> Paul, 15/01/2015. </remarks> /// /// <param name="t"> The TransactionSinceBlock to process. </param> protected void RefundBitcoinDeposit(TransactionSinceBlock t, string notes, SenderToDepositRow s2d, MetaOrderType orderType) { m_daemon.MarkTransactionAsRefundedStart(t.TxId, s2d.deposit_address, m_market.symbol_pair, orderType); // get public key out of transaction string firstPubKey = GetAllPubkeysFromBitcoinTransaction(t.TxId).First(); PublicKey pk = new PublicKey(firstPubKey, m_daemon.m_AddressByteType); // refund deposit string sentTxid = m_bitcoin.SendToAddress(pk.AddressBase58, t.Amount); // mark as such m_daemon.MarkTransactionAsRefundedEnd(t.TxId, sentTxid, MetaOrderStatus.refunded, t.Amount, notes); }
/// <summary> Gets bitshares account from bitcoin deposit. </summary> /// /// <remarks> Paul, 05/02/2015. </remarks> /// /// <param name="t"> The TransactionSinceBlock to process. </param> /// /// <returns> The bitshares account from bitcoin deposit. </returns> protected SenderToDepositRow GetBitsharesAccountFromBitcoinDeposit(TransactionSinceBlock t) { // look up the deposit address in our map of sender->deposit SenderToDepositRow senderToDeposit = m_daemon.m_Database.GetSenderDepositIgnoreReferral(t.Address, m_market.symbol_pair); if (senderToDeposit != null) { return senderToDeposit; } else { return null; } }
public abstract void HandleBitcoinDeposit(TransactionSinceBlock t);