@trufnetwork/sdk-js 0.2.4 → 0.3.1
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.
- package/README.md +85 -12
- package/dist/cjs/client/client.cjs +41 -32
- package/dist/cjs/client/client.cjs.map +2 -2
- package/dist/cjs/client/getLastTransactions.cjs +85 -0
- package/dist/cjs/client/getLastTransactions.cjs.map +7 -0
- package/dist/cjs/client/listStreams.cjs +46 -0
- package/dist/cjs/client/listStreams.cjs.map +7 -0
- package/dist/cjs/contracts-api/{stream.cjs → action.cjs} +121 -163
- package/dist/cjs/contracts-api/action.cjs.map +7 -0
- package/dist/cjs/contracts-api/composedAction.cjs +183 -0
- package/dist/cjs/contracts-api/composedAction.cjs.map +7 -0
- package/dist/cjs/contracts-api/{destroyStream.cjs → deleteStream.cjs} +16 -16
- package/dist/cjs/contracts-api/deleteStream.cjs.map +7 -0
- package/dist/cjs/contracts-api/deployStream.cjs +33 -16
- package/dist/cjs/contracts-api/deployStream.cjs.map +3 -3
- package/dist/cjs/contracts-api/primitiveAction.cjs +92 -0
- package/dist/cjs/contracts-api/primitiveAction.cjs.map +7 -0
- package/dist/cjs/index.common.cjs +6 -6
- package/dist/cjs/index.common.cjs.map +1 -1
- package/dist/cjs/types/transaction.cjs +19 -0
- package/dist/cjs/types/transaction.cjs.map +7 -0
- package/dist/cjs/util/EthereumAddress.cjs +0 -1
- package/dist/cjs/util/EthereumAddress.cjs.map +2 -2
- package/dist/cjs/util/StreamId.cjs +7 -2
- package/dist/cjs/util/StreamId.cjs.map +2 -2
- package/dist/esm/client/client.mjs +41 -32
- package/dist/esm/client/client.mjs.map +2 -2
- package/dist/esm/client/getLastTransactions.mjs +64 -0
- package/dist/esm/client/getLastTransactions.mjs.map +7 -0
- package/dist/esm/client/listStreams.mjs +25 -0
- package/dist/esm/client/listStreams.mjs.map +7 -0
- package/dist/esm/contracts-api/{stream.mjs → action.mjs} +118 -160
- package/dist/esm/contracts-api/action.mjs.map +7 -0
- package/dist/esm/contracts-api/composedAction.mjs +156 -0
- package/dist/esm/contracts-api/composedAction.mjs.map +7 -0
- package/dist/esm/contracts-api/deleteStream.mjs +24 -0
- package/dist/esm/contracts-api/deleteStream.mjs.map +7 -0
- package/dist/esm/contracts-api/deployStream.mjs +23 -21
- package/dist/esm/contracts-api/deployStream.mjs.map +2 -2
- package/dist/esm/contracts-api/primitiveAction.mjs +71 -0
- package/dist/esm/contracts-api/primitiveAction.mjs.map +7 -0
- package/dist/esm/index.common.mjs +6 -6
- package/dist/esm/index.common.mjs.map +1 -1
- package/dist/esm/types/transaction.mjs +1 -0
- package/dist/esm/types/transaction.mjs.map +7 -0
- package/dist/esm/util/EthereumAddress.mjs +0 -1
- package/dist/esm/util/EthereumAddress.mjs.map +2 -2
- package/dist/esm/util/StreamId.mjs +7 -2
- package/dist/esm/util/StreamId.mjs.map +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/client/client.d.ts +38 -15
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/getLastTransactions.d.ts +5 -0
- package/dist/types/client/getLastTransactions.d.ts.map +1 -0
- package/dist/types/client/listStreams.d.ts +12 -0
- package/dist/types/client/listStreams.d.ts.map +1 -0
- package/dist/types/contracts-api/{stream.d.ts → action.d.ts} +35 -54
- package/dist/types/contracts-api/action.d.ts.map +1 -0
- package/dist/types/contracts-api/{composedStream.d.ts → composedAction.d.ts} +11 -22
- package/dist/types/contracts-api/composedAction.d.ts.map +1 -0
- package/dist/types/contracts-api/{destroyStream.d.ts → deleteStream.d.ts} +7 -7
- package/dist/types/contracts-api/deleteStream.d.ts.map +1 -0
- package/dist/types/contracts-api/deployStream.d.ts +2 -2
- package/dist/types/contracts-api/deployStream.d.ts.map +1 -1
- package/dist/types/contracts-api/primitiveAction.d.ts +33 -0
- package/dist/types/contracts-api/primitiveAction.d.ts.map +1 -0
- package/dist/types/index.common.d.ts +7 -7
- package/dist/types/types/transaction.d.ts +13 -0
- package/dist/types/types/transaction.d.ts.map +1 -0
- package/dist/types/util/EthereumAddress.d.ts.map +1 -1
- package/dist/types/util/StreamId.d.ts +2 -0
- package/dist/types/util/StreamId.d.ts.map +1 -1
- package/package.json +10 -6
- package/dist/cjs/client/listAllStreams.cjs +0 -51
- package/dist/cjs/client/listAllStreams.cjs.map +0 -7
- package/dist/cjs/contracts/composed_stream_template.json +0 -1638
- package/dist/cjs/contracts/composed_stream_template_unix.json +0 -2122
- package/dist/cjs/contracts/contractsContent.cjs +0 -65
- package/dist/cjs/contracts/contractsContent.cjs.map +0 -7
- package/dist/cjs/contracts/primitive_stream_template.json +0 -952
- package/dist/cjs/contracts/primitive_stream_template_unix.json +0 -1173
- package/dist/cjs/contracts-api/composedStream.cjs +0 -137
- package/dist/cjs/contracts-api/composedStream.cjs.map +0 -7
- package/dist/cjs/contracts-api/destroyStream.cjs.map +0 -7
- package/dist/cjs/contracts-api/primitiveStream.cjs +0 -86
- package/dist/cjs/contracts-api/primitiveStream.cjs.map +0 -7
- package/dist/cjs/contracts-api/stream.cjs.map +0 -7
- package/dist/esm/client/listAllStreams.mjs +0 -30
- package/dist/esm/client/listAllStreams.mjs.map +0 -7
- package/dist/esm/contracts/composed_stream_template.json +0 -1638
- package/dist/esm/contracts/composed_stream_template_unix.json +0 -2122
- package/dist/esm/contracts/contractsContent.mjs +0 -33
- package/dist/esm/contracts/contractsContent.mjs.map +0 -7
- package/dist/esm/contracts/primitive_stream_template.json +0 -952
- package/dist/esm/contracts/primitive_stream_template_unix.json +0 -1173
- package/dist/esm/contracts-api/composedStream.mjs +0 -116
- package/dist/esm/contracts-api/composedStream.mjs.map +0 -7
- package/dist/esm/contracts-api/destroyStream.mjs +0 -24
- package/dist/esm/contracts-api/destroyStream.mjs.map +0 -7
- package/dist/esm/contracts-api/primitiveStream.mjs +0 -65
- package/dist/esm/contracts-api/primitiveStream.mjs.map +0 -7
- package/dist/esm/contracts-api/stream.mjs.map +0 -7
- package/dist/types/client/listAllStreams.d.ts +0 -14
- package/dist/types/client/listAllStreams.d.ts.map +0 -1
- package/dist/types/contracts/contractsContent.d.ts +0 -6
- package/dist/types/contracts/contractsContent.d.ts.map +0 -1
- package/dist/types/contracts-api/composedStream.d.ts.map +0 -1
- package/dist/types/contracts-api/destroyStream.d.ts.map +0 -1
- package/dist/types/contracts-api/primitiveStream.d.ts +0 -39
- package/dist/types/contracts-api/primitiveStream.d.ts.map +0 -1
- package/dist/types/contracts-api/stream.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ The TN SDK provides developers with tools to interact with the Truf Network, a d
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
7
7
|
### Prerequisites
|
|
8
|
-
- Node.js 18 or later
|
|
8
|
+
- Node.js 18 or later (For enabling Explorer-related features, please use Node.js 18)
|
|
9
9
|
|
|
10
10
|
### Installation
|
|
11
11
|
```bash
|
|
@@ -46,23 +46,54 @@ const client = new NodeTNClient({
|
|
|
46
46
|
const streamId = await StreamId.generate("my-data-stream");
|
|
47
47
|
await client.deployStream(streamId, "primitive", true);
|
|
48
48
|
|
|
49
|
-
const stream = client.
|
|
50
|
-
streamId,
|
|
51
|
-
dataProvider: client.address(),
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// here simplified, you might need to wait for the tx using client.waitForTx
|
|
55
|
-
await stream.initializeStream();
|
|
49
|
+
const stream = client.loadPrimitiveAction();
|
|
56
50
|
|
|
57
51
|
// Insert data, simplified
|
|
58
52
|
await stream.insertRecords([
|
|
59
|
-
{
|
|
53
|
+
{ stream: client.ownStreamLocator(streamId), eventTime: new Date("2024-01-01").getTime() / 1000, value: "100.5" }
|
|
60
54
|
]);
|
|
61
55
|
|
|
62
56
|
// Read data
|
|
63
57
|
const data = await stream.getRecord({
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
stream: client.ownStreamLocator(streamId),
|
|
59
|
+
from: new Date("2024-01-01").getTime() / 1000,
|
|
60
|
+
to: new Date("2024-01-02").getTime() / 1000,
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Explorer interaction
|
|
65
|
+
|
|
66
|
+
To enable Explorer-related features, you need to set the `neonConnectionString` in the `NodeTNClient` constructor.
|
|
67
|
+
You can request the explorer write only connection string by contacting us.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const client = new NodeTNClient({
|
|
71
|
+
// other options...
|
|
72
|
+
neonConnectionString: yourNeonConnectionString,
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Explorer interaction
|
|
77
|
+
|
|
78
|
+
To enable Explorer-related features, you need to set the `neonConnectionString` in the `NodeTNClient` constructor.
|
|
79
|
+
You can request the explorer write only connection string by contacting us.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const client = new NodeTNClient({
|
|
83
|
+
// other options...
|
|
84
|
+
neonConnectionString: yourNeonConnectionString,
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Explorer interaction
|
|
89
|
+
|
|
90
|
+
To enable Explorer-related features, you need to set the `neonConnectionString` in the `NodeTNClient` constructor.
|
|
91
|
+
You can request the explorer write only connection string by contacting us.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const client = new NodeTNClient({
|
|
95
|
+
// other options...
|
|
96
|
+
neonConnectionString: yourNeonConnectionString,
|
|
66
97
|
});
|
|
67
98
|
```
|
|
68
99
|
|
|
@@ -101,7 +132,49 @@ import { ... } from "npm:@trufnetwork/sdk-js"
|
|
|
101
132
|
|
|
102
133
|
### Deno Environment Permissions
|
|
103
134
|
|
|
104
|
-
By default, some dependencies requires environment permissions. If you need to run without environment permissions, please see [this GitHub issue](https://github.com/denoland/deno/issues/20898#issuecomment-2500396620) for workarounds
|
|
135
|
+
By default, some dependencies requires environment permissions. If you need to run without environment permissions, please see [this GitHub issue](https://github.com/denoland/deno/issues/20898#issuecomment-2500396620) for workarounds.# Serverless Deployment Notes
|
|
136
|
+
|
|
137
|
+
## Handling Crypto Hashing in Serverless Environments
|
|
138
|
+
|
|
139
|
+
When deploying to serverless environments, some Node.js modules like `crypto-hash` may not work as expected due to
|
|
140
|
+
compatibility issues. To resolve this, you can create a shim for the `crypto-hash` module and use
|
|
141
|
+
Webpack's `NormalModuleReplacementPlugin` to replace it during the build process.
|
|
142
|
+
|
|
143
|
+
### Steps to Add a Crypto Hash Shim
|
|
144
|
+
|
|
145
|
+
#### 1. Create a Shim File
|
|
146
|
+
|
|
147
|
+
Add a new file named `crypto-hash-sync.js` to your project:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
import { createHash } from 'crypto';
|
|
151
|
+
|
|
152
|
+
export const sha1 = (input) => createHash('sha1').update(input).digest('hex');
|
|
153
|
+
export const sha256 = (input) => createHash('sha256').update(input).digest('hex');
|
|
154
|
+
export const sha384 = (input) => createHash('sha384').update(input).digest('hex');
|
|
155
|
+
export const sha512 = (input) => createHash('sha512').update(input).digest('hex');
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### 2. Update Your Webpack Configuration
|
|
159
|
+
|
|
160
|
+
Modify your `next.config.js` (or equivalent Webpack configuration file) to include the following:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
const path = require('path');
|
|
164
|
+
|
|
165
|
+
module.exports = {
|
|
166
|
+
webpack: (config, {isServer, webpack}) => {
|
|
167
|
+
// Add shim for crypto-hash
|
|
168
|
+
config.plugins.push(
|
|
169
|
+
new webpack.NormalModuleReplacementPlugin(
|
|
170
|
+
/crypto-hash/,
|
|
171
|
+
path.resolve(__dirname, 'crypto-hash-sync.js')
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
return config;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
```
|
|
105
178
|
|
|
106
179
|
## Support
|
|
107
180
|
|
|
@@ -24,18 +24,21 @@ __export(client_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(client_exports);
|
|
26
26
|
var import_kwil_js = require("@kwilteam/kwil-js");
|
|
27
|
-
var
|
|
27
|
+
var import_composedAction = require("../contracts-api/composedAction.cjs");
|
|
28
28
|
var import_deployStream = require("../contracts-api/deployStream.cjs");
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
29
|
+
var import_deleteStream = require("../contracts-api/deleteStream.cjs");
|
|
30
|
+
var import_primitiveAction = require("../contracts-api/primitiveAction.cjs");
|
|
31
|
+
var import_action = require("../contracts-api/action.cjs");
|
|
32
32
|
var import_EthereumAddress = require("../util/EthereumAddress.cjs");
|
|
33
|
-
var
|
|
33
|
+
var import_listStreams = require("./listStreams.cjs");
|
|
34
|
+
var import_getLastTransactions = require("./getLastTransactions.cjs");
|
|
34
35
|
var BaseTNClient = class {
|
|
35
36
|
kwilClient;
|
|
36
37
|
signerInfo;
|
|
38
|
+
neonConnectionString;
|
|
37
39
|
constructor(options) {
|
|
38
40
|
this.signerInfo = options.signerInfo;
|
|
41
|
+
this.neonConnectionString = options.neonConnectionString;
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
41
44
|
* Waits for a transaction to be mined by TN.
|
|
@@ -49,14 +52,14 @@ var BaseTNClient = class {
|
|
|
49
52
|
const receipt = await this.getKwilClient()["txInfoClient"](txHash).catch(() => ({ data: void 0, status: void 0 }));
|
|
50
53
|
switch (receipt.status) {
|
|
51
54
|
case 200:
|
|
52
|
-
if (receipt.data?.tx_result
|
|
53
|
-
resolve(receipt.data);
|
|
54
|
-
} else {
|
|
55
|
+
if (receipt.data?.tx_result?.log !== void 0 && receipt.data?.tx_result?.log.includes("ERROR")) {
|
|
55
56
|
reject(
|
|
56
57
|
new Error(
|
|
57
58
|
`Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`
|
|
58
59
|
)
|
|
59
60
|
);
|
|
61
|
+
} else {
|
|
62
|
+
resolve(receipt.data);
|
|
60
63
|
}
|
|
61
64
|
break;
|
|
62
65
|
case void 0:
|
|
@@ -96,6 +99,12 @@ var BaseTNClient = class {
|
|
|
96
99
|
}
|
|
97
100
|
return this.kwilClient;
|
|
98
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns the Neon connection string used by the client.
|
|
104
|
+
*/
|
|
105
|
+
getNeonConnectionString() {
|
|
106
|
+
return this.neonConnectionString;
|
|
107
|
+
}
|
|
99
108
|
/**
|
|
100
109
|
* Deploys a new stream.
|
|
101
110
|
* @param streamId - The ID of the stream to deploy.
|
|
@@ -104,25 +113,25 @@ var BaseTNClient = class {
|
|
|
104
113
|
* @param contractVersion
|
|
105
114
|
* @returns A promise that resolves to a generic response containing the transaction receipt.
|
|
106
115
|
*/
|
|
107
|
-
async deployStream(streamId, streamType, synchronous
|
|
116
|
+
async deployStream(streamId, streamType, synchronous) {
|
|
108
117
|
return await (0, import_deployStream.deployStream)({
|
|
109
118
|
streamId,
|
|
110
119
|
streamType,
|
|
111
120
|
synchronous,
|
|
112
121
|
kwilClient: this.getKwilClient(),
|
|
113
122
|
kwilSigner: this.getKwilSigner(),
|
|
114
|
-
|
|
123
|
+
neonConnectionString: this.getNeonConnectionString()
|
|
115
124
|
});
|
|
116
125
|
}
|
|
117
126
|
/**
|
|
118
127
|
* Destroys a stream.
|
|
119
|
-
* @param
|
|
128
|
+
* @param stream - The StreamLocator of the stream to destroy.
|
|
120
129
|
* @param synchronous - Whether the destruction should be synchronous.
|
|
121
130
|
* @returns A promise that resolves to a generic response containing the transaction receipt.
|
|
122
131
|
*/
|
|
123
|
-
async destroyStream(
|
|
124
|
-
return await (0,
|
|
125
|
-
|
|
132
|
+
async destroyStream(stream, synchronous) {
|
|
133
|
+
return await (0, import_deleteStream.deleteStream)({
|
|
134
|
+
stream,
|
|
126
135
|
synchronous,
|
|
127
136
|
kwilClient: this.getKwilClient(),
|
|
128
137
|
kwilSigner: this.getKwilSigner()
|
|
@@ -130,35 +139,27 @@ var BaseTNClient = class {
|
|
|
130
139
|
}
|
|
131
140
|
/**
|
|
132
141
|
* Loads an already deployed stream, permitting its API usage.
|
|
133
|
-
* @param stream - The locator of the stream to load.
|
|
134
142
|
* @returns An instance of IStream.
|
|
135
143
|
*/
|
|
136
|
-
|
|
137
|
-
return new
|
|
144
|
+
loadAction() {
|
|
145
|
+
return new import_action.Action(
|
|
138
146
|
this.getKwilClient(),
|
|
139
|
-
this.getKwilSigner()
|
|
140
|
-
stream
|
|
147
|
+
this.getKwilSigner()
|
|
141
148
|
);
|
|
142
149
|
}
|
|
143
150
|
/**
|
|
144
151
|
* Loads a primitive stream.
|
|
145
|
-
* @param stream - The locator of the primitive stream to load.
|
|
146
152
|
* @returns An instance of IPrimitiveStream.
|
|
147
153
|
*/
|
|
148
|
-
|
|
149
|
-
return
|
|
154
|
+
loadPrimitiveAction() {
|
|
155
|
+
return import_primitiveAction.PrimitiveAction.fromStream(this.loadAction());
|
|
150
156
|
}
|
|
151
157
|
/**
|
|
152
158
|
* Loads a composed stream.
|
|
153
|
-
* @param stream - The locator of the composed stream to load.
|
|
154
159
|
* @returns An instance of IComposedStream.
|
|
155
160
|
*/
|
|
156
|
-
|
|
157
|
-
return
|
|
158
|
-
this.getKwilClient(),
|
|
159
|
-
this.getKwilSigner(),
|
|
160
|
-
stream
|
|
161
|
-
);
|
|
161
|
+
loadComposedAction() {
|
|
162
|
+
return import_composedAction.ComposedAction.fromStream(this.loadAction(), this.getNeonConnectionString());
|
|
162
163
|
}
|
|
163
164
|
/**
|
|
164
165
|
* Creates a new stream locator.
|
|
@@ -180,11 +181,19 @@ var BaseTNClient = class {
|
|
|
180
181
|
}
|
|
181
182
|
/**
|
|
182
183
|
* Returns all streams from the TN network.
|
|
183
|
-
* @param
|
|
184
|
+
* @param input - The input parameters for listing streams.
|
|
184
185
|
* @returns A promise that resolves to a list of stream locators.
|
|
185
186
|
*/
|
|
186
|
-
async
|
|
187
|
-
return (0,
|
|
187
|
+
async getListStreams(input) {
|
|
188
|
+
return (0, import_listStreams.listStreams)(this.getKwilClient(), this.getKwilSigner(), input);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Returns the last write activity across streams.
|
|
192
|
+
* @param input - The input parameters for getting last transactions.
|
|
193
|
+
* @returns A promise that resolves to a list of last transactions.
|
|
194
|
+
*/
|
|
195
|
+
async getLastTransactions(input) {
|
|
196
|
+
return (0, import_getLastTransactions.getLastTransactions)(this.getKwilClient(), this.getKwilSigner(), input);
|
|
188
197
|
}
|
|
189
198
|
/**
|
|
190
199
|
* Get the default chain id for a provider. Use with caution, as this decreases the security of the TN.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/client/client.ts"],
|
|
4
|
-
"sourcesContent": ["import { Client, KwilSigner, NodeKwil, WebKwil } from \"@kwilteam/kwil-js\";\nimport { KwilConfig } from \"@kwilteam/kwil-js/dist/api_client/config\";\nimport { Kwil } from \"@kwilteam/kwil-js/dist/client/kwil\";\nimport { EthSigner } from \"@kwilteam/kwil-js/dist/core/
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsD;AAQtD,4BAA+B;AAC/B,0BAA6B;AAC7B,
|
|
4
|
+
"sourcesContent": ["import { Client, KwilSigner, NodeKwil, WebKwil } from \"@kwilteam/kwil-js\";\nimport { KwilConfig } from \"@kwilteam/kwil-js/dist/api_client/config\";\nimport { Kwil } from \"@kwilteam/kwil-js/dist/client/kwil\";\nimport { EthSigner } from \"@kwilteam/kwil-js/dist/core/signature\";\nimport { EnvironmentType } from \"@kwilteam/kwil-js/dist/core/enums\";\nimport { GenericResponse } from \"@kwilteam/kwil-js/dist/core/resreq\";\nimport { TxReceipt } from \"@kwilteam/kwil-js/dist/core/tx\";\nimport { TxInfoReceipt } from \"@kwilteam/kwil-js/dist/core/txQuery\";\nimport { ComposedAction } from \"../contracts-api/composedAction\";\nimport { deployStream } from \"../contracts-api/deployStream\";\nimport { deleteStream } from \"../contracts-api/deleteStream\";\nimport { PrimitiveAction } from \"../contracts-api/primitiveAction\";\nimport { Action } from \"../contracts-api/action\";\nimport { StreamType } from \"../contracts-api/contractValues\";\nimport { StreamLocator } from \"../types/stream\";\nimport { EthereumAddress } from \"../util/EthereumAddress\";\nimport { StreamId } from \"../util/StreamId\";\nimport { listStreams } from \"./listStreams\";\nimport { getLastTransactions } from \"./getLastTransactions\";\n\nexport interface SignerInfo {\n // we need to have the address upfront to create the KwilSigner, instead of relying on the signer to return it asynchronously\n address: string;\n signer: EthSigner;\n}\n\nexport type TNClientOptions = {\n endpoint: string;\n signerInfo: SignerInfo;\n neonConnectionString?: string;\n} & Omit<KwilConfig, \"kwilProvider\">;\n\nexport interface ListStreamsInput {\n dataProvider?: string;\n limit?: number;\n offset?: number;\n orderBy?: string;\n}\n\n/**\n * @param dataProvider optional address; when omitted or null, returns for all providers\n * @param limitSize max rows to return (default 6, max 100)\n */\nexport interface GetLastTransactionsInput {\n dataProvider?: string;\n limitSize?: number;\n}\n\nexport abstract class BaseTNClient<T extends EnvironmentType> {\n protected kwilClient: Kwil<T> | undefined;\n protected signerInfo: SignerInfo;\n protected neonConnectionString: string | undefined;\n\n protected constructor(options: TNClientOptions) {\n this.signerInfo = options.signerInfo;\n this.neonConnectionString = options.neonConnectionString;\n }\n\n /**\n * Waits for a transaction to be mined by TN.\n * @param txHash - The transaction hash to wait for.\n * @param timeout - The timeout in milliseconds.\n * @returns A promise that resolves to the transaction info receipt.\n */\n async waitForTx(txHash: string, timeout = 12000): Promise<TxInfoReceipt> {\n return new Promise<TxInfoReceipt>(async (resolve, reject) => {\n const interval = setInterval(async () => {\n const receipt = await this.getKwilClient()\n [\"txInfoClient\"](txHash)\n .catch(() => ({ data: undefined, status: undefined }));\n switch (receipt.status) {\n case 200:\n if (receipt.data?.tx_result?.log !== undefined && receipt.data?.tx_result?.log.includes(\"ERROR\")) {\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ))\n } else {\n resolve(receipt.data!);\n }\n break;\n case undefined:\n break;\n default:\n reject(\n new Error(\n `Transaction failed: status ${receipt.status} : log message ${receipt.data?.tx_result.log}`,\n ),\n );\n }\n }, 1000);\n setTimeout(() => {\n clearInterval(interval);\n reject(new Error(\"Transaction failed: Timeout\"));\n }, timeout);\n });\n }\n\n /**\n * Returns the Kwil signer used by the client.\n * @returns An instance of KwilSigner.\n */\n getKwilSigner(): KwilSigner {\n return new KwilSigner(\n this.signerInfo.signer,\n this.address().getAddress(),\n );\n }\n\n /**\n * Returns the Kwil client used by the client.\n * @returns An instance of Kwil.\n * @throws If the Kwil client is not initialized.\n */\n getKwilClient(): Kwil<EnvironmentType> {\n if (!this.kwilClient) {\n throw new Error(\"Kwil client not initialized\");\n }\n return this.kwilClient;\n }\n\n /**\n * Returns the Neon connection string used by the client.\n */\n getNeonConnectionString(): string | undefined {\n return this.neonConnectionString;\n }\n\n /**\n * Deploys a new stream.\n * @param streamId - The ID of the stream to deploy.\n * @param streamType - The type of the stream.\n * @param synchronous - Whether the deployment should be synchronous.\n * @param contractVersion\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async deployStream(\n streamId: StreamId,\n streamType: StreamType,\n synchronous?: boolean,\n ): Promise<GenericResponse<TxReceipt>> {\n return await deployStream({\n streamId,\n streamType,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n neonConnectionString: this.getNeonConnectionString(),\n });\n }\n\n /**\n * Destroys a stream.\n * @param stream - The StreamLocator of the stream to destroy.\n * @param synchronous - Whether the destruction should be synchronous.\n * @returns A promise that resolves to a generic response containing the transaction receipt.\n */\n async destroyStream(\n stream: StreamLocator,\n synchronous?: boolean,\n ): Promise<GenericResponse<TxReceipt>> {\n return await deleteStream({\n stream,\n synchronous,\n kwilClient: this.getKwilClient(),\n kwilSigner: this.getKwilSigner(),\n });\n }\n\n /**\n * Loads an already deployed stream, permitting its API usage.\n * @returns An instance of IStream.\n */\n loadAction(): Action {\n return new Action(\n this.getKwilClient() as WebKwil | NodeKwil,\n this.getKwilSigner(),\n );\n }\n\n /**\n * Loads a primitive stream.\n * @returns An instance of IPrimitiveStream.\n */\n loadPrimitiveAction(): PrimitiveAction {\n return PrimitiveAction.fromStream(this.loadAction());\n }\n\n /**\n * Loads a composed stream.\n * @returns An instance of IComposedStream.\n */\n loadComposedAction(): ComposedAction {\n return ComposedAction.fromStream(this.loadAction(), this.getNeonConnectionString());\n }\n\n /**\n * Creates a new stream locator.\n * @param streamId - The ID of the stream.\n * @returns A StreamLocator object.\n */\n ownStreamLocator(streamId: StreamId): StreamLocator {\n return {\n streamId,\n dataProvider: this.address(),\n };\n }\n\n /**\n * Returns the address of the signer used by the client.\n * @returns An instance of EthereumAddress.\n */\n address(): EthereumAddress {\n return new EthereumAddress(this.signerInfo.address);\n }\n\n /**\n * Returns all streams from the TN network.\n * @param input - The input parameters for listing streams.\n * @returns A promise that resolves to a list of stream locators.\n */\n async getListStreams(input: ListStreamsInput): Promise<StreamLocator[]> {\n return listStreams(this.getKwilClient() as WebKwil | NodeKwil,this.getKwilSigner(),input);\n }\n\n /**\n * Returns the last write activity across streams.\n * @param input - The input parameters for getting last transactions.\n * @returns A promise that resolves to a list of last transactions.\n */\n async getLastTransactions(input: GetLastTransactionsInput): Promise<any[]> {\n return getLastTransactions(this.getKwilClient() as WebKwil | NodeKwil,this.getKwilSigner(),input);\n }\n\n /**\n * Get the default chain id for a provider. Use with caution, as this decreases the security of the TN.\n * @param provider - The provider URL.\n * @returns A promise that resolves to the chain ID.\n */\n public static async getDefaultChainId(provider: string) {\n const kwilClient = new Client({\n kwilProvider: provider,\n });\n const chainInfo = await kwilClient[\"chainInfoClient\"]();\n return chainInfo.data?.chain_id;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsD;AAQtD,4BAA+B;AAC/B,0BAA6B;AAC7B,0BAA6B;AAC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AAAA;AAAA;AAAA;AAAA,EAMA,UAA2B;AACzB,WAAO,IAAI,uCAAgB,KAAK,WAAW,OAAO;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,eAAe,OAAmD;AACtE,eAAO,gCAAY,KAAK,cAAc,GAAwB,KAAK,cAAc,GAAE,KAAK;AAAA,EAC1F;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOE,MAAM,oBAAoB,OAAiD;AACvE,eAAO,gDAAoB,KAAK,cAAc,GAAwB,KAAK,cAAc,GAAE,KAAK;AAAA,EACpG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOF,aAAoB,kBAAkB,UAAkB;AACtD,UAAM,aAAa,IAAI,sBAAO;AAAA,MAC5B,cAAc;AAAA,IAChB,CAAC;AACD,UAAM,YAAY,MAAM,WAAW,iBAAiB,EAAE;AACtD,WAAO,UAAU,MAAM;AAAA,EACzB;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/client/getLastTransactions.ts
|
|
21
|
+
var getLastTransactions_exports = {};
|
|
22
|
+
__export(getLastTransactions_exports, {
|
|
23
|
+
getLastTransactions: () => getLastTransactions
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(getLastTransactions_exports);
|
|
26
|
+
var INDEXER_BASE = "https://indexer.infra.truf.network";
|
|
27
|
+
var RPC_URL = "https://gateway.mainnet.truf.network/rpc/v1";
|
|
28
|
+
async function getLastTransactions(kwilClient, kwilSigner, input) {
|
|
29
|
+
const res = await kwilClient.call(
|
|
30
|
+
{
|
|
31
|
+
name: "get_last_transactions",
|
|
32
|
+
namespace: "main",
|
|
33
|
+
inputs: {
|
|
34
|
+
$data_provider: input.dataProvider ?? null,
|
|
35
|
+
$limit_size: input.limitSize ?? 6
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
kwilSigner
|
|
39
|
+
);
|
|
40
|
+
const rows = res.data?.result || [];
|
|
41
|
+
const tasks = rows.map(({ created_at, method }) => {
|
|
42
|
+
const blockHeight = Number(created_at);
|
|
43
|
+
if (Number.isNaN(blockHeight)) {
|
|
44
|
+
return Promise.reject(new Error(`Invalid block height returned: ${created_at}`));
|
|
45
|
+
}
|
|
46
|
+
const txUrl = `${INDEXER_BASE}/v0/chain/transactions?from-block=${blockHeight}&to-block=${blockHeight}&order=asc&limit=1`;
|
|
47
|
+
const txPromise = fetch(txUrl).then(async (resp) => {
|
|
48
|
+
if (!resp.ok) throw new Error(`Indexer fetch failed: ${resp.status}`);
|
|
49
|
+
const json = await resp.json();
|
|
50
|
+
if (!json.ok || json.data.length === 0) {
|
|
51
|
+
return { sender: "(unknown)", hash: "(unknown)" };
|
|
52
|
+
}
|
|
53
|
+
const { hash, sender } = json.data[0];
|
|
54
|
+
return { sender, hash };
|
|
55
|
+
});
|
|
56
|
+
const rpcPromise = fetch(RPC_URL, {
|
|
57
|
+
method: "POST",
|
|
58
|
+
headers: { "Content-Type": "application/json" },
|
|
59
|
+
body: JSON.stringify({
|
|
60
|
+
jsonrpc: "2.0",
|
|
61
|
+
method: "chain.block",
|
|
62
|
+
params: { height: blockHeight },
|
|
63
|
+
id: 1
|
|
64
|
+
})
|
|
65
|
+
}).then(async (resp) => {
|
|
66
|
+
if (!resp.ok) {
|
|
67
|
+
const txt = await resp.text();
|
|
68
|
+
throw new Error(`RPC fetch failed: ${resp.status} \u2013 ${txt}`);
|
|
69
|
+
}
|
|
70
|
+
const rpc = await resp.json();
|
|
71
|
+
return rpc.result.block.header.stamp_ms;
|
|
72
|
+
});
|
|
73
|
+
return Promise.all([txPromise, rpcPromise]).then(
|
|
74
|
+
([{ sender, hash }, stampMs]) => ({
|
|
75
|
+
blockHeight,
|
|
76
|
+
method,
|
|
77
|
+
sender,
|
|
78
|
+
transactionHash: hash,
|
|
79
|
+
stampMs
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
return Promise.all(tasks);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=getLastTransactions.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/client/getLastTransactions.ts"],
|
|
4
|
+
"sourcesContent": ["import { WebKwil, NodeKwil, KwilSigner } from \"@kwilteam/kwil-js\";\r\nimport { GetLastTransactionsInput } from \"./client\";\r\nimport { LastTransaction } from \"../types/transaction\";\r\n\r\nconst INDEXER_BASE = \"https://indexer.infra.truf.network\";\r\nconst RPC_URL = \"https://gateway.mainnet.truf.network/rpc/v1\";\r\n\r\nexport async function getLastTransactions(\r\n kwilClient: WebKwil | NodeKwil,\r\n kwilSigner: KwilSigner,\r\n input: GetLastTransactionsInput\r\n): Promise<LastTransaction[]> {\r\n // 1) call your SQL action\r\n const res = await kwilClient.call(\r\n {\r\n name: \"get_last_transactions\",\r\n namespace: \"main\",\r\n inputs: {\r\n $data_provider: input.dataProvider ?? null,\r\n $limit_size: input.limitSize ?? 6,\r\n },\r\n },\r\n kwilSigner\r\n );\r\n const rows = (res.data?.result as { created_at: number; method: string }[]) || [];\r\n\r\n // 2) build per-block Promises\r\n const tasks = rows.map(({ created_at, method }) => {\r\n const blockHeight = Number(created_at);\r\n if (Number.isNaN(blockHeight)) {\r\n return Promise.reject(new Error(`Invalid block height returned: ${created_at}`));\r\n }\r\n\r\n const txUrl = `${INDEXER_BASE}/v0/chain/transactions`\r\n + `?from-block=${blockHeight}&to-block=${blockHeight}`\r\n + `&order=asc&limit=1`;\r\n\r\n // INDEXER: always return a { sender, hash } object\r\n const txPromise = fetch(txUrl).then(async (resp) => {\r\n if (!resp.ok) throw new Error(`Indexer fetch failed: ${resp.status}`);\r\n const json = (await resp.json()) as {\r\n ok: boolean;\r\n data: Array<{ hash: string; sender: string }>;\r\n };\r\n if (!json.ok || json.data.length === 0) {\r\n return { sender: \"(unknown)\", hash: \"(unknown)\" };\r\n }\r\n const { hash, sender } = json.data[0];\r\n return { sender, hash };\r\n });\r\n\r\n // RPC: get stamp_ms\r\n const rpcPromise = fetch(RPC_URL, {\r\n method: \"POST\",\r\n headers: { \"Content-Type\": \"application/json\" },\r\n body: JSON.stringify({\r\n jsonrpc: \"2.0\",\r\n method: \"chain.block\",\r\n params: { height: blockHeight },\r\n id: 1,\r\n }),\r\n }).then(async (resp) => {\r\n if (!resp.ok) {\r\n const txt = await resp.text();\r\n throw new Error(`RPC fetch failed: ${resp.status} \u2013 ${txt}`);\r\n }\r\n const rpc = (await resp.json()) as {\r\n result: { block: { header: { stamp_ms: number } } };\r\n };\r\n return rpc.result.block.header.stamp_ms;\r\n });\r\n\r\n // wait for both\r\n return Promise.all([txPromise, rpcPromise]).then(\r\n ([{ sender, hash }, stampMs]) => ({\r\n blockHeight,\r\n method,\r\n sender,\r\n transactionHash: hash,\r\n stampMs,\r\n })\r\n );\r\n });\r\n\r\n // 3) await all in parallel\r\n return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,QAAS,EAAE,QAAQ,YAAY;AAAA,QAC/B,IAAS;AAAA,MACb,CAAC;AAAA,IACL,CAAC,EAAE,KAAK,OAAO,SAAS;AACpB,UAAI,CAAC,KAAK,IAAI;AACV,cAAM,MAAM,MAAM,KAAK,KAAK;AAC5B,cAAM,IAAI,MAAM,qBAAqB,KAAK,MAAM,WAAM,GAAG,EAAE;AAAA,MAC/D;AACA,YAAM,MAAO,MAAM,KAAK,KAAK;AAG7B,aAAO,IAAI,OAAO,MAAM,OAAO;AAAA,IACnC,CAAC;AAGD,WAAO,QAAQ,IAAI,CAAC,WAAW,UAAU,CAAC,EAAE;AAAA,MACxC,CAAC,CAAC,EAAE,QAAQ,KAAK,GAAG,OAAO,OAAO;AAAA,QAC9B;AAAA,QACA;AAAA,QACA;AAAA,QACA,iBAAiB;AAAA,QACjB;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ,CAAC;AAGD,SAAO,QAAQ,IAAI,KAAK;AAC5B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/client/listStreams.ts
|
|
21
|
+
var listStreams_exports = {};
|
|
22
|
+
__export(listStreams_exports, {
|
|
23
|
+
listStreams: () => listStreams
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(listStreams_exports);
|
|
26
|
+
var import_EthereumAddress = require("../util/EthereumAddress.cjs");
|
|
27
|
+
var import_StreamId = require("../util/StreamId.cjs");
|
|
28
|
+
async function listStreams(kwilClient, kwilSigner, input) {
|
|
29
|
+
const result = await kwilClient.call({
|
|
30
|
+
inputs: {
|
|
31
|
+
$data_provider: input.dataProvider,
|
|
32
|
+
$limit: input.limit,
|
|
33
|
+
$offset: input.offset,
|
|
34
|
+
$order_by: input.orderBy
|
|
35
|
+
},
|
|
36
|
+
name: "list_streams",
|
|
37
|
+
namespace: "main"
|
|
38
|
+
}, kwilSigner);
|
|
39
|
+
return await Promise.all(
|
|
40
|
+
(result.data?.result).map(async (database) => ({
|
|
41
|
+
streamId: await import_StreamId.StreamId.generate(database.stream_id),
|
|
42
|
+
dataProvider: new import_EthereumAddress.EthereumAddress(database.data_provider)
|
|
43
|
+
}))
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=listStreams.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/client/listStreams.ts"],
|
|
4
|
+
"sourcesContent": ["import {StreamLocator} from \"../types/stream\";\nimport {EthereumAddress} from \"../util/EthereumAddress\";\nimport {StreamId} from \"../util/StreamId\";\nimport {Database} from \"@kwilteam/kwil-js/dist/core/database\";\nimport {ListStreamsInput} from \"./client\";\nimport {KwilSigner, NodeKwil, WebKwil} from \"@kwilteam/kwil-js\";\n\n/**\n * List all streams from the TN network.\n * @param kwilClient - The Kwil client.\n * @param kwilSigner - The Kwil signer.\n * @param input - The input parameters for listing streams.\n * @returns A list of stream locators.\n */\nexport async function listStreams(\n kwilClient: WebKwil | NodeKwil,\n kwilSigner: KwilSigner,\n input: ListStreamsInput\n): Promise<StreamLocator[]> {\n const result = await kwilClient.call({\n inputs: {\n $data_provider: input.dataProvider,\n $limit: input.limit,\n $offset: input.offset,\n $order_by: input.orderBy,\n },\n name: \"list_streams\",\n namespace: \"main\",\n }, kwilSigner);\n\n return await Promise.all(\n (result.data?.result as {\n data_provider: string;\n stream_id: string;\n stream_type: string;\n created_at: number;\n }[]).map(async (database) => ({\n streamId: await StreamId.generate(database.stream_id),\n dataProvider: new EthereumAddress(database.data_provider),\n }))\n );\n}"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,6BAA8B;AAC9B,sBAAuB;AAYvB,eAAsB,YACpB,YACA,YACA,OAC0B;AACxB,QAAM,SAAS,MAAM,WAAW,KAAK;AAAA,IACjC,QAAQ;AAAA,MACJ,gBAAgB,MAAM;AAAA,MACtB,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,WAAW,MAAM;AAAA,IACrB;AAAA,IACA,MAAM;AAAA,IACN,WAAW;AAAA,EACf,GAAG,UAAU;AAEb,SAAO,MAAM,QAAQ;AAAA,KAChB,OAAO,MAAM,QAKT,IAAI,OAAO,cAAc;AAAA,MAC1B,UAAU,MAAM,yBAAS,SAAS,SAAS,SAAS;AAAA,MACpD,cAAc,IAAI,uCAAgB,SAAS,aAAa;AAAA,IAC5D,EAAE;AAAA,EACN;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|