Commit bb1d5725 authored by Jeremy Bokobza's avatar Jeremy Bokobza

Removed the cointype in a few places

parent c2cde249
......@@ -147,18 +147,16 @@ namespace Breeze.Wallet
/// <summary>
/// Processes a block received from the network.
/// </summary>
/// <param name="coinType">The type of coin this block relates to.</param>
/// <param name="height">The height of the block in the blockchain.</param>
/// <param name="block">The block.</param>
void ProcessBlock(CoinType coinType, int height, Block block);
void ProcessBlock(int height, Block block);
/// <summary>
/// Processes a transaction received from the network.
/// </summary>
/// <param name="coinType">The type of coin this transaction relates to.</param>
/// <param name="transaction">The transaction.</param>
/// <param name="blockHeight">The height of the block this transaction came from. Null if it was not a transaction included in a block.</param>
/// <param name="blockTime">The block time.</param>
void ProcessTransaction(CoinType coinType, NBitcoin.Transaction transaction, int? blockHeight = null, uint? blockTime = null);
void ProcessTransaction(Transaction transaction, int? blockHeight = null, uint? blockTime = null);
}
}
......@@ -9,13 +9,11 @@ namespace Breeze.Wallet.Notifications
public class BlockObserver : SignalObserver<Block>
{
private readonly ConcurrentChain chain;
private readonly CoinType coinType;
private readonly IWalletManager walletManager;
public BlockObserver(ConcurrentChain chain, CoinType coinType, IWalletManager walletManager)
public BlockObserver(ConcurrentChain chain, IWalletManager walletManager)
{
this.chain = chain;
this.coinType = coinType;
this.walletManager = walletManager;
}
......@@ -28,7 +26,7 @@ namespace Breeze.Wallet.Notifications
var hash = block.Header.GetHash();
var height = this.chain.GetBlock(hash).Height;
this.walletManager.ProcessBlock(this.coinType, height, block);
this.walletManager.ProcessBlock(height, block);
}
}
}
......@@ -8,13 +8,10 @@ namespace Breeze.Wallet.Notifications
/// </summary>
public class TransactionObserver : SignalObserver<Transaction>
{
private readonly CoinType coinType;
private readonly IWalletManager walletManager;
public TransactionObserver(CoinType coinType, IWalletManager walletManager)
public TransactionObserver(IWalletManager walletManager)
{
this.coinType = coinType;
this.walletManager = walletManager;
}
......@@ -24,7 +21,7 @@ namespace Breeze.Wallet.Notifications
/// <param name="transaction">The new transaction</param>
protected override void OnNextCore(Transaction transaction)
{
this.walletManager.ProcessTransaction(this.coinType, transaction);
this.walletManager.ProcessTransaction(transaction);
}
}
}
......@@ -38,9 +38,9 @@ namespace Breeze.Wallet
await this.WaitForChainDownloadAsync();
// subscribe to receiving blocks and transactions
BlockSubscriber sub = new BlockSubscriber(this.signals.Blocks, new BlockObserver(this.chain, this.coinType, this.walletManager));
BlockSubscriber sub = new BlockSubscriber(this.signals.Blocks, new BlockObserver(this.chain, this.walletManager));
sub.Subscribe();
TransactionSubscriber txSub = new TransactionSubscriber(this.signals.Transactions, new TransactionObserver(this.coinType, this.walletManager));
TransactionSubscriber txSub = new TransactionSubscriber(this.signals.Transactions, new TransactionObserver(this.walletManager));
txSub.Subscribe();
// start syncing blocks
......
......@@ -424,7 +424,7 @@ namespace Breeze.Wallet
Transaction transaction = Transaction.Parse(transactionHex);
TxPayload payload = new TxPayload(transaction);
foreach (var node in connectionManager.ConnectedNodes)
foreach (var node in this.connectionManager.ConnectedNodes)
{
node.SendMessage(payload);
}
......@@ -433,19 +433,19 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public void ProcessBlock(CoinType coinType, int height, Block block)
public void ProcessBlock(int height, Block block)
{
Console.WriteLine($"block notification: height: {height}, block hash: {block.Header.GetHash()}, coin type: {coinType}");
foreach (Transaction transaction in block.Transactions)
{
this.ProcessTransaction(coinType, transaction, height, block.Header.Time);
this.ProcessTransaction(transaction, height, block.Header.Time);
}
// update the wallets with the last processed block height
foreach (var wallet in this.Wallets)
{
foreach (var accountRoot in wallet.AccountsRoot.Where(a => a.CoinType == coinType))
foreach (var accountRoot in wallet.AccountsRoot.Where(a => a.CoinType == this.coinType))
{
accountRoot.LastBlockSyncedHeight = height;
}
......@@ -453,9 +453,9 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public void ProcessTransaction(CoinType coinType, Transaction transaction, int? blockHeight = null, uint? blockTime = null)
public void ProcessTransaction(Transaction transaction, int? blockHeight = null, uint? blockTime = null)
{
Console.WriteLine($"transaction notification: tx hash {transaction.GetHash()}, coin type: {coinType}");
Console.WriteLine($"transaction notification: tx hash {transaction.GetHash()}, coin type: {this.coinType}");
foreach (var pubKey in this.PubKeys)
{
......@@ -463,7 +463,7 @@ namespace Breeze.Wallet
var utxo = transaction.Outputs.SingleOrDefault(o => pubKey == o.ScriptPubKey);
if (utxo != null)
{
AddTransactionToWallet(coinType, transaction.GetHash(), transaction.Time, transaction.Outputs.IndexOf(utxo), utxo.Value, pubKey, blockHeight, blockTime);
AddTransactionToWallet(transaction.GetHash(), transaction.Time, transaction.Outputs.IndexOf(utxo), utxo.Value, pubKey, blockHeight, blockTime);
}
// if the inputs have a reference to a transaction containing one of our scripts
......@@ -474,7 +474,7 @@ namespace Breeze.Wallet
// compare the index of the output in its original transaction and the index references in the input
if (input.PrevOut.N == tTx.Index)
{
AddTransactionToWallet(coinType, transaction.GetHash(), transaction.Time, null, -tTx.Amount, pubKey, blockHeight, blockTime, tTx.Hash, tTx.Index);
AddTransactionToWallet(transaction.GetHash(), transaction.Time, null, -tTx.Amount, pubKey, blockHeight, blockTime, tTx.Hash, tTx.Index);
}
}
}
......@@ -483,7 +483,6 @@ namespace Breeze.Wallet
/// <summary>
/// Adds the transaction to the wallet.
/// </summary>
/// <param name="coinType">Type of the coin.</param>
/// <param name="transactionHash">The transaction hash.</param>
/// <param name="time">The time.</param>
/// <param name="index">The index.</param>
......@@ -493,17 +492,17 @@ namespace Breeze.Wallet
/// <param name="blockTime">The block time.</param>
/// <param name="spendingTransactionId">The id of the transaction containing the output being spent, if this is a spending transaction.</param>
/// <param name="spendingTransactionIndex">The index of the output in the transaction being referenced, if this is a spending transaction.</param>
private void AddTransactionToWallet(CoinType coinType, uint256 transactionHash, uint time, int? index, Money amount, Script script, int? blockHeight = null, uint? blockTime = null, uint256 spendingTransactionId = null, int? spendingTransactionIndex = null)
private void AddTransactionToWallet(uint256 transactionHash, uint time, int? index, Money amount, Script script, int? blockHeight = null, uint? blockTime = null, uint256 spendingTransactionId = null, int? spendingTransactionIndex = null)
{
// selects all the transactions we already have in the wallet
var txs = this.Wallets.SelectMany(w => w.GetAllTransactionsByCoinType(coinType));
var txs = this.Wallets.SelectMany(w => w.GetAllTransactionsByCoinType(this.coinType));
// add this transaction if it is not in the list
if (txs.All(t => t.Id != transactionHash || t.Index != index))
{
foreach (var wallet in this.Wallets)
{
foreach (var accountRoot in wallet.AccountsRoot.Where(a => a.CoinType == coinType))
foreach (var accountRoot in wallet.AccountsRoot.Where(a => a.CoinType == this.coinType))
{
foreach (var account in accountRoot.Accounts)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment