-
Notifications
You must be signed in to change notification settings - Fork 60
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
Showing
6 changed files
with
242 additions
and
1 deletion.
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
114 changes: 114 additions & 0 deletions
114
src/main/java/console/command/category/BalanceOpCommand.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,114 @@ | ||
package console.command.category; | ||
|
||
import console.command.model.BasicCategoryCommand; | ||
import console.command.model.CommandInfo; | ||
import console.command.model.CommandType; | ||
import console.command.model.HelpInfo; | ||
import java.lang.reflect.Field; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class BalanceOpCommand extends BasicCategoryCommand { | ||
public static final CommandInfo GET_BALANCE = | ||
new CommandInfo( | ||
"getBalance", | ||
"Get balance of the account", | ||
HelpInfo::getBalanceHelp, | ||
(consoleInitializer, params, pwd) -> | ||
consoleInitializer.getPrecompiledFace().getBalance(params), | ||
1, | ||
1); | ||
public static final CommandInfo ADD_BALANCE = | ||
new CommandInfo( | ||
"addBalance", | ||
"Add balance to the account", | ||
HelpInfo::addBalanceHelp, | ||
(consoleInitializer, params, pwd) -> | ||
consoleInitializer.getPrecompiledFace().addBalance(params), | ||
2, | ||
2); | ||
public static final CommandInfo SUB_BALANCE = | ||
new CommandInfo( | ||
"subBalance", | ||
"Sub balance from the account", | ||
HelpInfo::subBalanceHelp, | ||
(consoleInitializer, params, pwd) -> | ||
consoleInitializer.getPrecompiledFace().subBalance(params), | ||
2, | ||
2); | ||
public static final CommandInfo REGISTER_CALLER = | ||
new CommandInfo( | ||
"registerCaller", | ||
"Register caller to the account", | ||
HelpInfo::registerBalancePrecompiledCallerHelp, | ||
(consoleInitializer, params, pwd) -> | ||
consoleInitializer | ||
.getPrecompiledFace() | ||
.registerBalancePrecompiledCaller(params), | ||
1, | ||
1); | ||
public static final CommandInfo UNREGISTER_CALLER = | ||
new CommandInfo( | ||
"unregisterCaller", | ||
"Unregister caller from the account", | ||
HelpInfo::unregisterBalancePrecompiledCallerHelp, | ||
(consoleInitializer, params, pwd) -> | ||
consoleInitializer | ||
.getPrecompiledFace() | ||
.unregisterBalancePrecompiledCaller(params), | ||
1, | ||
1); | ||
protected static final Map<String, CommandInfo> commandToCommandInfo = new HashMap<>(); | ||
|
||
static { | ||
Field[] fields = BalanceOpCommand.class.getDeclaredFields(); | ||
for (Field field : fields) { | ||
if (field.getType().equals(CommandInfo.class)) { | ||
try { | ||
CommandInfo constantCommandInfo = (CommandInfo) field.get(null); | ||
commandToCommandInfo.put(constantCommandInfo.getCommand(), constantCommandInfo); | ||
if (constantCommandInfo.getOptionCommand() != null) { | ||
List<String> subCommandList = constantCommandInfo.getOptionCommand(); | ||
for (String s : subCommandList) { | ||
commandToCommandInfo.put(s, constantCommandInfo); | ||
} | ||
} | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public BalanceOpCommand() { | ||
super(CommandType.BALANCE_PRECOMPILED_OP); | ||
} | ||
|
||
@Override | ||
public CommandInfo getCommandInfo(String command) { | ||
if (commandToCommandInfo.containsKey(command)) { | ||
return commandToCommandInfo.get(command); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<String> getAllCommand(boolean isWasm, boolean isAuthOpen) { | ||
return commandToCommandInfo | ||
.keySet() | ||
.stream() | ||
.filter( | ||
key -> | ||
!(isWasm && !commandToCommandInfo.get(key).isWasmSupport() | ||
|| (!isAuthOpen | ||
&& commandToCommandInfo.get(key).isNeedAuthOpen()))) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public Map<String, CommandInfo> getAllCommandInfo(boolean isWasm) { | ||
return commandToCommandInfo; | ||
} | ||
} |
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