Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Whirlpool
whirlpool-client-cli
Commits
8cc43509
Commit
8cc43509
authored
Sep 02, 2019
by
zeroleak
Browse files
/rest/utxos: sort utxos by lastActivity
parent
fdeec878
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
8 deletions
+34
-8
src/main/java/com/samourai/whirlpool/cli/api/protocol/beans/ApiWallet.java
.../samourai/whirlpool/cli/api/protocol/beans/ApiWallet.java
+4
-3
src/main/java/com/samourai/whirlpool/cli/api/protocol/rest/ApiWalletStateResponse.java
...irlpool/cli/api/protocol/rest/ApiWalletStateResponse.java
+0
-2
src/main/java/com/samourai/whirlpool/cli/api/protocol/rest/ApiWalletUtxosResponse.java
...irlpool/cli/api/protocol/rest/ApiWalletUtxosResponse.java
+30
-3
No files found.
src/main/java/com/samourai/whirlpool/cli/api/protocol/beans/ApiWallet.java
View file @
8cc43509
package
com.samourai.whirlpool.cli.api.protocol.beans
;
import
com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo
;
import
com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxoPriorityComparator
;
import
java.util.Collection
;
import
java.util.Comparator
;
import
java.util.stream.Collectors
;
public
class
ApiWallet
{
...
...
@@ -10,11 +10,12 @@ public class ApiWallet {
private
long
balance
;
private
String
zpub
;
public
ApiWallet
(
Collection
<
WhirlpoolUtxo
>
whirlpoolUtxos
,
String
zpub
)
{
public
ApiWallet
(
Collection
<
WhirlpoolUtxo
>
whirlpoolUtxos
,
String
zpub
,
Comparator
<
WhirlpoolUtxo
>
comparator
)
{
this
.
utxos
=
whirlpoolUtxos
.
stream
()
.
sorted
(
new
WhirlpoolUtxoPriorityC
omparator
()
)
.
sorted
(
c
omparator
)
.
map
(
whirlpoolUtxo
->
new
ApiUtxo
(
whirlpoolUtxo
))
.
collect
(
Collectors
.
toList
());
this
.
balance
=
...
...
src/main/java/com/samourai/whirlpool/cli/api/protocol/rest/ApiWalletStateResponse.java
View file @
8cc43509
...
...
@@ -2,7 +2,6 @@ package com.samourai.whirlpool.cli.api.protocol.rest;
import
com.samourai.whirlpool.cli.api.protocol.beans.ApiUtxo
;
import
com.samourai.whirlpool.client.wallet.beans.MixOrchestratorState
;
import
com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxoPriorityComparator
;
import
com.samourai.whirlpool.client.wallet.beans.WhirlpoolWalletState
;
import
java.util.Collection
;
import
java.util.stream.Collectors
;
...
...
@@ -28,7 +27,6 @@ public class ApiWalletStateResponse {
mixState
.
getUtxosMixing
()
.
stream
()
.
sorted
(
new
WhirlpoolUtxoPriorityComparator
())
.
map
(
whirlpoolUtxo
->
new
ApiUtxo
(
whirlpoolUtxo
))
.
collect
(
Collectors
.
toList
());
}
...
...
src/main/java/com/samourai/whirlpool/cli/api/protocol/rest/ApiWalletUtxosResponse.java
View file @
8cc43509
package
com.samourai.whirlpool.cli.api.protocol.rest
;
import
com.google.common.primitives.Ints
;
import
com.samourai.whirlpool.cli.api.protocol.beans.ApiWallet
;
import
com.samourai.whirlpool.client.wallet.WhirlpoolWallet
;
import
com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo
;
import
java.util.Comparator
;
import
java8.lang.Longs
;
public
class
ApiWalletUtxosResponse
{
private
ApiWallet
deposit
;
...
...
@@ -9,11 +13,34 @@ public class ApiWalletUtxosResponse {
private
ApiWallet
postmix
;
public
ApiWalletUtxosResponse
(
WhirlpoolWallet
whirlpoolWallet
)
throws
Exception
{
Comparator
<
WhirlpoolUtxo
>
comparator
=
(
o1
,
o2
)
->
{
// last activity first
if
(
o1
.
getLastActivity
()
!=
null
||
o2
.
getLastActivity
()
!=
null
)
{
if
(
o1
.
getLastActivity
()
!=
null
&&
o2
.
getLastActivity
()
==
null
)
{
return
-
1
;
}
if
(
o2
.
getLastActivity
()
!=
null
&&
o1
.
getLastActivity
()
==
null
)
{
return
1
;
}
int
compare
=
Longs
.
compare
(
o2
.
getLastActivity
(),
o1
.
getLastActivity
());
if
(
compare
!=
0
)
{
return
compare
;
}
}
// last confirmed
return
Ints
.
compare
(
o1
.
getUtxo
().
confirmations
,
o2
.
getUtxo
().
confirmations
);
};
this
.
deposit
=
new
ApiWallet
(
whirlpoolWallet
.
getUtxosDeposit
(),
whirlpoolWallet
.
getZpubDeposit
());
this
.
premix
=
new
ApiWallet
(
whirlpoolWallet
.
getUtxosPremix
(),
whirlpoolWallet
.
getZpubPremix
());
new
ApiWallet
(
whirlpoolWallet
.
getUtxosDeposit
(),
whirlpoolWallet
.
getZpubDeposit
(),
comparator
);
this
.
premix
=
new
ApiWallet
(
whirlpoolWallet
.
getUtxosPremix
(),
whirlpoolWallet
.
getZpubPremix
(),
comparator
);
this
.
postmix
=
new
ApiWallet
(
whirlpoolWallet
.
getUtxosPostmix
(),
whirlpoolWallet
.
getZpubPostmix
());
new
ApiWallet
(
whirlpoolWallet
.
getUtxosPostmix
(),
whirlpoolWallet
.
getZpubPostmix
(),
comparator
);
}
public
ApiWallet
getDeposit
()
{
...
...
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