Skip to content

Commit

Permalink
[WTCH-328] Add default bean of SenderAddressProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
dgeorgiev committed Jun 14, 2024
1 parent 180a46a commit 8460a46
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.wavesenterprise.sdk.spring.autoconfigure.contract.properties.Contract
import com.wavesenterprise.sdk.spring.autoconfigure.contract.properties.LegacyContractsPropertiesConfiguration
import com.wavesenterprise.sdk.spring.autoconfigure.contract.update.ContractsUpdateConfig
import com.wavesenterprise.sdk.spring.autoconfigure.node.service.NodeServicesAutoConfiguration
import com.wavesenterprise.sdk.spring.autoconfigure.signer.WeTxServiceTxSignerAutoConfiguration
import org.springframework.boot.autoconfigure.AutoConfigureAfter
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.context.annotation.Configuration
Expand All @@ -22,6 +23,7 @@ import org.springframework.context.annotation.Import
)
@AutoConfigureAfter(
NodeServicesAutoConfiguration::class,
WeTxServiceTxSignerAutoConfiguration::class,
)
@ConditionalOnClass(
ContractBlockingClientFactory::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import com.wavesenterprise.sdk.spring.autoconfigure.node.holder.NodeBlockingServ
import com.wavesenterprise.sdk.spring.autoconfigure.node.holder.NodeClient
import com.wavesenterprise.sdk.spring.autoconfigure.node.legacy.LegacyNodeConfiguration
import com.wavesenterprise.sdk.spring.autoconfigure.node.properties.CacheProperties
import com.wavesenterprise.sdk.spring.autoconfigure.node.properties.NodeConfiguration
import com.wavesenterprise.sdk.spring.autoconfigure.node.properties.NodeProperties
import com.wavesenterprise.sdk.spring.autoconfigure.node.properties.NodePropertiesConfiguration
import com.wavesenterprise.sdk.spring.autoconfigure.node.properties.RateLimiterProperties
import com.wavesenterprise.sdk.spring.autoconfigure.node.service.NodeServicesAutoConfiguration
import org.springframework.boot.autoconfigure.AutoConfigureBefore
Expand All @@ -40,8 +40,7 @@ import org.springframework.context.annotation.Import
)
@Import(
LegacyNodeConfiguration::class,
NodePropertiesConfiguration::class,
NodeCredentialsProviderConfiguration::class,
NodeConfiguration::class,
)
@ConditionalOnClass(
NodeBlockingServiceFactory::class,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
package com.wavesenterprise.sdk.spring.autoconfigure.node.properties

import com.wavesenterprise.sdk.node.client.blocking.credentials.DefaultNodeCredentialsProvider
import com.wavesenterprise.sdk.node.client.blocking.credentials.NodeCredentialsProvider
import com.wavesenterprise.sdk.node.domain.Address
import com.wavesenterprise.sdk.node.domain.Password
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
@EnableConfigurationProperties(
NodeCredentialsProperties::class,
)
@ConditionalOnProperty(value = ["node.legacy-mode"], havingValue = "false", matchIfMissing = true)
class NodePropertiesConfiguration {
class NodeConfiguration {

@Bean
@ConfigurationProperties(prefix = "node")
fun nodeConfigurationProperties() = NodeConfigurationProperties()

@Bean
@ConditionalOnMissingBean
fun nodeCredentialsProvider(
nodeCredentialsProperties: NodeCredentialsProperties,
): NodeCredentialsProvider =
DefaultNodeCredentialsProvider(
credentialsMap = nodeCredentialsProperties.addresses.map { (address, password) ->
Address.fromBase58(address) to password?.let { Password(password) }
}.toMap()
)

@Bean
@ConditionalOnMissingBean
fun nodeProperties(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package com.wavesenterprise.sdk.spring.autoconfigure.signer

import com.wavesenterprise.sdk.node.client.blocking.credentials.DefaultSenderAddressProvider
import com.wavesenterprise.sdk.node.client.blocking.credentials.NodeCredentialsProvider
import com.wavesenterprise.sdk.node.client.blocking.credentials.SenderAddressProvider
import com.wavesenterprise.sdk.node.client.blocking.node.NodeBlockingServiceFactory
import com.wavesenterprise.sdk.node.client.blocking.tx.TxService
import com.wavesenterprise.sdk.node.domain.Address
import com.wavesenterprise.sdk.node.domain.Password
import com.wavesenterprise.sdk.spring.autoconfigure.contract.ContractAutoConfiguration
import com.wavesenterprise.sdk.spring.autoconfigure.node.legacy.LegacyNodeConfigurationProperties
import com.wavesenterprise.sdk.spring.autoconfigure.node.properties.NodeConfigurationProperties
import com.wavesenterprise.sdk.spring.autoconfigure.node.properties.NodeCredentialsProperties
import com.wavesenterprise.sdk.spring.autoconfigure.node.service.NodeServicesAutoConfiguration
import com.wavesenterprise.sdk.tx.signer.TxSigner
import com.wavesenterprise.sdk.tx.signer.node.TxServiceTxSigner
import com.wavesenterprise.sdk.tx.signer.node.credentials.Credentials
import com.wavesenterprise.sdk.tx.signer.node.credentials.SignCredentialsProvider
import com.wavesenterprise.sdk.tx.signer.node.factory.TxServiceTxSignerFactory
import org.springframework.boot.autoconfigure.AutoConfigureAfter
import org.springframework.boot.autoconfigure.AutoConfigureBefore
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.annotation.Bean
Expand All @@ -21,8 +31,40 @@ import org.springframework.context.annotation.Configuration
TxSigner::class,
)
@AutoConfigureAfter(NodeServicesAutoConfiguration::class)
@AutoConfigureBefore(ContractAutoConfiguration::class)
class WeTxServiceTxSignerAutoConfiguration {

@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(LegacyNodeConfigurationProperties::class)
fun defaultLegacySenderAddressProvider(
txServiceTxSignerFactory: TxServiceTxSignerFactory,
legacyNodeConfigurationProperties: LegacyNodeConfigurationProperties,
): SenderAddressProvider {
val firstNodeCredentials = legacyNodeConfigurationProperties.getConfigForUsage()
.filter { it.value.nodeOwnerAddress != null }
.map { entry ->
Address.fromBase58(entry.value.nodeOwnerAddress!!) to
entry.value.keyStorePassword?.let { Password(it) }
}.toMap().entries.firstOrNull()
?: throw IllegalStateException("No credentials found in 'node' properties in legacy mode")
val senderAddress = firstNodeCredentials.key
return DefaultSenderAddressProvider(senderAddress)
}

@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(NodeConfigurationProperties::class)
fun defaultSenderAddressProvider(
txServiceTxSignerFactory: TxServiceTxSignerFactory,
nodeCredentialsProperties: NodeCredentialsProperties,
): SenderAddressProvider {
val firstNodeCredentials = nodeCredentialsProperties.addresses.entries.firstOrNull()
?: throw IllegalStateException("No credentials found in 'node' properties")
val senderAddress = firstNodeCredentials.key
return DefaultSenderAddressProvider(Address.fromBase58(senderAddress))
}

@Bean
@ConditionalOnMissingBean
fun txSigner(
Expand Down
16 changes: 15 additions & 1 deletion we-autoconfigure/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
contracts:
is-enabled: false
config:
test-one:
validation-enabled: false
Expand All @@ -22,4 +21,19 @@ contracts:
enabled: false
contractCreatorAddress: 4L4XEpNpesX9r6rVJ8hW1TrMiNCZ6SMvRuWPKB7T47wKfnp4D84XBUv7xsa36CGwoyK3fzfojivwonHNrsX2fLBL

node:
credentials-provider:
addresses:
3NqmRauaV87hhJPz1wzS6wx8kqWD5i7coCM: password
3NqNVU8XpEWLR86zvGAyZ6QL4xSse1EDb7K: password
3NoqQ88SuVBYuUimRWp3zeKLAYT66xLn5s3: password
config:
node-0:
http:
xApiKey: xApiKey
xPrivacyApiKey: xPrivacyApiKey
url: https://localhost.com
loggerLevel: FULL
read-timeout: 30000

debug: true
1 change: 0 additions & 1 deletion we-starters/we-starter-contract-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dependencies {
api(project(":we-autoconfigure"))
api("com.wavesenterprise:we-node-client-grpc-blocking-client")
api("com.wavesenterprise:we-contract-sdk-blocking-client")
api("com.wavesenterprise:we-tx-signer-node")
api("io.github.openfeign:feign-core")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm")
}

0 comments on commit 8460a46

Please sign in to comment.