@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Spiko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # `@effect-blockchain/stellar`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Stellar blockchain toolkit for Effect.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @effect-blockchain/stellar effect @stellar/stellar-sdk
9
+ ```
10
+
11
+ ## License
12
+
13
+ MIT
@@ -0,0 +1,48 @@
1
+ import * as Schema from "effect/Schema";
2
+ /**
3
+ * A Stellar account address: a `G…` ed25519 public key strkey (56 base32 characters, checksum verified). Input is
4
+ * upper-cased before validation.
5
+ *
6
+ * @since 0.1.0
7
+ * @category schemas
8
+ */
9
+ export declare const StellarAccountAddress: Schema.brand<Schema.decodeTo<Schema.declare<string, string>, Schema.decodeTo<Schema.String, Schema.String, never, never>, never, never>, "StellarAccountAddress">;
10
+ /**
11
+ * @since 0.1.0
12
+ * @category models
13
+ */
14
+ export type StellarAccountAddress = typeof StellarAccountAddress.Type;
15
+ /**
16
+ * A Stellar (Soroban) contract address: a `C…` contract strkey (56 base32 characters, checksum verified). Input is
17
+ * upper-cased before validation.
18
+ *
19
+ * @since 0.1.0
20
+ * @category schemas
21
+ */
22
+ export declare const StellarContractAddress: Schema.brand<Schema.decodeTo<Schema.declare<string, string>, Schema.decodeTo<Schema.String, Schema.String, never, never>, never, never>, "StellarContractAddress">;
23
+ /**
24
+ * @since 0.1.0
25
+ * @category models
26
+ */
27
+ export type StellarContractAddress = typeof StellarContractAddress.Type;
28
+ /**
29
+ * Either a Stellar account address or a Stellar contract address.
30
+ *
31
+ * @since 0.1.0
32
+ * @category schemas
33
+ */
34
+ export declare const StellarAddress: Schema.Union<readonly [Schema.brand<Schema.decodeTo<Schema.declare<string, string>, Schema.decodeTo<Schema.String, Schema.String, never, never>, never, never>, "StellarAccountAddress">, Schema.brand<Schema.decodeTo<Schema.declare<string, string>, Schema.decodeTo<Schema.String, Schema.String, never, never>, never, never>, "StellarContractAddress">]>;
35
+ /**
36
+ * @since 0.1.0
37
+ * @category models
38
+ */
39
+ export type StellarAddress = typeof StellarAddress.Type;
40
+ /**
41
+ * The all-zero ed25519 account, used by Soroban as a placeholder source account (`contract.NULL_ACCOUNT` in
42
+ * `@stellar/stellar-sdk`).
43
+ *
44
+ * @since 0.1.0
45
+ * @category constants
46
+ */
47
+ export declare const NULL_ADDRESS: StellarAccountAddress;
48
+ //# sourceMappingURL=StellarAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarAddress.d.ts","sourceRoot":"","sources":["../src/StellarAddress.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAiBvC;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,mKAejC,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAC,IAAI,CAAA;AAIrE;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,oKAelC,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,OAAO,sBAAsB,CAAC,IAAI,CAAA;AAEvE;;;;;GAKG;AACH,eAAO,MAAM,cAAc,gWAAgE,CAAA;AAE3F;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,IAAI,CAAA;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,qBAE1B,CAAA"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Stellar account (`G…`) and contract (`C…`) addresses, validated as strkeys.
3
+ *
4
+ * Muxed accounts (`M…`) are rejected: they are an off-chain multiplexing convenience on top of a `G…` account and
5
+ * cannot hold balances or be used as contract arguments.
6
+ *
7
+ * @since 0.1.0
8
+ */
9
+ import { StrKey } from "@stellar/stellar-sdk";
10
+ import { pipe } from "effect/Function";
11
+ import * as Predicate from "effect/Predicate";
12
+ import * as Schema from "effect/Schema";
13
+ import * as SchemaGetter from "effect/SchemaGetter";
14
+ import * as SchemaTransformation from "effect/SchemaTransformation";
15
+ // Declared so arbitraries encode random 32-byte payloads: random base32 strings almost never pass the CRC16 checksum.
16
+ const strKey = (expected, isValid, encode) => Schema.declare(u => Predicate.isString(u) && isValid(u), {
17
+ expected,
18
+ toCodecArbitrary: () => Schema.link()(Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/u)), {
19
+ decode: SchemaGetter.transform(hex => encode(Buffer.from(hex, "hex"))),
20
+ encode: SchemaGetter.forbiddenEncoding
21
+ })
22
+ });
23
+ const stellarAccountAddressRegex = /^G[A-Z2-7]{55}$/u;
24
+ /**
25
+ * A Stellar account address: a `G…` ed25519 public key strkey (56 base32 characters, checksum verified). Input is
26
+ * upper-cased before validation.
27
+ *
28
+ * @since 0.1.0
29
+ * @category schemas
30
+ */
31
+ export const StellarAccountAddress = /*#__PURE__*/pipe(Schema.String, /*#__PURE__*/Schema.decodeTo(/*#__PURE__*/Schema.String.check(/*#__PURE__*/Schema.isUppercased()), /*#__PURE__*/SchemaTransformation.toUpperCase()), /*#__PURE__*/Schema.check(/*#__PURE__*/Schema.isPattern(stellarAccountAddressRegex, {
32
+ expected: "a valid Stellar account address"
33
+ })), /*#__PURE__*/Schema.decodeTo(/*#__PURE__*/strKey("a valid Stellar account checksum", StrKey.isValidEd25519PublicKey, StrKey.encodeEd25519PublicKey), /*#__PURE__*/SchemaTransformation.passthrough()), /*#__PURE__*/Schema.brand("StellarAccountAddress"), /*#__PURE__*/Schema.annotate({
34
+ identifier: "StellarAccountAddress",
35
+ title: "Stellar account address",
36
+ description: "a valid Stellar account address, starting with G and followed by 55 base32 characters e.g. \"GBYIQXBKEB655EB3WTRITS6RR5GXEP6SQRBLPREZHNFYKT7WBMTMPR3H\""
37
+ }));
38
+ const stellarContractAddressRegex = /^C[A-Z2-7]{55}$/u;
39
+ /**
40
+ * A Stellar (Soroban) contract address: a `C…` contract strkey (56 base32 characters, checksum verified). Input is
41
+ * upper-cased before validation.
42
+ *
43
+ * @since 0.1.0
44
+ * @category schemas
45
+ */
46
+ export const StellarContractAddress = /*#__PURE__*/pipe(Schema.String, /*#__PURE__*/Schema.decodeTo(/*#__PURE__*/Schema.String.check(/*#__PURE__*/Schema.isUppercased()), /*#__PURE__*/SchemaTransformation.toUpperCase()), /*#__PURE__*/Schema.check(/*#__PURE__*/Schema.isPattern(stellarContractAddressRegex, {
47
+ expected: "a valid Stellar contract address"
48
+ })), /*#__PURE__*/Schema.decodeTo(/*#__PURE__*/strKey("a valid Stellar contract checksum", StrKey.isValidContract, StrKey.encodeContract), /*#__PURE__*/SchemaTransformation.passthrough()), /*#__PURE__*/Schema.brand("StellarContractAddress"), /*#__PURE__*/Schema.annotate({
49
+ identifier: "StellarContractAddress",
50
+ title: "Stellar contract address",
51
+ description: "a valid Stellar contract address, starting with C and followed by 55 base32 characters e.g. \"CCAANR7HZNOXYZD7SXS2WQLV5BAOXSRZ7V4O43IANSB355QN2RNG7WVC\""
52
+ }));
53
+ /**
54
+ * Either a Stellar account address or a Stellar contract address.
55
+ *
56
+ * @since 0.1.0
57
+ * @category schemas
58
+ */
59
+ export const StellarAddress = /*#__PURE__*/Schema.Union([StellarAccountAddress, StellarContractAddress]);
60
+ /**
61
+ * The all-zero ed25519 account, used by Soroban as a placeholder source account (`contract.NULL_ACCOUNT` in
62
+ * `@stellar/stellar-sdk`).
63
+ *
64
+ * @since 0.1.0
65
+ * @category constants
66
+ */
67
+ export const NULL_ADDRESS = /*#__PURE__*/StellarAccountAddress.make("GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF");
68
+ //# sourceMappingURL=StellarAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarAddress.js","names":[],"sources":["../src/StellarAddress.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;AAQA,SAAS,MAAM,QAAQ,sBAAsB;AAC7C,SAAS,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAK,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,YAAY,MAAM,qBAAqB;AACnD,OAAO,KAAK,oBAAoB,MAAM,6BAA6B;AAEnE;AACA,MAAM,MAAM,GAAG,CAAC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AG,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,KAAK,cAAC,MAAM,CAAC,SAAS,CAAC,2BAA2B,EAAE;EAAE,QAAQ,EAAE;AAAkC,CAAE,CAAC,CAAC,eAC7G,MAAM,CAAC,QAAQ,cACb,MAAM,CAAC,mCAAmC,EAAE,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,cAAc,CAAC,eAC1F,oBAAoB,CAAC,WAAW,EAAE,CACnC,eACD,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,eACtC,MAAM,CAAC,QAAQ,CAAC;EACd,UAAU,EAAE,wBAAwB;EACpC,KAAK,EAAE,0BAA0B;EACjC,WAAW,EACT;CACH,CAAC,CACH;AAQD;;;;;;AAMA,OAAO,MAAM,cAAc,gBAAG,MAAM,CAAC,KAAK,CAAC,CAAC,qBAAqB,EAAE,sBAAsB,CAAC,CAAC;AAQ3F;;;;;;;AAOA,OAAO,MAAM,YAAY,gBAA0B,qBAAqB,CAAC,IAAI,CAC3E,0DAA0D,CAC3D","ignoreList":[]}
@@ -0,0 +1,41 @@
1
+ import * as Schema from "effect/Schema";
2
+ /**
3
+ * A contract event, decoded from the raw `getEvents` event. The encoded side is the RPC shape (`ledger`, `txHash`,
4
+ * `topic`), the decoded side uses the names shared with the other chains (`blockNumber`, `transactionHash`, `topics`).
5
+ *
6
+ * - `id` is the RPC event id, a 19-digit TOID and a 10-digit event index: sorting ids as strings gives chain order.
7
+ * - `topics` and `value` are base64 XDR `ScVal`s, left undecoded. The RPC omits `topic` when empty.
8
+ * - `inSuccessfulContractCall` is kept raw: filtering out events of failed calls is the indexer's job. Stellar RPC
9
+ * stopped sending it once it was always `true` (protocol 23 no longer emits events of failed calls), so a missing
10
+ * field decodes to `true`.
11
+ *
12
+ * @since 0.1.0
13
+ * @category schemas
14
+ */
15
+ export declare const StellarContractEvent: Schema.decodeTo<Schema.Struct<{
16
+ readonly id: Schema.String;
17
+ readonly type: Schema.Literals<readonly ["contract", "system", "diagnostic"]>;
18
+ readonly contractId: Schema.brand<Schema.decodeTo<Schema.declare<string, string>, Schema.decodeTo<Schema.String, Schema.String, never, never>, never, never>, "StellarContractAddress">;
19
+ readonly topics: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
20
+ readonly value: Schema.String;
21
+ readonly blockNumber: Schema.decodeTo<Schema.BigInt, Schema.Int, never, never>;
22
+ readonly ledgerClosedAt: Schema.String;
23
+ readonly transactionHash: Schema.decodeTo<Schema.brand<Schema.decodeTo<Schema.String, Schema.decodeTo<Schema.String, Schema.String, never, never>, never, never>, "StellarTransactionHash">, Schema.String, never, never>;
24
+ readonly inSuccessfulContractCall: Schema.withDecodingDefaultKey<Schema.Boolean, never>;
25
+ }>, Schema.Struct<{
26
+ readonly contractId: Schema.toEncoded<Schema.brand<Schema.decodeTo<Schema.declare<string, string>, Schema.decodeTo<Schema.String, Schema.String, never, never>, never, never>, "StellarContractAddress">>;
27
+ readonly id: Schema.toEncoded<Schema.String>;
28
+ readonly inSuccessfulContractCall: Schema.toEncoded<Schema.withDecodingDefaultKey<Schema.Boolean, never>>;
29
+ readonly ledger: Schema.toEncoded<Schema.decodeTo<Schema.BigInt, Schema.Int, never, never>>;
30
+ readonly ledgerClosedAt: Schema.toEncoded<Schema.String>;
31
+ readonly topic: Schema.toEncoded<Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>>;
32
+ readonly txHash: Schema.toEncoded<Schema.decodeTo<Schema.brand<Schema.decodeTo<Schema.String, Schema.decodeTo<Schema.String, Schema.String, never, never>, never, never>, "StellarTransactionHash">, Schema.String, never, never>>;
33
+ readonly type: Schema.toEncoded<Schema.Literals<readonly ["contract", "system", "diagnostic"]>>;
34
+ readonly value: Schema.toEncoded<Schema.String>;
35
+ }>, never, never>;
36
+ /**
37
+ * @since 0.1.0
38
+ * @category models
39
+ */
40
+ export type StellarContractEvent = typeof StellarContractEvent.Type;
41
+ //# sourceMappingURL=StellarContractEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarContractEvent.d.ts","sourceRoot":"","sources":["../src/StellarContractEvent.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAcvC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;iBAahC,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,oBAAoB,CAAC,IAAI,CAAA"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Soroban contract events, as returned by Stellar RPC `getEvents`.
3
+ *
4
+ * @since 0.1.0
5
+ */
6
+ import * as Effect from "effect/Effect";
7
+ import { identity } from "effect/Function";
8
+ import * as Schema from "effect/Schema";
9
+ import * as SchemaTransformation from "effect/SchemaTransformation";
10
+ import { LedgerFromNumber } from "./internal/LedgerFromNumber.js";
11
+ import { StellarContractAddress } from "./StellarAddress.js";
12
+ import { StellarTransactionHash } from "./StellarTransactionHash.js";
13
+ // the RPC sends the hash without `0x`: encode back to that shape
14
+ const RpcTransactionHash = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.decodeTo(StellarTransactionHash, /*#__PURE__*/SchemaTransformation.transform({
15
+ decode: identity,
16
+ encode: hash => hash.replace(/^0x/u, "")
17
+ })));
18
+ /**
19
+ * A contract event, decoded from the raw `getEvents` event. The encoded side is the RPC shape (`ledger`, `txHash`,
20
+ * `topic`), the decoded side uses the names shared with the other chains (`blockNumber`, `transactionHash`, `topics`).
21
+ *
22
+ * - `id` is the RPC event id, a 19-digit TOID and a 10-digit event index: sorting ids as strings gives chain order.
23
+ * - `topics` and `value` are base64 XDR `ScVal`s, left undecoded. The RPC omits `topic` when empty.
24
+ * - `inSuccessfulContractCall` is kept raw: filtering out events of failed calls is the indexer's job. Stellar RPC
25
+ * stopped sending it once it was always `true` (protocol 23 no longer emits events of failed calls), so a missing
26
+ * field decodes to `true`.
27
+ *
28
+ * @since 0.1.0
29
+ * @category schemas
30
+ */
31
+ export const StellarContractEvent = /*#__PURE__*/Schema.Struct({
32
+ id: Schema.String.check(Schema.isPattern(/^\d{19}-\d{10}$/u)),
33
+ type: Schema.Literals(["contract", "system", "diagnostic"]),
34
+ contractId: StellarContractAddress,
35
+ topics: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
36
+ value: Schema.String,
37
+ blockNumber: LedgerFromNumber,
38
+ ledgerClosedAt: Schema.String,
39
+ transactionHash: RpcTransactionHash,
40
+ inSuccessfulContractCall: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(true)))
41
+ }).pipe(/*#__PURE__*/Schema.encodeKeys({
42
+ topics: "topic",
43
+ blockNumber: "ledger",
44
+ transactionHash: "txHash"
45
+ }), /*#__PURE__*/Schema.annotate({
46
+ identifier: "StellarContractEvent",
47
+ title: "Stellar contract event"
48
+ }));
49
+ //# sourceMappingURL=StellarContractEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarContractEvent.js","names":[],"sources":["../src/StellarContractEvent.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,SAAS,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,oBAAoB,MAAM,6BAA6B;AACnE,SAAS,gBAAgB,QAAQ,gCAAgC;AACjE,SAAS,sBAAsB,QAAQ,qBAAqB;AAC5D,SAAS,sBAAsB,QAAQ,6BAA6B;AAEpE;AACA,MAAM,kBAAkB,gBAAG,MAAM,CAAC,MAAM,CAAC,IAAI,cAC3C,MAAM,CAAC,QAAQ,CACb,sBAAsB,eACtB,oBAAoB,CAAC,SAAS,CAAC;EAAE,MAAM,EAAE,QAAQ;EAAE,MAAM,EAAG,IAAY,IAAK,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;AAAC,CAAE,CAAC,CACzG,CACF;AAED;;;;;;;;;;;;;AAaA,OAAO,MAAM,oBAAoB,gBAAG,MAAM,CAAC,MAAM,CAAC;EAChD,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;EAC7D,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;EAC3D,UAAU,EAAE,sBAAsB;EAClC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;EAC3F,KAAK,EAAE,MAAM,CAAC,MAAM;EACpB,WAAW,EAAE,gBAAgB;EAC7B,cAAc,EAAE,MAAM,CAAC,MAAM;EAC7B,eAAe,EAAE,kBAAkB;EACnC,wBAAwB,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;CAClG,CAAC,CAAC,IAAI,cACL,MAAM,CAAC,UAAU,CAAC;EAAE,MAAM,EAAE,OAAO;EAAE,WAAW,EAAE,QAAQ;EAAE,eAAe,EAAE;AAAQ,CAAE,CAAC,eACxF,MAAM,CAAC,QAAQ,CAAC;EAAE,UAAU,EAAE,sBAAsB;EAAE,KAAK,EAAE;AAAwB,CAAE,CAAC,CACzF","ignoreList":[]}
@@ -0,0 +1,121 @@
1
+ import * as Config from "effect/Config";
2
+ import * as Context from "effect/Context";
3
+ import * as Duration from "effect/Duration";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import * as Schedule from "effect/Schedule";
7
+ import * as Stream from "effect/Stream";
8
+ import type { StellarContractEvent } from "./StellarContractEvent.ts";
9
+ import type { StellarEventsFilter, StellarRpcError } from "./StellarRpc.ts";
10
+ import { StellarRpc } from "./StellarRpc.ts";
11
+ /**
12
+ * The default `maxBlockRange`: 10000 ledgers, the most a Stellar RPC scans per request (`LedgerScanLimit` in
13
+ * https://github.com/stellar/stellar-rpc/blob/main/cmd/stellar-rpc/internal/methods/get_events.go).
14
+ *
15
+ * @since 0.1.0
16
+ * @category constants
17
+ */
18
+ export declare const DEFAULT_MAX_BLOCK_RANGE = 10000;
19
+ /**
20
+ * A {@link StellarEventsFilter} without its paging fields (`limit`, `cursor`), over the inclusive ledger range
21
+ * `[fromBlock, toBlock]`. `contractIds` has no size limit here.
22
+ *
23
+ * @since 0.1.0
24
+ * @category models
25
+ */
26
+ export type StellarIndexerFilter = Omit<StellarEventsFilter, "limit" | "cursor">;
27
+ /**
28
+ * The events of the ledgers `[fromBlock, toBlock]` (both inclusive), in chain order, emitted by
29
+ * {@link StellarIndexer.Service.streamEvents}.
30
+ *
31
+ * A batch is emitted for every range, even without events. Delivery is at-least-once: save `batch.toBlock` once the
32
+ * batch is handled and resume from `toBlock + 1`. RPC nodes keep about 7 days of ledgers: an older `fromBlock` fails
33
+ * the stream with `Pruned`.
34
+ *
35
+ * @since 0.1.0
36
+ * @category models
37
+ */
38
+ export interface StellarIndexerBatch {
39
+ readonly fromBlock: bigint;
40
+ readonly toBlock: bigint;
41
+ readonly events: ReadonlyArray<StellarContractEvent>;
42
+ }
43
+ /**
44
+ * The {@link StellarIndexer.Service.streamEvents} options.
45
+ *
46
+ * @since 0.1.0
47
+ * @category models
48
+ */
49
+ export interface StellarIndexerStreamOptions {
50
+ readonly filter: Omit<StellarIndexerFilter, "fromBlock" | "toBlock">;
51
+ readonly fromBlock: bigint;
52
+ /** The stream ends after the batch reaching it, and is empty when `fromBlock > toBlock`. */
53
+ readonly toBlock?: bigint | undefined;
54
+ /**
55
+ * When to read the head again once caught up, `Schedule.spaced(DEFAULT_POLL_INTERVAL)` by default. It restarts after
56
+ * each batch, and its end ends the stream: `Schedule.recurs(0)` drains to the head and stops.
57
+ */
58
+ readonly poll?: Schedule.Schedule<unknown> | undefined;
59
+ /** Retries a step failing with a transient reason ({@link JsonRpc.isTransient}) at the same ledger. Off by default. */
60
+ readonly retry?: Schedule.Schedule<unknown, StellarRpcError> | undefined;
61
+ }
62
+ declare const StellarIndexer_base: Context.ServiceClass<StellarIndexer, "@effect-blockchain/stellar/StellarIndexer", {
63
+ /** The latest ledger minus the configured confirmations, never below 0. */
64
+ readonly lastConfirmedBlock: Effect.Effect<bigint, StellarRpcError>;
65
+ /**
66
+ * Every contract event matching `filter`, in chain order (event id order). Events of failed contract calls
67
+ * (`inSuccessfulContractCall: false`) are dropped. `fromBlock > toBlock` returns no events.
68
+ */
69
+ readonly fetchEvents: (filter: StellarIndexerFilter) => Effect.Effect<ReadonlyArray<StellarContractEvent>, StellarRpcError>;
70
+ /**
71
+ * The events matching `filter` from `fromBlock` on, in batches of at most `maxBlockRange` confirmed ledgers,
72
+ * following the confirmed head.
73
+ */
74
+ readonly streamEvents: (options: StellarIndexerStreamOptions) => Stream.Stream<StellarIndexerBatch, StellarRpcError>;
75
+ }>;
76
+ /**
77
+ * @since 0.1.0
78
+ * @category services
79
+ */
80
+ export declare class StellarIndexer extends StellarIndexer_base {
81
+ }
82
+ /**
83
+ * The default `poll` spacing of {@link StellarIndexer.Service.streamEvents}: 10 seconds.
84
+ *
85
+ * @since 0.1.0
86
+ * @category constants
87
+ */
88
+ export declare const DEFAULT_POLL_INTERVAL: Duration.Duration;
89
+ /**
90
+ * Builds a {@link StellarIndexer} over the provided {@link StellarRpc}.
91
+ *
92
+ * - `confirmations`: ledgers kept behind the latest one, default {@link StellarNetwork.defaultConfirmations} of the
93
+ * RPC's network.
94
+ * - `maxBlockRange`: ledgers per range, a positive integer, default {@link DEFAULT_MAX_BLOCK_RANGE}.
95
+ * - `limit`: `getEvents` page size, default 1000, at most 10000.
96
+ *
97
+ * @since 0.1.0
98
+ * @category layers
99
+ */
100
+ export declare const layer: (options?: {
101
+ readonly confirmations?: number | undefined;
102
+ readonly maxBlockRange?: number | undefined;
103
+ readonly limit?: number | undefined;
104
+ }) => Layer.Layer<StellarIndexer, never, StellarRpc>;
105
+ /**
106
+ * Builds an {@link StellarIndexer} like {@link layer}, reading the options from `Config`.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * import * as StellarIndexer from "@effect-blockchain/stellar/StellarIndexer"
111
+ * import * as Config from "effect/Config"
112
+ *
113
+ * const IndexerLive = StellarIndexer.layerConfig({ confirmations: Config.Int("STELLAR_CONFIRMATIONS") })
114
+ * ```
115
+ *
116
+ * @since 0.1.0
117
+ * @category layers
118
+ */
119
+ export declare const layerConfig: (options: Config.Wrap<NonNullable<Parameters<typeof layer>[0]>>) => Layer.Layer<StellarIndexer, Config.ConfigError, StellarRpc>;
120
+ export {};
121
+ //# sourceMappingURL=StellarIndexer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarIndexer.d.ts","sourceRoot":"","sources":["../src/StellarIndexer.ts"],"names":[],"mappings":"AAqCA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAErE,OAAO,KAAK,EAAuB,mBAAmB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAChG,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA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ACH,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,QAA+B,CAAA;AAY5E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,aAAa;IAC7B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3C,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACpC,KAAQ,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,EAAE,UAAU,CAgFnD,CAAA;AAEH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,YACb,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAC7D,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,CACJ,CAAA"}
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Soroban contract event indexing on top of {@link StellarRpc}: the last confirmed ledger, the events of a set of
3
+ * contracts over a ledger range, and a stream of them following the confirmed head.
4
+ *
5
+ * A range is split into ranges of at most `maxBlockRange` ledgers, each paged with `getEvents` until its cursor is
6
+ * `undefined`. `contractIds` is split into groups of 5, the RPC limit per filter (`MaxContractIDsLimit` in
7
+ * https://github.com/stellar/go-stellar-sdk/blob/main/protocols/rpc/get_events.go), merged back in event id order. A
8
+ * cursor page is pinned to the endpoint that issued it, so when it fails the group restarts once from its first page.
9
+ * Any other failure fails the whole call and drops the events already read: the caller retries the same range.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import type { StellarIndexerFilter } from "@effect-blockchain/stellar/StellarIndexer"
14
+ * import { StellarIndexer } from "@effect-blockchain/stellar/StellarIndexer"
15
+ * import * as Effect from "effect/Effect"
16
+ * import * as Schedule from "effect/Schedule"
17
+ * import * as Stream from "effect/Stream"
18
+ *
19
+ * declare const filter: Omit<StellarIndexerFilter, "fromBlock" | "toBlock">
20
+ * declare const cursor: bigint
21
+ * declare const save: (ledger: bigint) => Effect.Effect<void>
22
+ *
23
+ * const program = Effect.gen(function*() {
24
+ * const indexer = yield* StellarIndexer
25
+ * // once caught up, read the head after 1 s, 2 s, 4 s... at most every minute
26
+ * const poll = Schedule.min([Schedule.exponential("1 second"), Schedule.spaced("1 minute")])
27
+ * yield* indexer.streamEvents({ filter, fromBlock: cursor + BigInt(1), poll }).pipe(
28
+ * Stream.runForEach((batch) => save(batch.toBlock))
29
+ * )
30
+ * })
31
+ * ```
32
+ *
33
+ * @since 0.1.0
34
+ */
35
+ import * as JsonRpc from "@effect-blockchain/core/JsonRpc";
36
+ import * as Arr from "effect/Array";
37
+ import * as BigInt_ from "effect/BigInt";
38
+ import * as Config from "effect/Config";
39
+ import * as Context from "effect/Context";
40
+ import * as Duration from "effect/Duration";
41
+ import * as Effect from "effect/Effect";
42
+ import * as Layer from "effect/Layer";
43
+ import * as Option from "effect/Option";
44
+ import * as Order from "effect/Order";
45
+ import * as Schedule from "effect/Schedule";
46
+ import * as Stream from "effect/Stream";
47
+ import * as StellarNetwork from "./StellarNetwork.js";
48
+ import { StellarRpc } from "./StellarRpc.js";
49
+ /**
50
+ * The default `maxBlockRange`: 10000 ledgers, the most a Stellar RPC scans per request (`LedgerScanLimit` in
51
+ * https://github.com/stellar/stellar-rpc/blob/main/cmd/stellar-rpc/internal/methods/get_events.go).
52
+ *
53
+ * @since 0.1.0
54
+ * @category constants
55
+ */
56
+ export const DEFAULT_MAX_BLOCK_RANGE = 10_000;
57
+ /**
58
+ * @since 0.1.0
59
+ * @category services
60
+ */
61
+ export class StellarIndexer extends /*#__PURE__*/Context.Service()("@effect-blockchain/stellar/StellarIndexer") {}
62
+ /**
63
+ * The default `poll` spacing of {@link StellarIndexer.Service.streamEvents}: 10 seconds.
64
+ *
65
+ * @since 0.1.0
66
+ * @category constants
67
+ */
68
+ export const DEFAULT_POLL_INTERVAL = /*#__PURE__*/Duration.seconds(10);
69
+ const MAX_CONTRACT_IDS = 5;
70
+ const byId = /*#__PURE__*/Order.mapInput(Order.String, event => event.id);
71
+ /**
72
+ * Builds a {@link StellarIndexer} over the provided {@link StellarRpc}.
73
+ *
74
+ * - `confirmations`: ledgers kept behind the latest one, default {@link StellarNetwork.defaultConfirmations} of the
75
+ * RPC's network.
76
+ * - `maxBlockRange`: ledgers per range, a positive integer, default {@link DEFAULT_MAX_BLOCK_RANGE}.
77
+ * - `limit`: `getEvents` page size, default 1000, at most 10000.
78
+ *
79
+ * @since 0.1.0
80
+ * @category layers
81
+ */
82
+ export const layer = (options = {}) => Layer.effect(StellarIndexer, Effect.gen(function* () {
83
+ const rpc = yield* StellarRpc;
84
+ const maxBlockRange = options.maxBlockRange ?? DEFAULT_MAX_BLOCK_RANGE;
85
+ if (!Number.isSafeInteger(maxBlockRange) || maxBlockRange < 1) {
86
+ return yield* Effect.die(new RangeError(`maxBlockRange must be a positive integer, got ${maxBlockRange}`));
87
+ }
88
+ const confirmations = BigInt(options.confirmations ?? StellarNetwork.defaultConfirmations(rpc.network));
89
+ const range = BigInt(maxBlockRange);
90
+ const {
91
+ limit
92
+ } = options;
93
+ const lastConfirmedBlock = rpc.getLatestLedger.pipe(Effect.map(ledger => BigInt_.max(ledger.sequence - confirmations, BigInt(0))), Effect.withSpan("StellarIndexer.lastConfirmedBlock"));
94
+ const fetchEvents = Effect.fn("StellarIndexer.fetchEvents")(filter => {
95
+ if (filter.fromBlock > filter.toBlock) return Effect.succeed([]);
96
+ const groups = Arr.chunksOf(filter.contractIds, MAX_CONTRACT_IDS);
97
+ const starts = Arr.makeBy(Number((filter.toBlock - filter.fromBlock) / range) + 1, i => filter.fromBlock + BigInt(i) * range);
98
+ return Effect.forEach(starts, fromBlock => {
99
+ const toBlock = BigInt_.min(fromBlock + range - BigInt(1), filter.toBlock);
100
+ return Effect.forEach(groups, contractIds => {
101
+ const group = {
102
+ ...filter,
103
+ contractIds,
104
+ fromBlock,
105
+ toBlock,
106
+ limit
107
+ };
108
+ // a cursor page has no fallback: when it fails, the group restarts once from its first page
109
+ return Stream.paginate(Option.none(), cursor => rpc.getEvents({
110
+ ...group,
111
+ cursor: Option.getOrUndefined(cursor)
112
+ }).pipe(Effect.mapBoth({
113
+ onFailure: error => Option.isNone(cursor) ? error : {
114
+ cursorPage: error
115
+ },
116
+ onSuccess: page => [page.events, Option.map(Option.fromUndefinedOr(page.cursor), Option.some)]
117
+ }))).pipe(Stream.runCollect, Effect.retry({
118
+ times: 1,
119
+ while: error => "cursorPage" in error
120
+ }), Effect.mapError(error => "cursorPage" in error ? error.cursorPage : error));
121
+ }).pipe(Effect.map(found => groups.length > 1 ? Arr.sort(Arr.flatten(found), byId) : Arr.flatten(found)));
122
+ }).pipe(Effect.map(ranges => Arr.flatten(ranges).filter(event => event.inSuccessfulContractCall)));
123
+ });
124
+ return StellarIndexer.of({
125
+ lastConfirmedBlock,
126
+ fetchEvents,
127
+ streamEvents: ({
128
+ filter,
129
+ fromBlock,
130
+ poll = Schedule.spaced(DEFAULT_POLL_INTERVAL),
131
+ retry,
132
+ toBlock
133
+ }) => {
134
+ if (toBlock !== undefined && fromBlock > toBlock) return Stream.empty;
135
+ // the head last read is reused while it covers `next` (the confirmed head only moves forward), else polled
136
+ const step = ({
137
+ head,
138
+ next
139
+ }) => (next <= head ? Effect.succeed(head) : lastConfirmedBlock.pipe(Effect.repeat({
140
+ schedule: poll,
141
+ until: confirmed => confirmed >= next
142
+ }))).pipe(Effect.flatMap(confirmed => {
143
+ const cap = toBlock === undefined ? confirmed : BigInt_.min(confirmed, toBlock);
144
+ if (next > cap) return Effect.succeed([[], Option.none()]);
145
+ const end = BigInt_.min(next + range - BigInt(1), cap);
146
+ return fetchEvents({
147
+ ...filter,
148
+ fromBlock: next,
149
+ toBlock: end
150
+ }).pipe(Effect.map(events => [[{
151
+ fromBlock: next,
152
+ toBlock: end,
153
+ events
154
+ }], end === toBlock ? Option.none() : Option.some({
155
+ next: end + BigInt(1),
156
+ head: confirmed
157
+ })]));
158
+ }));
159
+ return Stream.paginate(
160
+ // a head below `fromBlock`: the first step reads it
161
+ {
162
+ next: fromBlock,
163
+ head: fromBlock - BigInt(1)
164
+ }, retry === undefined ? step : remaining => Effect.retry(step(remaining), {
165
+ schedule: retry,
166
+ while: error => JsonRpc.isTransient(error.reason)
167
+ }));
168
+ }
169
+ });
170
+ }));
171
+ /**
172
+ * Builds an {@link StellarIndexer} like {@link layer}, reading the options from `Config`.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * import * as StellarIndexer from "@effect-blockchain/stellar/StellarIndexer"
177
+ * import * as Config from "effect/Config"
178
+ *
179
+ * const IndexerLive = StellarIndexer.layerConfig({ confirmations: Config.Int("STELLAR_CONFIRMATIONS") })
180
+ * ```
181
+ *
182
+ * @since 0.1.0
183
+ * @category layers
184
+ */
185
+ export const layerConfig = options => Layer.unwrap(Effect.map(Config.unwrap(options), layer));
186
+ //# sourceMappingURL=StellarIndexer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarIndexer.js","names":[],"sources":["../src/StellarIndexer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,OAAO,KAAK,OAAO,MAAM,iCAAiC;AAC1D,OAAO,KAAK,GAAG,MAAM,cAAc;AACnC,OAAO,KAAK,OAAO,MAAM,eAAe;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AA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M,CAAC,CAAC;MAAC,CAAE,EAChD,KAAK,KAAK,SAAS,GACf,IAAI,GACH,SAAS,IACV,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;QAAE,QAAQ,EAAE,KAAK;QAAE,KAAK,EAAG,KAAK,IAAK,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM;MAAC,CAAE,CAAC,CAC5G;IACH;GACD,CAAC;AACJ,CAAC,CAAC,CACH;AAEH;;;;;;;;;;;;;;AAcA,OAAO,MAAM,WAAW,GACtB,OAA8D,IAE9D,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,56 @@
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 declare const mainnets: readonly ["Stellar"];
12
+ /**
13
+ * @since 0.1.0
14
+ * @category constants
15
+ */
16
+ export declare const testnets: readonly ["StellarTestnet"];
17
+ /**
18
+ * Every supported network, mainnets first.
19
+ *
20
+ * @since 0.1.0
21
+ * @category constants
22
+ */
23
+ export declare const networks: readonly ["Stellar", "StellarTestnet"];
24
+ /**
25
+ * A named Stellar network: `Stellar` (public mainnet) or `StellarTestnet`.
26
+ *
27
+ * @since 0.1.0
28
+ * @category schemas
29
+ */
30
+ export declare const StellarNetwork: Schema.Literals<readonly ["Stellar", "StellarTestnet"]>;
31
+ /**
32
+ * @since 0.1.0
33
+ * @category models
34
+ */
35
+ export type StellarNetwork = typeof StellarNetwork.Type;
36
+ /**
37
+ * The network passphrase, used to sign transactions and reported by `getNetwork`.
38
+ *
39
+ * @since 0.1.0
40
+ * @category conversions
41
+ */
42
+ export declare const toPassphrase: (network: StellarNetwork) => string;
43
+ /**
44
+ * Ledgers to wait behind the latest closed ledger before treating it as confirmed: `0`, Stellar has no forks and a
45
+ * ledger is final once closed.
46
+ *
47
+ * @since 0.1.0
48
+ * @category getters
49
+ */
50
+ export declare const defaultConfirmations: (network: StellarNetwork) => number;
51
+ /**
52
+ * @since 0.1.0
53
+ * @category predicates
54
+ */
55
+ export declare const isTestnet: (network: StellarNetwork) => boolean;
56
+ //# sourceMappingURL=StellarNetwork.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StellarNetwork.d.ts","sourceRoot":"","sources":["../src/StellarNetwork.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;GAGG;AACH,eAAO,MAAM,QAAQ,YAAI,SAAS,CAAU,CAAA;AAE5C;;;GAGG;AACH,eAAO,MAAM,QAAQ,YAAI,gBAAgB,CAAU,CAAA;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,wCAAsC,CAAA;AAE3D;;;;;GAKG;AACH,eAAO,MAAM,cAAc,yDAIzB,CAAA;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,IAAI,CAAA;AAQvD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,YAAa,cAAc,KAAG,MAA8B,CAAA;AAUrF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,YAAa,cAAc,KAAG,MAAgC,CAAA;AAE/F;;;GAGG;AACH,eAAO,MAAM,SAAS,YAAa,cAAc,KAAG,OACW,CAAA"}