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;
|
}
|
|
}
|