Skip to content

Commit b20654f

Browse files
committed
fix(cli): return txid directly from ForCli methods, eliminate LAST_BROADCAST_TX_ID ThreadLocal
Replace the thread-local side-channel (LAST_BROADCAST_TX_ID) with direct return values — all *ForCli methods now return the txid String (null on failure) instead of void/boolean. deployContractForCli returns Pair<contractAddress, txid>; callContractForCli returns Triple<String, Long, Long> with txid as the left element. Other fixes in this commit: - Use lenient JSON parsing in Utils.formatMessageString to tolerate malformed on-chain data (e.g. asset #436 description on Nile) - Add QA manifest entry for the help command (noauth-help type) - Fix test compilation: update overrides to match new signatures
1 parent 6784a93 commit b20654f

16 files changed

Lines changed: 579 additions & 418 deletions

docs/standard-cli-contract-spec.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,22 @@ Rules:
752752
- future command output expansion should prefer additive changes inside `data` rather than changing the top-level
753753
envelope shape
754754

755+
### Broadcast Command Payload
756+
757+
On-chain broadcast commands (send-coin, transfer-asset, trigger-contract, deploy-contract,
758+
freeze-balance, vote-witness, etc.) include transaction-specific fields under `data` when the
759+
broadcast succeeds.
760+
761+
Rules:
762+
763+
- a successful single-sign broadcast must include `"txid"` under `data`
764+
- a successful multi-sign submission must not include `"txid"` under `data` because multi-sign
765+
submits a partially-signed transaction to a coordinator, not directly to the network; no txid
766+
is generated at broadcast time
767+
- deploy-contract must additionally include `"contract_address"` (base58Check) under `data`
768+
- callers that require a txid must check that `data.txid` is present; its absence means the
769+
transaction was submitted for multi-sign coordination
770+
755771
### Text and JSON Consistency
756772

757773
Text mode and JSON mode are two renderings of the same command outcome.

qa/lib/case_resolver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def smoke_expectation(case_type):
9494
mapping = {
9595
"offline-success": "success",
9696
"noauth-success": "success",
97+
"noauth-help": "help_dual",
9798
"auth-success": "success",
9899
"stateful-success": "success",
99100
"stateful-replay-execution": "stateful_replay_execution",
@@ -143,7 +144,8 @@ def build_smoke_case(label, row, values):
143144
"json_path_absent": json_path_absent,
144145
"error_code": error_code,
145146
"text_contains": text_contains,
146-
"text_absent": ["Error:", "Usage:"] if smoke_expectation(case_type) == "success" else [],
147+
"text_absent": ["Error:", "Usage:"] if smoke_expectation(case_type) == "success"
148+
else ["Error:"] if smoke_expectation(case_type) == "help_dual" else [],
147149
"preflight": preflight,
148150
"unresolved_placeholders": unresolved,
149151
"excluded": case_type == "excluded-interactive",

qa/manifest.tsv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ clear-wallet-keystore|offline-success|auth|private_key|--force
100100
reset-wallet|offline-success|auth|private_key|--confirm delete-all-wallets
101101
modify-wallet-name|auth-success|auth|private_key|--name renamed-wallet
102102
generate-sub-account|offline-success|auth-mnemonic|mnemonic|--index 1 --name qasubaccount
103-
help|help_dual|empty|none|
103+
help|noauth-help|empty|none|

src/main/java/org/tron/common/utils/Utils.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,15 @@ public static Date strToDateLong(String strDate) {
186186

187187
public static String formatMessageString(Message message) {
188188
String result = JsonFormat.printToString(message, true);
189-
return new GsonBuilder().setPrettyPrinting().create()
190-
.toJson(JsonParser.parseString(result));
189+
try {
190+
com.google.gson.stream.JsonReader reader =
191+
new com.google.gson.stream.JsonReader(new java.io.StringReader(result));
192+
reader.setLenient(true);
193+
return new GsonBuilder().setPrettyPrinting().create()
194+
.toJson(JsonParser.parseReader(reader));
195+
} catch (com.google.gson.JsonSyntaxException e) {
196+
return result;
197+
}
191198
}
192199

193200
public static String printTransactionExceptId(Chain.Transaction transaction)

0 commit comments

Comments
 (0)