Skip to content

Commit 0b8055d

Browse files
committed
2 parents ec89b2e + a2dd3a7 commit 0b8055d

1 file changed

Lines changed: 110 additions & 18 deletions

File tree

core/src/main/java/eu/bittrade/libs/steemj/SteemJ.java

Lines changed: 110 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.TimeZone;
1313
import java.util.UUID;
1414

15+
import com.google.common.collect.Lists;
1516
import org.apache.commons.lang3.tuple.ImmutablePair;
1617
import org.bitcoinj.core.ECKey;
1718
import org.bitcoinj.core.Sha256Hash;
@@ -71,6 +72,7 @@
7172
import eu.bittrade.libs.steemj.base.models.VoteState;
7273
import eu.bittrade.libs.steemj.base.models.Witness;
7374
import eu.bittrade.libs.steemj.base.models.WitnessSchedule;
75+
import eu.bittrade.libs.steemj.base.models.operations.ClaimRewardBalanceOperation;
7476
import eu.bittrade.libs.steemj.base.models.operations.CommentOperation;
7577
import eu.bittrade.libs.steemj.base.models.operations.CommentOptionsOperation;
7678
import eu.bittrade.libs.steemj.base.models.operations.CustomJsonOperation;
@@ -3607,17 +3609,16 @@ public void deletePostOrComment(AccountName postOrCommentAuthor, Permlink postOr
36073609
* <ul>
36083610
* <li>This method will write data on the blockchain. As all writing
36093611
* 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
36113613
* {@link SteemJConfig#getDefaultAccount() DefaultAccount} needs to be
36123614
* configured in the {@link SteemJConfig#getPrivateKeyStorage()
36133615
* PrivateKeyStorage}.</li>
36143616
* <li>This method will automatically use the
36153617
* {@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>
36213622
* </ul>
36223623
*
36233624
* @param to
@@ -3670,21 +3671,12 @@ public TransferOperation transfer(AccountName to, AssetSymbolType assetType, dou
36703671
* <code>SteemJ.transfer(new AccountName("accounta"), new AccountName("accountb"), AssetSymbolType.SBD, 1.0, "My memo");</code>
36713672
*
36723673
* <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
36753675
* 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
36773677
* {@link SteemJConfig#getDefaultAccount() DefaultAccount} needs to be
36783678
* 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}.
36883680
*
36893681
* @param from
36903682
* The account from which to transfer currency.
@@ -3738,4 +3730,104 @@ public TransferOperation transfer(AccountName from, AccountName to, AssetSymbolT
37383730
this.broadcastTransaction(signedTransaction);
37393731
return transferOperation;
37403732
}
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+
}
37413833
}

0 commit comments

Comments
 (0)