-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Overledger New actions added (read from smart contract and sign a transaction) and modification of existing Actions (Prepare and execute transactions) - tied to issue ticket submitted to Pipedream #14228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
60944ee
9bf2aca
d192f17
29d88f5
4ff3794
2b4a1a8
ee22f40
281f0d6
9dff018
08bc1ae
6193c92
f3f62a3
c0f9c61
a149d10
a2ec749
f7a15ba
271233d
f59b702
7e639e0
1ae32d0
6ef7e41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { | ||
NETWORK_OPTIONS, TECHNOLOGY_OPTIONS, | ||
} from "../../common/constants.mjs"; | ||
import { parseObject } from "../../common/utils.mjs"; | ||
import overledger from "../../overledger.app.mjs"; | ||
|
||
export default { | ||
key: "overledger-read-from-a-smart-contract", | ||
name: "Read from a smart contract", | ||
description: "Reads data from a specified smart contract on the Overledger network.", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
overledger, | ||
philbuuza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
environment: { | ||
propDefinition: [ | ||
overledger, | ||
"environment", | ||
], | ||
}, | ||
locationTechnology: { | ||
type: "string", | ||
label: "Location Technology", | ||
description: "The technology of the blockchain that the transaction will be submitted to", | ||
options: TECHNOLOGY_OPTIONS, | ||
reloadProps: true, | ||
}, | ||
functionName: { | ||
type: "string", | ||
label: "Function Name", | ||
description: "The name of the function to call on the smart contract.", | ||
}, | ||
inputParameters: { | ||
type: "string[]", | ||
label: "Input Parameters", | ||
description: "The input parameters for the smart contract function, provide both type and value in object format. Example: {\"type\":\"uint256\",\"value\":\"5\"} or {\"type\":\"address\",\"value\":\"0x3....ed8\"}", | ||
optional: true, | ||
default: [], | ||
}, | ||
smartContractId: { | ||
type: "string", | ||
label: "Smart Contract ID", | ||
description: "The ID/address of the smart contract to interact with.", | ||
}, | ||
outputParameters: { | ||
type: "string[]", | ||
label: "Output Parameters", | ||
description: "Each output parameter expected, provide just the type in object format. Example - 1) function returns one uint256 value: {\"type\": \"uint256\"} or 2) function returns two address values: {\"type\": \"address\"},{\"type\": \"address\"}", | ||
optional: true, | ||
default: [], | ||
}, | ||
}, | ||
async additionalProps() { | ||
const props = {}; | ||
if (this.locationTechnology) { | ||
props.locationNetwork = { | ||
type: "string", | ||
label: "Location Network", | ||
description: "The blockchain network the transaction will be submitted to.", | ||
options: NETWORK_OPTIONS[this.locationTechnology], | ||
}; | ||
} | ||
return props; | ||
}, | ||
async run({ $ }) { | ||
|
||
const requestBody = { | ||
location: { | ||
technology: this.locationTechnology, | ||
network: this.locationNetwork, | ||
}, | ||
functionName: this.functionName, | ||
inputParameters: parseObject(this.inputParameters), //parse these values using the parseObject function at this shouls turn the JSON string into JSON objects to used in the request body. | ||
philbuuza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
smartContractId: this.smartContractId, | ||
outputParameters: parseObject(this.outputParameters), | ||
}; | ||
// Make the API call to Overledger | ||
const response = await this.overledger.readFromSmartContract({ | ||
$, | ||
environment: this.environment, | ||
data: requestBody, | ||
philbuuza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
$.export("$summary", `Successfully read from contract: ${this.smartContractId}`); | ||
return response; | ||
}, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import overledger from "../../overledger.app.mjs"; | ||
import { TECHNOLOGY_OPTIONS, UNIT_OPTIONS } from "../../common/constants.mjs"; | ||
Check failure on line 2 in components/overledger/actions/sign-a-transaction/sign-a-transaction.mjs
|
||
|
||
export default { | ||
key: "overledger-sign-a-transaction", | ||
name: "Sign a transaction", | ||
description: "Sign a transaction using Overledger - Part 2 of [Overledger Pattern](https://developers.quant.network/reference/overledger-pattern). [See documentation](https://developers.quant.network/reference/sandboxsigning)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
overledger, | ||
philbuuza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
environment: { | ||
propDefinition: [ | ||
overledger, | ||
"environment", | ||
], | ||
}, | ||
locationTechnology: { | ||
type: "string", | ||
label: "Location Technology", | ||
description: "The blockchain technology used for this transaction, e.g., ethereum, substrate - required in order to set the dltfee", | ||
options: TECHNOLOGY_OPTIONS, | ||
reloadProps: true, | ||
}, | ||
keyId: { | ||
type: "string", | ||
label: "Signing Account ID", | ||
description: "The ID/address of the blockchain account that will sign the transaction.", | ||
}, | ||
requestId: { | ||
type: "string", | ||
label: "Request ID", | ||
description: "The Request ID assigned to a preparation request in Overledger. This should be set to the requestId parameter found in the response object of the 'Prepare Transaction' Overledger action.", | ||
}, | ||
transactionSigningResponderName: { | ||
type: "string", | ||
label: "Transaction Signing Responder Name", | ||
description: "The name of the Transaction Signing Responder you would like to use. The CTA Transaction Signing Responder is the Quant-provided signer for testnet accounts.", | ||
}, | ||
nativeData: { | ||
type: "object", | ||
label: "Native Data", | ||
description: "An object representing the transaction required to be signed - This should be set to the nativeData object of the 'Prepare Transaction' Overledger action.", | ||
}, | ||
}, | ||
async run({ $ }) { | ||
//default values of gatewayFee and dltfee hard coded into params. | ||
const gatewayFee = { | ||
amount: "0", | ||
unit: "QNT", | ||
}; | ||
// Define DLT Fee and dynamically set the 'unit/symbol' from UNIT_OPTIONS | ||
const dltFee = { | ||
amount: "0.000019897764079968", | ||
unit: UNIT_OPTIONS[this.locationTechnology] || "ETH", // Use default if not found | ||
}; | ||
Comment on lines
+48
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider making fee amounts configurable The Consider adding these as configurable props: props: {
// ... existing props
gatewayFeeAmount: {
type: "string",
label: "Gateway Fee Amount",
description: "The amount of the gateway fee",
default: "0",
},
dltFeeAmount: {
type: "string",
label: "DLT Fee Amount",
description: "The amount of the DLT fee",
default: "0.000019897764079968",
},
}, Then update the const gatewayFee = {
amount: this.gatewayFeeAmount,
unit: "QNT",
};
const dltFee = {
amount: this.dltFeeAmount,
unit: UNIT_OPTIONS[this.locationTechnology] || "ETH",
}; This change allows users to specify custom fee amounts when needed. |
||
// Sign the transaction | ||
const requestBody = { | ||
keyId: this.keyId, | ||
gatewayFee: gatewayFee, | ||
requestId: this.requestId, | ||
dltFee: dltFee, | ||
nativeData: this.nativeData, | ||
transactionSigningResponderName: this.transactionSigningResponderName, | ||
}; | ||
|
||
const response = await this.overledger.signTransaction({ | ||
$, | ||
philbuuza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
environment: this.environment, | ||
data: requestBody, | ||
}); | ||
Comment on lines
+67
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for signTransaction call The current implementation doesn't handle potential errors from the Wrap the API call in a try-catch block: try {
const response = await this.overledger.signTransaction({
$,
environment: this.environment,
data: requestBody,
});
$.export("$summary", "Transaction signed successfully");
return response;
} catch (error) {
console.error("Error signing transaction:", error);
throw error;
} This change will log any errors and re-throw them, allowing for better error handling and debugging. |
||
$.export("$summary", "Transaction signed successfully"); | ||
return response; | ||
}, | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.