Skip to content

Commit

Permalink
Merge pull request #518 from casper-ecosystem/CSDK-230
Browse files Browse the repository at this point in the history
Fix toInfoGetTransactionResult method to parse V1 deploy result
  • Loading branch information
alexmyshchyshyn authored Feb 24, 2025
2 parents 195ad5b + 50eb0cf commit e754a0a
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/rpc/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,28 +252,39 @@ export class InfoGetDeployResult {
@jsonMember({ name: 'deploy', constructor: Deploy })
deploy: Deploy;

@jsonMember({
name: 'execution_info',
constructor: DeployExecutionInfo
})
executionResults: DeployExecutionInfo;
@jsonMember({ name: 'execution_info', constructor: DeployExecutionInfo })
executionInfo?: DeployExecutionInfo;

@jsonArrayMember(DeployExecutionResult, {
name: 'execution_results'
})
// Legacy execution results V1
@jsonArrayMember(DeployExecutionResult, { name: 'execution_results' })
executionResultsV1?: DeployExecutionResult[];

rawJSON: any;

/**
* Converts the deployment result into a transaction result.
* It prefers the newer executionInfo format if available,
* otherwise falls back to legacy execution results.
*/
toInfoGetTransactionResult(): InfoGetTransactionResult {
let executionInfo: ExecutionInfo;

if (this.executionInfo) {
executionInfo = new ExecutionInfo(
this.executionInfo.blockHash,
this.executionInfo.blockHeight,
this.executionInfo.executionResult
);
} else if (this.executionResultsV1 && this.executionResultsV1.length > 0) {
executionInfo = ExecutionInfo.fromV1(this.executionResultsV1);
} else {
throw new Error('Invalid Execution Info');
}

return new InfoGetTransactionResult(
this.apiVersion,
Deploy.newTransactionFromDeploy(this.deploy),
new ExecutionInfo(
this.executionResults.blockHash,
this.executionResults.blockHeight,
this.executionResults.executionResult
),
executionInfo,
this.rawJSON
);
}
Expand Down

0 comments on commit e754a0a

Please sign in to comment.