| 267 | ); |
| 268 | |
| 269 | class Encoder { |
| 270 | static encode({actionScript, variables, wallet}) { |
| 271 | const encoder = new Encoder(actionScript, variables, wallet); |
| 272 | |
| 273 | return encoder.encode(); |
| 274 | } |
| 275 | |
| 276 | constructor(actionScript, variables, wallet, isAdvanced = null) { |
| 277 | this.actionScript = actionScript; |
| 278 | this.variables = variables; |
| 279 | this.variables["wallet"] = wallet; |
| 280 | this.isAdvanced = ( |
| 281 | isAdvanced === null |
| 282 | ? Validator.isAdvanced(actionScript) |
| 283 | : !!isAdvanced |
| 284 | ); |
| 285 | this.knownCallResultVariables = {}; |
| 286 | } |
| 287 | |
| 288 | encode() { |
| 289 | this.parseActionScriptDefinitions(); |
| 290 | this.constructCallsAndResultsFormat(); |
| 291 | |
| 292 | return { |
| 293 | calls: this.calls, |
| 294 | callABIs: this.callABIs, |
| 295 | resultToParse: this.resultToParse, |
| 296 | isAdvanced: this.isAdvanced, |
| 297 | }; |
| 298 | } |
| 299 | |
| 300 | static encodeSequence({sequence, variables, wallet}) { |
| 301 | const isAdvanced = sequence.some(({ actionScript, resultsToApply }) => ( |
| 302 | !!resultsToApply && resultsToApply.length > 0 || |
| 303 | Validator.isAdvanced(actionScript) |
| 304 | )); |
| 305 | |
| 306 | let sequenceCallIndex = 0; |
| 307 | const encoded = []; |
| 308 | const sequenceKnownCallResultVariables = []; |
| 309 | const sequenceCallIndices = []; |
| 310 | let calls = []; |
| 311 | for (const { actionScript, resultsToApply } of sequence) { |
| 312 | const encoder = new Encoder( |
| 313 | actionScript, variables, wallet, isAdvanced |
| 314 | ); |
| 315 | |
| 316 | encoder.parseActionScriptDefinitions(); |
| 317 | encoder.callIndex = sequenceCallIndex; |
| 318 | encoder.calls = calls; |
| 319 | sequenceCallIndices.push(sequenceCallIndex); |
| 320 | |
| 321 | for (const { sequenceIndex, result, variable } of resultsToApply) { |
| 322 | const resultToApply = sequenceKnownCallResultVariables[sequenceIndex][result]; |
| 323 | encoder.knownCallResultVariables[variable] = resultToApply; |
| 324 | } |
| 325 | |
| 326 | encoded.push(encoder.encode()); |
nothing calls this directly
no outgoing calls
no test coverage detected