|
12 | 12 | import java.util.TimeZone; |
13 | 13 | import java.util.UUID; |
14 | 14 |
|
| 15 | +import com.google.common.collect.Lists; |
15 | 16 | import org.apache.commons.lang3.tuple.ImmutablePair; |
16 | 17 | import org.bitcoinj.core.ECKey; |
17 | 18 | import org.bitcoinj.core.Sha256Hash; |
|
71 | 72 | import eu.bittrade.libs.steemj.base.models.VoteState; |
72 | 73 | import eu.bittrade.libs.steemj.base.models.Witness; |
73 | 74 | import eu.bittrade.libs.steemj.base.models.WitnessSchedule; |
| 75 | +import eu.bittrade.libs.steemj.base.models.operations.ClaimRewardBalanceOperation; |
74 | 76 | import eu.bittrade.libs.steemj.base.models.operations.CommentOperation; |
75 | 77 | import eu.bittrade.libs.steemj.base.models.operations.CommentOptionsOperation; |
76 | 78 | import eu.bittrade.libs.steemj.base.models.operations.CustomJsonOperation; |
@@ -3607,17 +3609,16 @@ public void deletePostOrComment(AccountName postOrCommentAuthor, Permlink postOr |
3607 | 3609 | * <ul> |
3608 | 3610 | * <li>This method will write data on the blockchain. As all writing |
3609 | 3611 | * operations, a private key is required to sign the transaction. For a |
3610 | | - * follow operation the private posting key of the |
| 3612 | + * transfer operation the private active key of the |
3611 | 3613 | * {@link SteemJConfig#getDefaultAccount() DefaultAccount} needs to be |
3612 | 3614 | * configured in the {@link SteemJConfig#getPrivateKeyStorage() |
3613 | 3615 | * PrivateKeyStorage}.</li> |
3614 | 3616 | * <li>This method will automatically use the |
3615 | 3617 | * {@link SteemJConfig#getDefaultAccount() DefaultAccount} as the account |
3616 | | - * that will follow the <code>accountToFollow</code> - If no default account |
3617 | | - * has been provided, this method will throw an error. If you do not want to |
3618 | | - * configure the following account as a default account, please use the |
3619 | | - * {@link #follow(AccountName, AccountName)} method and provide the |
3620 | | - * following account separately.</li> |
| 3618 | + * to transfer from. If no default account has been provided, this method will throw an error. If you |
| 3619 | + * do not want to configure the following account as a default account, please use the |
| 3620 | + * {@link #transfer(AccountName, AccountName, AssetSymbolType, double, String)} method and provide the |
| 3621 | + * <code>from</code> account separately.</li> |
3621 | 3622 | * </ul> |
3622 | 3623 | * |
3623 | 3624 | * @param to |
@@ -3670,21 +3671,12 @@ public TransferOperation transfer(AccountName to, AssetSymbolType assetType, dou |
3670 | 3671 | * <code>SteemJ.transfer(new AccountName("accounta"), new AccountName("accountb"), AssetSymbolType.SBD, 1.0, "My memo");</code> |
3671 | 3672 | * |
3672 | 3673 | * <b>Attention</b> |
3673 | | - * <ul> |
3674 | | - * <li>This method will write data on the blockchain. As all writing |
| 3674 | + * This method will write data on the blockchain. As all writing |
3675 | 3675 | * operations, a private key is required to sign the transaction. For a |
3676 | | - * follow operation the private posting key of the |
| 3676 | + * transfer operation the private active key of the |
3677 | 3677 | * {@link SteemJConfig#getDefaultAccount() DefaultAccount} needs to be |
3678 | 3678 | * configured in the {@link SteemJConfig#getPrivateKeyStorage() |
3679 | | - * PrivateKeyStorage}.</li> |
3680 | | - * <li>This method will automatically use the |
3681 | | - * {@link SteemJConfig#getDefaultAccount() DefaultAccount} as the account |
3682 | | - * that will follow the <code>accountToFollow</code> - If no default account |
3683 | | - * has been provided, this method will throw an error. If you do not want to |
3684 | | - * configure the following account as a default account, please use the |
3685 | | - * {@link #follow(AccountName, AccountName)} method and provide the |
3686 | | - * following account separately.</li> |
3687 | | - * </ul> |
| 3679 | + * PrivateKeyStorage}. |
3688 | 3680 | * |
3689 | 3681 | * @param from |
3690 | 3682 | * The account from which to transfer currency. |
@@ -3738,4 +3730,104 @@ public TransferOperation transfer(AccountName from, AccountName to, AssetSymbolT |
3738 | 3730 | this.broadcastTransaction(signedTransaction); |
3739 | 3731 | return transferOperation; |
3740 | 3732 | } |
| 3733 | + |
| 3734 | + /** |
| 3735 | + * Claim all available Steem, SDB and VEST (Steam Power) rewards for the default account. |
| 3736 | + * |
| 3737 | + * <b>Attention</b> |
| 3738 | + * <ul> |
| 3739 | + * <li>This method will write data on the blockchain if a reward balance is available to be claimed. As with all writing |
| 3740 | + * operations, a private key is required to sign the transaction. See {@link SteemJConfig#getPrivateKeyStorage() |
| 3741 | + * PrivateKeyStorage}.</li> |
| 3742 | + * <li>This method will automatically use the |
| 3743 | + * {@link SteemJConfig#getDefaultAccount() DefaultAccount} as the account |
| 3744 | + * that will follow the <code>accountToFollow</code> - If no default account |
| 3745 | + * has been provided, this method will throw an error. If you do not want to |
| 3746 | + * configure the following account as a default account, please use the |
| 3747 | + * {@link #follow(AccountName, AccountName)} method and provide the |
| 3748 | + * following account separately.</li> |
| 3749 | + * </ul> |
| 3750 | + * |
| 3751 | + * @return The ClaimOperation for reward balances found. This will only have been broadcast if one of the balances |
| 3752 | + * is non-zero. |
| 3753 | + * @throws SteemCommunicationException |
| 3754 | + * <ul> |
| 3755 | + * <li>If the server was not able to answer the request in the |
| 3756 | + * given time (see |
| 3757 | + * {@link eu.bittrade.libs.steemj.configuration.SteemJConfig#setResponseTimeout(int) |
| 3758 | + * setResponseTimeout}).</li> |
| 3759 | + * <li>If there is a connection problem.</li> |
| 3760 | + * </ul> |
| 3761 | + * @throws SteemResponseException |
| 3762 | + * <ul> |
| 3763 | + * <li>If the SteemJ is unable to transform the JSON response |
| 3764 | + * into a Java object.</li> |
| 3765 | + * <li>If the Server returned an error object.</li> |
| 3766 | + * </ul> |
| 3767 | + * @throws SteemInvalidTransactionException |
| 3768 | + * If there is a problem while signing the transaction. |
| 3769 | + */ |
| 3770 | + public ClaimRewardBalanceOperation claimRewards() |
| 3771 | + throws SteemCommunicationException, SteemResponseException, SteemInvalidTransactionException { |
| 3772 | + if (SteemJConfig.getInstance().getDefaultAccount().isEmpty()) { |
| 3773 | + throw new InvalidParameterException(NO_DEFAULT_ACCOUNT_ERROR_MESSAGE); |
| 3774 | + } |
| 3775 | + |
| 3776 | + return claimRewards(SteemJConfig.getInstance().getDefaultAccount()); |
| 3777 | + } |
| 3778 | + |
| 3779 | + /** |
| 3780 | + * Claim all available Steem, SDB and VEST (Steam Power) rewards for the specified account. |
| 3781 | + * |
| 3782 | + * <b>Attention</b> |
| 3783 | + * This method will write data on the blockchain if a reward balance is available to be claimed. As with all writing |
| 3784 | + * operations, a private key is required to sign the transaction. See {@link SteemJConfig#getPrivateKeyStorage() |
| 3785 | + * PrivateKeyStorage}. |
| 3786 | + * |
| 3787 | + * @param accountName |
| 3788 | + * The account to claim rewards for. |
| 3789 | + * @return The ClaimOperation for reward balances found. This will only have been broadcast if one of the balances |
| 3790 | + * is non-zero. |
| 3791 | + * @throws SteemCommunicationException |
| 3792 | + * <ul> |
| 3793 | + * <li>If the server was not able to answer the request in the |
| 3794 | + * given time (see |
| 3795 | + * {@link eu.bittrade.libs.steemj.configuration.SteemJConfig#setResponseTimeout(int) |
| 3796 | + * setResponseTimeout}).</li> |
| 3797 | + * <li>If there is a connection problem.</li> |
| 3798 | + * </ul> |
| 3799 | + * @throws SteemResponseException |
| 3800 | + * <ul> |
| 3801 | + * <li>If the SteemJ is unable to transform the JSON response |
| 3802 | + * into a Java object.</li> |
| 3803 | + * <li>If the Server returned an error object.</li> |
| 3804 | + * </ul> |
| 3805 | + * @throws SteemInvalidTransactionException |
| 3806 | + * If there is a problem while signing the transaction. |
| 3807 | + */ |
| 3808 | + public ClaimRewardBalanceOperation claimRewards(AccountName accountName) |
| 3809 | + throws SteemCommunicationException, SteemResponseException, SteemInvalidTransactionException { |
| 3810 | + // Get extended account info to determine reward balances |
| 3811 | + ExtendedAccount extendedAccount = this.getAccounts(Lists.newArrayList(accountName)).get(0); |
| 3812 | + Asset steemReward = extendedAccount.getRewardSteemBalance(); |
| 3813 | + Asset sbdReward = extendedAccount.getRewardSdbBalance(); |
| 3814 | + Asset vestingReward = extendedAccount.getRewardVestingBalance(); |
| 3815 | + |
| 3816 | + // Create claim operation based on available reward balances |
| 3817 | + ClaimRewardBalanceOperation claimOperation = new ClaimRewardBalanceOperation(accountName, |
| 3818 | + steemReward, sbdReward, vestingReward); |
| 3819 | + |
| 3820 | + // Broadcast claim operation if there are any balances available |
| 3821 | + if (steemReward.getAmount() > 0 || sbdReward.getAmount() > 0 || vestingReward.getAmount() > 0) { |
| 3822 | + ArrayList<Operation> operations = new ArrayList<>(); |
| 3823 | + operations.add(claimOperation); |
| 3824 | + GlobalProperties globalProperties = this.getDynamicGlobalProperties(); |
| 3825 | + SignedTransaction signedTransaction = new SignedTransaction(globalProperties.getHeadBlockId(), operations, |
| 3826 | + null); |
| 3827 | + signedTransaction.sign(); |
| 3828 | + this.broadcastTransaction(signedTransaction); |
| 3829 | + } |
| 3830 | + |
| 3831 | + return claimOperation; |
| 3832 | + } |
3741 | 3833 | } |
0 commit comments