Skip to content

Commit 81a2895

Browse files
emiliyankhendrikebbersmustafauzunn
authored
feat: HIP-1313 (#2572)
Signed-off-by: emiliyank <e.kadiyski@gmail.com> Signed-off-by: Mustafa Uzun <mustafa.uzun@limechain.tech> Co-authored-by: Hendrik Ebbers <hendrik.ebbers@web.de> Co-authored-by: Mustafa Uzun <mustafa.uzun@limechain.tech>
1 parent 51a9c69 commit 81a2895

19 files changed

Lines changed: 302 additions & 18 deletions

.github/workflows/build.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,12 @@ jobs:
176176

177177
- name: Prepare Hiero Solo
178178
id: solo
179-
uses: hiero-ledger/hiero-solo-action@4d42a74e8e644a2753f3bb7a2afa429305375b14 # v0.16
179+
uses: hiero-ledger/hiero-solo-action@4d42a74e8e644a2753f3bb7a2afa429305375b14 # v0.17
180180
with:
181181
installMirrorNode: true
182-
mirrorNodeVersion: v0.145.2
183-
hieroVersion: v0.70.0-rc.2
182+
soloVersion: v0.65.0
183+
mirrorNodeVersion: v0.153.0
184+
hieroVersion: v0.73.0
184185

185186
- name: Build SDK
186187
run: ./gradlew assemble
@@ -249,9 +250,10 @@ jobs:
249250

250251
- name: Prepare Hiero Solo (DUAL MODE)
251252
id: solo
252-
uses: hiero-ledger/hiero-solo-action@4d42a74e8e644a2753f3bb7a2afa429305375b14 # v0.16
253+
uses: hiero-ledger/hiero-solo-action@4d42a74e8e644a2753f3bb7a2afa429305375b14 # v0.17
253254
with:
254255
installMirrorNode: true
256+
soloVersion: v0.65.0
255257
dualMode: true
256258
hieroVersion: v0.68.0
257259
mirrorNodeVersion: v0.142.0
@@ -306,11 +308,12 @@ jobs:
306308

307309
- name: Prepare Hiero Solo
308310
id: solo
309-
uses: hiero-ledger/hiero-solo-action@4d42a74e8e644a2753f3bb7a2afa429305375b14 # v0.16
311+
uses: hiero-ledger/hiero-solo-action@4d42a74e8e644a2753f3bb7a2afa429305375b14 # v0.17
310312
with:
311313
installMirrorNode: true
312-
mirrorNodeVersion: v0.145.2
313-
hieroVersion: v0.70.0-rc.2
314+
soloVersion: v0.65.0
315+
mirrorNodeVersion: v0.153.0
316+
hieroVersion: v0.73.0
314317

315318
- name: Build SDK
316319
run: ./gradlew assemble

examples/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ abstract class RunAllExample : DefaultTask() {
8181
.filter {
8282
it != "MirrorNodeContractQueriesExample"
8383
} // disabled due to consensus node issue
84+
.filter { it != "HookStoreExample" }
85+
.filter { it != "AccountHooksExample" }
86+
.filter { it != "ContractHooksExample" }
87+
.filter { it != "TransferTransactionHooksExample" }
8488
.toList()
8589

8690
exampleClasses.forEach { className ->
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
package com.hedera.hashgraph.sdk.examples;
3+
4+
import com.hedera.hashgraph.sdk.*;
5+
import com.hedera.hashgraph.sdk.logger.LogLevel;
6+
import com.hedera.hashgraph.sdk.logger.Logger;
7+
import io.github.cdimascio.dotenv.Dotenv;
8+
import java.util.Objects;
9+
10+
/**
11+
* Create a Hedera account using high-volume throttles.
12+
*/
13+
class HighVolumeAccountCreateExample {
14+
15+
/*
16+
* See .env.sample in the examples folder root for how to specify values below
17+
* or set environment variables with the same names.
18+
*/
19+
20+
/**
21+
* Operator's account ID.
22+
* Used to sign and pay for operations on Hedera.
23+
*/
24+
private static final AccountId OPERATOR_ID =
25+
AccountId.fromString(Objects.requireNonNull(Dotenv.load().get("OPERATOR_ID")));
26+
27+
/**
28+
* Operator's private key.
29+
*/
30+
private static final PrivateKey OPERATOR_KEY =
31+
PrivateKey.fromString(Objects.requireNonNull(Dotenv.load().get("OPERATOR_KEY")));
32+
33+
/**
34+
* HEDERA_NETWORK defaults to testnet if not specified in dotenv file.
35+
* Network can be: localhost, testnet, previewnet or mainnet.
36+
*/
37+
private static final String HEDERA_NETWORK = Dotenv.load().get("HEDERA_NETWORK", "testnet");
38+
39+
/**
40+
* SDK_LOG_LEVEL defaults to SILENT if not specified in dotenv file.
41+
* Log levels can be: TRACE, DEBUG, INFO, WARN, ERROR, SILENT.
42+
* <p>
43+
* Important pre-requisite: set simple logger log level to same level as the SDK_LOG_LEVEL,
44+
* for example via VM options: -Dorg.slf4j.simpleLogger.log.org.hiero=trace
45+
*/
46+
private static final String SDK_LOG_LEVEL = Dotenv.load().get("SDK_LOG_LEVEL", "SILENT");
47+
48+
public static void main(String[] args) throws Exception {
49+
System.out.println("High-Volume Account Create Example Start!");
50+
51+
/*
52+
* Step 0:
53+
* Create and configure the SDK Client.
54+
*/
55+
Client client = ClientHelper.forName(HEDERA_NETWORK);
56+
// All generated transactions will be paid by this account and signed by this key.
57+
client.setOperator(OPERATOR_ID, OPERATOR_KEY);
58+
// Attach logger to the SDK Client.
59+
client.setLogger(new Logger(LogLevel.valueOf(SDK_LOG_LEVEL)));
60+
61+
/*
62+
* Step 1:
63+
* Generate ED25519 private and public key pair for the account.
64+
*/
65+
PrivateKey privateKey = PrivateKey.generateED25519();
66+
PublicKey publicKey = privateKey.getPublicKey();
67+
System.out.println("Future account private key: " + privateKey);
68+
System.out.println("Future account public key: " + publicKey);
69+
70+
/*
71+
* Step 2:
72+
* Create a new account using high-volume throttles and set a fee limit.
73+
*/
74+
System.out.println("Creating new account with high-volume throttles...");
75+
TransactionResponse accountCreateTxResponse = new AccountCreateTransaction()
76+
.setKeyWithoutAlias(publicKey)
77+
.setInitialBalance(Hbar.from(1))
78+
.setHighVolume(true)
79+
.setMaxTransactionFee(Hbar.from(5))
80+
.execute(client);
81+
82+
// This will wait for the receipt to become available.
83+
TransactionReceipt accountCreateTxReceipt = accountCreateTxResponse.getReceipt(client);
84+
AccountId newAccountId = accountCreateTxReceipt.accountId;
85+
Objects.requireNonNull(newAccountId);
86+
System.out.println("Created account with ID: " + newAccountId);
87+
88+
/*
89+
* Clean up:
90+
* Delete created account.
91+
*/
92+
new AccountDeleteTransaction()
93+
.setTransferAccountId(OPERATOR_ID)
94+
.setAccountId(newAccountId)
95+
.freezeWith(client)
96+
.sign(privateKey)
97+
.execute(client)
98+
.getReceipt(client);
99+
100+
client.close();
101+
102+
System.out.println("High-Volume Account Create Example Complete!");
103+
}
104+
}

sdk/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ tasks.withType<Test>().configureEach {
5858
}
5959

6060
tasks.testIntegration {
61-
maxParallelForks = (Runtime.getRuntime().availableProcessors()).coerceAtLeast(1)
61+
maxParallelForks = 1
6262
failFast = true
6363
}
6464

sdk/src/main/java/com/hedera/hashgraph/sdk/Transaction.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ public abstract class Transaction<T extends Transaction<T>>
132132

133133
private String memo = "";
134134

135+
private boolean highVolume = false;
136+
135137
List<CustomFeeLimit> customFeeLimits = new ArrayList<>();
136138

137139
private Key batchKey = null;
@@ -156,6 +158,7 @@ public abstract class Transaction<T extends Transaction<T>>
156158
setTransactionValidDuration(DEFAULT_TRANSACTION_VALID_DURATION);
157159
setMaxTransactionFee(Hbar.fromTinybars(txBody.getTransactionFee()));
158160
setTransactionMemo(txBody.getMemo());
161+
setHighVolume(txBody.getHighVolume());
159162

160163
sourceTransactionBody = txBody;
161164
}
@@ -245,6 +248,7 @@ public abstract class Transaction<T extends Transaction<T>>
245248
DurationConverter.fromProtobuf(sourceTransactionBody.getTransactionValidDuration()));
246249
setMaxTransactionFee(Hbar.fromTinybars(sourceTransactionBody.getTransactionFee()));
247250
setTransactionMemo(sourceTransactionBody.getMemo());
251+
setHighVolume(sourceTransactionBody.getHighVolume());
248252

249253
this.customFeeLimits = sourceTransactionBody.getMaxCustomFeesList().stream()
250254
.map(CustomFeeLimit::fromProtobuf)
@@ -859,6 +863,30 @@ public final T setTransactionMemo(String memo) {
859863
return (T) this;
860864
}
861865

866+
/**
867+
* Extract the high-volume flag.
868+
*
869+
* @return true if high-volume throttles are enabled, false otherwise
870+
*/
871+
public final boolean getHighVolume() {
872+
return highVolume;
873+
}
874+
875+
/**
876+
* If set to true, this transaction uses high-volume throttles and pricing
877+
* for entity creation. It only affects supported transaction types; otherwise,
878+
* it is ignored.
879+
*
880+
* @param highVolume true to enable high-volume throttles, false otherwise
881+
* @return {@code this}
882+
*/
883+
public final T setHighVolume(boolean highVolume) {
884+
requireNotFrozen();
885+
this.highVolume = highVolume;
886+
// noinspection unchecked
887+
return (T) this;
888+
}
889+
862890
/**
863891
* batchify method is used to mark a transaction as part of a batch transaction or make it so-called inner transaction.
864892
* The Transaction will be frozen and signed by the operator of the client.
@@ -1236,7 +1264,8 @@ protected TransactionBody.Builder spawnBodyBuilder(@Nullable Client client) {
12361264
.setTransactionValidDuration(DurationConverter.toProtobuf(transactionValidDuration).toBuilder())
12371265
.addAllMaxCustomFees(
12381266
customFeeLimits.stream().map(CustomFeeLimit::toProtobuf).collect(Collectors.toList()))
1239-
.setMemo(memo);
1267+
.setMemo(memo)
1268+
.setHighVolume(highVolume);
12401269
if (batchKey != null) {
12411270
builder.setBatchKey(batchKey.toProtobufKey());
12421271
}

sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionRecord.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ public final class TransactionRecord {
192192
*/
193193
public final List<PendingAirdropRecord> pendingAirdropRecords;
194194

195+
/**
196+
* A pricing multiplier for high-volume entity creation.
197+
* <p>
198+
* If the transaction that produced this record was flagged as
199+
* high-volume, this field SHALL contain the pricing multiplier
200+
* applied to the transaction fee.<br/>
201+
* If the transaction was not flagged as high-volume, this field
202+
* SHALL be zero.
203+
*/
204+
public final long highVolumePricingMultiplier;
205+
195206
TransactionRecord(
196207
TransactionReceipt transactionReceipt,
197208
ByteString transactionHash,
@@ -216,7 +227,8 @@ public final class TransactionRecord {
216227
@Nullable ByteString prngBytes,
217228
@Nullable Integer prngNumber,
218229
ByteString evmAddress,
219-
List<PendingAirdropRecord> pendingAirdropRecords) {
230+
List<PendingAirdropRecord> pendingAirdropRecords,
231+
long highVolumePricingMultiplier) {
220232
this.receipt = transactionReceipt;
221233
this.transactionHash = transactionHash;
222234
this.consensusTimestamp = consensusTimestamp;
@@ -244,6 +256,7 @@ public final class TransactionRecord {
244256
this.prngBytes = prngBytes;
245257
this.prngNumber = prngNumber;
246258
this.evmAddress = evmAddress;
259+
this.highVolumePricingMultiplier = highVolumePricingMultiplier;
247260
}
248261

249262
/**
@@ -345,7 +358,8 @@ static TransactionRecord fromProtobuf(
345358
transactionRecord.hasPrngBytes() ? transactionRecord.getPrngBytes() : null,
346359
transactionRecord.hasPrngNumber() ? transactionRecord.getPrngNumber() : null,
347360
transactionRecord.getEvmAddress(),
348-
pendingAirdropRecords);
361+
pendingAirdropRecords,
362+
transactionRecord.getHighVolumePricingMultiplier());
349363
}
350364

351365
/**
@@ -475,6 +489,8 @@ com.hedera.hashgraph.sdk.proto.TransactionRecord toProtobuf() {
475489
}
476490
}
477491

492+
transactionRecord.setHighVolumePricingMultiplier(highVolumePricingMultiplier);
493+
478494
return transactionRecord.build();
479495
}
480496

@@ -504,6 +520,7 @@ public String toString() {
504520
.add("prngNumber", prngNumber)
505521
.add("evmAddress", Hex.toHexString(evmAddress.toByteArray()))
506522
.add("pendingAirdropRecords", pendingAirdropRecords.toString())
523+
.add("highVolumePricingMultiplier", highVolumePricingMultiplier)
507524
.toString();
508525
}
509526

sdk/src/main/proto/hints_key_publication.proto

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ syntax = "proto3";
1313
package com.hedera.hapi.services.auxiliary.hints;
1414

1515
// SPDX-License-Identifier: Apache-2.0
16-
import "hints_types.proto";
17-
1816
option java_package = "com.hedera.hapi.services.auxiliary.hints.legacy";
1917
// <<<pbj.java_package = "com.hedera.hapi.services.auxiliary.hints">>> This comment is special code for setting PBJ Compiler java package
2018

sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionRecordTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ private static TransactionRecord spawnRecordExample(@Nullable ByteString prngByt
8888
AccountId.fromString("0.0.123"),
8989
AccountId.fromString("0.0.124"),
9090
TokenId.fromString("0.0.12345")),
91-
123)));
91+
123)),
92+
1000L);
9293
}
9394

9495
@Test

0 commit comments

Comments
 (0)