11import { Address } from "../address" ;
22import { Err } from "../errors" ;
3+ import { ITransactionOnNetwork } from "../interfaceOfNetwork" ;
34import { EndpointDefinition , ResultsParser , ReturnCode , Type , UntypedOutcomeBundle } from "../smartcontracts" ;
4- import { TransactionEvent , TransactionOutcome , findEventsByIdentifier } from "./resources" ;
5+ import { TransactionOutcome , findEventsByIdentifier } from "./resources" ;
6+
7+ enum Events {
8+ SCDeploy = "SCDeploy" ,
9+ SignalError = "signalError" ,
10+ WriteLog = "writeLog" ,
11+ }
512
613interface IAbi {
714 getEndpoint ( name : string ) : EndpointDefinition ;
@@ -28,15 +35,31 @@ export class SmartContractTransactionsOutcomeParser {
2835
2936 constructor ( options ?: { abi ?: IAbi ; legacyResultsParser ?: ILegacyResultsParser } ) {
3037 this . abi = options ?. abi ;
31-
32- // Prior v13, we've advertised that people can override the "ResultsParser" to alter it's behavior in case of exotic flows.
33- // Now, since the new "SmartContractTransactionsOutcomeParser" (still) depends on the legacy "ResultsParser",
34- // at least until "return data parts of direct outcome of contract call" are included on API & Proxy responses (on GET transaction),
35- // we have to allow the same level of customization (for exotic flows).
3638 this . legacyResultsParser = options ?. legacyResultsParser || new ResultsParser ( ) ;
3739 }
3840
39- parseDeploy ( options : { transactionOutcome : TransactionOutcome } ) : {
41+ parseDeploy (
42+ options : { transactionOutcome : TransactionOutcome } | { transactionOnNetwork : ITransactionOnNetwork } ,
43+ ) : {
44+ returnCode : string ;
45+ returnMessage : string ;
46+ contracts : {
47+ address : string ;
48+ ownerAddress : string ;
49+ codeHash : Uint8Array ;
50+ } [ ] ;
51+ } {
52+ if ( "transactionOutcome" in options ) {
53+ return this . parseDeployGivenTransactionOutcome ( options . transactionOutcome ) ;
54+ }
55+
56+ return this . parseDeployGivenTransactionOnNetwork ( options . transactionOnNetwork ) ;
57+ }
58+
59+ /**
60+ * Legacy approach.
61+ */
62+ protected parseDeployGivenTransactionOutcome ( transactionOutcome : TransactionOutcome ) : {
4063 returnCode : string ;
4164 returnMessage : string ;
4265 contracts : {
@@ -45,8 +68,8 @@ export class SmartContractTransactionsOutcomeParser {
4568 codeHash : Uint8Array ;
4669 } [ ] ;
4770 } {
48- const directCallOutcome = options . transactionOutcome . directSmartContractCallOutcome ;
49- const events = findEventsByIdentifier ( options . transactionOutcome , " SCDeploy" ) ;
71+ const directCallOutcome = transactionOutcome . directSmartContractCallOutcome ;
72+ const events = findEventsByIdentifier ( transactionOutcome , Events . SCDeploy ) ;
5073 const contracts = events . map ( ( event ) => this . parseScDeployEvent ( event ) ) ;
5174
5275 return {
@@ -56,7 +79,19 @@ export class SmartContractTransactionsOutcomeParser {
5679 } ;
5780 }
5881
59- private parseScDeployEvent ( event : TransactionEvent ) : {
82+ protected parseDeployGivenTransactionOnNetwork ( _transactionOnNetwork : ITransactionOnNetwork ) : {
83+ returnCode : string ;
84+ returnMessage : string ;
85+ contracts : {
86+ address : string ;
87+ ownerAddress : string ;
88+ codeHash : Uint8Array ;
89+ } [ ] ;
90+ } {
91+ throw new Error ( "Not implemented." ) ;
92+ }
93+
94+ private parseScDeployEvent ( event : { topics : Uint8Array [ ] } ) : {
6095 address : string ;
6196 ownerAddress : string ;
6297 codeHash : Uint8Array ;
@@ -76,12 +111,34 @@ export class SmartContractTransactionsOutcomeParser {
76111 } ;
77112 }
78113
79- parseExecute ( options : { transactionOutcome : TransactionOutcome ; function ?: string } ) : {
114+ parseExecute (
115+ options :
116+ | { transactionOutcome : TransactionOutcome ; function ?: string }
117+ | { transactionOnNetwork : ITransactionOnNetwork ; function ?: string } ,
118+ ) : {
80119 values : any [ ] ;
81120 returnCode : string ;
82121 returnMessage : string ;
83122 } {
84- const directCallOutcome = options . transactionOutcome . directSmartContractCallOutcome ;
123+ if ( "transactionOutcome" in options ) {
124+ return this . parseExecuteGivenTransactionOutcome ( options . transactionOutcome , options . function ) ;
125+ }
126+
127+ return this . parseExecuteGivenTransactionOnNetwork ( options . transactionOnNetwork , options . function ) ;
128+ }
129+
130+ /**
131+ * Legacy approach.
132+ */
133+ protected parseExecuteGivenTransactionOutcome (
134+ transactionOutcome : TransactionOutcome ,
135+ functionName ?: string ,
136+ ) : {
137+ values : any [ ] ;
138+ returnCode : string ;
139+ returnMessage : string ;
140+ } {
141+ const directCallOutcome = transactionOutcome . directSmartContractCallOutcome ;
85142
86143 if ( ! this . abi ) {
87144 return {
@@ -91,7 +148,7 @@ export class SmartContractTransactionsOutcomeParser {
91148 } ;
92149 }
93150
94- const functionName = options . function || directCallOutcome . function ;
151+ functionName = functionName || directCallOutcome . function ;
95152
96153 if ( ! functionName ) {
97154 throw new Err (
@@ -115,4 +172,15 @@ export class SmartContractTransactionsOutcomeParser {
115172 returnMessage : legacyTypedBundle . returnMessage ,
116173 } ;
117174 }
175+
176+ protected parseExecuteGivenTransactionOnNetwork (
177+ _transactionOnNetwork : ITransactionOnNetwork ,
178+ _functionName ?: string ,
179+ ) : {
180+ values : any [ ] ;
181+ returnCode : string ;
182+ returnMessage : string ;
183+ } {
184+ throw new Error ( "Not implemented." ) ;
185+ }
118186}
0 commit comments