From e2a8cef45b96b69cca5ccb4bf3923a48c579e084 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 14 May 2024 09:35:21 +0900 Subject: [PATCH 1/4] chore: bump finschia-proto:4.0.0-rc2 --- examples/multisig-example/build.gradle.kts | 2 +- examples/query-example/build.gradle.kts | 2 +- examples/with-tx-wrapper-example/build.gradle.kts | 2 +- examples/without-tx-wrapper-example/build.gradle.kts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/multisig-example/build.gradle.kts b/examples/multisig-example/build.gradle.kts index 18602dd..75b330e 100644 --- a/examples/multisig-example/build.gradle.kts +++ b/examples/multisig-example/build.gradle.kts @@ -14,7 +14,7 @@ dependencies { // Finschia sdk implementation("network.finschia:finschia-kt-crypto:0.2.2") - implementation("network.finschia:finschia-proto:2.0.0") + implementation("network.finschia:finschia-proto:4.0.0-rc2") implementation(project(":tx")) } diff --git a/examples/query-example/build.gradle.kts b/examples/query-example/build.gradle.kts index ca293c7..e16a3e1 100644 --- a/examples/query-example/build.gradle.kts +++ b/examples/query-example/build.gradle.kts @@ -7,7 +7,7 @@ dependencies { // Finschia sdk implementation("network.finschia:finschia-kt-crypto:0.2.2") - implementation("network.finschia:finschia-proto:2.0.0") + implementation("network.finschia:finschia-proto:4.0.0-rc2") implementation(project(":tx")) } diff --git a/examples/with-tx-wrapper-example/build.gradle.kts b/examples/with-tx-wrapper-example/build.gradle.kts index 1a7315f..f9a05ec 100644 --- a/examples/with-tx-wrapper-example/build.gradle.kts +++ b/examples/with-tx-wrapper-example/build.gradle.kts @@ -7,7 +7,7 @@ dependencies { // Finschia sdk implementation("network.finschia:finschia-kt-crypto:0.2.2") - implementation("network.finschia:finschia-proto:2.0.0") + implementation("network.finschia:finschia-proto:4.0.0-rc2") implementation(project(":tx")) } diff --git a/examples/without-tx-wrapper-example/build.gradle.kts b/examples/without-tx-wrapper-example/build.gradle.kts index 6164072..26672fb 100644 --- a/examples/without-tx-wrapper-example/build.gradle.kts +++ b/examples/without-tx-wrapper-example/build.gradle.kts @@ -11,7 +11,7 @@ dependencies { // Finschia sdk implementation("network.finschia:finschia-kt-crypto:0.2.2") - implementation("network.finschia:finschia-proto:2.0.0") + implementation("network.finschia:finschia-proto:4.0.0-rc2") } application { From 41a5f8118f225183f72514be4ab270ed2044a839 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 14 May 2024 09:35:52 +0900 Subject: [PATCH 2/4] chore: add new example for swap and transfer in single tx --- .../finschia/sdk/example/SwapAndTransfer.kt | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 examples/with-tx-wrapper-example/src/main/kotlin/network/finschia/sdk/example/SwapAndTransfer.kt diff --git a/examples/with-tx-wrapper-example/src/main/kotlin/network/finschia/sdk/example/SwapAndTransfer.kt b/examples/with-tx-wrapper-example/src/main/kotlin/network/finschia/sdk/example/SwapAndTransfer.kt new file mode 100644 index 0000000..34f3ac2 --- /dev/null +++ b/examples/with-tx-wrapper-example/src/main/kotlin/network/finschia/sdk/example/SwapAndTransfer.kt @@ -0,0 +1,74 @@ +package network.finschia.sdk.example + +import io.grpc.ManagedChannelBuilder +import network.finschia.sdk.account.HDWallet +import network.finschia.sdk.base.Tx + +suspend fun main() { + // Change me for your environment + val chainId = "sim" + val hrpPrefix = "link" + val host = "localhost" + val port = 9090 + val fromDenom = "cony" + val toDenom = "peb" + val conyAmount = "1" + val swapRateFromConyToPeb = "148079656000000" + val amountToTransfer = swapRateFromConyToPeb.toBigInteger().multiply(conyAmount.toBigInteger()) + val kaiaAddress = "0xf7bAc63fc7CEaCf0589F25454Ecf5C2ce904997c" + val gasLimit: Long = 150000 + val seqNum: Long = 14 + + // Initialize gRPC channel + val channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build() + + // Sender's info + val mnemonic = "mind flame tobacco sense move hammer drift crime ring globe art gaze cinnamon helmet cruise special produce notable negative wait path scrap recall have" + val hdWallet = HDWallet.loadFromMnemonic(mnemonic) + val aliceKey = hdWallet.getKeyWallet(0) + val aliceAddress = aliceKey.address.toBech32(hrpPrefix) + + // Build MsgSwap + val amountFromDenom = cosmos.base.v1beta1.coin { + amount = conyAmount + denom = fromDenom + } + val msgSwap = lbm.fswap.v1.msgSwap { + this.fromCoinAmount = amountFromDenom + this.toDenom = toDenom + this.fromAddress = aliceAddress + } + + // Build MsgTransfer + val msgTransfer = lbm.fbridge.v1.msgTransfer { + this.amount = amountToTransfer.toString() + this.sender = aliceAddress + this.receiver = kaiaAddress + } + + // Build Tx with two messages + val tx = Tx.newBuilder() + .setChainId(chainId) + .addMessage(com.google.protobuf.any { + typeUrl = "/lbm.fswap.v1.MsgSwap" + value = msgSwap.toByteString() + }) + .addMessage(com.google.protobuf.any { + typeUrl = "/lbm.fbridge.v1.MsgTransfer" + value = msgTransfer.toByteString() + }) + .addSigner(aliceKey, seqNum) + .setFee(cosmos.tx.v1beta1.fee { this.gasLimit = gasLimit }) + .setMemo("") + .build() + + // Sign Tx + tx.sign(aliceKey, 0) + + // Send Tx + val resultTxHash = TxClient(channel).use { + it.broadcastTx(tx) + } + + println(resultTxHash) +} From e8bb39eedb5ef5bac81a7a8e2ac19fead3483d2d Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 14 May 2024 16:23:01 +0900 Subject: [PATCH 3/4] chore: jdk 8(no longer available) -> 11 --- .github/workflows/build-test.yml | 2 +- .github/workflows/tag.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index b317a77..bde3b79 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: temurin - java-version: 8 + java-version: 11 - name: Gradle Cache uses: burrunan/gradle-cache-action@v1 diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 48ee151..0142bdc 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -13,8 +13,8 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - java-version: 8 distribution: temurin + java-version: 11 - name: Validate Gradle wrapper uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3 From b04a8308718f9557c69adab02c00be3e681706d8 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 14 May 2024 16:30:52 +0900 Subject: [PATCH 4/4] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 625a9ea..1a88210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Added * [\#21](https://github.com/Finschia/finschia-kt/pull/21) add MsgCreateValidator examples for single and multi-sig * [\#22](https://github.com/Finschia/finschia-kt/pull/22) bump up finschia-proto:2.0.0 +* [\#23](https://github.com/Finschia/finschia-kt/pull/23) add new example for MsgSwap&MsgTransfer Tx ### Changed * [\#19](https://github.com/Finschia/finschia-kt/pull/19) change the value of AminoMsg to the general type