Skip to content

Commit 4625e96

Browse files
philbuuzacoderabbitai[bot]luancazarine
authored
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)
* overledger new actions added - read from smart contract and sign a transaction * Update components/overledger/actions/read-from-a-smart-contract/read-from-smart-contract.mjs Success message alteration to align with current context Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update components/overledger/actions/read-from-a-smart-contract/read-from-smart-contract.mjs inputParameters is an array of Objects so no need to parseObject Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * modified read from smart contract parameters * modified readfromsmart contract transaction, prepare-sign-execute transaction actions * modified readfromsmart contract transaction, prepare-sign-execute transaction actions * modified readfromsmart contract transaction, prepare-sign-execute transaction actions * modified readfromsmart contract transaction, prepare-sign-execute transaction actions * modified Overledger.app to add instance selection between Sandbox and Live Overledger * modified Overledger.app to add instance selection between Sandbox and Live Overledger - altered basURL in hook methods create and delete * comments added to explain actions modifications * added versioning updates to actions and overledger pckage.json. as well as component key adjustments to alin with pipedream requirements * code revisions made based on pull request review * added enironment prop to commmon sources file (base.mjs) and updated delete and creathooks to take in this param * fixed issue with sign-a-transaction default nativeData being undefined now is object * removal of default actions prop values on sign-transaction - stop error flag * tested and ammended read-from smart contract ans sign transcation to prevent failures --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Luan Cazarine <[email protected]>
1 parent 7c88114 commit 4625e96

File tree

10 files changed

+266
-35
lines changed

10 files changed

+266
-35
lines changed

components/overledger/actions/execute-signed-transaction/execute-signed-transaction.mjs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,39 @@ export default {
44
key: "overledger-execute-signed-transaction",
55
name: "Execute Signed Transaction",
66
description: "Executes a signed transaction by sending it to a blockchain node via Overledger. [See the documentation](https://developers.quant.network/reference/executesignedrequest)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
overledger,
11+
environment: {
12+
propDefinition: [
13+
overledger,
14+
"environment",
15+
],
16+
},
1117
requestId: {
1218
type: "string",
1319
label: "Request ID",
14-
description: "The ID of the request for executing a signed transaction.",
20+
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.",
1521
},
1622
signedTransaction: {
1723
type: "string",
1824
label: "Signed Transaction",
19-
description: "The signed transaction data.",
25+
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.",
2026
optional: true,
2127
},
2228
},
2329
async run({ $ }) {
30+
31+
const requestBody = {
32+
requestId: this.requestId,
33+
signedTransaction: this.signedTransaction,
34+
};
35+
2436
const response = await this.overledger.executeSignedTransaction({
2537
$,
26-
data: {
27-
requestId: this.requestId,
28-
signedTransaction: this.signedTransaction,
29-
},
38+
environment: this.environment,
39+
data: requestBody,
3040
});
3141

3242
$.export("$summary", `Successfully executed signed transaction with Request ID ${this.requestId}`);

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

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ export default {
88
key: "overledger-prepare-smart-contract-transaction",
99
name: "Prepare Smart Contract Transaction",
1010
description: "Prepares a smart contract transaction for signing on the Overledger platform. [See the documentation](https://developers.quant.network/reference/preparesmartcontractwrite)",
11-
version: "0.0.1",
11+
version: "0.0.2",
1212
type: "action",
1313
props: {
1414
overledger,
15+
environment: {
16+
propDefinition: [
17+
overledger,
18+
"environment",
19+
],
20+
},
1521
locationTechnology: {
1622
type: "string",
1723
label: "Location Technology",
@@ -22,19 +28,19 @@ export default {
2228
signingAccountId: {
2329
type: "string",
2430
label: "Signing Account ID",
25-
description: "The blockchain account that will sign the transaction.",
31+
description: "The blockchain account ID/address that will be sending this transaction",
32+
},
33+
smartContractId: {
34+
type: "string",
35+
label: "Smart Contract ID",
36+
description: "The ID/address of the smart contract to interact with.",
37+
2638
},
2739
functionName: {
2840
type: "string",
2941
label: "Function Name",
3042
description: "The name of the function to call on the smart contract.",
3143
},
32-
smartContractId: {
33-
propDefinition: [
34-
overledger,
35-
"smartContractId",
36-
],
37-
},
3844
inputParameters: {
3945
type: "string[]",
4046
label: "Input Parameters",
@@ -55,18 +61,21 @@ export default {
5561
return props;
5662
},
5763
async run({ $ }) {
64+
const requestBody = {
65+
location: {
66+
technology: this.locationTechnology,
67+
network: this.locationNetwork,
68+
},
69+
signingAccountId: this.signingAccountId,
70+
functionName: this.functionName,
71+
smartContractId: this.smartContractId,
72+
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.
73+
};
74+
5875
const response = await this.overledger.prepareSmartContractTransaction({
5976
$,
60-
data: {
61-
location: {
62-
technology: this.locationTechnology,
63-
network: this.locationNetwork,
64-
},
65-
signingAccountId: this.signingAccountId,
66-
functionName: this.functionName,
67-
smartContractId: this.smartContractId,
68-
inputParameters: this.inputParameters && parseObject(this.inputParameters),
69-
},
77+
environment: this.environment,
78+
data: requestBody,
7079
});
7180
$.export("$summary", "Smart contract transaction prepared successfully");
7281
return response;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import {
2+
NETWORK_OPTIONS, TECHNOLOGY_OPTIONS,
3+
} from "../../common/constants.mjs";
4+
import { parseObject } from "../../common/utils.mjs";
5+
import overledger from "../../overledger.app.mjs";
6+
7+
export default {
8+
key: "overledger-read-from-a-smart-contract",
9+
name: "Read from a smart contract",
10+
description: "Reads data from a specified smart contract on the Overledger network.",
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
overledger,
15+
environment: {
16+
propDefinition: [
17+
overledger,
18+
"environment",
19+
],
20+
},
21+
locationTechnology: {
22+
type: "string",
23+
label: "Location Technology",
24+
description: "The technology of the blockchain that the transaction will be submitted to",
25+
options: TECHNOLOGY_OPTIONS,
26+
reloadProps: true,
27+
},
28+
functionName: {
29+
type: "string",
30+
label: "Function Name",
31+
description: "The name of the function to call on the smart contract.",
32+
},
33+
inputParameters: {
34+
type: "string[]",
35+
label: "Input Parameters",
36+
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\"}",
37+
optional: true,
38+
default: [],
39+
},
40+
smartContractId: {
41+
type: "string",
42+
label: "Smart Contract ID",
43+
description: "The ID/address of the smart contract to interact with.",
44+
},
45+
outputParameters: {
46+
type: "string[]",
47+
label: "Output Parameters",
48+
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\"}",
49+
optional: true,
50+
default: [],
51+
},
52+
},
53+
async additionalProps() {
54+
const props = {};
55+
if (this.locationTechnology) {
56+
props.locationNetwork = {
57+
type: "string",
58+
label: "Location Network",
59+
description: "The blockchain network the transaction will be submitted to.",
60+
options: NETWORK_OPTIONS[this.locationTechnology],
61+
};
62+
}
63+
return props;
64+
},
65+
async run({ $ }) {
66+
67+
const requestBody = {
68+
location: {
69+
technology: this.locationTechnology,
70+
network: this.locationNetwork,
71+
},
72+
functionName: this.functionName,
73+
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.
74+
smartContractId: this.smartContractId,
75+
outputParameters: parseObject(this.outputParameters),
76+
};
77+
// Make the API call to Overledger
78+
const response = await this.overledger.readFromSmartContract({
79+
$,
80+
environment: this.environment,
81+
data: requestBody,
82+
});
83+
$.export("$summary", `Successfully read from contract: ${this.smartContractId}`);
84+
return response;
85+
},
86+
};
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import overledger from "../../overledger.app.mjs";
2+
import { TECHNOLOGY_OPTIONS, UNIT_OPTIONS } from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "overledger-sign-a-transaction",
6+
name: "Sign a transaction",
7+
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)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
overledger,
12+
environment: {
13+
propDefinition: [
14+
overledger,
15+
"environment",
16+
],
17+
},
18+
locationTechnology: {
19+
type: "string",
20+
label: "Location Technology",
21+
description: "The blockchain technology used for this transaction, e.g., ethereum, substrate - required in order to set the dltfee",
22+
options: TECHNOLOGY_OPTIONS,
23+
reloadProps: true,
24+
},
25+
keyId: {
26+
type: "string",
27+
label: "Signing Account ID",
28+
description: "The ID/address of the blockchain account that will sign the transaction.",
29+
},
30+
requestId: {
31+
type: "string",
32+
label: "Request ID",
33+
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.",
34+
},
35+
transactionSigningResponderName: {
36+
type: "string",
37+
label: "Transaction Signing Responder Name",
38+
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.",
39+
},
40+
nativeData: {
41+
type: "object",
42+
label: "Native Data",
43+
description: "An object representing the transaction required to be signed - This should be set to the nativeData object of the 'Prepare Transaction' Overledger action.",
44+
},
45+
},
46+
async run({ $ }) {
47+
//default values of gatewayFee and dltfee hard coded into params.
48+
const gatewayFee = {
49+
amount: "0",
50+
unit: "QNT",
51+
};
52+
// Define DLT Fee and dynamically set the 'unit/symbol' from UNIT_OPTIONS
53+
const dltFee = {
54+
amount: "0.000019897764079968",
55+
unit: UNIT_OPTIONS[this.locationTechnology] || "ETH", // Use default if not found
56+
};
57+
// Sign the transaction
58+
const requestBody = {
59+
keyId: this.keyId,
60+
gatewayFee: gatewayFee,
61+
requestId: this.requestId,
62+
dltFee: dltFee,
63+
nativeData: this.nativeData,
64+
transactionSigningResponderName: this.transactionSigningResponderName,
65+
};
66+
67+
const response = await this.overledger.signTransaction({
68+
$,
69+
environment: this.environment,
70+
data: requestBody,
71+
});
72+
$.export("$summary", "Transaction signed successfully");
73+
return response;
74+
},
75+
};

components/overledger/common/constants.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,22 @@ export const NETWORK_OPTIONS = {
5050
"Sandbox",
5151
],
5252
};
53+
//Overledger environment to be used - Test or Live
54+
export const OVERLEDGER_INSTANCE = [
55+
{
56+
label: "Sandbox",
57+
value: "sandbox",
58+
},
59+
{
60+
label: "Overledger",
61+
value: "overledger",
62+
},
63+
];
64+
///unit options to allow for the correct selection based on the location network
65+
export const UNIT_OPTIONS = {
66+
"ethereum": "ETH", // Ethereum's token symbol is ETH
67+
"substrate": "DOT", // Polkadot's token symbol is DOT
68+
"xrp ledger": "XRP", // XRP Ledger's token symbol is XRP
69+
"bitcoin": "BTC", // Bitcoin's token symbol is BTC
70+
"hyperledger fabric": "FAB", // Placeholder for Hyperledger Fabric's token symbol
71+
};

components/overledger/overledger.app.mjs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { axios } from "@pipedream/platform";
2+
import { OVERLEDGER_INSTANCE } from "./common/constants.mjs";
23

34
export default {
45
type: "app",
@@ -9,24 +10,32 @@ export default {
910
label: "Smart Contract ID",
1011
description: "The ID of the smart contract to interact with.",
1112
},
13+
environment: {
14+
type: "string",
15+
label: "Overledger Instance",
16+
description: "Select the Overledger instance to be used",
17+
options: OVERLEDGER_INSTANCE,
18+
},
1219
},
1320
methods: {
14-
_baseUrl() {
15-
return "https://api.overledger.io";
16-
},
1721
_headers() {
1822
return {
1923
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
2024
"Content-Type": "application/json",
2125
"API-Version": "3.0.0",
2226
};
2327
},
28+
_getBaseUrl(environment) { //conditional for environment url selection.
29+
return environment === "sandbox"
30+
? "https://api.sandbox.overledger.io"
31+
: "https://api.overledger.io";
32+
},
2433
_makeRequest({
25-
$ = this, path, ...otherOpts
34+
$ = this, environment, path, ...otherOpts
2635
}) {
2736
return axios($, {
2837
...otherOpts,
29-
url: this._baseUrl() + path,
38+
url: this._getBaseUrl(environment) + path,
3039
headers: this._headers(),
3140
});
3241
},
@@ -37,6 +46,20 @@ export default {
3746
...opts,
3847
});
3948
},
49+
readFromSmartContract(opts = {}) {
50+
return this._makeRequest({
51+
method: "POST",
52+
path: "/api/smart-contracts/read",
53+
...opts,
54+
});
55+
},
56+
signTransaction(opts = {}) {
57+
return this._makeRequest({
58+
method: "POST",
59+
path: "/api/transaction-signing-sandbox",
60+
...opts,
61+
});
62+
},
4063
executeSignedTransaction(opts = {}) {
4164
return this._makeRequest({
4265
method: "POST",
@@ -54,11 +77,12 @@ export default {
5477
});
5578
},
5679
deleteHook({
57-
path, webhookId,
80+
path, webhookId, ...opts
5881
}) {
5982
return this._makeRequest({
6083
method: "DELETE",
6184
path: `/api/webhooks/${path}/${webhookId}`,
85+
...opts,
6286
});
6387
},
6488
},

components/overledger/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/overledger",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream Overledger Components",
55
"main": "overledger.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)