KKSU
2024-04-22 e323f70b56b7ddcfe91d8112cf46873f626b7cfb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cc.mrbird.febs.mall.chain;
 
import cc.mrbird.febs.common.exception.FebsException;
import io.reactivex.Flowable;
import lombok.extern.slf4j.Slf4j;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.DefaultBlockParameterNumber;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.http.HttpService;
import org.web3j.tx.gas.StaticGasProvider;
 
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author
 * @date 2022-03-23
 **/
@Slf4j
public class ChainService {
    private final static Map<String, ContractChainService> contractMap = new HashMap<>();
 
    static {
        for (ChainEnum chain : ChainEnum.values()) {
            contractMap.put(chain.name(), new EthService(chain.getUrl(), chain.getAddress(), chain.getPrivateKey(), chain.getContractAddress()));
//            if ("TRX".equals(chain.getChain())) {
//                contractMap.put(chain.name(), new TrxService(chain.getAddress(), chain.getPrivateKey(), chain.getContractAddress(), chain.getApiKey()));
//            } else {
//                contractMap.put(chain.name(), new EthService(chain.getUrl(), chain.getAddress(), chain.getPrivateKey(), chain.getContractAddress()));
//            }
        }
    }
 
    private ChainService() {
    }
 
    public final static ChainService INSTANCE = new ChainService();
 
    public static ContractChainService getInstance(String chainType) {
        ContractChainService contract = contractMap.get(chainType);
        if (contract == null) {
            throw new FebsException("参数错误");
        }
 
        return contract;
    }
 
}