Skip to content

Commit 29d88f5

Browse files
committed
modified read from smart contract parameters
1 parent d192f17 commit 29d88f5

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

components/overledger/actions/prepare-smart-contract-transaction/prepare-smart-contract-transaction.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export default {
3030
description: "The name of the function to call on the smart contract.",
3131
},
3232
smartContractId: {
33-
propDefinition: [
34-
overledger,
35-
"smartContractId",
36-
],
33+
type: "string",
34+
label: "Smart Contract ID",
35+
description: "The ID/address of the smart contract to interact with.",
36+
3737
},
3838
inputParameters: {
3939
type: "string[]",

components/overledger/actions/read-from-a-smart-contract/read-from-smart-contract.mjs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@ export default {
2424
label: "Function Name",
2525
description: "The name of the function to call on the smart contract.",
2626
},
27-
inptParameters: {
27+
inputParameters: {
2828
type: "string[]",
29-
label: "Input Parameters",
30-
description: "The input parameters for the smart contract function, in JSON format.",
29+
label: "Input Parameters - Stringified Objects",
30+
description: "The input parameters for the smart contract function, in JSON string format. Example: `['{\"type\":\"string\",\"value\":\"param1\"}', '{\"type\":\"uint256\",\"value\":\"param2\"}']`",
3131
optional: true,
3232
},
3333
smartContractId: {
34-
propDefinition: [
35-
overledger,
36-
"smartContractId",
37-
],
34+
type: "string",
35+
label: "Smart Contract ID",
36+
description: "The ID/address of the smart contract to interact with.",
37+
},
38+
outputParameters: {
39+
type: "string[]",
40+
label: "Output Parameters",
41+
description: "The type of output parameter required e.g., address, string",
3842
},
3943
},
4044
async additionalProps() {
@@ -50,20 +54,28 @@ export default {
5054
return props;
5155
},
5256
async run({ $ }) {
53-
const response = await this.overledger.readFromSmartContract({
54-
$,
55-
data: {
56-
location: {
57-
technology: this.locationTechnology,
58-
network: this.locationNetwork,
59-
},
60-
functionName: this.functionName,
61-
smartContractId: this.smartContractId,
62-
inputParameters: this.inputParameters,
57+
58+
const requestBody = {
59+
location: {
60+
technology: this.locationTechnology,
61+
network: this.locationNetwork,
6362
},
64-
});
63+
functionName: this.functionName,
64+
inputParameters: parseObject(this.inputParameters),
65+
smartContractId: this.smartContractId,
66+
outputParameters: parseObject(this.outputParameters),
67+
};
6568

66-
$.export("$summary", `Successfully read from contract: ${this.smartContractId}`);
67-
return response;
69+
try {
70+
// Make the API call to Overledger
71+
const response = await this.overledger.readFromSmartContract({
72+
$,
73+
data: requestBody,
74+
});
75+
$.export("$summary", `Successfully read from contract: ${this.smartContractId}`);
76+
return response;
77+
} catch (error) {
78+
throw new Error(`Failed to read from smart contract: ${error.message}`);
79+
}
6880
},
6981
};

0 commit comments

Comments
 (0)