Skip to content

Commit

Permalink
Add domain extension to get escrow account address (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
channa-figure authored and Carolyn Russell committed Jun 2, 2021
1 parent 0ffe566 commit b1ce8ab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
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)
}
}

0 comments on commit b1ce8ab

Please sign in to comment.