Skip to content

Commit 4ff3794

Browse files
committed
modified readfromsmart contract transaction, prepare-sign-execute transaction actions
1 parent 29d88f5 commit 4ff3794

File tree

6 files changed

+65
-33
lines changed

6 files changed

+65
-33
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export default {
1111
requestId: {
1212
type: "string",
1313
label: "Request ID",
14-
description: "The ID of the request for executing a signed transaction.",
14+
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.",
1515
},
1616
signedTransaction: {
1717
type: "string",
1818
label: "Signed Transaction",
19-
description: "The signed transaction data.",
19+
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.",
2020
optional: true,
2121
},
2222
},

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
NETWORK_OPTIONS, TECHNOLOGY_OPTIONS,
2+
NETWORK_OPTIONS, TECHNOLOGY_OPTIONS
33
} from "../../common/constants.mjs";
44
import { parseObject } from "../../common/utils.mjs";
55
import overledger from "../../overledger.app.mjs";
@@ -22,19 +22,19 @@ export default {
2222
signingAccountId: {
2323
type: "string",
2424
label: "Signing Account ID",
25-
description: "The blockchain account that will sign the transaction.",
26-
},
27-
functionName: {
28-
type: "string",
29-
label: "Function Name",
30-
description: "The name of the function to call on the smart contract.",
25+
description: "The blockchain account (address) that you will be sending this transaction",
3126
},
3227
smartContractId: {
3328
type: "string",
3429
label: "Smart Contract ID",
3530
description: "The ID/address of the smart contract to interact with.",
3631

3732
},
33+
functionName: {
34+
type: "string",
35+
label: "Function Name",
36+
description: "The name of the function to call on the smart contract.",
37+
},
3838
inputParameters: {
3939
type: "string[]",
4040
label: "Input Parameters",
@@ -55,18 +55,20 @@ export default {
5555
return props;
5656
},
5757
async run({ $ }) {
58+
const requestBody = {
59+
location: {
60+
technology: this.locationTechnology,
61+
network: this.locationNetwork,
62+
},
63+
signingAccountId: this.signingAccountId,
64+
functionName: this.functionName,
65+
smartContractId: this.smartContractId,
66+
inputParameters: parseObject(this.inputParameters),
67+
}
68+
5869
const response = await this.overledger.prepareSmartContractTransaction({
5970
$,
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-
},
71+
data: requestBody,
7072
});
7173
$.export("$summary", "Smart contract transaction prepared successfully");
7274
return response;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,12 @@ export default {
6565
smartContractId: this.smartContractId,
6666
outputParameters: parseObject(this.outputParameters),
6767
};
68-
69-
try {
7068
// Make the API call to Overledger
7169
const response = await this.overledger.readFromSmartContract({
7270
$,
7371
data: requestBody,
7472
});
7573
$.export("$summary", `Successfully read from contract: ${this.smartContractId}`);
7674
return response;
77-
} catch (error) {
78-
throw new Error(`Failed to read from smart contract: ${error.message}`);
79-
}
8075
},
8176
};

components/overledger/actions/sign-a-transaction/sign-a-transaction.mjs

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

34
export default {
45
key: "overledger-sign-smart-contract-transaction",
@@ -16,27 +17,50 @@ export default {
1617
requestId: {
1718
type: "string",
1819
label: "requestId",
19-
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.",
20+
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.",
2021
},
2122
transactionSigningResponderName: {
2223
type: "string",
23-
label: "Transaction Signing Responder",
24+
label: "Transaction Signing Responder Name",
2425
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.",
2526
},
2627
nativeData: {
2728
type: "object",
2829
label: "the transaction data required to be signed",
2930
description: "A JSON object representing the transaction required to be signed.",
3031
},
32+
locationTechnology: {
33+
type: "string",
34+
label: "Location Technology",
35+
description: "The blockchain technology used for this transaction, e.g., ethereum, substrate.",
36+
optional: true,
37+
// Reference the output of the previous step
38+
default: ({ steps }) => steps.prepare_smart_contract_transaction?.locationTechnology,
39+
},
3140
},
3241
async run({ $ }) {
42+
const gatewayFee = {
43+
amount: "100",
44+
unit: "QNT",
45+
};
46+
// Define DLT Fee and dynamically set the 'unit' from UNIT_OPTIONS
47+
const dltFee = {
48+
amount: "0.000019897764079968",
49+
unit: UNIT_OPTIONS[this.locationTechnology] || "ETH" // Use default if not found
50+
};
3351
// Sign the transaction
52+
const requestBody = {
53+
keyId: this.keyId,
54+
gatewayFee: gatewayFee,
55+
requestId: this.requestId,
56+
dltFee: dltFee,
57+
nativeData: this.nativeData,
58+
transactionSigningResponderName: this.transactionSigningResponderName,
59+
}
60+
3461
const response = await this.overledger.signTransaction({
3562
$,
36-
data: {
37-
requestId: this.requestId,
38-
nativeData: this.nativeData,
39-
},
63+
data: requestBody,
4064
});
4165
$.export("$summary", "Transaction signed successfully");
4266
return response;

components/overledger/common/constants.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,11 @@ export const NETWORK_OPTIONS = {
5050
"Sandbox",
5151
],
5252
};
53+
54+
export const UNIT_OPTIONS = {
55+
"ethereum": "ETH", // Ethereum's token symbol is ETH
56+
"substrate": "DOT", // Polkadot's token symbol is DOT
57+
"xrp ledger": "XRP", // XRP Ledger's token symbol is XRP
58+
"bitcoin": "BTC", // Bitcoin's token symbol is BTC
59+
"hyperledger fabric": "FAB", // Placeholder for Hyperledger Fabric's token symbol
60+
};

components/overledger/overledger.app.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export default {
1414
_baseUrl() {
1515
return "https://api.overledger.io";
1616
},
17+
_sanboxBaseUrl(){
18+
return "https://api.sandbox.overledger.io";
19+
},
1720
_headers() {
1821
return {
1922
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
@@ -33,23 +36,23 @@ export default {
3336
prepareSmartContractTransaction(opts = {}) {
3437
return this._makeRequest({
3538
method: "POST",
36-
baseUrl: this._baseUrl(),
39+
baseUrl: this._sanboxBaseUrl(),
3740
path: "/api/preparations/transactions/smart-contracts/write",
3841
...opts,
3942
});
4043
},
4144
readFromSmartContract(opts = {}) {
4245
return this._makeRequest({
4346
method: "POST",
44-
baseUrl: this._baseUrl(),
47+
baseUrl: this._sanboxBaseUrl(),
4548
path: "/api/smart-contracts/read",
4649
...opts,
4750
});
4851
},
4952
signTransaction(opts = {}) {
5053
return this._makeRequest({
5154
method: "POST",
52-
baseUrl: "https://api.sandbox.overledger.io",
55+
baseUrl: this._sanboxBaseUrl(),
5356
path: "/api/transaction-signing-sandbox",
5457
...opts,
5558
});

0 commit comments

Comments
 (0)