Skip to content

Commit

Permalink
build: use the 'org.web3j.solidity' Gradle plugin to compile contracts
Browse files Browse the repository at this point in the history
Signed-off-by: Jendrik Johannes <[email protected]>
  • Loading branch information
jjohannes committed Jul 23, 2024
1 parent ebd210e commit fdaf59b
Show file tree
Hide file tree
Showing 645 changed files with 248 additions and 22,167 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ org.gradle.jvmargs=-Xmx6144m -Dfile.encoding=UTF-8

# Enable Gradle caching
org.gradle.configuration-cache=true
org.gradle.caching=true
# org.gradle.caching=true -- TODO disable until 'org.web3j.solidity' is compatible

# Enable parallel workers
org.gradle.parallel=true
Expand Down
1 change: 1 addition & 0 deletions gradle/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ dependencies {
implementation("org.gradlex:extra-java-module-info:1.8")
implementation("org.gradlex:jvm-dependency-conflict-resolution:2.0")
implementation("org.gradlex:java-module-dependencies:1.6.5")
implementation("org.web3j.solidity:solidity-gradle-plugin:0.5.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ abstract class GitClone : DefaultTask() {
exec.exec {
if (!localClone.dir(".git").asFile.exists()) {
workingDir = localClone.asFile.parentFile
commandLine(
"git",
"clone",
"https://github.com/hashgraph/hedera-protobufs.git",
"-q"
)
commandLine("git", "clone", url.get(), "-q")
} else {
workingDir = localClone.asFile
commandLine("git", "fetch", "-q")
Expand Down
62 changes: 62 additions & 0 deletions hedera-node/test-clients/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@
*/

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.hedera.gradle.tasks.GitClone
import org.web3j.solidity.gradle.plugin.EVMVersion
import org.web3j.solidity.gradle.plugin.OutputComponent
import org.web3j.solidity.gradle.plugin.SolidityCompile
import org.web3j.solidity.gradle.plugin.SolidityResolve
import org.web3j.solidity.gradle.plugin.SoliditySourceSet

plugins {
id("com.hedera.gradle.services")
id("com.hedera.gradle.shadow-jar")
id("org.web3j.solidity")
}

description = "Hedera Services Test Clients for End to End Tests (EET)"
Expand All @@ -34,6 +41,61 @@ mainModuleInfo {
runtimeOnly("org.junit.platform.launcher")
}

// Clone 'hedera-smart-contracts' to obtain system contracts
val cloneSmartContracts =
tasks.register<GitClone>("cloneSmartContracts") {
offline = gradle.startParameter.isOffline
url = "https://github.com/hashgraph/hedera-smart-contracts.git"
localCloneDirectory = layout.buildDirectory.dir("hedera-smart-contracts")
tag = "v0.9.0"
}

// General solidity configuration
solidity {
setCombinedOutputComponents()
setOutputComponents(OutputComponent.BIN, OutputComponent.ABI)
// evmVersion = EVMVersion.CANCUN
// prettyJson = true --- does not work due to bug in plugin
optimize = false
allowPaths.add(layout.projectDirectory.dir("src/main/solidity").asFile.absolutePath)
allowPaths.add(
layout.buildDirectory
.dir("hedera-smart-contracts/contracts/system-contracts")
.get()
.asFile
.absolutePath
)
}

sourceSets.main {
withConvention(SoliditySourceSet::class) {
solidity {
destinationDirectory = layout.buildDirectory.dir("generated/solidity")
// TODO remove this filtering and make all 'sol' files compile
include("AbandoningParent/*")
include("AddressValueRet/*")
include("AutoCreationModes/*")
include("Child/*")
include("Placeholder/*")
include("Returner/*")
include("AssociateTryCatch/*")
}
}
}

tasks.withType<SolidityResolve>().configureEach {
inputs.dir(cloneSmartContracts.flatMap { it.localCloneDirectory })
}

tasks.withType<SolidityCompile>().configureEach {
inputs.dir(cloneSmartContracts.flatMap { it.localCloneDirectory })
}

tasks.processResources { from(tasks.named("compileSolidity")) { into("contract/contracts") } }

// TODO register separate SolidityCompile - complete configuration of task
tasks.register<SolidityCompile>("compileSolidityParis") { evmVersion = EVMVersion.PARIS }

sourceSets {
// Needed because "resource" directory is misnamed. See
// https://github.com/hashgraph/hedera-services/issues/3361
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@
import org.json.JSONTokener;

public class Utils {
public static final String RESOURCE_PATH = "src/main/resource/contract/contracts/%1$s/%1$s%2$s";
public static final String RESOURCE_PATH = "src/main/resource/contract/contracts/%1$s%2$s";

public static final String UNIQUE_CLASSPATH_RESOURCE_TPL = "contract/contracts/%s/%s";
public static final String UNIQUE_CLASSPATH_RESOURCE_TPL = "contract/contracts/%s";
private static final Logger log = LogManager.getLogger(Utils.class);
private static final String JSON_EXTENSION = ".json";
private static final String JSON_EXTENSION = ".abi";

public static ByteString eventSignatureOf(String event) {
return ByteString.copyFrom(Hash.keccak256(Bytes.wrap(event.getBytes())).toArray());
Expand Down Expand Up @@ -192,8 +192,7 @@ public static String getABIFor(final FunctionType type, final String functionNam

public static String getResourceABIFor(
final FunctionType type, final String functionName, final String contractName) {
final var resourcePath =
String.format(UNIQUE_CLASSPATH_RESOURCE_TPL, contractName, contractName + JSON_EXTENSION);
final var resourcePath = String.format(UNIQUE_CLASSPATH_RESOURCE_TPL, contractName + JSON_EXTENSION);
try (final var input = Utils.class.getClassLoader().getResourceAsStream(resourcePath)) {
return getFunctionAbiFrom(input, functionName, type);
} catch (final IOException e) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit fdaf59b

Please sign in to comment.