Skip to content

Commit

Permalink
Merge branch 'feature/WTCH-191' into 'dev'
Browse files Browse the repository at this point in the history
[WTCH-191] Add AliasService

Closes WTCH-191

See merge request development/we/java-sdk/we-node-client!83
  • Loading branch information
ashalaginov committed Dec 8, 2023
2 parents 641fdd5 + 6e9d1a4 commit 4a16530
Show file tree
Hide file tree
Showing 32 changed files with 419 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wavesenterprise.sdk.node.client.blocking.alias

import com.wavesenterprise.sdk.node.domain.Address
import com.wavesenterprise.sdk.node.domain.Alias
import java.util.Optional

interface AliasService {
fun getAliasesByAddress(address: Address): List<Alias>
fun getAddressByAlias(alias: Alias): Optional<Address>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wavesenterprise.sdk.node.client.blocking.lb

import com.wavesenterprise.sdk.node.client.blocking.address.AddressService
import com.wavesenterprise.sdk.node.client.blocking.alias.AliasService
import com.wavesenterprise.sdk.node.client.blocking.blocks.BlocksService
import com.wavesenterprise.sdk.node.client.blocking.contract.ContractService
import com.wavesenterprise.sdk.node.client.blocking.event.BlockchainEventsService
Expand All @@ -20,39 +21,34 @@ class LoadBalancingServiceFactory(
private val privacyDataNodesCacheLoadBalancerPostInvokeHandler: PrivacyDataNodesCacheLoadBalancerPostInvokeHandler,
) : NodeBlockingServiceFactory {

override fun txService() =
createService(TxService::class.java) {
it.txService()
}

override fun contractService(): ContractService =
createService(ContractService::class.java) {
it.contractService()
}

override fun addressService(): AddressService =
createService(AddressService::class.java) {
it.addressService()
}

override fun nodeInfoService(): NodeInfoService =
createService(NodeInfoService::class.java) {
it.nodeInfoService()
override fun aliasService(): AliasService =
createService(AliasService::class.java) {
it.aliasService()
}

override fun privacyService(): PrivacyService =
createService(PrivacyService::class.java) {
it.privacyService()
override fun blockchainEventsService(): BlockchainEventsService =
createService(BlockchainEventsService::class.java) {
it.blockchainEventsService()
}

override fun blocksService(): BlocksService =
createService(BlocksService::class.java) {
it.blocksService()
}

override fun blockchainEventsService(): BlockchainEventsService =
createService(BlockchainEventsService::class.java) {
it.blockchainEventsService()
override fun contractService(): ContractService =
createService(ContractService::class.java) {
it.contractService()
}

override fun nodeInfoService(): NodeInfoService =
createService(NodeInfoService::class.java) {
it.nodeInfoService()
}

override fun nodeUtilsService(): NodeUtilsService =
Expand All @@ -65,6 +61,16 @@ class LoadBalancingServiceFactory(
it.pkiService()
}

override fun privacyService(): PrivacyService =
createService(PrivacyService::class.java) {
it.privacyService()
}

override fun txService() =
createService(TxService::class.java) {
it.txService()
}

@Suppress("UNCHECKED_CAST")
private fun <T> createService(
clazz: Class<T>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wavesenterprise.sdk.node.client.blocking.node

import com.wavesenterprise.sdk.node.client.blocking.address.AddressService
import com.wavesenterprise.sdk.node.client.blocking.alias.AliasService
import com.wavesenterprise.sdk.node.client.blocking.blocks.BlocksService
import com.wavesenterprise.sdk.node.client.blocking.contract.ContractService
import com.wavesenterprise.sdk.node.client.blocking.event.BlockchainEventsService
Expand All @@ -10,13 +11,14 @@ import com.wavesenterprise.sdk.node.client.blocking.tx.TxService
import com.wavesenterprise.sdk.node.client.blocking.util.NodeUtilsService

interface NodeBlockingServiceFactory {
fun txService(): TxService
fun contractService(): ContractService
fun addressService(): AddressService
fun nodeInfoService(): NodeInfoService
fun privacyService(): PrivacyService
fun blocksService(): BlocksService
fun aliasService(): AliasService
fun blockchainEventsService(): BlockchainEventsService
fun blocksService(): BlocksService
fun contractService(): ContractService
fun nodeInfoService(): NodeInfoService
fun nodeUtilsService(): NodeUtilsService
fun pkiService(): PkiService
fun privacyService(): PrivacyService
fun txService(): TxService
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ data class Address(val bytes: ByteArray) {
WeBase58.decode(string)
)

@JvmStatic
fun String.toDomain(): Address = Address.fromBase58(this)

inline val ByteArray.address: Address get() = Address(this)

inline val String.base58Address: Address get() = fromBase58(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ data class Alias(val value: String) {
fun fromString(str: String): Alias =
Alias(str)

@JvmStatic
fun String.toDomain(): Alias = fromString(this.substring(ALIAS_START_INDEX))

private const val ALIAS_START_INDEX = 8

inline val String.alias: Alias get() = Alias(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ enum class NodeErrorCode(val code: Int) {
INVALID_PUBLIC_KEY(108),
INVALID_PASSWORD(115),
CUSTOM_VALIDATION_ERROR(199),
DATA_KEY_NOT_EXISTS(304),
ALIAS_NOT_EXIST(302),
DATA_KEY_NOT_EXIST(304),
CONTRACT_NOT_FOUND(600),
POLICY_DOES_NOT_EXIST(612),
PRIVACY_API_KEY_NOT_VALID(614),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.wavesenterprise.sdk.node.exception.NodeError
import com.wavesenterprise.sdk.node.exception.NodeErrorInfoHolder
import com.wavesenterprise.sdk.node.exception.NodeException

class DataKeyNotExistsException(
class AliasNotExistException(
override val nodeError: NodeError,
override val cause: Exception,
) : NodeException(cause), NodeErrorInfoHolder
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wavesenterprise.sdk.node.exception.specific

import com.wavesenterprise.sdk.node.exception.NodeError
import com.wavesenterprise.sdk.node.exception.NodeErrorInfoHolder
import com.wavesenterprise.sdk.node.exception.NodeException

class DataKeyNotExistException(
override val nodeError: NodeError,
override val cause: Exception,
) : NodeException(cause), NodeErrorInfoHolder
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.wavesenterprise.sdk.node.exception.specific

import com.wavesenterprise.sdk.node.exception.NodeError
import com.wavesenterprise.sdk.node.exception.NodeErrorCode
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.ALIAS_NOT_EXIST
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.CONTRACT_NOT_FOUND
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.CUSTOM_VALIDATION_ERROR
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.DATA_KEY_NOT_EXISTS
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.DATA_KEY_NOT_EXIST
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.INVALID_ADDRESS
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.INVALID_PASSWORD
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.INVALID_PUBLIC_KEY
Expand All @@ -26,7 +27,8 @@ object SpecificExceptionMapper {
INVALID_PUBLIC_KEY -> InvalidPublicKeyException(nodeError, cause = exception)
INVALID_PASSWORD -> InvalidPasswordException(nodeError, cause = exception)
CUSTOM_VALIDATION_ERROR -> CustomValidationErrorException(nodeError, cause = exception)
DATA_KEY_NOT_EXISTS -> DataKeyNotExistsException(nodeError, cause = exception)
ALIAS_NOT_EXIST -> AliasNotExistException(nodeError, exception)
DATA_KEY_NOT_EXIST -> DataKeyNotExistException(nodeError, cause = exception)
CONTRACT_NOT_FOUND -> ContractNotFoundException(nodeError, cause = exception)
POLICY_DOES_NOT_EXIST -> PolicyDoesNotExistException(nodeError, cause = exception)
PRIVACY_API_KEY_NOT_VALID -> PrivacyApiKeyNotValidException(nodeError, cause = exception)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wavesenterprise.sdk.node.client.grpc.blocking.node
package com.wavesenterprise.sdk.node.client.grpc.blocking.address

import com.wavesenterprise.sdk.node.client.blocking.address.AddressService
import com.wavesenterprise.sdk.node.domain.Address
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.wavesenterprise.sdk.node.client.grpc.blocking.alias

import com.wavesenterprise.sdk.node.client.blocking.alias.AliasService
import com.wavesenterprise.sdk.node.domain.Address
import com.wavesenterprise.sdk.node.domain.Alias
import java.util.Optional

class AliasGrpcBlockingService : AliasService {
override fun getAliasesByAddress(address: Address): List<Alias> {
TODO("Not yet implemented")
}

override fun getAddressByAlias(alias: Alias): Optional<Address> {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.wavesenterprise.sdk.node.domain.contract.ExecutionErrorRequest
import com.wavesenterprise.sdk.node.domain.contract.ExecutionSuccessRequest
import com.wavesenterprise.sdk.node.domain.contract.keys.ContractKeyRequest
import com.wavesenterprise.sdk.node.domain.contract.keys.ContractKeysRequest
import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistsException
import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException
import io.grpc.Channel
import io.grpc.ClientInterceptor
import io.grpc.Status
Expand Down Expand Up @@ -68,7 +68,7 @@ class ContractGrpcBlockingService(
null
else {
when (val mappedException = GrpcNodeErrorMapper.mapToGeneralException(ex)) {
is DataKeyNotExistsException -> null
is DataKeyNotExistException -> null
else -> throw mappedException
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.wavesenterprise.sdk.node.client.grpc.blocking.factory
import com.wavesenterprise.protobuf.service.contract.ContractServiceGrpc
import com.wavesenterprise.protobuf.service.messagebroker.BlockchainEventsServiceGrpc
import com.wavesenterprise.sdk.node.client.blocking.address.AddressService
import com.wavesenterprise.sdk.node.client.blocking.alias.AliasService
import com.wavesenterprise.sdk.node.client.blocking.blocks.BlocksService
import com.wavesenterprise.sdk.node.client.blocking.contract.ContractService
import com.wavesenterprise.sdk.node.client.blocking.event.BlockchainEventsService
Expand All @@ -23,10 +24,22 @@ class GrpcNodeServiceFactory(
private val channel: Channel,
) : NodeBlockingServiceFactory {

override fun txService(): TxService {
return TxGrpcBlockingService(
override fun addressService(): AddressService {
TODO("Not yet implemented")
}

override fun aliasService(): AliasService {
TODO("Not yet implemented")
}

override fun blockchainEventsService(): BlockchainEventsService =
BlockchainEventsGrpcBlockingService(
channel = channel,
grpc = BlockchainEventsServiceGrpc.newBlockingStub(channel),
)

override fun blocksService(): BlocksService {
TODO("Not yet implemented")
}

override fun contractService(): ContractService {
Expand All @@ -38,33 +51,25 @@ class GrpcNodeServiceFactory(
)
}

override fun addressService(): AddressService {
override fun nodeInfoService(): NodeInfoService {
TODO("Not yet implemented")
}

override fun nodeInfoService(): NodeInfoService {
override fun nodeUtilsService(): NodeUtilsService {
TODO("Not yet implemented")
}

override fun privacyService(): PrivacyService {
override fun pkiService(): PkiService {
TODO("Not yet implemented")
}

override fun blocksService(): BlocksService {
override fun privacyService(): PrivacyService {
TODO("Not yet implemented")
}

override fun blockchainEventsService(): BlockchainEventsService =
BlockchainEventsGrpcBlockingService(
override fun txService(): TxService {
return TxGrpcBlockingService(
channel = channel,
grpc = BlockchainEventsServiceGrpc.newBlockingStub(channel),
)

override fun nodeUtilsService(): NodeUtilsService {
TODO("Not yet implemented")
}

override fun pkiService(): PkiService {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.wavesenterprise.sdk.node.exception.NodeError
import com.wavesenterprise.sdk.node.exception.NodeException
import com.wavesenterprise.sdk.node.exception.specific.ContractNotFoundException
import com.wavesenterprise.sdk.node.exception.specific.CustomValidationErrorException
import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistsException
import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException
import com.wavesenterprise.sdk.node.exception.specific.InvalidAddressException
import com.wavesenterprise.sdk.node.exception.specific.InvalidSignatureException
import com.wavesenterprise.sdk.node.exception.specific.PolicyDoesNotExistException
Expand Down Expand Up @@ -106,8 +106,8 @@ internal class GrpcNodeErrorMapperTest {
} returns expectedNodeError.message
val ex = GrpcNodeErrorMapper.mapToGeneralException(statusRuntimeException)
ex.apply {
assertTrue(this is DataKeyNotExistsException).let {
(this as DataKeyNotExistsException).apply {
assertTrue(this is DataKeyNotExistException).let {
(this as DataKeyNotExistException).apply {
assertEquals(expectedNodeError.error, nodeError.error)
assertEquals(expectedNodeError.message, nodeError.message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class ContractGrpcBlockingServiceTest {
StatusRuntimeException(status, metadata)
every {
metadata.get(Metadata.Key.of("error-code", Metadata.ASCII_STRING_MARSHALLER))
} returns NodeErrorCode.DATA_KEY_NOT_EXISTS.code.toString()
} returns NodeErrorCode.DATA_KEY_NOT_EXIST.code.toString()
every {
metadata.get(
Metadata.Key.of("error-message", Metadata.ASCII_STRING_MARSHALLER)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.wavesenterprise.sdk.node.client.feign.address

import com.wavesenterprise.sdk.node.client.blocking.address.AddressService
import com.wavesenterprise.sdk.node.client.http.AddressDto.Companion.toDomain
import com.wavesenterprise.sdk.node.client.http.DataEntryDto.Companion.toDomain
import com.wavesenterprise.sdk.node.client.http.address.AddressDto.Companion.toDomain
import com.wavesenterprise.sdk.node.client.http.address.SignMessageRequestDto.Companion.toDto
import com.wavesenterprise.sdk.node.client.http.address.SignMessageResponseDto.Companion.toDomain
import com.wavesenterprise.sdk.node.client.http.address.VerifyMessageSignatureRequestDto.Companion.toDto
import com.wavesenterprise.sdk.node.client.http.address.VerifyMessageSignatureResponseDto.Companion.toDomain
import com.wavesenterprise.sdk.node.domain.Address
import com.wavesenterprise.sdk.node.domain.Address.Companion.toDomain
import com.wavesenterprise.sdk.node.domain.DataEntry
import com.wavesenterprise.sdk.node.domain.DataKey
import com.wavesenterprise.sdk.node.domain.PublicKey
import com.wavesenterprise.sdk.node.domain.address.SignMessageRequest
import com.wavesenterprise.sdk.node.domain.address.SignMessageResponse
import com.wavesenterprise.sdk.node.domain.address.VerifyMessageSignatureRequest
import com.wavesenterprise.sdk.node.domain.address.VerifyMessageSignatureResponse
import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistsException
import com.wavesenterprise.sdk.node.exception.specific.DataKeyNotExistException
import java.util.Optional

class FeignAddressService(
Expand All @@ -33,7 +34,7 @@ class FeignAddressService(
address = address.asBase58String(),
key = key.value,
).map { it.toDomain() }
} catch (ex: DataKeyNotExistsException) {
} catch (ex: DataKeyNotExistException) {
Optional.empty()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wavesenterprise.sdk.node.client.feign.address

import com.wavesenterprise.sdk.node.client.http.AddressDto
import com.wavesenterprise.sdk.node.client.http.DataEntryDto
import com.wavesenterprise.sdk.node.client.http.address.AddressDto
import com.wavesenterprise.sdk.node.client.http.address.SignMessageRequestDto
import com.wavesenterprise.sdk.node.client.http.address.SignMessageResponseDto
import com.wavesenterprise.sdk.node.client.http.address.VerifyMessageSignatureRequestDto
Expand Down
Loading

0 comments on commit 4a16530

Please sign in to comment.