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
6a9a322b
Commit
6a9a322b
authored
Apr 30, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added get history
parent
0a7b7a87
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
15 deletions
+63
-15
WalletController.cs
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
+21
-3
IWalletManager.cs
Breeze/src/Breeze.Wallet/IWalletManager.cs
+8
-1
RequestModels.cs
Breeze/src/Breeze.Wallet/Models/RequestModels.cs
+10
-1
WalletHistoryModel.cs
Breeze/src/Breeze.Wallet/Models/WalletHistoryModel.cs
+16
-5
Wallet.cs
Breeze/src/Breeze.Wallet/Wallet.cs
+1
-1
WalletManager.cs
Breeze/src/Breeze.Wallet/WalletManager.cs
+7
-4
No files found.
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
View file @
6a9a322b
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Net
;
...
...
@@ -176,11 +177,11 @@ namespace Breeze.Wallet.Controllers
/// <summary>
/// Retrieves the history of a wallet.
/// </summary>
/// <param name="
model">The name of the wallet
.</param>
/// <param name="
request">The request parameters
.</param>
/// <returns></returns>
[
Route
(
"history"
)]
[
HttpGet
]
public
IActionResult
GetHistory
([
FromQuery
]
Wallet
Name
model
)
public
IActionResult
GetHistory
([
FromQuery
]
Wallet
HistoryRequest
request
)
{
// checks the request is valid
if
(!
this
.
ModelState
.
IsValid
)
...
...
@@ -191,8 +192,25 @@ namespace Breeze.Wallet.Controllers
try
{
return
this
.
Json
(
this
.
walletManager
.
GetHistory
(
model
.
Name
))
;
WalletHistoryModel
model
=
new
WalletHistoryModel
{
Transactions
=
new
List
<
TransactionItem
>()}
;
var
accounts
=
this
.
walletManager
.
GetAccountsByCoinType
(
request
.
WalletName
,
request
.
CoinType
).
ToList
();
foreach
(
var
address
in
accounts
.
SelectMany
(
a
=>
a
.
ExternalAddresses
).
Concat
(
accounts
.
SelectMany
(
a
=>
a
.
InternalAddresses
)))
{
foreach
(
var
transaction
in
address
.
Transactions
)
{
model
.
Transactions
.
Add
(
new
TransactionItem
{
Amount
=
transaction
.
Amount
,
Confirmed
=
transaction
.
Confirmed
,
Timestamp
=
transaction
.
CreationTime
,
TransactionId
=
transaction
.
Id
,
Address
=
address
.
Address
});
}
}
return
this
.
Json
(
model
.
Transactions
.
OrderByDescending
(
t
=>
t
.
Timestamp
));
}
catch
(
Exception
e
)
{
...
...
Breeze/src/Breeze.Wallet/IWalletManager.cs
View file @
6a9a322b
using
System
;
using
System.Collections.Generic
;
using
Breeze.Wallet.Models
;
using
NBitcoin
;
...
...
@@ -75,7 +76,13 @@ namespace Breeze.Wallet
WalletBalanceModel
GetBalance
(
string
walletName
);
WalletHistoryModel
GetHistory
(
string
walletName
);
/// <summary>
/// Gets a list of accounts filtered by coin type.
/// </summary>
/// <param name="walletName">The name of the wallet to look into.</param>
/// <param name="coinType">The type of coin to filter by.</param>
/// <returns></returns>
IEnumerable
<
HdAccount
>
GetAccountsByCoinType
(
string
walletName
,
CoinType
coinType
);
WalletBuildTransactionModel
BuildTransaction
(
string
password
,
string
address
,
Money
amount
,
string
feeType
,
bool
allowUnconfirmed
);
...
...
Breeze/src/Breeze.Wallet/Models/
WalletCreation
.cs
→
Breeze/src/Breeze.Wallet/Models/
RequestModels
.cs
View file @
6a9a322b
...
...
@@ -47,7 +47,16 @@ namespace Breeze.Wallet.Models
public
string
Network
{
get
;
set
;
}
}
public
class
WalletName
public
class
WalletHistoryRequest
{
[
Required
(
ErrorMessage
=
"The name of the wallet is missing."
)]
public
string
WalletName
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"The type of coin for which history is requested is missing."
)]
public
CoinType
CoinType
{
get
;
set
;
}
}
public
class
WalletName
{
[
Required
(
ErrorMessage
=
"The name of the wallet is missing."
)]
public
string
Name
{
get
;
set
;
}
...
...
Breeze/src/Breeze.Wallet/Models/WalletHistoryModel.cs
View file @
6a9a322b
using
System.Collections.Generic
;
using
System
;
using
System.Collections.Generic
;
using
Breeze.Wallet.JsonConverters
;
using
NBitcoin
;
using
NBitcoin.JsonConverters
;
using
Newtonsoft.Json
;
namespace
Breeze.Wallet.Models
...
...
@@ -12,8 +15,15 @@ namespace Breeze.Wallet.Models
public
class
TransactionItem
{
[
JsonProperty
(
PropertyName
=
"txId"
)]
public
string
TransactionId
{
get
;
set
;
}
/// <summary>
/// The Base58 representation of this address.
/// </summary>
[
JsonProperty
(
PropertyName
=
"address"
)]
public
string
Address
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"txId"
)]
[
JsonConverter
(
typeof
(
UInt256JsonConverter
))]
public
uint256
TransactionId
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"amount"
)]
public
Money
Amount
{
get
;
set
;
}
...
...
@@ -22,6 +32,7 @@ namespace Breeze.Wallet.Models
public
bool
Confirmed
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"timestamp"
)]
public
string
Timestamp
{
get
;
set
;
}
}
[
JsonConverter
(
typeof
(
DateTimeOffsetConverter
))]
public
DateTimeOffset
Timestamp
{
get
;
set
;
}
}
}
Breeze/src/Breeze.Wallet/Wallet.cs
View file @
6a9a322b
...
...
@@ -223,7 +223,7 @@ namespace Breeze.Wallet
/// <summary>
/// The index of this scriptPubKey in the transaction it is contained.
/// </summary>
[
JsonProperty
(
PropertyName
=
"index"
)]
[
JsonProperty
(
PropertyName
=
"index"
,
NullValueHandling
=
NullValueHandling
.
Ignore
)]
public
int
?
Index
{
get
;
set
;
}
/// <summary>
...
...
Breeze/src/Breeze.Wallet/WalletManager.cs
View file @
6a9a322b
...
...
@@ -211,9 +211,12 @@ namespace Breeze.Wallet
throw
new
System
.
NotImplementedException
();
}
public
WalletHistoryModel
GetHistory
(
string
walletName
)
/// <inheritdoc />
public
IEnumerable
<
HdAccount
>
GetAccountsByCoinType
(
string
walletName
,
CoinType
coinType
)
{
throw
new
System
.
NotImplementedException
();
return
this
.
Wallets
.
SelectMany
(
w
=>
w
.
AccountsRoot
.
Where
(
a
=>
a
.
CoinType
==
coinType
)).
SelectMany
(
a
=>
a
.
Accounts
);
}
public
WalletBuildTransactionModel
BuildTransaction
(
string
password
,
string
address
,
Money
amount
,
string
feeType
,
bool
allowUnconfirmed
)
...
...
@@ -250,7 +253,7 @@ namespace Breeze.Wallet
public
void
ProcessTransaction
(
CoinType
coinType
,
Transaction
transaction
,
int
?
blockHeight
=
null
,
uint
?
blockTime
=
null
)
{
Console
.
WriteLine
(
$"transaction notification: tx hash
{
transaction
.
GetHash
()}
, coin type:
{
coinType
}
"
);
foreach
(
var
k
in
this
.
PubKeys
)
{
// check if the outputs contain one of our addresses
...
...
@@ -267,7 +270,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
,
k
,
blockHeight
,
blockTime
);
}
}
...
...
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