forked from zold-io/java-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
441 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2018 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package io.zold.api; | ||
|
||
import java.util.Comparator; | ||
import org.cactoos.iterable.Filtered; | ||
import org.cactoos.iterable.IterableEnvelope; | ||
import org.cactoos.iterable.LengthOf; | ||
import org.cactoos.iterable.Sorted; | ||
|
||
/** | ||
* {@link Remote} nodes that should receive taxes. | ||
* | ||
* @since 1.0 | ||
*/ | ||
public final class TaxBeneficiaries extends IterableEnvelope<Remote> { | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param nodes Remote nodes to select from. | ||
*/ | ||
public TaxBeneficiaries(final Iterable<Remote> nodes) { | ||
super(() -> new Sorted<>( | ||
Comparator.comparing(Remote::score), | ||
new Filtered<>( | ||
// @checkstyle MagicNumberCheck (1 line) | ||
n -> new LengthOf(n.score().suffixes()).intValue() >= 16, | ||
nodes | ||
) | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2018 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package io.zold.api; | ||
|
||
import org.cactoos.Proc; | ||
import org.cactoos.text.FormattedText; | ||
import org.cactoos.text.UncheckedText; | ||
|
||
/** | ||
* Taxes payment algorithm. | ||
* | ||
* @since 1.0 | ||
* @todo #40:30min Implement tax payment to remote nodes. | ||
* Payment should happen only if the wallet is in debt of more than | ||
* 1 Zold. Debt is difference between current taxes that should have | ||
* been paid by wallet (see whitepaper for formula) and how much it | ||
* already paid in the past. A first algorithm could pay the | ||
* max to each node until there is nothing else to pay. The test | ||
* must also be updated. | ||
*/ | ||
public final class Taxes implements Proc<Wallet> { | ||
|
||
/** | ||
* The beneficiary nodes. | ||
*/ | ||
private final Iterable<Remote> bnfs; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param nodes Remote nodes. | ||
*/ | ||
public Taxes(final Iterable<Remote> nodes) { | ||
this.bnfs = new TaxBeneficiaries(nodes); | ||
} | ||
|
||
@Override | ||
public void exec(final Wallet wallet) { | ||
throw new UnsupportedOperationException( | ||
new UncheckedText( | ||
new FormattedText( | ||
"paying taxes to %s not yet supported", | ||
this.bnfs | ||
) | ||
).asString() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.