Skip to content

Commit

Permalink
<feat>(console): add sendRawTransaction feature. (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay authored Oct 15, 2024
1 parent dd3c678 commit 481c9ee
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/console/command/category/ContractOpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public static void setIsWasm(boolean wasm) {
DEPLOY.setMinParamLength(wasm ? 2 : 1);
}

public static final CommandInfo SEND_RAW_TRANSACTION =
new CommandInfo(
"sendRawTransaction",
"Send a raw signed transaction to chain",
() -> HelpInfo.deployHelp(isWasm),
(consoleInitializer, params, pwd) ->
consoleInitializer.getConsoleContractFace().sendRawTransaction(params),
1,
1);

public static final CommandInfo DEPLOY =
new CommandInfo(
"deploy",
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/console/command/model/HelpInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ public static void getTotalTransactionCountHelp() {
System.out.println("Usage: \ngetTotalTransactionCount");
}

public static void sendRawTransactionHelp() {
System.out.println("Send a raw signed transaction to chain.");
System.out.println("Usage: \nsendRawTransaction [rawTransactionHex]");
System.out.println(
"* rawTransactionHex -- Raw signed transaction in hex, and it is encoded by Tars.");
}

public static void deployHelp(boolean isWasm) {
if (!isWasm) {
System.out.println(
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/console/contract/ConsoleContractFace.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import console.ConsoleInitializer;

public interface ConsoleContractFace {

void sendRawTransaction(String[] params) throws Exception;

void deploy(String[] params, String pwd) throws Exception;

void call(String[] params, String pwd) throws Exception;
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/console/contract/ConsoleContractImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.fisco.bcos.sdk.v3.client.Client;
import org.fisco.bcos.sdk.v3.client.exceptions.ClientException;
import org.fisco.bcos.sdk.v3.client.protocol.response.Abi;
import org.fisco.bcos.sdk.v3.client.protocol.response.BcosTransactionReceipt;
import org.fisco.bcos.sdk.v3.codec.ContractCodecException;
import org.fisco.bcos.sdk.v3.codec.EventEncoder;
import org.fisco.bcos.sdk.v3.codec.datatypes.generated.tuples.generated.Tuple2;
Expand Down Expand Up @@ -124,6 +125,31 @@ public void setExtension(byte[] extension) {
this.extension = extension;
}

@Override
public void sendRawTransaction(String[] params) throws Exception {
String rawTx = params[0];
BcosTransactionReceipt bcosTransactionReceipt = client.sendTransaction(rawTx, false);
TransactionReceipt transactionReceipt = bcosTransactionReceipt.getTransactionReceipt();
System.out.println("transaction hash: " + transactionReceipt.getTransactionHash());
ConsoleUtils.singleLine();
System.out.println("transaction status: " + transactionReceipt.getStatus());

if (transactionReceipt.getStatus() == 0) {
System.out.println("description: " + "transaction executed successfully");
}
ConsoleUtils.singleLine();
System.out.println("Receipt message: " + transactionReceipt.getMessage());
System.out.println("Return message: " + transactionReceipt.getOutput());
ConsoleUtils.singleLine();
if (transactionReceipt.getLogEntries() != null
&& !transactionReceipt.getLogEntries().isEmpty()) {
System.out.println("Event logs");
for (TransactionReceipt.Logs logEntry : transactionReceipt.getLogEntries()) {
System.out.println(logEntry);
}
}
}

@Override
public void deploy(String[] params, String pwd) throws Exception {
List<String> paramsList = new ArrayList<>(Arrays.asList(params));
Expand Down

0 comments on commit 481c9ee

Please sign in to comment.