-
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.
<feat>(resource): custom command update resource (#6)
Co-authored-by: yangfang2 <[email protected]>
- Loading branch information
1 parent
e0bf638
commit 058dd57
Showing
13 changed files
with
214 additions
and
94 deletions.
There are no files selected for viewing
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
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
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
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
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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/webank/wecross/stub/web3/custom/CommandHandler.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,27 @@ | ||
package com.webank.wecross.stub.web3.custom; | ||
|
||
import com.webank.wecross.stub.Account; | ||
import com.webank.wecross.stub.BlockManager; | ||
import com.webank.wecross.stub.Connection; | ||
import com.webank.wecross.stub.Driver; | ||
import com.webank.wecross.stub.Path; | ||
|
||
public interface CommandHandler { | ||
/** | ||
* handle custom command | ||
* | ||
* @param path rule id | ||
* @param args command args | ||
* @param account if needs to sign | ||
* @param blockManager if needs to verify transaction | ||
* @param connection chain connection | ||
* @param callback callback | ||
*/ | ||
void handle( | ||
Path path, | ||
Object[] args, | ||
Account account, | ||
BlockManager blockManager, | ||
Connection connection, | ||
Driver.CustomCommandCallback callback); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/webank/wecross/stub/web3/custom/CommandHandlerDispatcher.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,25 @@ | ||
package com.webank.wecross.stub.web3.custom; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CommandHandlerDispatcher { | ||
private static final Logger logger = LoggerFactory.getLogger(CommandHandlerDispatcher.class); | ||
|
||
private final Map<String, CommandHandler> commandMapper = new HashMap<>(); | ||
|
||
public void registerCommandHandler(String command, CommandHandler commandHandler) { | ||
commandMapper.putIfAbsent(command, commandHandler); | ||
} | ||
|
||
public CommandHandler matchCommandHandler(String command) { | ||
CommandHandler commandHandler = commandMapper.get(command); | ||
if (Objects.isNull(commandHandler)) { | ||
logger.warn(" Unsupported command: {}", command); | ||
} | ||
return commandHandler; | ||
} | ||
} |
Oops, something went wrong.