Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add domain extension to get escrow account address #121

Merged
1 commit merged into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features
* IBC denom API #97
* `/ibc/all`
* Add get escrow account address method for ibc #119

### Improvements
* Removed hash conversion #66
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package io.provenance.explorer.grpc.extensions

import com.google.common.io.BaseEncoding
import com.google.protobuf.Any
import com.google.protobuf.ByteString
import cosmos.auth.v1beta1.Auth
import cosmos.base.query.v1beta1.Pagination
import cosmos.crypto.multisig.Keys
import io.provenance.explorer.domain.core.logger
import io.provenance.explorer.domain.core.toBech32Data
import io.provenance.explorer.domain.extensions.edPubKeyToBech32
import io.provenance.explorer.domain.extensions.secpPubKeyToBech32
import io.provenance.explorer.domain.extensions.toBase64
import io.provenance.explorer.domain.extensions.toSha256
import io.provenance.explorer.service.prettyRole
import io.provenance.marker.v1.Access
import io.provenance.marker.v1.MarkerAccount
Expand Down Expand Up @@ -80,7 +83,13 @@ fun Any.toAddress(hrpPrefix: String) =
else -> null.also { logger().error("This typeUrl is not supported as a consensus address: $typeUrl") }
}


//TODO: Once cosmos-sdk implements a grpc endpoint for this we can replace this with grpc Issue: https://github.com/cosmos/cosmos-sdk/issues/9437
fun getEscrowAccountAddress(portId: String, channelId: String, hrpPrefix: String) : String {
val contents = "${portId}/${channelId}".toByteArray()
var preImage = "ics20-1".encodeToByteArray() + 0x0.toByte() + contents
val hash = preImage.toSha256().copyOfRange(0, 20)
return hash.toBech32Data(hrpPrefix).address
}


fun getPaginationBuilder(offset: Int, limit: Int) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
//package io.provenance.explorer.domain
//
//class ExtensionsTest {
//
//
//}
package io.provenance.explorer.domain

import io.provenance.explorer.grpc.extensions.getEscrowAccountAddress
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

class ExtensionsTest {

@Test
@Tag("junit-jupiter")
fun `should return escrow account address with given portId channelId and prefix`() {
val result = getEscrowAccountAddress("transfer", "channel", "cosmos")
assertEquals("cosmos1dm7fargcm8km25nxe6xldj0y0j2dawg8h5s03l", result)
}
}