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
848c1a11
Commit
848c1a11
authored
May 17, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made history smarter
parent
6ab3dbb1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
30 deletions
+102
-30
ApiSpecification.md
Breeze.Documentation/ApiSpecification.md
+19
-11
WalletController.cs
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
+34
-10
WalletHistoryModel.cs
Breeze/src/Breeze.Wallet/Models/WalletHistoryModel.cs
+49
-9
No files found.
Breeze.Documentation/ApiSpecification.md
View file @
848c1a11
...
...
@@ -235,20 +235,28 @@ This endpoint will get the last address containing no transaction or will create
### Responses
```
{
"transactions
": [
"transactions
History": [
{
"address": "1H2jbtknP6jRYx2riaXJf3H9Mb1JC6kcL2",
"txId": "b800f9b24a9c49a375cddf4fc8c484722af0bec7d23ac65b782daf1b0089bb29",
"amount": -50360386,
"confirmed": true,
"timestamp": "1337803568"
"type": "send",
"id": "6358161c713688e372481fce7f20f3f8692ab2e4e657f3d9afa750ebee54e6c3",
"amount": 500000,
"payments": [
{
"destinationAddress": "mt7W2Zf69KC9472TPCzUeLLhBDSmC82AWz",
"amount": 500000
}
],
"fee": 100000,
"confirmedInBlock": 1122310,
"timestamp": "1494594937"
},
{
"address": "1H2jbtknP6jRYx2riaXJf3H9Mb1JC6kcL2",
"txId": "9c0560a34f88573a71ebf68a2540cb7215b55bc2ddee0af3cb1dc343f2f3e0da",
"amount": 53845026,
"confirmed": true,
"timestamp": "1337605326"
"type": "received",
"toAddress": "mnDsG7kTYCeVNqnEmfvdYeNgZwxhjqm2jc",
"id": "75ce74643aae01ccbe2bbc05efb4788cc9a16a9192add4d7082561a40a541057",
"amount": 110000000,
"confirmedInBlock": 1122292,
"timestamp": "1494591670"
}
]
}
...
...
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
View file @
848c1a11
...
...
@@ -185,26 +185,50 @@ namespace Breeze.Wallet.Controllers
try
{
WalletHistoryModel
model
=
new
WalletHistoryModel
{
Transactions
=
new
List
<
TransactionItem
>()
};
WalletHistoryModel
model
=
new
WalletHistoryModel
{
Transactions
History
=
new
List
<
TransactionItemModel
>()
};
// get transactions contained in the wallet
var
addresses
=
this
.
walletManager
.
GetHistoryByCoinType
(
request
.
WalletName
,
request
.
CoinType
);
foreach
(
var
address
in
addresses
)
foreach
(
var
address
in
addresses
.
Where
(
a
=>
!
a
.
IsChangeAddress
())
)
{
foreach
(
var
transaction
in
address
.
Transactions
)
{
model
.
Transactions
.
Add
(
new
TransactionItem
TransactionItemModel
item
=
new
TransactionItemModel
();
if
(
transaction
.
Amount
>
Money
.
Zero
)
{
Amount
=
transaction
.
Amount
,
Confirmed
=
transaction
.
IsConfirmed
(),
Timestamp
=
transaction
.
CreationTime
,
TransactionId
=
transaction
.
Id
,
Address
=
address
.
Address
});
item
.
Type
=
TransactionItemType
.
Received
;
item
.
ToAddress
=
address
.
Address
;
item
.
Amount
=
transaction
.
Amount
;
}
else
{
item
.
Type
=
TransactionItemType
.
Send
;
item
.
Amount
=
Money
.
Zero
;
item
.
Payments
=
new
List
<
PaymentDetailModel
>();
foreach
(
var
payment
in
transaction
.
Payments
)
{
item
.
Payments
.
Add
(
new
PaymentDetailModel
{
DestinationAddress
=
payment
.
DestinationAddress
,
Amount
=
payment
.
Amount
});
item
.
Amount
+=
payment
.
Amount
;
}
var
changeAddress
=
addresses
.
Single
(
a
=>
a
.
IsChangeAddress
()
&&
a
.
Transactions
.
Any
(
t
=>
t
.
Id
==
transaction
.
Id
));
item
.
Fee
=
transaction
.
Amount
.
Abs
()
-
item
.
Amount
-
changeAddress
.
Transactions
.
First
(
t
=>
t
.
Id
==
transaction
.
Id
).
Amount
;
}
item
.
Id
=
transaction
.
Id
;
item
.
Timestamp
=
transaction
.
CreationTime
;
item
.
ConfirmedInBlock
=
transaction
.
BlockHeight
;
model
.
TransactionsHistory
.
Add
(
item
);
}
}
model
.
Transactions
=
model
.
Transactions
.
OrderByDescending
(
t
=>
t
.
Timestamp
).
ToList
();
model
.
Transactions
History
=
model
.
TransactionsHistory
.
OrderByDescending
(
t
=>
t
.
Timestamp
).
ToList
();
return
this
.
Json
(
model
);
}
catch
(
Exception
e
)
...
...
Breeze/src/Breeze.Wallet/Models/WalletHistoryModel.cs
View file @
848c1a11
...
...
@@ -4,35 +4,75 @@ using Breeze.Wallet.JsonConverters;
using
NBitcoin
;
using
NBitcoin.JsonConverters
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Converters
;
using
Newtonsoft.Json.Serialization
;
namespace
Breeze.Wallet.Models
{
public
class
WalletHistoryModel
{
[
JsonProperty
(
PropertyName
=
"transactions"
)]
public
List
<
TransactionItem
>
Transactions
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"transactions
History
"
)]
public
List
<
TransactionItem
Model
>
TransactionsHistory
{
get
;
set
;
}
}
public
class
TransactionItem
public
class
TransactionItem
Model
{
[
JsonProperty
(
PropertyName
=
"type"
)]
[
JsonConverter
(
typeof
(
StringEnumConverter
),
true
)]
public
TransactionItemType
Type
{
get
;
set
;
}
/// <summary>
/// The Base58 representation of this address.
/// </summary>
[
JsonProperty
(
PropertyName
=
"
address"
)]
public
string
Address
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"
toAddress"
,
NullValueHandling
=
NullValueHandling
.
Ignore
)]
public
string
To
Address
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"
txI
d"
)]
[
JsonProperty
(
PropertyName
=
"
i
d"
)]
[
JsonConverter
(
typeof
(
UInt256JsonConverter
))]
public
uint256
Transaction
Id
{
get
;
set
;
}
public
uint256
Id
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"amount"
)]
public
Money
Amount
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"confirmed"
)]
public
bool
Confirmed
{
get
;
set
;
}
/// <summary>
/// A list of payments made out in this transaction.
/// </summary>
[
JsonProperty
(
PropertyName
=
"payments"
,
NullValueHandling
=
NullValueHandling
.
Ignore
)]
public
ICollection
<
PaymentDetailModel
>
Payments
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"fee"
,
NullValueHandling
=
NullValueHandling
.
Ignore
)]
public
Money
Fee
{
get
;
set
;
}
/// <summary>
/// The height of the block in which this transaction was confirmed.
/// </summary>
[
JsonProperty
(
PropertyName
=
"confirmedInBlock"
,
NullValueHandling
=
NullValueHandling
.
Ignore
)]
public
int
?
ConfirmedInBlock
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"timestamp"
)]
[
JsonConverter
(
typeof
(
DateTimeOffsetConverter
))]
public
DateTimeOffset
Timestamp
{
get
;
set
;
}
}
public
class
PaymentDetailModel
{
/// <summary>
/// The Base58 representation of the destination address.
/// </summary>
[
JsonProperty
(
PropertyName
=
"destinationAddress"
)]
public
string
DestinationAddress
{
get
;
set
;
}
/// <summary>
/// The transaction amount.
/// </summary>
[
JsonProperty
(
PropertyName
=
"amount"
)]
[
JsonConverter
(
typeof
(
MoneyJsonConverter
))]
public
Money
Amount
{
get
;
set
;
}
}
public
enum
TransactionItemType
{
Received
,
Send
}
}
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