@effect-blockchain/stellar 0.0.0-stage → 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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/StellarAddress.d.ts +48 -0
  4. package/dist/StellarAddress.d.ts.map +1 -0
  5. package/dist/StellarAddress.js +68 -0
  6. package/dist/StellarAddress.js.map +1 -0
  7. package/dist/StellarContractEvent.d.ts +41 -0
  8. package/dist/StellarContractEvent.d.ts.map +1 -0
  9. package/dist/StellarContractEvent.js +49 -0
  10. package/dist/StellarContractEvent.js.map +1 -0
  11. package/dist/StellarIndexer.d.ts +121 -0
  12. package/dist/StellarIndexer.d.ts.map +1 -0
  13. package/dist/StellarIndexer.js +186 -0
  14. package/dist/StellarIndexer.js.map +1 -0
  15. package/dist/StellarNetwork.d.ts +56 -0
  16. package/dist/StellarNetwork.d.ts.map +1 -0
  17. package/dist/StellarNetwork.js +67 -0
  18. package/dist/StellarNetwork.js.map +1 -0
  19. package/dist/StellarRpc.d.ts +198 -0
  20. package/dist/StellarRpc.d.ts.map +1 -0
  21. package/dist/StellarRpc.js +244 -0
  22. package/dist/StellarRpc.js.map +1 -0
  23. package/dist/StellarTransactionHash.d.ts +17 -0
  24. package/dist/StellarTransactionHash.d.ts.map +1 -0
  25. package/dist/StellarTransactionHash.js +29 -0
  26. package/dist/StellarTransactionHash.js.map +1 -0
  27. package/dist/index.d.ts +28 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +29 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/internal/LedgerFromNumber.d.ts +2 -0
  32. package/dist/internal/LedgerFromNumber.d.ts.map +1 -0
  33. package/dist/internal/LedgerFromNumber.js +12 -0
  34. package/dist/internal/LedgerFromNumber.js.map +1 -0
  35. package/dist/internal/rpcMethods.d.ts +2 -0
  36. package/dist/internal/rpcMethods.d.ts.map +1 -0
  37. package/dist/internal/rpcMethods.js +64 -0
  38. package/dist/internal/rpcMethods.js.map +1 -0
  39. package/package.json +68 -3
  40. package/src/StellarAddress.ts +114 -0
  41. package/src/StellarContractEvent.ts +54 -0
  42. package/src/StellarIndexer.ts +260 -0
  43. package/src/StellarNetwork.ts +82 -0
  44. package/src/StellarRpc.ts +371 -0
  45. package/src/StellarTransactionHash.ts +41 -0
  46. package/src/index.ts +35 -0
  47. package/src/internal/LedgerFromNumber.ts +11 -0
  48. package/src/internal/rpcMethods.ts +54 -0
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Named Stellar networks and their passphrases.
3
+ *
4
+ * @since 0.1.0
5
+ */
6
+ import * as Schema from "effect/Schema";
7
+ /**
8
+ * @since 0.1.0
9
+ * @category constants
10
+ */
11
+ export const mainnets = ["Stellar"];
12
+ /**
13
+ * @since 0.1.0
14
+ * @category constants
15
+ */
16
+ export const testnets = ["StellarTestnet"];
17
+ /**
18
+ * Every supported network, mainnets first.
19
+ *
20
+ * @since 0.1.0
21
+ * @category constants
22
+ */
23
+ export const networks = [...mainnets, ...testnets];
24
+ /**
25
+ * A named Stellar network: `Stellar` (public mainnet) or `StellarTestnet`.
26
+ *
27
+ * @since 0.1.0
28
+ * @category schemas
29
+ */
30
+ export const StellarNetwork = /*#__PURE__*/Schema.Literals(networks).annotate({
31
+ identifier: "StellarNetwork",
32
+ title: "Stellar network",
33
+ description: "a Stellar network name"
34
+ });
35
+ // same values as `Networks.PUBLIC` / `Networks.TESTNET` in `@stellar/stellar-sdk`
36
+ const passphrases = {
37
+ Stellar: "Public Global Stellar Network ; September 2015",
38
+ StellarTestnet: "Test SDF Network ; September 2015"
39
+ };
40
+ /**
41
+ * The network passphrase, used to sign transactions and reported by `getNetwork`.
42
+ *
43
+ * @since 0.1.0
44
+ * @category conversions
45
+ */
46
+ export const toPassphrase = network => passphrases[network];
47
+ const confirmations = {
48
+ // SCP gives deterministic finality, a closed ledger is never reverted:
49
+ // https://developers.stellar.org/docs/learn/fundamentals/stellar-consensus-protocol
50
+ Stellar: 0,
51
+ // same consensus as mainnet (testnet resets wipe all history, they do not reorganise closed ledgers)
52
+ StellarTestnet: 0
53
+ };
54
+ /**
55
+ * Ledgers to wait behind the latest closed ledger before treating it as confirmed: `0`, Stellar has no forks and a
56
+ * ledger is final once closed.
57
+ *
58
+ * @since 0.1.0
59
+ * @category getters
60
+ */
61
+ export const defaultConfirmations = network => confirmations[network];
62
+ /**
63
+ * @since 0.1.0
64
+ * @category predicates
65
+ */
66
+ export const isTestnet = network => testnets.includes(network);
67
+ //# sourceMappingURL=StellarNetwork.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarNetwork.js","names":[],"sources":["../src/StellarNetwork.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,OAAO,KAAK,MAAM,MAAM,eAAe;AAEvC;;;;AAIA,OAAO,MAAM,QAAQ,GAAG,CAAC,SAAS,CAAU;AAE5C;;;;AAIA,OAAO,MAAM,QAAQ,GAAG,CAAC,gBAAgB,CAAU;AAEnD;;;;;;AAMA,OAAO,MAAM,QAAQ,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAG,QAAQ,CAAU;AAE3D;;;;;;AAMA,OAAO,MAAM,cAAc,gBAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC;EAC/D,UAAU,EAAE,gBAAgB;EAC5B,KAAK,EAAE,iBAAiB;EACxB,WAAW,EAAE;CACd,CAAC;AAQF;AACA,MAAM,WAAW,GAAmC;EAClD,OAAO,EAAE,gDAAgD;EACzD,cAAc,EAAE;CACjB;AAED;;;;;;AAMA,OAAO,MAAM,YAAY,GAAI,OAAuB,IAAa,WAAW,CAAC,OAAO,CAAC;AAErF,MAAM,aAAa,GAAmC;EACpD;EACA;EACA,OAAO,EAAE,CAAC;EACV;EACA,cAAc,EAAE;CACjB;AAED;;;;;;;AAOA,OAAO,MAAM,oBAAoB,GAAI,OAAuB,IAAa,aAAa,CAAC,OAAO,CAAC;AAE/F;;;;AAIA,OAAO,MAAM,SAAS,GAAI,OAAuB,IAC9C,QAA0C,CAAC,QAAQ,CAAC,OAAO,CAAC","ignoreList":[]}
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Typed, read-only Stellar RPC methods over an ordered list of endpoints with fallback.
3
+ *
4
+ * A call starts at the first endpoint and moves to the next one on failure, except on `WrongNetwork`. Each endpoint
5
+ * is checked once to serve the configured network (`getNetwork` passphrase). Every method is a read, so retries and
6
+ * fallback are safe. Methods are named after the RPC method. A `getEvents` page cursor is only sent to the endpoint
7
+ * that issued it, with no fallback.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import type { StellarContractAddress } from "@effect-blockchain/stellar/StellarAddress"
12
+ * import * as StellarRpc from "@effect-blockchain/stellar/StellarRpc"
13
+ * import * as Effect from "effect/Effect"
14
+ *
15
+ * declare const contract: StellarContractAddress
16
+ *
17
+ * // the first page of events of `contract` over the last 100 ledgers
18
+ * const recent = Effect.gen(function*() {
19
+ * const rpc = yield* StellarRpc.StellarRpc
20
+ * const { sequence } = yield* rpc.getLatestLedger
21
+ * return yield* rpc.getEvents({ contractIds: [contract], fromBlock: sequence - BigInt(100), toBlock: sequence })
22
+ * })
23
+ * ```
24
+ *
25
+ * @since 0.1.0
26
+ */
27
+ import * as JsonRpc from "@effect-blockchain/core/JsonRpc";
28
+ import * as Arr from "effect/Array";
29
+ import * as Config from "effect/Config";
30
+ import * as Context from "effect/Context";
31
+ import type * as Duration from "effect/Duration";
32
+ import * as Effect from "effect/Effect";
33
+ import type * as HttpClient from "effect/http/HttpClient";
34
+ import * as Layer from "effect/Layer";
35
+ import type * as Redacted from "effect/Redacted";
36
+ import * as Schema from "effect/Schema";
37
+ import type { StellarContractAddress } from "./StellarAddress.ts";
38
+ import type { StellarContractEvent } from "./StellarContractEvent.ts";
39
+ import * as StellarNetwork from "./StellarNetwork.ts";
40
+ /**
41
+ * A Stellar RPC endpoint. The `name` is shown in errors and spans and routes cursors, so it must be unique; the `url`
42
+ * is never logged.
43
+ *
44
+ * @since 0.1.0
45
+ * @category models
46
+ */
47
+ export interface StellarRpcEndpoint {
48
+ readonly name: string;
49
+ readonly url: Redacted.Redacted<string>;
50
+ }
51
+ declare const StellarRpcError_base: Schema.Class<StellarRpcError, Schema.TaggedStruct<"StellarRpcError", {
52
+ readonly reason: Schema.Union<readonly [typeof JsonRpc.Unavailable, typeof JsonRpc.InvalidResponse, typeof JsonRpc.Lagging, typeof JsonRpc.Pruned, typeof JsonRpc.Rejected, typeof JsonRpc.WrongNetwork]>;
53
+ readonly method: Schema.String;
54
+ readonly endpoint: Schema.String;
55
+ readonly code: Schema.optional<Schema.Number>;
56
+ readonly cause: Schema.Defect;
57
+ }>, import("effect/Cause").YieldableError>;
58
+ /**
59
+ * A failed call: its `reason` (a {@link JsonRpc.Reason}, matched with `Effect.catchReason`), the JSON-RPC error code or
60
+ * HTTP status as `code`, and a `cause` without the endpoint URL. After several endpoints, the error is the last one
61
+ * and `cause` is an `AggregateError` of each endpoint's error, in order.
62
+ *
63
+ * On Stellar, `Unavailable` includes the code -32603, `InvalidResponse` an event outside the `getEvents` filter,
64
+ * `Lagging` a latest ledger below `toBlock`, and `Pruned` an oldest retained ledger above `fromBlock` (or the cursor).
65
+ *
66
+ * @since 0.1.0
67
+ * @category errors
68
+ */
69
+ export declare class StellarRpcError extends StellarRpcError_base {
70
+ /**
71
+ * @since 0.1.0
72
+ */
73
+ get message(): string;
74
+ }
75
+ /**
76
+ * Where a `getEvents` page stopped: the RPC paging cursor and the endpoint that issued it. Opaque: only pass it back to
77
+ * `getEvents` with the same filter.
78
+ *
79
+ * @since 0.1.0
80
+ * @category schemas
81
+ */
82
+ export declare const StellarEventsCursor: Schema.brand<Schema.Struct<{
83
+ readonly endpoint: Schema.String;
84
+ readonly cursor: Schema.String;
85
+ }>, "StellarEventsCursor">;
86
+ /**
87
+ * @since 0.1.0
88
+ * @category models
89
+ */
90
+ export type StellarEventsCursor = typeof StellarEventsCursor.Type;
91
+ /**
92
+ * A `getEvents` filter over the inclusive ledger range `[fromBlock, toBlock]`.
93
+ *
94
+ * - `contractIds`: 1 to 5 contracts (the RPC limit).
95
+ * - `topics`: RPC topic filters, each a list of 1 to 4 segments: a base64 XDR `ScVal`, `"*"` (any one topic) or a
96
+ * final `"**"` (any number of topics). An event matches when it matches any filter.
97
+ * - `limit`: page size, default 1000, at most 10000.
98
+ * - `cursor`: the cursor of the previous page, to continue from it on the same endpoint.
99
+ *
100
+ * @since 0.1.0
101
+ * @category models
102
+ */
103
+ export interface StellarEventsFilter {
104
+ readonly contractIds: Arr.NonEmptyReadonlyArray<StellarContractAddress>;
105
+ readonly fromBlock: bigint;
106
+ readonly toBlock: bigint;
107
+ readonly topics?: ReadonlyArray<ReadonlyArray<string>> | undefined;
108
+ readonly limit?: number | undefined;
109
+ readonly cursor?: StellarEventsCursor | undefined;
110
+ }
111
+ /**
112
+ * One `getEvents` page, in chain order (sorted by event id). `cursor` is `undefined` once the range is done.
113
+ *
114
+ * @since 0.1.0
115
+ * @category models
116
+ */
117
+ export interface StellarEventsPage {
118
+ readonly events: ReadonlyArray<StellarContractEvent>;
119
+ readonly cursor: StellarEventsCursor | undefined;
120
+ }
121
+ /**
122
+ * @since 0.1.0
123
+ * @category models
124
+ */
125
+ export interface StellarNetworkInfo {
126
+ readonly passphrase: string;
127
+ readonly protocolVersion: number;
128
+ }
129
+ /**
130
+ * @since 0.1.0
131
+ * @category models
132
+ */
133
+ export interface StellarLatestLedger {
134
+ readonly sequence: bigint;
135
+ /** Hex hash of the ledger. */
136
+ readonly id: string;
137
+ readonly protocolVersion: number;
138
+ }
139
+ declare const StellarRpc_base: Context.ServiceClass<StellarRpc, "@effect-blockchain/stellar/StellarRpc", {
140
+ readonly network: StellarNetwork.StellarNetwork;
141
+ /**
142
+ * `getNetwork`, verified against `network` once per endpoint then served from that check: `protocolVersion` is the
143
+ * one seen at the check, `getLatestLedger` has the current one.
144
+ */
145
+ readonly getNetwork: Effect.Effect<StellarNetworkInfo, StellarRpcError>;
146
+ /** `getLatestLedger` */
147
+ readonly getLatestLedger: Effect.Effect<StellarLatestLedger, StellarRpcError>;
148
+ /**
149
+ * `getEvents` for contract events, one page in chain order (by event id), only answered by an endpoint whose latest
150
+ * ledger has reached `toBlock` and that still retains `fromBlock`. Events above `toBlock` are dropped, and an event of
151
+ * another type, of another contract or below `fromBlock` fails with `InvalidResponse`.
152
+ *
153
+ * `cursor` is `undefined` once the RPC cursor passes `toBlock`. A short page is not the end of the range: the RPC
154
+ * scans at most 10000 ledgers per request. A short page stopping at a latest ledger below `toBlock` fails `Lagging`.
155
+ */
156
+ readonly getEvents: (filter: StellarEventsFilter) => Effect.Effect<StellarEventsPage, StellarRpcError>;
157
+ }>;
158
+ /**
159
+ * @since 0.1.0
160
+ * @category services
161
+ */
162
+ export declare class StellarRpc extends StellarRpc_base {
163
+ }
164
+ /**
165
+ * Builds a {@link StellarRpc} over `endpoints`, tried in order, sending requests with the provided `HttpClient`
166
+ * (e.g. `FetchHttpClient.layer`). `timeout` (default 30 seconds) bounds each attempt, `retries` (default 3) and
167
+ * `retryDelay` (default 500 millis) set the backoff before falling back: see {@link JsonRpc.Unavailable}.
168
+ *
169
+ * @since 0.1.0
170
+ * @category layers
171
+ */
172
+ export declare const layer: (options: {
173
+ readonly network: StellarNetwork.StellarNetwork;
174
+ readonly endpoints: Arr.NonEmptyReadonlyArray<StellarRpcEndpoint>;
175
+ readonly timeout?: Duration.Input | undefined;
176
+ readonly retries?: number | undefined;
177
+ readonly retryDelay?: Duration.Input | undefined;
178
+ }) => Layer.Layer<StellarRpc, never, HttpClient.HttpClient>;
179
+ /**
180
+ * Builds an {@link StellarRpc} like {@link layer}, reading the options from `Config`. Endpoint URLs stay `Redacted`.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * import * as StellarRpc from "@effect-blockchain/stellar/StellarRpc"
185
+ * import * as Config from "effect/Config"
186
+ *
187
+ * const RpcLive = StellarRpc.layerConfig({
188
+ * network: Config.succeed("Stellar"),
189
+ * endpoints: Config.all([Config.all({ name: Config.succeed("main"), url: Config.Redacted("STELLAR_RPC_URL") })])
190
+ * })
191
+ * ```
192
+ *
193
+ * @since 0.1.0
194
+ * @category layers
195
+ */
196
+ export declare const layerConfig: (options: Config.Wrap<Parameters<typeof layer>[0]>) => Layer.Layer<StellarRpc, Config.ConfigError, HttpClient.HttpClient>;
197
+ export {};
198
+ //# sourceMappingURL=StellarRpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarRpc.d.ts","sourceRoot":"","sources":["../src/StellarRpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,OAAO,MAAM,iCAAiC,CAAA;AAC1D,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAEnC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAA;AACzD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAEhD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;CACxC;;;;;;;;AAED;;;;;;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AC,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC;IACvE,wBAAwB;8BACE,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,eAAe,CAAC;IAC7E;;;;;;;OAOG;wBACiB,CAAC,MAAM,EAAE,mBAAmB,KAAK,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,eAAe,CAAC;;AArBxG;;;GAGG;AACH,qBAAa,UAAW,SAAQ,eAkBa;CAAG;AAgBhD;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,YAAa;IAC7B,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,cAAc,CAAA;IAC/C,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAA;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAA;IAC7C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAA;CACjD,KAAG,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,CA8IrD,CAAA;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,YACb,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAChD,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CACX,CAAA"}
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Typed, read-only Stellar RPC methods over an ordered list of endpoints with fallback.
3
+ *
4
+ * A call starts at the first endpoint and moves to the next one on failure, except on `WrongNetwork`. Each endpoint
5
+ * is checked once to serve the configured network (`getNetwork` passphrase). Every method is a read, so retries and
6
+ * fallback are safe. Methods are named after the RPC method. A `getEvents` page cursor is only sent to the endpoint
7
+ * that issued it, with no fallback.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import type { StellarContractAddress } from "@effect-blockchain/stellar/StellarAddress"
12
+ * import * as StellarRpc from "@effect-blockchain/stellar/StellarRpc"
13
+ * import * as Effect from "effect/Effect"
14
+ *
15
+ * declare const contract: StellarContractAddress
16
+ *
17
+ * // the first page of events of `contract` over the last 100 ledgers
18
+ * const recent = Effect.gen(function*() {
19
+ * const rpc = yield* StellarRpc.StellarRpc
20
+ * const { sequence } = yield* rpc.getLatestLedger
21
+ * return yield* rpc.getEvents({ contractIds: [contract], fromBlock: sequence - BigInt(100), toBlock: sequence })
22
+ * })
23
+ * ```
24
+ *
25
+ * @since 0.1.0
26
+ */
27
+ import * as JsonRpc from "@effect-blockchain/core/JsonRpc";
28
+ import * as Arr from "effect/Array";
29
+ import * as BigInt_ from "effect/BigInt";
30
+ import * as Config from "effect/Config";
31
+ import * as Context from "effect/Context";
32
+ import * as Effect from "effect/Effect";
33
+ import * as Layer from "effect/Layer";
34
+ import * as Order from "effect/Order";
35
+ import * as Ref from "effect/Ref";
36
+ import * as Schema from "effect/Schema";
37
+ import * as RpcMethods from "./internal/rpcMethods.js";
38
+ import * as StellarNetwork from "./StellarNetwork.js";
39
+ /**
40
+ * A failed call: its `reason` (a {@link JsonRpc.Reason}, matched with `Effect.catchReason`), the JSON-RPC error code or
41
+ * HTTP status as `code`, and a `cause` without the endpoint URL. After several endpoints, the error is the last one
42
+ * and `cause` is an `AggregateError` of each endpoint's error, in order.
43
+ *
44
+ * On Stellar, `Unavailable` includes the code -32603, `InvalidResponse` an event outside the `getEvents` filter,
45
+ * `Lagging` a latest ledger below `toBlock`, and `Pruned` an oldest retained ledger above `fromBlock` (or the cursor).
46
+ *
47
+ * @since 0.1.0
48
+ * @category errors
49
+ */
50
+ export class StellarRpcError extends /*#__PURE__*/Schema.TaggedError()("StellarRpcError", {
51
+ reason: JsonRpc.Reason,
52
+ method: Schema.String,
53
+ endpoint: Schema.String,
54
+ code: /*#__PURE__*/Schema.optional(Schema.Number),
55
+ cause: /*#__PURE__*/Schema.Defect()
56
+ }) {
57
+ /**
58
+ * @since 0.1.0
59
+ */
60
+ get message() {
61
+ return `${this.method} failed on ${this.endpoint}: ${this.reason._tag}${this.code === undefined ? "" : ` (${this.code})`}`;
62
+ }
63
+ }
64
+ /**
65
+ * Where a `getEvents` page stopped: the RPC paging cursor and the endpoint that issued it. Opaque: only pass it back to
66
+ * `getEvents` with the same filter.
67
+ *
68
+ * @since 0.1.0
69
+ * @category schemas
70
+ */
71
+ export const StellarEventsCursor = /*#__PURE__*/Schema.Struct({
72
+ endpoint: Schema.String,
73
+ cursor: Schema.String
74
+ }).pipe(/*#__PURE__*/Schema.brand("StellarEventsCursor"));
75
+ /**
76
+ * @since 0.1.0
77
+ * @category services
78
+ */
79
+ export class StellarRpc extends /*#__PURE__*/Context.Service()("@effect-blockchain/stellar/StellarRpc") {}
80
+ // JSON-RPC internal error: stellar-rpc returns it for its own database or I/O failures, retry then fall back
81
+ const codes = /*#__PURE__*/new Map([[-32603, "Unavailable"]]);
82
+ // stellar-rpc's out-of-range start, current ("startLedger must be within the ledger range: X - Y") and older
83
+ // ("startLedger must be between the oldest ledger: X and the latest ledger: Y ...")
84
+ const ledgerRangeError = /startLedger must be \D*(\d+)\D+(\d+)/u;
85
+ // the ledger of a TOID cursor: ledger << 32 | transaction << 12 | operation
86
+ const cursorLedger = cursor => BigInt(cursor.slice(0, 19)) >> BigInt(32);
87
+ const byId = /*#__PURE__*/Order.mapInput(Order.String, event => event.id);
88
+ /**
89
+ * Builds a {@link StellarRpc} over `endpoints`, tried in order, sending requests with the provided `HttpClient`
90
+ * (e.g. `FetchHttpClient.layer`). `timeout` (default 30 seconds) bounds each attempt, `retries` (default 3) and
91
+ * `retryDelay` (default 500 millis) set the backoff before falling back: see {@link JsonRpc.Unavailable}.
92
+ *
93
+ * @since 0.1.0
94
+ * @category layers
95
+ */
96
+ export const layer = options => Layer.effect(StellarRpc, Effect.gen(function* () {
97
+ const {
98
+ network
99
+ } = options;
100
+ const passphrase = StellarNetwork.toPassphrase(network);
101
+ const rpc = yield* JsonRpc.make({
102
+ spanPrefix: "StellarRpc",
103
+ network,
104
+ endpoints: options.endpoints,
105
+ timeout: options.timeout,
106
+ retries: options.retries,
107
+ retryDelay: options.retryDelay,
108
+ codes,
109
+ checkNetwork: (send, endpoint) => send(RpcMethods.getNetwork, undefined).pipe(Effect.flatMap(info => info.passphrase === passphrase ? Effect.succeed(info) : Effect.fail(new StellarRpcError({
110
+ reason: new JsonRpc.WrongNetwork({
111
+ expected: passphrase,
112
+ actual: info.passphrase
113
+ }),
114
+ method: RpcMethods.getNetwork.name,
115
+ endpoint,
116
+ cause: new Error(`expected passphrase "${passphrase}" for ${network}, got "${info.passphrase}"`)
117
+ })))),
118
+ makeError: fields => new StellarRpcError(fields)
119
+ });
120
+ const {
121
+ call,
122
+ fail,
123
+ withFallback
124
+ } = rpc;
125
+ // retention is not cached (the oldest ledger moves): getHealth checks it with the head, and the RPC's own
126
+ // out-of-range error on getEvents is mapped back to Pruned or Lagging
127
+ const guard = Effect.fnUntraced(function* (endpoint, fromBlock, toBlock) {
128
+ if ((yield* Ref.get(endpoint.head)) >= toBlock) return;
129
+ const health = yield* call(endpoint, RpcMethods.getHealth, undefined);
130
+ yield* Ref.update(endpoint.head, BigInt_.max(health.latestLedger));
131
+ const method = RpcMethods.getEvents.name;
132
+ if (health.latestLedger < toBlock) {
133
+ return yield* fail(endpoint, method, new JsonRpc.Lagging({
134
+ head: health.latestLedger,
135
+ toBlock
136
+ }), new Error(`latest ledger ${health.latestLedger} is below toBlock ${toBlock}`));
137
+ }
138
+ if (health.oldestLedger > fromBlock) {
139
+ return yield* fail(endpoint, method, new JsonRpc.Pruned(), new Error(`oldest ledger ${health.oldestLedger} is above fromBlock ${fromBlock}`));
140
+ }
141
+ });
142
+ // `start` is lazy: a cursor that failed to encode is not a TOID
143
+ const outOfRange = (error, start) => {
144
+ const match = error.reason._tag === "Rejected" && error.cause instanceof Error ? ledgerRangeError.exec(error.cause.message) : null;
145
+ if (match === null) return error;
146
+ return new StellarRpcError({
147
+ reason: start() < BigInt(match[1]) ? new JsonRpc.Pruned() : new JsonRpc.Lagging({
148
+ head: BigInt(match[2]),
149
+ toBlock: start()
150
+ }),
151
+ method: error.method,
152
+ endpoint: error.endpoint,
153
+ code: error.code,
154
+ cause: error.cause
155
+ });
156
+ };
157
+ const getEventsOn = Effect.fnUntraced(function* (endpoint, filter) {
158
+ const {
159
+ cursor,
160
+ fromBlock,
161
+ toBlock
162
+ } = filter;
163
+ const method = RpcMethods.getEvents.name;
164
+ const limit = filter.limit ?? 1000;
165
+ if (cursor === undefined) yield* guard(endpoint, fromBlock, toBlock);
166
+ const page = yield* call(endpoint, RpcMethods.getEvents, {
167
+ ...(cursor === undefined ? {
168
+ startLedger: fromBlock,
169
+ endLedger: toBlock + BigInt(1)
170
+ } : {}),
171
+ filters: [{
172
+ type: "contract",
173
+ contractIds: filter.contractIds,
174
+ ...(filter.topics === undefined ? {} : {
175
+ topics: filter.topics
176
+ })
177
+ }],
178
+ pagination: {
179
+ limit,
180
+ ...(cursor === undefined ? {} : {
181
+ cursor: cursor.cursor
182
+ })
183
+ }
184
+ }).pipe(Effect.mapError(error => outOfRange(error, () => cursor === undefined ? fromBlock : cursorLedger(cursor.cursor))));
185
+ yield* Ref.update(endpoint.head, BigInt_.max(page.latestLedger));
186
+ const contracts = new Set(filter.contractIds);
187
+ const invalid = page.events.find(event => event.type !== "contract" || !contracts.has(event.contractId) || event.blockNumber < fromBlock);
188
+ if (invalid !== undefined) {
189
+ return yield* fail(endpoint, method, new JsonRpc.InvalidResponse(), new Error(`event ${invalid.id} is outside the filter`));
190
+ }
191
+ const last = cursorLedger(page.cursor);
192
+ const full = page.events.length >= limit;
193
+ if (!full && last < toBlock && last >= page.latestLedger) {
194
+ return yield* fail(endpoint, method, new JsonRpc.Lagging({
195
+ head: page.latestLedger,
196
+ toBlock
197
+ }), new Error(`latest ledger ${page.latestLedger} is below toBlock ${toBlock}`));
198
+ }
199
+ const done = last > toBlock || !full && last === toBlock;
200
+ return {
201
+ events: Arr.sort(page.events.filter(event => event.blockNumber <= toBlock), byId),
202
+ cursor: done ? undefined : StellarEventsCursor.make({
203
+ endpoint: endpoint.name,
204
+ cursor: page.cursor
205
+ })
206
+ };
207
+ });
208
+ return StellarRpc.of({
209
+ network,
210
+ getNetwork: withFallback(rpc.checkNetwork),
211
+ getLatestLedger: withFallback(endpoint => call(endpoint, RpcMethods.getLatestLedger, undefined).pipe(Effect.tap(ledger => Ref.update(endpoint.head, BigInt_.max(ledger.sequence))))),
212
+ getEvents: filter => {
213
+ const {
214
+ cursor
215
+ } = filter;
216
+ if (filter.fromBlock > filter.toBlock) return Effect.succeed({
217
+ events: [],
218
+ cursor: undefined
219
+ });
220
+ if (cursor === undefined) return withFallback(endpoint => getEventsOn(endpoint, filter));
221
+ // a cursor is only valid on the endpoint that issued it
222
+ return rpc.endpointOf(RpcMethods.getEvents.name, cursor).pipe(Effect.flatMap(endpoint => getEventsOn(endpoint, filter)));
223
+ }
224
+ });
225
+ }));
226
+ /**
227
+ * Builds an {@link StellarRpc} like {@link layer}, reading the options from `Config`. Endpoint URLs stay `Redacted`.
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * import * as StellarRpc from "@effect-blockchain/stellar/StellarRpc"
232
+ * import * as Config from "effect/Config"
233
+ *
234
+ * const RpcLive = StellarRpc.layerConfig({
235
+ * network: Config.succeed("Stellar"),
236
+ * endpoints: Config.all([Config.all({ name: Config.succeed("main"), url: Config.Redacted("STELLAR_RPC_URL") })])
237
+ * })
238
+ * ```
239
+ *
240
+ * @since 0.1.0
241
+ * @category layers
242
+ */
243
+ export const layerConfig = options => Layer.unwrap(Effect.map(Config.unwrap(options), layer));
244
+ //# sourceMappingURL=StellarRpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarRpc.js","names":[],"sources":["../src/Stell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AAM,CAAC,GAAG,CAAE,MAAM,IAAK,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAChF,CACF;IACD,SAAS,EAAG,MAAM,IAAI;MACpB,MAAM;QAAE;MAAM,CAAE,GAAG,MAAM;MACzB,IAAI,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,MAAM,CAAC,OAAO,CAAC;QAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE;MAAS,CAAE,CAAC;MAC/F,IAAI,MAAM,KAAK,SAAS,EAAE,OAAO,YAAY,CAAE,QAAQ,IAAK,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;MAC1F;MACA,OAAO,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CAC3D,MAAM,CAAC,OAAO,CAAE,QAAQ,IAAK,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAC5D;IACH;GACD,CAAC;AACJ,CAAC,CAAC,CACH;AAEH;;;;;;;;;;;;;;;;;AAiBA,OAAO,MAAM,WAAW,GACtB,OAAiD,IAEjD,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ import * as Schema from "effect/Schema";
2
+ /**
3
+ * A Stellar transaction hash: 32 bytes as lowercase hex.
4
+ *
5
+ * Decoding lower-cases the input and adds a `0x` prefix when missing, so the raw 64-hex form Horizon and RPC return
6
+ * is accepted and normalized to `0x…`. Encoding keeps the `0x` prefix: strip it before querying Stellar APIs.
7
+ *
8
+ * @since 0.1.0
9
+ * @category schemas
10
+ */
11
+ export declare const StellarTransactionHash: Schema.brand<Schema.decodeTo<Schema.String, Schema.decodeTo<Schema.String, Schema.String, never, never>, never, never>, "StellarTransactionHash">;
12
+ /**
13
+ * @since 0.1.0
14
+ * @category models
15
+ */
16
+ export type StellarTransactionHash = typeof StellarTransactionHash.Type;
17
+ //# sourceMappingURL=StellarTransactionHash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarTransactionHash.d.ts","sourceRoot":"","sources":["../src/StellarTransactionHash.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAKvC;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,mJAclC,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,OAAO,sBAAsB,CAAC,IAAI,CAAA"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Stellar transaction hashes.
3
+ *
4
+ * @since 0.1.0
5
+ */
6
+ import { identity, pipe } from "effect/Function";
7
+ import * as Schema from "effect/Schema";
8
+ import * as SchemaTransformation from "effect/SchemaTransformation";
9
+ const stellarTransactionHashRegex = /^0x[a-f0-9]{64}$/u;
10
+ /**
11
+ * A Stellar transaction hash: 32 bytes as lowercase hex.
12
+ *
13
+ * Decoding lower-cases the input and adds a `0x` prefix when missing, so the raw 64-hex form Horizon and RPC return
14
+ * is accepted and normalized to `0x…`. Encoding keeps the `0x` prefix: strip it before querying Stellar APIs.
15
+ *
16
+ * @since 0.1.0
17
+ * @category schemas
18
+ */
19
+ export const StellarTransactionHash = /*#__PURE__*/pipe(Schema.String, /*#__PURE__*/Schema.decodeTo(/*#__PURE__*/Schema.String.check(/*#__PURE__*/Schema.isLowercased()), /*#__PURE__*/SchemaTransformation.toLowerCase()), /*#__PURE__*/Schema.decodeTo(Schema.String, /*#__PURE__*/SchemaTransformation.transform({
20
+ decode: s => s.startsWith("0x") ? s : `0x${s}`,
21
+ encode: identity
22
+ })), /*#__PURE__*/Schema.check(/*#__PURE__*/Schema.isPattern(stellarTransactionHashRegex, {
23
+ message: "Not a valid Stellar transaction hash"
24
+ })), /*#__PURE__*/Schema.brand("StellarTransactionHash"), /*#__PURE__*/Schema.annotate({
25
+ identifier: "StellarTransactionHash",
26
+ title: "Stellar transaction hash",
27
+ description: "a valid Stellar transaction hash, 0x followed by 64 lowercase hexadecimal characters"
28
+ }));
29
+ //# sourceMappingURL=StellarTransactionHash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarTransactionHash.js","names":[],"sources":["../src/StellarTransactionHash.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,SAAS,QAAQ,EAAE,IAAI,QAAQ,iBAAiB;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,oBAAoB,MAAM,6BAA6B;AAEnE,MAAM,2BAA2B,GAAG,mBAAmB;AAEvD;;;;;;;;;AASA,OAAO,MAAM,sBAAsB,gBAAG,IAAI,CACxC,MAAM,CAAC,MAAM,eACb,MAAM,CAAC,QAAQ,cAAC,MAAM,CAAC,MAAM,CAAC,KAAK,cAAC,MAAM,CAAC,YAAY,EAAE,CAAC,eAAE,oBAAoB,CAAC,WAAW,EAAE,CAAC,eAC/F,MAAM,CAAC,QAAQ,CACb,MAAM,CAAC,MAAM,eACb,oBAAoB,CAAC,SAAS,CAAC;EAAE,MAAM,EAAG,CAAS,IAAM,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,EAAG;EAAE,MAAM,EAAE;AAAQ,CAAE,CAAC,CACjH,eACD,MAAM,CAAC,KAAK,cAAC,MAAM,CAAC,SAAS,CAAC,2BAA2B,EAAE;EAAE,OAAO,EAAE;AAAsC,CAAE,CAAC,CAAC,eAChH,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,eACtC,MAAM,CAAC,QAAQ,CAAC;EACd,UAAU,EAAE,wBAAwB;EACpC,KAAK,EAAE,0BAA0B;EACjC,WAAW,EAAE;CACd,CAAC,CACH","ignoreList":[]}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @since 0.1.0
3
+ */
4
+ /**
5
+ * @since 0.1.0
6
+ */
7
+ export * as StellarAddress from "./StellarAddress.ts";
8
+ /**
9
+ * @since 0.1.0
10
+ */
11
+ export * as StellarContractEvent from "./StellarContractEvent.ts";
12
+ /**
13
+ * @since 0.1.0
14
+ */
15
+ export * as StellarIndexer from "./StellarIndexer.ts";
16
+ /**
17
+ * @since 0.1.0
18
+ */
19
+ export * as StellarNetwork from "./StellarNetwork.ts";
20
+ /**
21
+ * @since 0.1.0
22
+ */
23
+ export * as StellarRpc from "./StellarRpc.ts";
24
+ /**
25
+ * @since 0.1.0
26
+ */
27
+ export * as StellarTransactionHash from "./StellarTransactionHash.ts";
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;GAEG;AACH,OAAO,KAAK,oBAAoB,MAAM,2BAA2B,CAAA;AAEjE;;GAEG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;GAEG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;GAEG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;GAEG;AACH,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @since 0.1.0
3
+ */
4
+ // @barrel: Auto-generated exports. Do not edit manually.
5
+ /**
6
+ * @since 0.1.0
7
+ */
8
+ export * as StellarAddress from "./StellarAddress.js";
9
+ /**
10
+ * @since 0.1.0
11
+ */
12
+ export * as StellarContractEvent from "./StellarContractEvent.js";
13
+ /**
14
+ * @since 0.1.0
15
+ */
16
+ export * as StellarIndexer from "./StellarIndexer.js";
17
+ /**
18
+ * @since 0.1.0
19
+ */
20
+ export * as StellarNetwork from "./StellarNetwork.js";
21
+ /**
22
+ * @since 0.1.0
23
+ */
24
+ export * as StellarRpc from "./StellarRpc.js";
25
+ /**
26
+ * @since 0.1.0
27
+ */
28
+ export * as StellarTransactionHash from "./StellarTransactionHash.js";
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;AAGA,OAAO,KAAK,cAAc,MAAM,qBAAqB;AAErD;;;AAGA,OAAO,KAAK,oBAAoB,MAAM,2BAA2B;AAEjE;;;AAGA,OAAO,KAAK,cAAc,MAAM,qBAAqB;AAErD;;;AAGA,OAAO,KAAK,cAAc,MAAM,qBAAqB;AAErD;;;AAGA,OAAO,KAAK,UAAU,MAAM,iBAAiB;AAE7C;;;AAGA,OAAO,KAAK,sBAAsB,MAAM,6BAA6B","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=LedgerFromNumber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LedgerFromNumber.d.ts","sourceRoot":"","sources":["../../src/internal/LedgerFromNumber.ts"],"names":[],"mappings":""}