Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Breeze
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
Breeze
Commits
bb1d5725
Commit
bb1d5725
authored
May 14, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed the cointype in a few places
parent
c2cde249
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
28 deletions
+20
-28
IWalletManager.cs
Breeze/src/Breeze.Wallet/IWalletManager.cs
+2
-4
BlockObserver.cs
Breeze/src/Breeze.Wallet/Notifications/BlockObserver.cs
+2
-4
TransactionObserver.cs
...ze/src/Breeze.Wallet/Notifications/TransactionObserver.cs
+3
-6
Tracker.cs
Breeze/src/Breeze.Wallet/Tracker.cs
+2
-2
WalletManager.cs
Breeze/src/Breeze.Wallet/WalletManager.cs
+11
-12
No files found.
Breeze/src/Breeze.Wallet/IWalletManager.cs
View file @
bb1d5725
...
...
@@ -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
);
}
}
Breeze/src/Breeze.Wallet/Notifications/BlockObserver.cs
View file @
bb1d5725
...
...
@@ -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
);
}
}
}
Breeze/src/Breeze.Wallet/Notifications/TransactionObserver.cs
View file @
bb1d5725
...
...
@@ -7,14 +7,11 @@ namespace Breeze.Wallet.Notifications
/// Observer that receives notifications about the arrival of new <see cref="Transaction"/>s.
/// </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
(
t
his
.
coinType
,
t
ransaction
);
this
.
walletManager
.
ProcessTransaction
(
transaction
);
}
}
}
Breeze/src/Breeze.Wallet/Tracker.cs
View file @
bb1d5725
...
...
@@ -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
...
...
Breeze/src/Breeze.Wallet/WalletManager.cs
View file @
bb1d5725
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment