Skip to content
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

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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
60944ee
overledger new actions added - read from smart contract and sign a tr…
philbuuza Oct 6, 2024
9bf2aca
Update components/overledger/actions/read-from-a-smart-contract/read-…
philbuuza Oct 7, 2024
d192f17
Update components/overledger/actions/read-from-a-smart-contract/read-…
philbuuza Oct 7, 2024
29d88f5
modified read from smart contract parameters
philbuuza Oct 7, 2024
4ff3794
modified readfromsmart contract transaction, prepare-sign-execute tra…
philbuuza Oct 8, 2024
2b4a1a8
modified readfromsmart contract transaction, prepare-sign-execute tra…
philbuuza Oct 8, 2024
ee22f40
modified readfromsmart contract transaction, prepare-sign-execute tra…
philbuuza Oct 8, 2024
281f0d6
modified readfromsmart contract transaction, prepare-sign-execute tra…
philbuuza Oct 8, 2024
9dff018
modified Overledger.app to add instance selection between Sandbox and…
philbuuza Oct 8, 2024
08bc1ae
modified Overledger.app to add instance selection between Sandbox and…
philbuuza Oct 8, 2024
6193c92
comments added to explain actions modifications
philbuuza Oct 8, 2024
f3f62a3
Merge branch 'master' into master
luancazarine Oct 8, 2024
c0f9c61
Merge branch 'master' into master
luancazarine Oct 8, 2024
a149d10
Merge branch 'master' into master
philbuuza Oct 9, 2024
a2ec749
added versioning updates to actions and overledger pckage.json. as w…
philbuuza Oct 9, 2024
f7a15ba
code revisions made based on pull request review
philbuuza Oct 10, 2024
271233d
added enironment prop to commmon sources file (base.mjs) and updated …
philbuuza Oct 11, 2024
f59b702
Merge branch 'master' into master
philbuuza Oct 14, 2024
7e639e0
fixed issue with sign-a-transaction default nativeData being undefine…
philbuuza Oct 15, 2024
1ae32d0
removal of default actions prop values on sign-transaction - stop err…
philbuuza Oct 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export default {
requestId: {
type: "string",
label: "Request ID",
description: "The ID of the request for executing a signed transaction.",
description: "The Overledger identifier assigned to the related transaction preparation request. This should be set to the requestId parameter found in the response object of the 'Prepare a Smart Contract Transaction' Overledger action.",
},
signedTransaction: {
type: "string",
label: "Signed Transaction",
description: "The signed transaction data.",
description: "The raw transaction bytecode after signing. This should be set to the signed parameter found in the response object of the 'Sign a Transaction' Overledger action.",
optional: true,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ export default {
signingAccountId: {
type: "string",
label: "Signing Account ID",
description: "The blockchain account that will sign the transaction.",
description: "The blockchain account (address) that you will be sending this transaction",
},
smartContractId: {
type: "string",
label: "Smart Contract ID",
description: "The ID/address of the smart contract to interact with.",

},
functionName: {
type: "string",
label: "Function Name",
description: "The name of the function to call on the smart contract.",
},
smartContractId: {
propDefinition: [
overledger,
"smartContractId",
],
},
inputParameters: {
type: "string[]",
label: "Input Parameters",
Expand All @@ -55,18 +55,20 @@ export default {
return props;
},
async run({ $ }) {
const requestBody = {
location: {
technology: this.locationTechnology,
network: this.locationNetwork,
},
signingAccountId: this.signingAccountId,
functionName: this.functionName,
smartContractId: this.smartContractId,
inputParameters: parseObject(this.inputParameters),
};

const response = await this.overledger.prepareSmartContractTransaction({
$,
data: {
location: {
technology: this.locationTechnology,
network: this.locationNetwork,
},
signingAccountId: this.signingAccountId,
functionName: this.functionName,
smartContractId: this.smartContractId,
inputParameters: this.inputParameters && parseObject(this.inputParameters),
},
data: requestBody,
});
$.export("$summary", "Smart contract transaction prepared successfully");
return response;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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-smart-contract",
name: "Read from Smart Contract",
description: "Reads data from a specified smart contract on the Overledger network.",
version: "0.0.1",
type: "action",
props: {
overledger,
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 - Stringified Objects",
description: "The input parameters for the smart contract function, in JSON string format. Example: `['{\"type\":\"string\",\"value\":\"param1\"}', '{\"type\":\"uint256\",\"value\":\"param2\"}']`",
optional: true,
},
luancazarine marked this conversation as resolved.
Show resolved Hide resolved
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: "The type of output parameter required e.g., address, string",
},
},
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),
smartContractId: this.smartContractId,
outputParameters: parseObject(this.outputParameters),
};
// Make the API call to Overledger
const response = await this.overledger.readFromSmartContract({
$,
data: requestBody,
});
luancazarine 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,72 @@
import overledger from "../../overledger.app.mjs";
import { UNIT_OPTIONS } from "../../common/constants.mjs";

export default {
key: "overledger-sign-smart-contract-transaction",
name: "Sign Smart Contract Transaction",
description: "Sign and send a transaction to a smart contract using Overledger",
version: "0.0.1",
type: "action",
props: {
overledger,
philbuuza marked this conversation as resolved.
Show resolved Hide resolved
keyId: {
type: "string",
label: "Signing Account ID",
description: "The blockchain account that will sign the transaction.",
},
requestId: {
type: "string",
label: "requestId",
description: "The ID assigned to a preparation request in Overledger. This should be set to the requestId parameter found in the response object of the 'Prepare Smart Contract 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: "A JSON object representing the transaction required to be signed.",
optional: true,
// Reference the output of the previous step
default: ({ steps }) => steps.prepare_smart_contract_transaction?.nativeData,
},
},
locationTechnology: {
type: "string",
label: "Location Technology",
description: "The blockchain technology used for this transaction, e.g., ethereum, substrate.",
optional: true,
// Reference the output of the previous step
default: ({ steps }) => steps.prepare_smart_contract_transaction?.locationTechnology,
},
luancazarine marked this conversation as resolved.
Show resolved Hide resolved
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 +46 to +54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider making fee amounts configurable

The gatewayFee and dltFee amounts are currently hardcoded. This may limit flexibility, especially if fee structures change or differ across networks and environments.

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 run method to use these props:

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
data: requestBody,
});
$.export("$summary", "Transaction signed successfully");
return response;
},
};
8 changes: 8 additions & 0 deletions components/overledger/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ export const NETWORK_OPTIONS = {
"Sandbox",
],
};
///unit options to allow for the correct selection based on the location network
export const UNIT_OPTIONS = {
"ethereum": "ETH", // Ethereum's token symbol is ETH
"substrate": "DOT", // Polkadot's token symbol is DOT
"xrp ledger": "XRP", // XRP Ledger's token symbol is XRP
"bitcoin": "BTC", // Bitcoin's token symbol is BTC
"hyperledger fabric": "FAB", // Placeholder for Hyperledger Fabric's token symbol
};
50 changes: 45 additions & 5 deletions components/overledger/overledger.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ import { axios } from "@pipedream/platform";
export default {
type: "app",
app: "overledger",
props: { //Options to allow for instance selection of Overledger environment - Sanbox or Live Overledger ro determine BaseURL
environment: {
type: "string",
label: "Overledger Instance",
description: "Select the Overledger environment.",
options: [
{
label: "Sandbox",
value: "sandbox",
},
{
label: "Overledger",
value: "overledger",
},
],
philbuuza marked this conversation as resolved.
Show resolved Hide resolved
optional: false,
},
},
propDefinitions: {
smartContractId: {
type: "string",
Expand All @@ -11,35 +29,55 @@ export default {
},
},
methods: {
_baseUrl() {
return "https://api.overledger.io";
},
_headers() {
return {
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
"Content-Type": "application/json",
"API-Version": "3.0.0",
};
},
_getBaseUrl() { //conditional to for environment selection.
return this.environment === "sandbox"
? "https://api.sandbox.overledger.io"
: "https://api.overledger.io";
},
_makeRequest({
$ = this, path, ...otherOpts
$ = this, baseUrl, path, ...otherOpts
philbuuza marked this conversation as resolved.
Show resolved Hide resolved
}) {
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
url: baseUrl + path,
luancazarine marked this conversation as resolved.
Show resolved Hide resolved
philbuuza marked this conversation as resolved.
Show resolved Hide resolved
headers: this._headers(),
});
},
prepareSmartContractTransaction(opts = {}) {
return this._makeRequest({
method: "POST",
baseUrl: this._getBaseUrl(),
philbuuza marked this conversation as resolved.
Show resolved Hide resolved
path: "/api/preparations/transactions/smart-contracts/write",
...opts,
});
},
readFromSmartContract(opts = {}) {
return this._makeRequest({
method: "POST",
baseUrl: this._getBaseUrl(),
philbuuza marked this conversation as resolved.
Show resolved Hide resolved
path: "/api/smart-contracts/read",
...opts,
});
},
signTransaction(opts = {}) {
return this._makeRequest({
method: "POST",
baseUrl: this._getBaseUrl(),
philbuuza marked this conversation as resolved.
Show resolved Hide resolved
path: "/api/transaction-signing-sandbox",
...opts,
});
},
executeSignedTransaction(opts = {}) {
return this._makeRequest({
method: "POST",
baseUrl: this._getBaseUrl(),
philbuuza marked this conversation as resolved.
Show resolved Hide resolved
path: "/api/executions/transactions",
...opts,
});
Expand All @@ -49,6 +87,7 @@ export default {
}) {
return this._makeRequest({
method: "POST",
baseUrl: this._baseUrl(),
philbuuza marked this conversation as resolved.
Show resolved Hide resolved
path: `/api/webhooks/${path}`,
...opts,
});
Expand All @@ -58,6 +97,7 @@ export default {
}) {
return this._makeRequest({
method: "DELETE",
baseUrl: this._baseUrl(),
path: `/api/webhooks/${path}/${webhookId}`,
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {
};
},
getSummary(body) {
return `New asccount event with transaction Id: ${body.transactionId}`;
return `New account event with transaction Id: ${body.transactionId}`;
},
},
sampleEmit,
Expand Down