Skip to content

Commit

Permalink
feat(kotlin): add kotlin example for comparison and add fluent interf…
Browse files Browse the repository at this point in the history
…ace back in
  • Loading branch information
mehcode committed Jun 9, 2022
1 parent ec79c78 commit 26b04cd
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
12 changes: 12 additions & 0 deletions sdk/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ repositories {
mavenCentral()
}

java {
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
}

dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
implementation("com.google.code.findbugs:jsr305:3.0.2")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.github.jnr:jnr-ffi:2.2.12")
implementation("com.fasterxml.jackson.core:jackson-core:2.13.3")
implementation("com.fasterxml.jackson.core:jackson-annotations:2.13.3")
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.3")
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).all {
kotlinOptions {
jvmTarget = "16"
}
}
14 changes: 11 additions & 3 deletions sdk/kotlin/examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id("org.jetbrains.kotlin.jvm") version "1.5.31"
`java-library`
}

Expand All @@ -7,13 +8,20 @@ repositories {
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
}

dependencies {
implementation(rootProject)
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.3")
implementation("com.google.code.findbugs:jsr305:3.0.2")
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).all {
kotlinOptions {
jvmTarget = "16"
}
}

tasks.addRule("Pattern: run<Example>: Runs an example.") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ class GetAccountBalanceExample {
public static void main(String[] args) {
var client = Client.forTestnet();

var query = new AccountBalanceQuery();
query.setAccountId(AccountId.parse("0.0.1001"));

var response = query.execute(client);
var response = new AccountBalanceQuery()
.setAccountId(AccountId.parse("0.0.1001"))
.execute(client);

System.out.printf("balance = %s\n", response.balance);
}
Expand Down
15 changes: 15 additions & 0 deletions sdk/kotlin/examples/src/main/kotlin/GetAccountBalanceExample.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@file:JvmName("GetAccountBalanceKtExample")

import com.hedera.hashgraph.sdk.AccountBalanceQuery
import com.hedera.hashgraph.sdk.AccountId
import com.hedera.hashgraph.sdk.Client

fun main() {
val client = Client.forTestnet()

val response = AccountBalanceQuery(
accountId = AccountId.parse("0.0.1001")
).execute(client)

println("balance = ${response.balance}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.hedera.hashgraph.sdk
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonTypeName

// TODO: use ContractAddress
/**
* Get the balance of a cryptocurrency account.
*
Expand All @@ -11,16 +12,36 @@ import com.fasterxml.jackson.annotation.JsonTypeName
* additional information.
*/
@JsonTypeName("accountBalance")
class AccountBalanceQuery : Query<AccountBalanceResponse>(AccountBalanceResponse::class.java) {
class AccountBalanceQuery(
/**
* The account ID for which information is requested.
*/
@set:JvmSynthetic
@JsonProperty
var accountId: AccountAddress? = null
var accountId: AccountAddress? = null,

/**
* The contract ID for which information is requested.
*/
@set:JvmSynthetic
@JsonProperty
var contractId: AccountAddress? = null
) : Query<AccountBalanceResponse>(AccountBalanceResponse::class.java) {
/**
* Sets the account ID for which information is requested.
*/
fun setAccountId(accountId: AccountAddress): AccountBalanceQuery {
this.accountId = accountId

return this
}

/**
* Sets the contract ID for which information is requested.
*/
fun setContractId(contractId: AccountAddress): AccountBalanceQuery {
this.contractId = contractId

return this
}
}

0 comments on commit 26b04cd

Please sign in to comment.