@@ -25,6 +25,7 @@ import {
25
25
EntryPointValue ,
26
26
EraSummary ,
27
27
ExecutionInfo ,
28
+ ExecutionResultV1 ,
28
29
Hash ,
29
30
InitiatorAddr ,
30
31
MinimalBlockInfo ,
@@ -831,14 +832,71 @@ export class SpeculativeExecResult {
831
832
} )
832
833
blockHash ?: Hash ;
833
834
834
- @jsonMember ( {
835
- name : 'execution_result' ,
836
- constructor : SpeculativeExecutionResult ,
837
- preserveNull : true
838
- } )
835
+ /**
836
+ * Execution result for Casper v2.0 (speculative execution format).
837
+ */
839
838
executionResult ?: SpeculativeExecutionResult ;
840
839
840
+ /**
841
+ * Execution result for Casper v1.5.x (legacy execution format).
842
+ */
843
+ executionResultV1 ?: ExecutionResultV1 ;
844
+
845
+ /**
846
+ * Stores the raw json object if version could not be parsed.
847
+ */
841
848
rawJSON ?: any ;
849
+
850
+ /**
851
+ * True if the parsed execution result matches Casper v1.5.x format.
852
+ */
853
+ get isV1 ( ) : boolean {
854
+ return ! ! this . executionResultV1 ;
855
+ }
856
+
857
+ /**
858
+ * True if the parsed execution result matches Casper v2.0 format.
859
+ */
860
+ get isV2 ( ) : boolean {
861
+ return ! ! this . executionResult ;
862
+ }
863
+
864
+ /**
865
+ * Parses and returns a version-aware SpeculativeExecResult from raw JSON.
866
+ * Supports both Casper v1.5.x and v2.0 formats.
867
+ */
868
+ static fromJSON ( json : any ) : SpeculativeExecResult {
869
+ const result = new SpeculativeExecResult ( ) ;
870
+
871
+ result . apiVersion = json ?. version ;
872
+ const execJson = json ?. result ?. execution_result ;
873
+ result . rawJSON = json ;
874
+
875
+ result . blockHash = execJson ?. block_hash
876
+ ? Hash . fromHex ( execJson . block_hash )
877
+ : undefined ;
878
+
879
+ if (
880
+ execJson &&
881
+ ( execJson . block_hash ||
882
+ execJson . limit !== undefined ||
883
+ execJson . consumed !== undefined )
884
+ ) {
885
+ // Casper v2.0
886
+ result . executionResult = new TypedJSON ( SpeculativeExecutionResult ) . parse (
887
+ execJson
888
+ ) ;
889
+ } else if ( execJson && ( 'Success' in execJson || 'Failure' in execJson ) ) {
890
+ // Casper v1.5.x
891
+ result . executionResultV1 = new TypedJSON ( ExecutionResultV1 ) . parse (
892
+ execJson
893
+ ) ;
894
+ } else {
895
+ console . warn ( 'Unknown execution_result format:' , execJson ) ;
896
+ }
897
+
898
+ return result ;
899
+ }
842
900
}
843
901
844
902
@jsonObject
0 commit comments