-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yangfang2
committed
Aug 5, 2024
1 parent
03c6fe3
commit 1c6f5aa
Showing
13 changed files
with
364 additions
and
209 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/main/java/com/webank/wecross/stub/web3/Web3BaseStubFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.webank.wecross.stub.web3; | ||
|
||
import com.webank.wecross.stub.Account; | ||
import com.webank.wecross.stub.Connection; | ||
import com.webank.wecross.stub.Driver; | ||
import com.webank.wecross.stub.StubFactory; | ||
import com.webank.wecross.stub.WeCrossContext; | ||
import com.webank.wecross.stub.web3.account.Web3AccountFactory; | ||
import com.webank.wecross.stub.web3.common.Web3Constant; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Web3BaseStubFactory implements StubFactory { | ||
private static final Logger logger = LoggerFactory.getLogger(Web3BaseStubFactory.class); | ||
|
||
@Override | ||
public void init(WeCrossContext weCrossContext) {} | ||
|
||
@Override | ||
public Driver newDriver() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Connection newConnection(String path) { | ||
try { | ||
logger.info("New connection: {}", path); | ||
Web3Connection connection = Web3ConnectionFactory.build(path, Web3Constant.STUB_TOML_NAME); | ||
|
||
// check proxy contract | ||
if (!connection.hasProxyDeployed()) { | ||
String errorMsg = "WeCrossProxy error: WeCrossProxy contract has not been deployed!"; | ||
System.out.println(errorMsg); | ||
throw new Exception(errorMsg); | ||
} | ||
|
||
// check hub contract | ||
if (!connection.hasHubDeployed()) { | ||
String errorMsg = "WeCrossHub error: WeCrossHub contract has not been deployed!"; | ||
System.out.println(errorMsg); | ||
throw new Exception(errorMsg); | ||
} | ||
return connection; | ||
} catch (Exception e) { | ||
logger.error("New connection fail, e: ", e); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public Account newAccount(Map<String, Object> properties) { | ||
return Web3AccountFactory.build(properties); | ||
} | ||
|
||
@Override | ||
public void generateAccount(String path, String[] args) {} | ||
|
||
@Override | ||
public void generateConnection(String path, String[] args) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 11 additions & 2 deletions
13
src/main/java/com/webank/wecross/stub/web3/Web3StubFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
package com.webank.wecross.stub.web3; | ||
|
||
import static com.webank.wecross.stub.web3.common.Web3Constant.WEB3_STUB_TYPE; | ||
|
||
import com.webank.wecross.stub.Stub; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Web3StubFactory { | ||
private final Logger logger = LoggerFactory.getLogger(Web3StubFactory.class); | ||
@Stub(WEB3_STUB_TYPE) | ||
public class Web3StubFactory extends Web3BaseStubFactory { | ||
private static final Logger logger = LoggerFactory.getLogger(Web3StubFactory.class); | ||
|
||
public static void main(String[] args) { | ||
System.out.printf( | ||
"This is %s Stub Plugin. Please copy this file to router/plugin/%n", WEB3_STUB_TYPE); | ||
} | ||
} |
Oops, something went wrong.