Skip to content

Commit

Permalink
Merge branch 'release/1.2.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ashalaginov committed Jan 8, 2024
2 parents 19f7ba6 + 4a16530 commit c15b976
Show file tree
Hide file tree
Showing 59 changed files with 1,267 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AtomicBroadcaster(
) {
private val txService: TxService = atomicAwareNodeBlockingServiceFactory.txService()

fun <T> doInAtomic(block: () -> T): T? {
fun <T> doInAtomic(block: () -> T): T {
atomicAwareContextManager.beginAtomic()
try {
val blockResult = block()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ package com.wavesenterprise.sdk.node.client.blocking.address

import com.wavesenterprise.sdk.node.domain.Address
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 java.util.Optional

interface AddressService {
fun getAddresses(): List<Address>
fun getAddressByPublicKey(publicKey: String): Address
fun getAddressValue(address: String, key: String): DataEntry?
fun getAddressValues(address: String): List<DataEntry>
fun getAddressByPublicKey(publicKey: PublicKey): Address
fun getAddressValue(address: Address, key: DataKey): Optional<DataEntry>
fun getAddressValues(address: Address): List<DataEntry>
fun signMessage(address: Address, request: SignMessageRequest): SignMessageResponse
fun verifyMessageSignature(address: Address, request: VerifyMessageSignatureRequest): VerifyMessageSignatureResponse
}
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 @@ -16,6 +16,7 @@ import com.wavesenterprise.sdk.node.exception.NodeInternalServerErrorException
import com.wavesenterprise.sdk.node.exception.NodeServiceUnavailableException
import com.wavesenterprise.sdk.node.exception.specific.ContractNotFoundException
import com.wavesenterprise.sdk.node.exception.specific.PolicyItemDataIsMissingException
import com.wavesenterprise.sdk.node.test.data.TestDataFactory.Companion.address
import io.mockk.Called
import io.mockk.every
import io.mockk.verify
Expand Down Expand Up @@ -355,7 +356,7 @@ class LoadBalancingServiceFactoryTest {
mockkAddressService2.getAddressValues(any())
} throws NodeServiceUnavailableException(cause = Exception())

val address = "address"
val address = address()
repeat(TESTS) { lb.addressService().getAddressValues(address) }
verify(atLeast = 50) { mockkAddressService1.getAddressValues(address) }
verify(atLeast = 1) { mockkAddressService2.getAddressValues(address) }
Expand Down
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
@@ -0,0 +1,11 @@
package com.wavesenterprise.sdk.node.domain.address

data class Message(val value: String) {
companion object {
@JvmStatic
fun fromString(value: String): Message =
Message(value)

inline val String.message: Message get() = Message(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wavesenterprise.sdk.node.domain.address

import com.wavesenterprise.sdk.node.domain.Password

data class SignMessageRequest(
val message: Message,
val password: Password,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wavesenterprise.sdk.node.domain.address

import com.wavesenterprise.sdk.node.domain.PublicKey
import com.wavesenterprise.sdk.node.domain.Signature

data class SignMessageResponse(
val message: Message,
val publicKey: PublicKey,
val signature: Signature,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wavesenterprise.sdk.node.domain.address

import com.wavesenterprise.sdk.node.domain.PublicKey
import com.wavesenterprise.sdk.node.domain.Signature

data class VerifyMessageSignatureRequest(
val message: Message,
val publicKey: PublicKey,
val signature: Signature,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wavesenterprise.sdk.node.domain.address

data class VerifyMessageSignatureResponse(
val valid: Boolean,
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.wavesenterprise.sdk.node.exception

@Suppress("MagicNumber")
enum class NodeErrorCode(val code: Int) {
INVALID_SIGNATURE(101),
INVALID_ADDRESS(102),
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
@@ -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 InvalidPasswordException(
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 InvalidPublicKeyException(
override val nodeError: NodeError,
override val cause: Exception,
) : NodeException(cause), NodeErrorInfoHolder
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ 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
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.INVALID_SIGNATURE
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.POLICY_DOES_NOT_EXIST
import com.wavesenterprise.sdk.node.exception.NodeErrorCode.POLICY_ITEM_DATA_IS_MISSING
Expand All @@ -21,8 +24,11 @@ object SpecificExceptionMapper {
when (code) {
INVALID_SIGNATURE -> InvalidSignatureException(nodeError, cause = exception)
INVALID_ADDRESS -> InvalidAddressException(nodeError, cause = exception)
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
@@ -0,0 +1,44 @@
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
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 java.util.Optional

class AddressGrpcBlockingService : AddressService {
override fun getAddresses(): List<Address> {
TODO("Not yet implemented")
}

override fun getAddressByPublicKey(publicKey: PublicKey): Address {
TODO("Not yet implemented")
}

override fun getAddressValue(address: Address, key: DataKey): Optional<DataEntry> {
TODO("Not yet implemented")
}

override fun getAddressValues(address: Address): List<DataEntry> {
TODO("Not yet implemented")
}

override fun signMessage(
address: Address,
request: SignMessageRequest
): SignMessageResponse {
TODO("Not yet implemented")
}

override fun verifyMessageSignature(
address: Address,
request: VerifyMessageSignatureRequest
): VerifyMessageSignatureResponse {
TODO("Not yet implemented")
}
}
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")
}
}
Loading

0 comments on commit c15b976

Please sign in to comment.