Skip to content

Commit e104e5b

Browse files
committed
kotlin support
1 parent 712b051 commit e104e5b

File tree

14 files changed

+557
-114
lines changed

14 files changed

+557
-114
lines changed

docusaurus.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ const config = {
150150
darkTheme: darkCodeTheme,
151151
additionalLanguages: [
152152
"rust",
153-
"swift"
153+
"swift",
154+
"kotlin"
154155
]
155156
},
156157
}),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
},
7373
"doc-snippets": {
7474
"extract": {
75-
"include": "./**/*.{ts,tsx,js,json,yaml,txt,md,graphql,cue}",
75+
"include": "./**/*.{ts,tsx,js,json,yaml,txt,md,graphql,cue,kt,kts}",
7676
"ignore": [
7777
"./**/node_modules/**",
7878
"./**/.polywrap/**",

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const sidebars = {
2020
label: 'Quick Start',
2121
items: [
2222
'quick-start/javascript',
23+
'quick-start/kotlin',
2324
'quick-start/swift',
2425
]
2526
},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+

snippets/quick-start/kt/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*
4+
* This generated file contains a sample Kotlin application project to get you started.
5+
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.3/userguide/building_java_projects.html in the Gradle documentation.
6+
*/
7+
8+
// $start: quickstart-kt-gradle-plugins
9+
plugins {
10+
id("org.jetbrains.kotlin.jvm") version "1.9.0"
11+
12+
// The versions of the JVM and serialization plugins must be the same
13+
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.0"
14+
15+
application
16+
}
17+
// $end
18+
19+
repositories {
20+
// Use Maven Central for resolving dependencies.
21+
mavenCentral()
22+
}
23+
24+
dependencies {
25+
// Use the Kotlin JUnit 5 integration.
26+
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
27+
28+
// Use the JUnit 5 integration.
29+
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.3")
30+
31+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
32+
33+
// This dependency is used by the application.
34+
implementation("com.google.guava:guava:32.1.1-jre")
35+
36+
// $start: quickstart-kt-gradle-dependencies
37+
// Add the polywrap-client and serialization dependency required by the Polywrap Client
38+
implementation("io.polywrap:polywrap-client:0.10.4")
39+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.1")
40+
// $end
41+
}
42+
43+
// Apply a specific Java toolchain to ease working on different environments.
44+
java { toolchain { languageVersion.set(JavaLanguageVersion.of(17)) } }
45+
46+
application {
47+
// Define the main class for the application.
48+
mainClass.set("quickstartkt.AppKt")
49+
}
50+
51+
tasks.named<Test>("test") {
52+
// Use JUnit Platform for unit tests.
53+
useJUnitPlatform()
54+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* This Kotlin source file was generated by the Gradle 'init' task.
3+
*/
4+
package quickstartkt
5+
6+
// $start: quickstart-kt-import-client
7+
import io.polywrap.configBuilder.polywrapClient // Import of the Polywrap Client itself
8+
import io.polywrap.core.resolution.Uri // The Polywrap Client uses the Uri class for invocations
9+
10+
// $end
11+
12+
fun main() {
13+
// $start: quickstart-kt-init-client
14+
val client = polywrapClient { addDefaults() }
15+
// $end
16+
17+
// $start: quickstart-kt-invoke-client
18+
val result =
19+
client.invoke<String>(
20+
uri = Uri("wrapscan.io/polywrap/sha3@1.0"),
21+
method = "sha3_256",
22+
args = mapOf("message" to "Hello Polywrap!")
23+
)
24+
25+
if (result.isFailure) {
26+
throw result.exceptionOrNull()!!
27+
}
28+
29+
println(result)
30+
// $end
31+
32+
// $start: quickstart-kt-uniswap
33+
val wethResult =
34+
client.invoke<Map<String, Any>>(
35+
uri = Uri("wrapscan.io/polywrap/uniswap-v3@1.0"),
36+
method = "fetchToken",
37+
args =
38+
mapOf(
39+
"address" to "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
40+
"chainId" to "MAINNET"
41+
)
42+
)
43+
44+
// Log the invocation error and stop execution if the invocation fails
45+
println(wethResult.getOrThrow())
46+
47+
val usdcResult =
48+
client.invoke<Map<String, Any>>(
49+
uri = Uri("wrapscan.io/polywrap/uniswap-v3@1.0"),
50+
method = "fetchToken",
51+
args =
52+
mapOf(
53+
"address" to "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
54+
"chainId" to "MAINNET"
55+
)
56+
)
57+
58+
// Log the invocation error and stop execution if the invocation fails
59+
println(usdcResult.getOrThrow())
60+
61+
val poolAddressResult =
62+
client.invoke<String>(
63+
uri = Uri("wrapscan.io/polywrap/uniswap-v3@1.0"),
64+
method = "getPoolAddress",
65+
args =
66+
mapOf(
67+
"tokenA" to wethResult.getOrDefault(null),
68+
"tokenB" to usdcResult.getOrDefault(null),
69+
"fee" to "MEDIUM"
70+
)
71+
)
72+
73+
// Log the invocation error and stop execution if the invocation fails
74+
println(poolAddressResult.getOrThrow())
75+
// $end
76+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* This Kotlin source file was generated by the Gradle 'init' task.
3+
*/
4+
package quickstartkt
5+
6+
import kotlin.test.Test
7+
import kotlin.test.assertNotNull
8+
9+
class AppTest {
10+
@Test fun appHasAGreeting() {
11+
val classUnderTest = App()
12+
assertNotNull(classUnderTest.greeting, "app should have a greeting")
13+
}
14+
}
62.2 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)