Skip to content

Commit 4f7d099

Browse files
authored
Replace CredentialsService with SignerService (#264)
1 parent 71609b0 commit 4f7d099

File tree

5 files changed

+63
-14
lines changed

5 files changed

+63
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## [[NEXT]](https://github.com/iExecBlockchainComputing/iexec-sms/releases/tag/vNEXT) 2024
66

7+
### New Features
8+
9+
- Replace `CredentialsService` with `SignerService`. (#264)
10+
711
### Quality
812

913
- Configure Gradle JVM Test Suite Plugin. (#259)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version=8.5.1
22
iexecCommonVersion=8.4.0
3-
iexecCommonsPocoVersion=3.2.0
3+
iexecCommonsPocoVersion=4.0.0-NEXT-SNAPSHOT
44

55
nexusUser
66
nexusPassword

src/main/java/com/iexec/sms/blockchain/IexecHubService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,20 +16,19 @@
1616

1717
package com.iexec.sms.blockchain;
1818

19-
2019
import com.iexec.commons.poco.chain.IexecHubAbstractService;
20+
import com.iexec.commons.poco.chain.SignerService;
2121
import org.springframework.beans.factory.annotation.Autowired;
2222
import org.springframework.stereotype.Service;
2323

24-
2524
@Service
2625
public class IexecHubService extends IexecHubAbstractService {
2726

2827
@Autowired
29-
public IexecHubService(CredentialsService credentialsService,
28+
public IexecHubService(SignerService signerService,
3029
Web3jService web3jService,
3130
BlockchainConfig blockchainConfig) {
32-
super(credentialsService.getCredentials(), web3jService, blockchainConfig.getHubAddress());
31+
super(signerService.getCredentials(), web3jService, blockchainConfig.getHubAddress());
3332
}
3433

3534
}

src/main/java/com/iexec/sms/blockchain/CredentialsService.java renamed to src/main/java/com/iexec/sms/blockchain/WalletConfiguration.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2024 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,16 @@
1616

1717
package com.iexec.sms.blockchain;
1818

19-
import com.iexec.common.chain.CredentialsAbstractService;
19+
import com.iexec.commons.poco.chain.SignerService;
20+
import org.springframework.context.annotation.Bean;
21+
import org.springframework.context.annotation.Configuration;
2022

21-
import org.springframework.stereotype.Service;
23+
import java.security.GeneralSecurityException;
2224

23-
@Service
24-
public class CredentialsService extends CredentialsAbstractService {
25-
26-
public CredentialsService() throws Exception {
27-
super();
25+
@Configuration
26+
public class WalletConfiguration {
27+
@Bean
28+
SignerService signerService(Web3jService web3jService, BlockchainConfig chainConfig) throws GeneralSecurityException {
29+
return new SignerService(web3jService.getWeb3j(), chainConfig.getId());
2830
}
2931
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2024 IEXEC BLOCKCHAIN TECH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.iexec.sms.blockchain;
18+
19+
import com.iexec.commons.poco.chain.SignerService;
20+
import org.junit.jupiter.api.Test;
21+
import org.springframework.boot.context.annotation.UserConfigurations;
22+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
23+
24+
import java.time.Duration;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
class WalletConfigurationTest {
29+
private final ApplicationContextRunner runner = new ApplicationContextRunner();
30+
31+
@Test
32+
void shouldCreateBeans() {
33+
runner.withBean(BlockchainConfig.class, 65535, true, "http://localhost:8545", "0xC129e7917b7c7DeDfAa5Fff1FB18d5D7050fE8ca", Duration.ofSeconds(5L), 1.0f, 0L)
34+
.withBean(IexecHubService.class)
35+
.withBean(Web3jService.class)
36+
.withConfiguration(UserConfigurations.of(WalletConfiguration.class))
37+
.run(context -> assertThat(context)
38+
.hasSingleBean(BlockchainConfig.class)
39+
.hasSingleBean(IexecHubService.class)
40+
.hasSingleBean(SignerService.class)
41+
.hasSingleBean(WalletConfiguration.class)
42+
.hasSingleBean(Web3jService.class));
43+
}
44+
}

0 commit comments

Comments
 (0)