@radix-effects/transaction-stream 0.1.2 → 0.1.4
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/dist/index.d.ts +1 -2
- package/dist/index.js +49 -52
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _radix_effects_gateway0 from "@radix-effects/gateway";
|
|
2
2
|
import { GatewayApiClient } from "@radix-effects/gateway";
|
|
3
|
-
import { Context, Duration, Effect,
|
|
3
|
+
import { Context, Duration, Effect, Option, Ref, Schema, Stream } from "effect";
|
|
4
4
|
import * as _radixdlt_babylon_gateway_api_sdk0 from "@radixdlt/babylon-gateway-api-sdk";
|
|
5
5
|
import * as effect_Effect0 from "effect/Effect";
|
|
6
6
|
|
|
@@ -48,7 +48,6 @@ declare class ConfigService extends ConfigService_base {
|
|
|
48
48
|
//#endregion
|
|
49
49
|
//#region src/streamer.d.ts
|
|
50
50
|
declare const TransactionStreamService_base: Effect.Service.Class<TransactionStreamService, "TransactionStreamService", {
|
|
51
|
-
readonly dependencies: readonly [Layer.Layer<GatewayApiClient, never, never>];
|
|
52
51
|
readonly effect: Effect.Effect<Stream.Stream<_radixdlt_babylon_gateway_api_sdk0.CommittedTransactionInfo[], _radix_effects_gateway0.InvalidRequestError | _radix_effects_gateway0.InternalServerError | _radix_effects_gateway0.NotSyncedUpError | _radix_effects_gateway0.RateLimitExceededError | _radix_effects_gateway0.UnknownGatewayError, ConfigService>, never, GatewayApiClient>;
|
|
53
52
|
}>;
|
|
54
53
|
declare class TransactionStreamService extends TransactionStreamService_base {}
|
package/dist/index.js
CHANGED
|
@@ -38,58 +38,55 @@ var ConfigService = class extends Context.Tag("Config")() {
|
|
|
38
38
|
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region src/streamer.ts
|
|
41
|
-
var TransactionStreamService = class extends Effect.Service()("TransactionStreamService", {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
yield*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})).pipe(Stream.filter((item) => item.length > 0));
|
|
91
|
-
})
|
|
92
|
-
}) {};
|
|
41
|
+
var TransactionStreamService = class extends Effect.Service()("TransactionStreamService", { effect: Effect.gen(function* () {
|
|
42
|
+
const gatewayApiClient = yield* GatewayApiClient;
|
|
43
|
+
const currentStateVersion = yield* gatewayApiClient.status.getCurrent().pipe(Effect.catchAll(Effect.die));
|
|
44
|
+
yield* Effect.logDebug(currentStateVersion.ledger_state);
|
|
45
|
+
return Stream.paginateEffect(1, () => Effect.gen(function* () {
|
|
46
|
+
const configRef = yield* ConfigService;
|
|
47
|
+
const config = yield* configRef.pipe(Ref.get);
|
|
48
|
+
const stateVersion = yield* config.stateVersion.pipe(Option.match({
|
|
49
|
+
onNone: () => gatewayApiClient.status.getCurrent().pipe(Effect.map((res) => res.ledger_state.state_version), Effect.catchAll(Effect.die)),
|
|
50
|
+
onSome: (version) => Effect.succeed(version)
|
|
51
|
+
}));
|
|
52
|
+
yield* Effect.logDebug(`fetching transactions from state version ${stateVersion}`);
|
|
53
|
+
const result = yield* gatewayApiClient.stream.innerClient.streamTransactions({ streamTransactionsRequest: {
|
|
54
|
+
limit_per_page: config.limitPerPage,
|
|
55
|
+
from_ledger_state: { state_version: stateVersion },
|
|
56
|
+
order: "Asc",
|
|
57
|
+
kind_filter: "User",
|
|
58
|
+
opt_ins: config.optIns
|
|
59
|
+
} }).pipe(Effect.catchTags({
|
|
60
|
+
AccountLockerNotFoundError: Effect.die,
|
|
61
|
+
EntityNotFoundError: Effect.die,
|
|
62
|
+
ErrorResponse: Effect.die,
|
|
63
|
+
InvalidEntityError: Effect.die,
|
|
64
|
+
InvalidTransactionError: Effect.die,
|
|
65
|
+
ResponseError: Effect.die,
|
|
66
|
+
TransactionNotFoundError: Effect.die
|
|
67
|
+
}));
|
|
68
|
+
yield* Effect.logDebug(`fetched ${result.items.length} transactions`);
|
|
69
|
+
const firstItem = pipe(result.items, Array.sortBy(Order.mapInput(Order.number, (tx) => tx.state_version)), Array.head);
|
|
70
|
+
const lastItem = pipe(result.items, Array.sortBy(Order.mapInput(Order.number, (tx) => tx.state_version)), Array.last);
|
|
71
|
+
yield* Option.all([firstItem, lastItem]).pipe(Option.match({
|
|
72
|
+
onNone: () => Effect.void,
|
|
73
|
+
onSome: ([first, last]) => Effect.log(`${first.round_timestamp} -> ${last.round_timestamp}`)
|
|
74
|
+
}));
|
|
75
|
+
const nextStateVersion = lastItem.pipe(Option.map((res) => res.state_version + 1), Option.getOrElse(() => stateVersion));
|
|
76
|
+
yield* Ref.update(configRef, (config$1) => {
|
|
77
|
+
return {
|
|
78
|
+
...config$1,
|
|
79
|
+
stateVersion: Option.some(nextStateVersion)
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
if (nextStateVersion === stateVersion) {
|
|
83
|
+
yield* Effect.logDebug("Waiting for new transactions...");
|
|
84
|
+
yield* Effect.sleep(config.waitTime);
|
|
85
|
+
return [[], Option.some(stateVersion)];
|
|
86
|
+
}
|
|
87
|
+
return [result.items, Option.some(nextStateVersion)];
|
|
88
|
+
})).pipe(Stream.filter((item) => item.length > 0));
|
|
89
|
+
}) }) {};
|
|
93
90
|
|
|
94
91
|
//#endregion
|
|
95
92
|
export { ConfigSchema, ConfigService, TransactionDetailsOptInsSchema, TransactionStreamService };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-effects/transaction-stream",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"effect": "^3.14.1",
|
|
28
|
-
"@radix-effects/gateway": "0.
|
|
28
|
+
"@radix-effects/gateway": "0.4.1"
|
|
29
29
|
},
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"scripts": {
|