Skip to content

Commit

Permalink
update properties name
Browse files Browse the repository at this point in the history
  • Loading branch information
dwusiq committed Mar 9, 2024
1 parent f7d6be9 commit f89462c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/dl/officialsite/aave/AaveService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AaveService {
BigInteger e23 = new BigInteger("100000000000000000000000");


@Autowired
// @Autowired
Web3j web3j;

@Autowired
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/dl/officialsite/aave/DeFiTokenYield.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DeFiTokenYield {

private String tokeName;

private String prococal;
private String protocol;

private String tokenAddress;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@Configuration
@ConditionalOnClass(Web3j.class)
@EnableConfigurationProperties({Web3jProperties.class,NetworkProperties.class})
@EnableConfigurationProperties({ Web3jProperties.class, NetworkProperties.class })
public class Web3jAutoConfiguration {

private static Log log = LogFactory.getLog(Web3jAutoConfiguration.class);
Expand All @@ -33,79 +33,67 @@ public class Web3jAutoConfiguration {
@Autowired
private NetworkProperties networkProperties;

public static final ConcurrentHashMap<String,Web3j> web3jMap = new ConcurrentHashMap<String,Web3j>();
public static final ConcurrentHashMap<String, Web3j> web3jMap = new ConcurrentHashMap<String, Web3j>();


@Bean
// @Bean
@ConditionalOnMissingBean
public Web3j web3j() {
//init map of web3j map(chainID,web3j)
initWeb3jMap();
public void web3j() {
for (int i = 0; i < networkProperties.getConfigs().length; i++) {
NetworkProperties.NetworkDetailProperties detail = networkProperties.getConfigs()[i];
Web3jService web3jService = buildService(detail.getRpc());
web3jMap.put(detail.getId(), Web3j.build(web3jService));
log.info("initWeb3jMap.current chain:" + detail.getName() + " rpc:" + detail.getRpc());
}

Web3jService web3jService = buildService(properties.getClientAddress());
log.info("Building service for endpoint: " + properties.getClientAddress());
return Web3j.build(web3jService);
}

@Bean
@ConditionalOnProperty(
prefix = Web3jProperties.WEB3J_PREFIX, name = "admin-client", havingValue =
"true")
@ConditionalOnProperty(prefix = Web3jProperties.WEB3J_PREFIX, name = "admin-client", havingValue = "true")
public Admin admin() {
Web3jService web3jService = buildService(properties.getClientAddress());
log.info("Building admin service for endpoint: " +
properties.getClientAddress());
return Admin.build(web3jService);
Web3jService web3jService = buildService(properties.getClientAddress());
log.info("Building admin service for endpoint: " +
properties.getClientAddress());
return Admin.build(web3jService);
}

private Web3jService buildService(String clientAddress) {
Web3jService web3jService;

if (clientAddress == null || clientAddress.equals("")) {
web3jService = new HttpService(createOkHttpClient());
} else if (clientAddress.startsWith("http")) {
web3jService = new HttpService(clientAddress, createOkHttpClient(), false);
} else if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
web3jService = new WindowsIpcService(clientAddress);
} else {
web3jService = new UnixIpcService(clientAddress);
}
Web3jService web3jService;

if (clientAddress == null || clientAddress.equals("")) {
web3jService = new HttpService(createOkHttpClient());
} else if (clientAddress.startsWith("http")) {
web3jService = new HttpService(clientAddress, createOkHttpClient(), false);
} else if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
web3jService = new WindowsIpcService(clientAddress);
} else {
web3jService = new UnixIpcService(clientAddress);
}

return web3jService;
return web3jService;
}

private OkHttpClient createOkHttpClient() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
configureLogging(builder);
configureTimeouts(builder);
return builder.build();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
configureLogging(builder);
configureTimeouts(builder);
return builder.build();
}

private void configureTimeouts(OkHttpClient.Builder builder) {
Long tos = properties.getHttpTimeoutSeconds();
if (tos != null) {
builder.connectTimeout(tos, TimeUnit.SECONDS);
builder.readTimeout(tos, TimeUnit.SECONDS); // Sets the socket timeout too
builder.writeTimeout(tos, TimeUnit.SECONDS);
}
Long tos = properties.getHttpTimeoutSeconds();
if (tos != null) {
builder.connectTimeout(tos, TimeUnit.SECONDS);
builder.readTimeout(tos, TimeUnit.SECONDS); // Sets the socket timeout too
builder.writeTimeout(tos, TimeUnit.SECONDS);
}
}

private static void configureLogging(OkHttpClient.Builder builder) {
if (log.isDebugEnabled()) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(log::debug);
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(logging);
}
}

private void initWeb3jMap(){
for(int i=0;i<networkProperties.getConfigs().length;i++){
NetworkProperties.NetworkDetailProperties detail = networkProperties.getConfigs()[i];
Web3jService web3jService = buildService(detail.getRpc());
web3jMap.put(detail.getId(),Web3j.build(web3jService));
log.info("initWeb3jMap.current chain:"+detail.getName()+" rpc:"+detail.getRpc());
if (log.isDebugEnabled()) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(log::debug);
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(logging);
}

}

}

0 comments on commit f89462c

Please sign in to comment.