@pipedream/overledger 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ import overledger from "../../overledger.app.mjs";
2
+
3
+ export default {
4
+ key: "overledger-execute-signed-transaction",
5
+ name: "Execute Signed Transaction",
6
+ 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",
8
+ type: "action",
9
+ props: {
10
+ overledger,
11
+ requestId: {
12
+ type: "string",
13
+ label: "Request ID",
14
+ description: "The ID of the request for executing a signed transaction.",
15
+ },
16
+ signedTransaction: {
17
+ type: "string",
18
+ label: "Signed Transaction",
19
+ description: "The signed transaction data.",
20
+ optional: true,
21
+ },
22
+ },
23
+ async run({ $ }) {
24
+ const response = await this.overledger.executeSignedTransaction({
25
+ $,
26
+ data: {
27
+ requestId: this.requestId,
28
+ signedTransaction: this.signedTransaction,
29
+ },
30
+ });
31
+
32
+ $.export("$summary", `Successfully executed signed transaction with Request ID ${this.requestId}`);
33
+ return response;
34
+ },
35
+ };
@@ -0,0 +1,74 @@
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-prepare-smart-contract-transaction",
9
+ name: "Prepare Smart Contract Transaction",
10
+ 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",
12
+ type: "action",
13
+ props: {
14
+ overledger,
15
+ locationTechnology: {
16
+ type: "string",
17
+ label: "Location Technology",
18
+ description: "The technology of the blockchain that the transaction will be submitted to",
19
+ options: TECHNOLOGY_OPTIONS,
20
+ reloadProps: true,
21
+ },
22
+ signingAccountId: {
23
+ type: "string",
24
+ 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.",
31
+ },
32
+ smartContractId: {
33
+ propDefinition: [
34
+ overledger,
35
+ "smartContractId",
36
+ ],
37
+ },
38
+ inputParameters: {
39
+ type: "string[]",
40
+ label: "Input Parameters",
41
+ description: "The input parameters for the smart contract function, in JSON format.",
42
+ optional: true,
43
+ },
44
+ },
45
+ async additionalProps() {
46
+ const props = {};
47
+ if (this.locationTechnology) {
48
+ props.locationNetwork = {
49
+ type: "string",
50
+ label: "Location Network",
51
+ description: "The blockchain network the transaction will be submitted to.",
52
+ options: NETWORK_OPTIONS[this.locationTechnology],
53
+ };
54
+ }
55
+ return props;
56
+ },
57
+ async run({ $ }) {
58
+ const response = await this.overledger.prepareSmartContractTransaction({
59
+ $,
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
+ },
70
+ });
71
+ $.export("$summary", "Smart contract transaction prepared successfully");
72
+ return response;
73
+ },
74
+ };
@@ -0,0 +1,52 @@
1
+ export const TECHNOLOGY_OPTIONS = [
2
+ {
3
+ label: "Ethereum",
4
+ value: "ethereum",
5
+ },
6
+ {
7
+ label: "Substrate",
8
+ value: "substrate",
9
+ },
10
+ {
11
+ label: "XRP Ledger",
12
+ value: "xrp ledger",
13
+ },
14
+ {
15
+ label: "Bitcoin",
16
+ value: "bitcoin",
17
+ },
18
+ {
19
+ label: "Hyperledger Fabric",
20
+ value: "hyperledger fabric",
21
+ },
22
+ ];
23
+
24
+ export const NETWORK_OPTIONS = {
25
+ "ethereum": [
26
+ "ethereum sepolia testnet",
27
+ "ethereum goerli testnet",
28
+ "ethereum mainnet",
29
+ "polygon mumbai testnet",
30
+ "polygon mainnet",
31
+ "avalanche fuji testnet",
32
+ "avalanche c-chain mainnet",
33
+ "xdc apothem testnet",
34
+ "xdc network mainnet",
35
+ "Defined on demand",
36
+ ],
37
+ "substrate": [
38
+ "polkadot westend",
39
+ "polkadot mainnet",
40
+ ],
41
+ "xrp ledger": [
42
+ "testnet",
43
+ "mainnet",
44
+ ],
45
+ "bitcoin": [
46
+ "testnet",
47
+ "mainnet",
48
+ ],
49
+ "hyperledger fabric": [
50
+ "Sandbox",
51
+ ],
52
+ };
@@ -0,0 +1,18 @@
1
+ export const parseObject = (obj) => {
2
+ if (Array.isArray(obj)) {
3
+ return obj.map((item) => {
4
+ if (typeof item === "string") {
5
+ try {
6
+ return JSON.parse(item);
7
+ } catch (e) {
8
+ return item;
9
+ }
10
+ }
11
+ return item;
12
+ });
13
+ }
14
+ if (typeof obj === "string") {
15
+ return JSON.parse(obj);
16
+ }
17
+ return obj;
18
+ };
@@ -1,11 +1,65 @@
1
+ import { axios } from "@pipedream/platform";
2
+
1
3
  export default {
2
4
  type: "app",
3
5
  app: "overledger",
4
- propDefinitions: {},
6
+ propDefinitions: {
7
+ smartContractId: {
8
+ type: "string",
9
+ label: "Smart Contract ID",
10
+ description: "The ID of the smart contract to interact with.",
11
+ },
12
+ },
5
13
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
14
+ _baseUrl() {
15
+ return "https://api.overledger.io";
16
+ },
17
+ _headers() {
18
+ return {
19
+ "Authorization": `Bearer ${this.$auth.oauth_access_token}`,
20
+ "Content-Type": "application/json",
21
+ "API-Version": "3.0.0",
22
+ };
23
+ },
24
+ _makeRequest({
25
+ $ = this, path, ...otherOpts
26
+ }) {
27
+ return axios($, {
28
+ ...otherOpts,
29
+ url: this._baseUrl() + path,
30
+ headers: this._headers(),
31
+ });
32
+ },
33
+ prepareSmartContractTransaction(opts = {}) {
34
+ return this._makeRequest({
35
+ method: "POST",
36
+ path: "/api/preparations/transactions/smart-contracts/write",
37
+ ...opts,
38
+ });
39
+ },
40
+ executeSignedTransaction(opts = {}) {
41
+ return this._makeRequest({
42
+ method: "POST",
43
+ path: "/api/executions/transactions",
44
+ ...opts,
45
+ });
46
+ },
47
+ createHook({
48
+ path, ...opts
49
+ }) {
50
+ return this._makeRequest({
51
+ method: "POST",
52
+ path: `/api/webhooks/${path}`,
53
+ ...opts,
54
+ });
55
+ },
56
+ deleteHook({
57
+ path, webhookId,
58
+ }) {
59
+ return this._makeRequest({
60
+ method: "DELETE",
61
+ path: `/api/webhooks/${path}/${webhookId}`,
62
+ });
9
63
  },
10
64
  },
11
- };
65
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/overledger",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Overledger Components",
5
5
  "main": "overledger.app.mjs",
6
6
  "keywords": [
@@ -11,5 +11,8 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "publishConfig": {
13
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^1.5.1"
14
17
  }
15
18
  }
@@ -0,0 +1,66 @@
1
+ import {
2
+ NETWORK_OPTIONS, TECHNOLOGY_OPTIONS,
3
+ } from "../../common/constants.mjs";
4
+ import overledger from "../../overledger.app.mjs";
5
+
6
+ export default {
7
+ props: {
8
+ overledger,
9
+ db: "$.service.db",
10
+ http: {
11
+ type: "$.interface.http",
12
+ customResponse: true,
13
+ },
14
+ locationTechnology: {
15
+ type: "string",
16
+ label: "Location Technology",
17
+ description: "The technology of the blockchain that the transaction will be submitted to",
18
+ options: TECHNOLOGY_OPTIONS,
19
+ reloadProps: true,
20
+ },
21
+ },
22
+ async additionalProps() {
23
+ const props = {};
24
+ if (this.locationTechnology) {
25
+ props.locationNetwork = {
26
+ type: "string",
27
+ label: "Location Network",
28
+ description: "The blockchain network the transaction will be submitted to.",
29
+ options: NETWORK_OPTIONS[this.locationTechnology],
30
+ };
31
+ }
32
+ return props;
33
+ },
34
+ hooks: {
35
+ async activate() {
36
+ const response = await this.overledger.createHook({
37
+ path: this.getPath(),
38
+ data: {
39
+ location: {
40
+ technology: this.locationTechnology,
41
+ network: this.locationNetwork,
42
+ },
43
+ callbackUrl: this.http.endpoint,
44
+ ...this.additionalData(),
45
+ },
46
+ });
47
+ this.db.set("webhookId", response.webhookId);
48
+ },
49
+ async deactivate() {
50
+ const webhookId = this.db.get("webhookId");
51
+ await this.overledger.deleteHook({
52
+ path: this.getPath(),
53
+ webhookId,
54
+ });
55
+ },
56
+ },
57
+ async run(event) {
58
+ const { body } = event;
59
+
60
+ this.$emit(body, {
61
+ id: body.transactionId || body?.smartContractEventUpdateDetails?.nativeData?.transactionHash,
62
+ summary: this.getSummary(body),
63
+ ts: Date.now(),
64
+ });
65
+ },
66
+ };
@@ -0,0 +1,35 @@
1
+ import common from "../common/base.mjs";
2
+ import sampleEmit from "./test-event.mjs";
3
+
4
+ export default {
5
+ ...common,
6
+ key: "overledger-new-contract-event-instant",
7
+ name: "New Smart Contract Event (Instant)",
8
+ description: "Emit new event when a smart contract releases a new event.",
9
+ version: "0.0.1",
10
+ type: "source",
11
+ dedupe: "unique",
12
+ props: {
13
+ ...common.props,
14
+ smartContractId: {
15
+ propDefinition: [
16
+ common.props.overledger,
17
+ "smartContractId",
18
+ ],
19
+ },
20
+ },
21
+ methods: {
22
+ getPath() {
23
+ return "smart-contract-events";
24
+ },
25
+ additionalData() {
26
+ return {
27
+ smartContractId: this.smartContractId,
28
+ };
29
+ },
30
+ getSummary(body) {
31
+ return `New contract event with transaction Hash: ${body?.smartContractEventUpdateDetails?.nativeData?.transactionHash}`;
32
+ },
33
+ },
34
+ sampleEmit,
35
+ };
@@ -0,0 +1,24 @@
1
+ export default {
2
+ "type": "smartContractEvent",
3
+ "webhookId": "6c964253-4b10-43a5-a812-9b30e92275a3",
4
+ "location": {
5
+ "technology": "ethereum",
6
+ "network": "polygon mumbai testnet"
7
+ },
8
+ "smartContractEventUpdateDetails": {
9
+ "smartContractId": "0x8590d37d55049de2555f0f9541325e7fe6b19b17",
10
+ "nativeData": {
11
+ "removed": false,
12
+ "logIndex": 0,
13
+ "transactionIndex": 0,
14
+ "transactionHash": "0xde2bbf9704d726ff395eb78217e9acb226b0ecb0b609021cccd7e67d99763db2",
15
+ "blockHash": "0x6d1a13d15fd0a90f361d3e368830bbe45c628382c4533d10f1a23ae699c781cc",
16
+ "blockNumber": "0x28b2471",
17
+ "address": "0x8590d37d55049de2555f0f9541325e7fe6b19b17",
18
+ "data": "0x0000000000000000000000001789d90438333751fdcca0d03d8952168b99ef02",
19
+ "topics": [
20
+ "0x2d1801d4e6df986759c8582affebc974bcf0cacfd5d2ab120eb776efa53dffa2"
21
+ ]
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,10 @@
1
+ export default {
2
+ "type": "account",
3
+ "webhookId": "20f6ce08-04b4-4ce4-94eb-e2304a0737af",
4
+ "accountId": "0x282f70d5af34aedaac479b12a08e189bbee83066",
5
+ "location": {
6
+ "technology": "ethereum",
7
+ "network": "polygon mumbai testnet"
8
+ },
9
+ "transactionId": "0xd65c16e476a5ad5fa89ffe14512bd7984e575a4370ac86ccfb88202da20f9262"
10
+ }
@@ -0,0 +1,34 @@
1
+ import common from "../common/base.mjs";
2
+ import sampleEmit from "./test-event.mjs";
3
+
4
+ export default {
5
+ ...common,
6
+ key: "overledger-watch-new-account-event-instant",
7
+ name: "New Account Event (Instant)",
8
+ description: "Emit new event for transactions to/from a specific account.",
9
+ version: "0.0.1",
10
+ type: "source",
11
+ dedupe: "unique",
12
+ props: {
13
+ ...common.props,
14
+ accountId: {
15
+ type: "string",
16
+ label: "Account Id",
17
+ description: "The blockchain account that will be monitored for transaction updates.",
18
+ },
19
+ },
20
+ methods: {
21
+ getPath() {
22
+ return "accounts";
23
+ },
24
+ additionalData() {
25
+ return {
26
+ accountId: this.accountId,
27
+ };
28
+ },
29
+ getSummary(body) {
30
+ return `New asccount event with transaction Id: ${body.transactionId}`;
31
+ },
32
+ },
33
+ sampleEmit,
34
+ };