Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add auto-renew account support for files and accounts #1228

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added
- `[Account|File][Create|Update]Transaction.[set|get]autoRenewAccountId()`
- `[Account|File].autoRenewAccountId`

## 2.18.1

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public final class AccountCreateTransaction extends Transaction<AccountCreateTra
@Nullable
private EvmAddress aliasEvmAddress = null;

@Nullable
private AccountId autoRenewAccount = null;

/**
* Constructor.
*/
Expand Down Expand Up @@ -401,6 +404,28 @@ public AccountCreateTransaction setAliasEvmAddress(EvmAddress aliasEvmAddress) {
return this;
}

/**
* ID of the account to charge for auto-renewal of this account
*
* @return the ID
*/
@Nullable
public AccountId getAutoRenewAccount() {
return autoRenewAccount;
}

/**
* Set the account to charge for auto-renewal of this account
*
* @param autoRenewAccount ID of the account to charge for auto-renewal of this account
* @return {@code this}
*/
public AccountCreateTransaction setAutoRenewAccount(AccountId autoRenewAccount) {
requireNotFrozen();
this.autoRenewAccount = autoRenewAccount;
return this;
}

/**
* Build the transaction body.
*
Expand Down Expand Up @@ -435,6 +460,10 @@ CryptoCreateTransactionBody.Builder build() {
builder.setStakedNodeId(stakedNodeId);
}

if (autoRenewAccount != null) {
builder.setAutoRenewAccount(autoRenewAccount.toProtobuf());
}

return builder;
}

Expand Down Expand Up @@ -480,6 +509,10 @@ void initFromTransactionBody() {

aliasKey = PublicKey.fromAliasBytes(body.getAlias());
aliasEvmAddress = EvmAddress.fromAliasBytes(body.getAlias());

if (body.hasAutoRenewAccount()) {
autoRenewAccount = AccountId.fromProtobuf(body.getAutoRenewAccount());
}
}

@Override
Expand Down
20 changes: 17 additions & 3 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/AccountInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public final class AccountInfo {
@Nullable
public final StakingInfo stakingInfo;

@Nullable
public final AccountId autoRenewAccountId;

/**
* Constructor.
*
Expand All @@ -172,14 +175,17 @@ public final class AccountInfo {
* @param receiveRecordThreshold @depreciated no replacement
* @param receiverSignatureRequired is the receiver's signature required
* @param expirationTime the expiration time
* @param autoRenewPeriod the auto renew period
* @param autoRenewPeriod the auto-renewal period
* @param liveHashes the live hashes
* @param tokenRelationships list of token id and token relationship records
* @param accountMemo the account melo
* @param ownedNfts number of nft's
* @param maxAutomaticTokenAssociations max number of token associations
* @param aliasKey public alias key
* @param ledgerId the ledger id
* @param ethereumNonce the Ethereum nonce
* @param stakingInfo the staking information
* @param autoRenewAccountId the auto-renewal account ID
*/
private AccountInfo(
AccountId accountId,
Expand All @@ -202,7 +208,8 @@ private AccountInfo(
@Nullable PublicKey aliasKey,
LedgerId ledgerId,
long ethereumNonce,
@Nullable StakingInfo stakingInfo
@Nullable StakingInfo stakingInfo,
@Nullable AccountId autoRenewAccountId
) {
this.accountId = accountId;
this.contractAccountId = contractAccountId;
Expand All @@ -228,6 +235,7 @@ private AccountInfo(
this.tokenAllowances = Collections.emptyList();
this.tokenNftAllowances = Collections.emptyList();
this.stakingInfo = stakingInfo;
this.autoRenewAccountId = autoRenewAccountId;
}

/**
Expand Down Expand Up @@ -278,7 +286,8 @@ static AccountInfo fromProtobuf(CryptoGetInfoResponse.AccountInfo accountInfo) {
aliasKey,
LedgerId.fromByteString(accountInfo.getLedgerId()),
accountInfo.getEthereumNonce(),
accountInfo.hasStakingInfo() ? StakingInfo.fromProtobuf(accountInfo.getStakingInfo()) : null
accountInfo.hasStakingInfo() ? StakingInfo.fromProtobuf(accountInfo.getStakingInfo()) : null,
accountInfo.hasAutoRenewAccount() ? AccountId.fromProtobuf(accountInfo.getAutoRenewAccount()) : null
);
}

Expand Down Expand Up @@ -337,6 +346,10 @@ CryptoGetInfoResponse.AccountInfo toProtobuf() {
accountInfoBuilder.setStakingInfo(stakingInfo.toProtobuf());
}

if (autoRenewAccountId != null) {
accountInfoBuilder.setAutoRenewAccount(autoRenewAccountId.toProtobuf());
}

return accountInfoBuilder.build();
}

Expand Down Expand Up @@ -364,6 +377,7 @@ public String toString() {
.add("ledgerId", ledgerId)
.add("ethereumNonce", ethereumNonce)
.add("stakingInfo", stakingInfo)
.add("autoRenewAccountId", autoRenewAccountId)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public final class AccountUpdateTransaction extends Transaction<AccountUpdateTra
@Nullable
private Boolean declineStakingReward = null;

@Nullable
private AccountId autoRenewAccount = null;

/**
* Constructor.
*/
Expand Down Expand Up @@ -459,6 +462,28 @@ public AccountUpdateTransaction clearDeclineStakingReward() {
return this;
}

/**
* ID of the account to charge for auto-renewal of this account
*
* @return the ID
*/
@Nullable
public AccountId getAutoRenewAccount() {
return autoRenewAccount;
}

/**
* Set the account to charge for auto-renewal of this account
*
* @param autoRenewAccount ID of the account to charge for auto-renewal of this account
* @return {@code this}
*/
public AccountUpdateTransaction setAutoRenewAccount(AccountId autoRenewAccount) {
requireNotFrozen();
this.autoRenewAccount = autoRenewAccount;
return this;
}

@Override
void validateChecksums(Client client) throws BadEntityIdException {
if (accountId != null) {
Expand Down Expand Up @@ -515,6 +540,10 @@ void initFromTransactionBody() {
if (body.hasStakedNodeId()) {
stakedNodeId = body.getStakedNodeId();
}

if (body.hasAutoRenewAccount()) {
autoRenewAccount = AccountId.fromProtobuf(body.getAutoRenewAccount());
}
}

@Override
Expand Down Expand Up @@ -564,6 +593,10 @@ CryptoUpdateTransactionBody.Builder build() {
builder.setDeclineReward(BoolValue.newBuilder().setValue(declineStakingReward).build());
}

if (autoRenewAccount != null) {
builder.setAutoRenewAccount(autoRenewAccount.toProtobuf());
}

return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public final class FileCreateTransaction extends Transaction<FileCreateTransacti
private byte[] contents = {};
private String fileMemo = "";

@Nullable
private AccountId autoRenewAccount = null;

/**
* Constructor.
*/
Expand Down Expand Up @@ -230,6 +233,28 @@ public FileCreateTransaction setFileMemo(String memo) {
return this;
}

/**
* ID of the account to charge for auto-renewal of this file
*
* @return the ID
*/
@Nullable
public AccountId getAutoRenewAccount() {
return autoRenewAccount;
}

/**
* Set the account to charge for auto-renewal of this file
*
* @param autoRenewAccount ID of the account to charge for auto-renewal of this file
* @return {@code this}
*/
public FileCreateTransaction setAutoRenewAccount(AccountId autoRenewAccount) {
requireNotFrozen();
this.autoRenewAccount = autoRenewAccount;
return this;
}

@Override
MethodDescriptor<com.hedera.hashgraph.sdk.proto.Transaction, TransactionResponse> getMethodDescriptor() {
return FileServiceGrpc.getCreateFileMethod();
Expand All @@ -253,6 +278,7 @@ void initFromTransactionBody() {
}
contents = body.getContents().toByteArray();
fileMemo = body.getMemo();
autoRenewAccount = AccountId.fromProtobuf(body.getAutoRenewAccount());
}

/**
Expand All @@ -272,6 +298,10 @@ FileCreateTransactionBody.Builder build() {
builder.setContents(ByteString.copyFrom(contents));
builder.setMemo(fileMemo);

if (autoRenewAccount != null) {
builder.setAutoRenewAccount(autoRenewAccount.toProtobuf());
}

return builder;
}

Expand Down
16 changes: 13 additions & 3 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/FileInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

/**
* Current information for a file, including its size.
*
* See <a href="https://docs.hedera.com/guides/docs/sdks/file-storage/get-file-info">Hedera Documentation</a>
*/
public final class FileInfo {
Expand Down Expand Up @@ -66,14 +65,18 @@ public final class FileInfo {
*/
public final LedgerId ledgerId;

@Nullable
public final AccountId autoRenewAccountId;

private FileInfo(
FileId fileId,
long size,
Instant expirationTime,
boolean isDeleted,
@Nullable KeyList keys,
String fileMemo,
LedgerId ledgerId
LedgerId ledgerId,
@Nullable AccountId autoRenewAccountId
) {
this.fileId = fileId;
this.size = size;
Expand All @@ -82,6 +85,7 @@ private FileInfo(
this.keys = keys;
this.fileMemo = fileMemo;
this.ledgerId = ledgerId;
this.autoRenewAccountId = autoRenewAccountId;
}

/**
Expand All @@ -102,7 +106,8 @@ static FileInfo fromProtobuf(FileGetInfoResponse.FileInfo fileInfo) {
fileInfo.getDeleted(),
keys,
fileInfo.getMemo(),
LedgerId.fromByteString(fileInfo.getLedgerId())
LedgerId.fromByteString(fileInfo.getLedgerId()),
AccountId.fromProtobuf(fileInfo.getAutoRenewAccount())
);
}

Expand Down Expand Up @@ -141,6 +146,10 @@ FileGetInfoResponse.FileInfo toProtobuf() {
fileInfoBuilder.setKeys(keyList);
}

if (autoRenewAccountId != null) {
fileInfoBuilder.setAutoRenewAccount(autoRenewAccountId.toProtobuf());
}

return fileInfoBuilder.build();
}

Expand All @@ -154,6 +163,7 @@ public String toString() {
.add("keys", keys)
.add("fileMemo", fileMemo)
.add("ledgerId", ledgerId)
.add("autoRenewAccountId", autoRenewAccountId)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public final class FileUpdateTransaction extends Transaction<FileUpdateTransacti
@Nullable
private String fileMemo = null;

@Nullable
private AccountId autoRenewAccount = null;

/**
* Constructor.
*/
Expand Down Expand Up @@ -264,6 +267,28 @@ public FileUpdateTransaction clearMemo() {
return this;
}

/**
* ID of the account to charge for auto-renewal of this file
*
* @return the ID
*/
@Nullable
public AccountId getAutoRenewAccount() {
return autoRenewAccount;
}

/**
* Set the account to charge for auto-renewal of this file
*
* @param autoRenewAccount ID of the account to charge for auto-renewal of this file
* @return {@code this}
*/
public FileUpdateTransaction setAutoRenewAccount(AccountId autoRenewAccount) {
requireNotFrozen();
this.autoRenewAccount = autoRenewAccount;
return this;
}

/**
* Initialize from the transaction body.
*/
Expand All @@ -281,6 +306,9 @@ void initFromTransactionBody() {
if (body.hasMemo()) {
fileMemo = body.getMemo().getValue();
}
if (body.hasAutoRenewAccount()) {
autoRenewAccount = AccountId.fromProtobuf(body.getAutoRenewAccount());
}
contents = body.getContents().toByteArray();
}

Expand All @@ -304,6 +332,9 @@ FileUpdateTransactionBody.Builder build() {
if (fileMemo != null) {
builder.setMemo(StringValue.of(fileMemo));
}
if (autoRenewAccount != null) {
builder.setAutoRenewAccount(autoRenewAccount.toProtobuf());
}

return builder;
}
Expand Down
Loading