Skip to content

Commit 8c159af

Browse files
committed
Add BankETHAddress table and related entities
1 parent 85dac6d commit 8c159af

File tree

5 files changed

+63
-14
lines changed

5 files changed

+63
-14
lines changed

server/src/main/java/com/exactpro/blockchain/coincento/CoincentoWallet.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.exactpro.blockchain.coincento;
22

3+
import com.exactpro.blockchain.entity.BankETHAddress;
34
import com.exactpro.blockchain.entity.Currency;
5+
import com.exactpro.blockchain.repository.BankETHAddressRepository;
46
import org.apache.logging.log4j.LogManager;
57
import org.apache.logging.log4j.Logger;
68
import org.springframework.beans.factory.annotation.Value;
@@ -24,7 +26,6 @@
2426
import java.nio.charset.StandardCharsets;
2527
import java.util.Arrays;
2628
import java.util.Collections;
27-
import java.util.Map;
2829
import java.util.Objects;
2930

3031
@Component
@@ -37,12 +38,17 @@ public class CoincentoWallet {
3738

3839
private final @NonNull Credentials credentials;
3940

41+
private final BankETHAddressRepository bankETHAddressRepository;
42+
4043
@Value("${ethereum.coincento}")
4144
private String coincentoAddress;
4245

43-
public CoincentoWallet(@NonNull Web3j web3j, @NonNull Credentials credentials) {
46+
public CoincentoWallet(@NonNull Web3j web3j,
47+
@NonNull Credentials credentials,
48+
BankETHAddressRepository bankETHAddressRepository) {
4449
this.web3j = Objects.requireNonNull(web3j);
4550
this.credentials = Objects.requireNonNull(credentials);
51+
this.bankETHAddressRepository = bankETHAddressRepository;
4652
}
4753

4854
public Mono<Void> transfer(
@@ -101,16 +107,10 @@ public Mono<Void> transfer(
101107
.map(EthGetTransactionCount::getTransactionCount);
102108
}
103109

104-
private static final Map<String, String> BIC_TO_ADDRESS = Map.of(
105-
"TESTUKLLXXX", "0xf17f52151EbEF6C7334FAD080c5704D77216b732",
106-
"TESTGETBXXX", "0xda6c0ca76e69b32c71301356043fb56d702dfb3d"
107-
);
108-
109110
private @NonNull Mono<String> getEthereumAddress(@NonNull String bic) {
110-
String address = BIC_TO_ADDRESS.get(bic);
111-
if (address == null) {
112-
return Mono.error(new Exception(String.format("BIC %s doesn't have associated Ethereum address", bic)));
113-
}
114-
return Mono.just(address);
111+
return bankETHAddressRepository.findByBic(bic)
112+
.singleOrEmpty()
113+
.switchIfEmpty(Mono.error(new Exception(String.format("BIC %s doesn't have associated Ethereum address", bic))))
114+
.map(BankETHAddress::getBic);
115115
}
116116
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.exactpro.blockchain.entity;
2+
3+
import org.springframework.data.annotation.Id;
4+
import org.springframework.data.relational.core.mapping.Column;
5+
import org.springframework.data.relational.core.mapping.Table;
6+
7+
@Table("BankETHAddress")
8+
public class BankETHAddress {
9+
@Id
10+
private String bic;
11+
12+
@Column("ethAddress")
13+
private String ethAddress;
14+
15+
public String getBic() {
16+
return bic;
17+
}
18+
19+
public void setBic(String bic) {
20+
this.bic = bic;
21+
}
22+
23+
public String getEthAddress() {
24+
return ethAddress;
25+
}
26+
27+
public void setEthAddress(String ethAddress) {
28+
this.ethAddress = ethAddress;
29+
}
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.exactpro.blockchain.repository;
2+
3+
import com.exactpro.blockchain.entity.BankETHAddress;
4+
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
5+
import org.springframework.lang.NonNull;
6+
import reactor.core.publisher.Flux;
7+
8+
public interface BankETHAddressRepository extends ReactiveCrudRepository<BankETHAddress, String> {
9+
@NonNull Flux<BankETHAddress> findByBic(String bic);
10+
}

server/src/main/resources/db/migration/V1__Initial_schema.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ CREATE TABLE ConversionRate (
4848
rate NUMERIC(10, 6) NOT NULL,
4949
FOREIGN KEY (baseCurrency) REFERENCES CurrencyCode(code),
5050
FOREIGN KEY (targetCurrency) REFERENCES CurrencyCode(code)
51-
);
51+
);
52+
53+
CREATE TABLE BankETHAddress (
54+
bic VARCHAR(255) NOT NULL PRIMARY KEY,
55+
ethAddress VARCHAR(255) NOT NULL UNIQUE
56+
);

server/src/main/resources/db/migration/V2__Initial_data.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ INSERT INTO ConversionRate (baseCurrency, targetCurrency, rate) VALUES
4646
('USD', 'USDC', 1.00),
4747
('USDC', 'USD', 1.00),
4848
('EUR', 'USDC', 1.14),
49-
('USDC', 'EUR', 0.88);
49+
('USDC', 'EUR', 0.88);
50+
51+
INSERT INTO BankETHAddress (bic, ethAddress) VALUES
52+
('TESTUKLLXXX', '0xf17f52151EbEF6C7334FAD080c5704D77216b732'),
53+
('TESTGETBXXX', '0xda6c0ca76e69b32c71301356043fb56d702dfb3d');

0 commit comments

Comments
 (0)