-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/WTCH-78' into 'dev'
[WTCH-78] Edit SignCredentialsProvider for use thread local Closes WTCH-78 See merge request waves-enterprise/java-sdk/we-node-client!12
- Loading branch information
Showing
8 changed files
with
55 additions
and
18 deletions.
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
...ner-node/src/main/kotlin/com/wavesenterprise/sdk/tx/signer/node/SignCredentialsService.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...er-node/src/main/kotlin/com/wavesenterprise/sdk/tx/signer/node/credentials/Credentials.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.wavesenterprise.sdk.tx.signer.node.credentials | ||
|
||
import com.wavesenterprise.sdk.node.domain.Address | ||
import com.wavesenterprise.sdk.node.domain.Password | ||
|
||
data class Credentials( | ||
val senderAddress: Address, | ||
val password: Password, | ||
) |
8 changes: 8 additions & 0 deletions
8
...tlin/com/wavesenterprise/sdk/tx/signer/node/credentials/DefaultSignCredentialsProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.wavesenterprise.sdk.tx.signer.node.credentials | ||
|
||
class DefaultSignCredentialsProvider( | ||
private val credentials: Credentials, | ||
) : SignCredentialsProvider { | ||
|
||
override fun credentials(): Credentials = credentials | ||
} |
5 changes: 5 additions & 0 deletions
5
...main/kotlin/com/wavesenterprise/sdk/tx/signer/node/credentials/SignCredentialsProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.wavesenterprise.sdk.tx.signer.node.credentials | ||
|
||
interface SignCredentialsProvider { | ||
fun credentials(): Credentials | ||
} |
5 changes: 5 additions & 0 deletions
5
...rc/main/kotlin/com/wavesenterprise/sdk/tx/signer/node/credentials/SpecifiedCredentials.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.wavesenterprise.sdk.tx.signer.node.credentials | ||
|
||
interface SpecifiedCredentials { | ||
fun <T> withCredentials(creds: Credentials, fn: () -> T): T | ||
} |
15 changes: 15 additions & 0 deletions
15
.../com/wavesenterprise/sdk/tx/signer/node/credentials/ThreadLocalSignCredentialsProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.wavesenterprise.sdk.tx.signer.node.credentials | ||
|
||
class ThreadLocalSignCredentialsProvider : SignCredentialsProvider, SpecifiedCredentials { | ||
private val threadLocal: ThreadLocal<Credentials> = ThreadLocal() | ||
|
||
override fun <T> withCredentials(creds: Credentials, fn: () -> T): T = | ||
try { | ||
threadLocal.set(creds) | ||
fn() | ||
} finally { | ||
threadLocal.remove() | ||
} | ||
|
||
override fun credentials(): Credentials = requireNotNull(threadLocal.get()) { "Credentials haven't been set" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters