@0xobelisk/graphql-client 1.2.0-pre.123 → 1.2.0-pre.125
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/client.d.ts +83 -1
- package/dist/decoders.d.ts +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +434 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +421 -15
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +63 -0
- package/package.json +1 -1
- package/src/client.ts +432 -18
- package/src/decoders.ts +100 -0
- package/src/index.ts +1 -0
- package/src/types.ts +66 -0
package/dist/index.mjs
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
Observable,
|
|
23
23
|
from
|
|
24
24
|
} from "@apollo/client";
|
|
25
|
+
import { BatchHttpLink } from "@apollo/client/link/batch-http";
|
|
25
26
|
import { RetryLink } from "@apollo/client/link/retry";
|
|
26
27
|
import { GraphQLWsLink } from "@apollo/client/link/subscriptions";
|
|
27
28
|
import { getMainDefinition } from "@apollo/client/utilities";
|
|
@@ -736,6 +737,77 @@ import "graphql";
|
|
|
736
737
|
|
|
737
738
|
// src/client.ts
|
|
738
739
|
import pluralize from "pluralize";
|
|
740
|
+
var SYSTEM_TABLE_FIELDS = {
|
|
741
|
+
dubheDappMarketplaceFees: [
|
|
742
|
+
"dappKey",
|
|
743
|
+
"listingId",
|
|
744
|
+
"coinType",
|
|
745
|
+
"totalFee",
|
|
746
|
+
"treasuryAmount",
|
|
747
|
+
"dappAmount",
|
|
748
|
+
"updatedAtCheckpoint",
|
|
749
|
+
"lastUpdateDigest"
|
|
750
|
+
],
|
|
751
|
+
dubheDappRuntimeState: [
|
|
752
|
+
"dappKey",
|
|
753
|
+
"admin",
|
|
754
|
+
"paused",
|
|
755
|
+
"settlementMode",
|
|
756
|
+
"creditPool",
|
|
757
|
+
"writeFeeShareBps",
|
|
758
|
+
"lastRuntimeEvent",
|
|
759
|
+
"lastRuntimeActor",
|
|
760
|
+
"lastRuntimeAmount",
|
|
761
|
+
"updatedAtCheckpoint",
|
|
762
|
+
"lastUpdateDigest"
|
|
763
|
+
],
|
|
764
|
+
dubheDappFeeState: [
|
|
765
|
+
"entityId",
|
|
766
|
+
"baseFeePerWrite",
|
|
767
|
+
"bytesFeePerByte",
|
|
768
|
+
"freeCredit",
|
|
769
|
+
"creditPool",
|
|
770
|
+
"totalSettled",
|
|
771
|
+
"updatedAtTimestampMs",
|
|
772
|
+
"lastUpdateDigest"
|
|
773
|
+
],
|
|
774
|
+
dubheDappRevenueState: [
|
|
775
|
+
"entityId",
|
|
776
|
+
"dappRevenue",
|
|
777
|
+
"coinType",
|
|
778
|
+
"updatedAtTimestampMs",
|
|
779
|
+
"lastUpdateDigest"
|
|
780
|
+
],
|
|
781
|
+
dubheMarketplaceListings: [
|
|
782
|
+
"dappKey",
|
|
783
|
+
"listingId",
|
|
784
|
+
"seller",
|
|
785
|
+
"recordType",
|
|
786
|
+
"price",
|
|
787
|
+
"coinType",
|
|
788
|
+
"isFungible",
|
|
789
|
+
"listedUntil",
|
|
790
|
+
"status",
|
|
791
|
+
"updatedAtCheckpoint",
|
|
792
|
+
"lastUpdateDigest"
|
|
793
|
+
],
|
|
794
|
+
dubheSessions: [
|
|
795
|
+
"dappKey",
|
|
796
|
+
"canonical",
|
|
797
|
+
"sessionWallet",
|
|
798
|
+
"expiresAt",
|
|
799
|
+
"active",
|
|
800
|
+
"updatedAtCheckpoint",
|
|
801
|
+
"lastUpdateDigest"
|
|
802
|
+
],
|
|
803
|
+
dubheUserStorages: [
|
|
804
|
+
"dappKey",
|
|
805
|
+
"canonicalOwner",
|
|
806
|
+
"userStorageId",
|
|
807
|
+
"updatedAtCheckpoint",
|
|
808
|
+
"lastUpdateDigest"
|
|
809
|
+
]
|
|
810
|
+
};
|
|
739
811
|
function mapCachePolicyToFetchPolicy(cachePolicy) {
|
|
740
812
|
switch (cachePolicy) {
|
|
741
813
|
case "cache-first":
|
|
@@ -752,6 +824,23 @@ function mapCachePolicyToFetchPolicy(cachePolicy) {
|
|
|
752
824
|
return "cache-first";
|
|
753
825
|
}
|
|
754
826
|
}
|
|
827
|
+
function buildHttpLink(config) {
|
|
828
|
+
const fetchFn = (input, init) => fetch(input, { ...config.fetchOptions, ...init ?? {} });
|
|
829
|
+
if (config.batchRequests) {
|
|
830
|
+
return new BatchHttpLink({
|
|
831
|
+
uri: config.endpoint,
|
|
832
|
+
headers: config.headers,
|
|
833
|
+
fetch: fetchFn,
|
|
834
|
+
batchInterval: config.batchInterval ?? 10,
|
|
835
|
+
batchMax: config.batchMax ?? 20
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
return createHttpLink({
|
|
839
|
+
uri: config.endpoint,
|
|
840
|
+
headers: config.headers,
|
|
841
|
+
fetch: fetchFn
|
|
842
|
+
});
|
|
843
|
+
}
|
|
755
844
|
var DubheGraphqlClient = class {
|
|
756
845
|
// Store current configuration for updates
|
|
757
846
|
constructor(config) {
|
|
@@ -762,11 +851,7 @@ var DubheGraphqlClient = class {
|
|
|
762
851
|
if (this.dubheMetadata) {
|
|
763
852
|
this.parseTableInfoFromConfig();
|
|
764
853
|
}
|
|
765
|
-
const httpLink =
|
|
766
|
-
uri: config.endpoint,
|
|
767
|
-
headers: config.headers,
|
|
768
|
-
fetch: (input, init) => fetch(input, { ...config.fetchOptions, ...init })
|
|
769
|
-
});
|
|
854
|
+
const httpLink = buildHttpLink(config);
|
|
770
855
|
const retryLink = new RetryLink({
|
|
771
856
|
delay: {
|
|
772
857
|
// Initial retry delay time (milliseconds)
|
|
@@ -887,11 +972,7 @@ var DubheGraphqlClient = class {
|
|
|
887
972
|
}
|
|
888
973
|
this.subscriptionClient = void 0;
|
|
889
974
|
}
|
|
890
|
-
const httpLink =
|
|
891
|
-
uri: this.currentConfig.endpoint,
|
|
892
|
-
headers: this.currentConfig.headers,
|
|
893
|
-
fetch: (input, init) => fetch(input, { ...this.currentConfig.fetchOptions, ...init })
|
|
894
|
-
});
|
|
975
|
+
const httpLink = buildHttpLink(this.currentConfig);
|
|
895
976
|
const retryLink = new RetryLink({
|
|
896
977
|
delay: {
|
|
897
978
|
initial: this.currentConfig.retryOptions?.delay?.initial || 300,
|
|
@@ -1531,6 +1612,204 @@ var DubheGraphqlClient = class {
|
|
|
1531
1612
|
totalCount: 0
|
|
1532
1613
|
};
|
|
1533
1614
|
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Query SceneStorage system rows indexed by the Dubhe indexer
|
|
1617
|
+
* (scene_storages table, exposed as dubheSceneStorages in GraphQL).
|
|
1618
|
+
* Field values live in the companion scene_storage_fields table —
|
|
1619
|
+
* see getSceneStorageFields.
|
|
1620
|
+
*/
|
|
1621
|
+
async getSceneStorages(options) {
|
|
1622
|
+
const filter = {};
|
|
1623
|
+
if (options?.dappKey)
|
|
1624
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1625
|
+
if (options?.sceneType)
|
|
1626
|
+
filter.sceneType = { equalTo: options.sceneType };
|
|
1627
|
+
if (options?.sceneId)
|
|
1628
|
+
filter.sceneId = { equalTo: options.sceneId };
|
|
1629
|
+
if (options?.isDestroyed !== void 0)
|
|
1630
|
+
filter.isDestroyed = { equalTo: options.isDestroyed };
|
|
1631
|
+
const query = gql`
|
|
1632
|
+
query GetSceneStorages(
|
|
1633
|
+
$first: Int
|
|
1634
|
+
$after: Cursor
|
|
1635
|
+
$filter: StoreDubheSceneStorageFilter
|
|
1636
|
+
$orderBy: [StoreDubheSceneStoragesOrderBy!]
|
|
1637
|
+
) {
|
|
1638
|
+
dubheSceneStorages(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1639
|
+
totalCount
|
|
1640
|
+
pageInfo {
|
|
1641
|
+
hasNextPage
|
|
1642
|
+
hasPreviousPage
|
|
1643
|
+
startCursor
|
|
1644
|
+
endCursor
|
|
1645
|
+
}
|
|
1646
|
+
edges {
|
|
1647
|
+
cursor
|
|
1648
|
+
node {
|
|
1649
|
+
sceneId
|
|
1650
|
+
dappKey
|
|
1651
|
+
sceneType
|
|
1652
|
+
authorizationKind
|
|
1653
|
+
authorizedPermitId
|
|
1654
|
+
isDestroyed
|
|
1655
|
+
createdAtCheckpoint
|
|
1656
|
+
updatedAtCheckpoint
|
|
1657
|
+
lastUpdateDigest
|
|
1658
|
+
lastEventSeq
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
`;
|
|
1664
|
+
const result = await this.apolloClient.query({
|
|
1665
|
+
query,
|
|
1666
|
+
variables: {
|
|
1667
|
+
first: options?.first ?? 100,
|
|
1668
|
+
after: options?.after,
|
|
1669
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1670
|
+
orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
|
|
1671
|
+
},
|
|
1672
|
+
fetchPolicy: "network-only"
|
|
1673
|
+
});
|
|
1674
|
+
if (result.error)
|
|
1675
|
+
throw result.error;
|
|
1676
|
+
return result.data?.dubheSceneStorages ?? {
|
|
1677
|
+
edges: [],
|
|
1678
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1679
|
+
totalCount: 0
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Query raw field rows of SceneStorages (scene_storage_fields table,
|
|
1684
|
+
* exposed as dubheSceneStorageFields in GraphQL). Values are hex-encoded
|
|
1685
|
+
* BCS — decode with the decoders exported from this package.
|
|
1686
|
+
*/
|
|
1687
|
+
async getSceneStorageFields(options) {
|
|
1688
|
+
const filter = {};
|
|
1689
|
+
if (options?.dappKey)
|
|
1690
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1691
|
+
if (options?.sceneIds && options.sceneIds.length > 0)
|
|
1692
|
+
filter.sceneId = { in: options.sceneIds };
|
|
1693
|
+
if (options?.sceneId)
|
|
1694
|
+
filter.sceneId = { equalTo: options.sceneId };
|
|
1695
|
+
if (options?.fieldName)
|
|
1696
|
+
filter.fieldName = { equalTo: options.fieldName };
|
|
1697
|
+
if (options?.isDeleted !== void 0)
|
|
1698
|
+
filter.isDeleted = { equalTo: options.isDeleted };
|
|
1699
|
+
const query = gql`
|
|
1700
|
+
query GetSceneStorageFields(
|
|
1701
|
+
$first: Int
|
|
1702
|
+
$after: Cursor
|
|
1703
|
+
$filter: StoreDubheSceneStorageFieldFilter
|
|
1704
|
+
$orderBy: [StoreDubheSceneStorageFieldsOrderBy!]
|
|
1705
|
+
) {
|
|
1706
|
+
dubheSceneStorageFields(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1707
|
+
totalCount
|
|
1708
|
+
pageInfo {
|
|
1709
|
+
hasNextPage
|
|
1710
|
+
hasPreviousPage
|
|
1711
|
+
startCursor
|
|
1712
|
+
endCursor
|
|
1713
|
+
}
|
|
1714
|
+
edges {
|
|
1715
|
+
cursor
|
|
1716
|
+
node {
|
|
1717
|
+
sceneId
|
|
1718
|
+
dappKey
|
|
1719
|
+
sceneType
|
|
1720
|
+
fieldName
|
|
1721
|
+
fieldValueRaw
|
|
1722
|
+
isDeleted
|
|
1723
|
+
updatedAtCheckpoint
|
|
1724
|
+
lastUpdateDigest
|
|
1725
|
+
lastEventSeq
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
`;
|
|
1731
|
+
const result = await this.apolloClient.query({
|
|
1732
|
+
query,
|
|
1733
|
+
variables: {
|
|
1734
|
+
first: options?.first ?? 1e3,
|
|
1735
|
+
after: options?.after,
|
|
1736
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1737
|
+
orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
|
|
1738
|
+
},
|
|
1739
|
+
fetchPolicy: "network-only"
|
|
1740
|
+
});
|
|
1741
|
+
if (result.error)
|
|
1742
|
+
throw result.error;
|
|
1743
|
+
return result.data?.dubheSceneStorageFields ?? {
|
|
1744
|
+
edges: [],
|
|
1745
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1746
|
+
totalCount: 0
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* Query ObjectStorage system rows indexed by the Dubhe indexer
|
|
1751
|
+
* (object_storages table, exposed as dubheObjectStorages in GraphQL).
|
|
1752
|
+
*/
|
|
1753
|
+
async getObjectStorages(options) {
|
|
1754
|
+
const filter = {};
|
|
1755
|
+
if (options?.dappKey)
|
|
1756
|
+
filter.dappKey = { equalTo: options.dappKey };
|
|
1757
|
+
if (options?.objectType)
|
|
1758
|
+
filter.objectType = { equalTo: options.objectType };
|
|
1759
|
+
if (options?.objectId)
|
|
1760
|
+
filter.objectId = { equalTo: options.objectId };
|
|
1761
|
+
if (options?.isDestroyed !== void 0)
|
|
1762
|
+
filter.isDestroyed = { equalTo: options.isDestroyed };
|
|
1763
|
+
const query = gql`
|
|
1764
|
+
query GetObjectStorages(
|
|
1765
|
+
$first: Int
|
|
1766
|
+
$after: Cursor
|
|
1767
|
+
$filter: StoreDubheObjectStorageFilter
|
|
1768
|
+
$orderBy: [StoreDubheObjectStoragesOrderBy!]
|
|
1769
|
+
) {
|
|
1770
|
+
dubheObjectStorages(first: $first, after: $after, filter: $filter, orderBy: $orderBy) {
|
|
1771
|
+
totalCount
|
|
1772
|
+
pageInfo {
|
|
1773
|
+
hasNextPage
|
|
1774
|
+
hasPreviousPage
|
|
1775
|
+
startCursor
|
|
1776
|
+
endCursor
|
|
1777
|
+
}
|
|
1778
|
+
edges {
|
|
1779
|
+
cursor
|
|
1780
|
+
node {
|
|
1781
|
+
objectId
|
|
1782
|
+
dappKey
|
|
1783
|
+
objectType
|
|
1784
|
+
entityIdRaw
|
|
1785
|
+
isDestroyed
|
|
1786
|
+
createdAtCheckpoint
|
|
1787
|
+
updatedAtCheckpoint
|
|
1788
|
+
lastUpdateDigest
|
|
1789
|
+
lastEventSeq
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
`;
|
|
1795
|
+
const result = await this.apolloClient.query({
|
|
1796
|
+
query,
|
|
1797
|
+
variables: {
|
|
1798
|
+
first: options?.first ?? 100,
|
|
1799
|
+
after: options?.after,
|
|
1800
|
+
filter: Object.keys(filter).length > 0 ? filter : void 0,
|
|
1801
|
+
orderBy: ["UPDATED_AT_CHECKPOINT_DESC"]
|
|
1802
|
+
},
|
|
1803
|
+
fetchPolicy: "network-only"
|
|
1804
|
+
});
|
|
1805
|
+
if (result.error)
|
|
1806
|
+
throw result.error;
|
|
1807
|
+
return result.data?.dubheObjectStorages ?? {
|
|
1808
|
+
edges: [],
|
|
1809
|
+
pageInfo: { hasNextPage: false, hasPreviousPage: false },
|
|
1810
|
+
totalCount: 0
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1534
1813
|
/**
|
|
1535
1814
|
* Query DApp runtime state (credit pool, admin, package version, etc.).
|
|
1536
1815
|
* Exposed as dubheDappRuntimeStates in GraphQL.
|
|
@@ -1828,15 +2107,55 @@ var DubheGraphqlClient = class {
|
|
|
1828
2107
|
if (customFields && customFields.length > 0) {
|
|
1829
2108
|
fields = customFields;
|
|
1830
2109
|
} else {
|
|
1831
|
-
const
|
|
1832
|
-
if (
|
|
1833
|
-
fields =
|
|
2110
|
+
const systemFields = SYSTEM_TABLE_FIELDS[tableName];
|
|
2111
|
+
if (systemFields) {
|
|
2112
|
+
fields = systemFields;
|
|
1834
2113
|
} else {
|
|
1835
|
-
|
|
2114
|
+
const autoFields = this.getTableFields(tableName);
|
|
2115
|
+
if (autoFields.length > 0) {
|
|
2116
|
+
fields = autoFields;
|
|
2117
|
+
} else {
|
|
2118
|
+
fields = [
|
|
2119
|
+
"createdAtTimestampMs",
|
|
2120
|
+
"updatedAtTimestampMs",
|
|
2121
|
+
"isDeleted",
|
|
2122
|
+
"lastUpdateDigest"
|
|
2123
|
+
];
|
|
2124
|
+
}
|
|
1836
2125
|
}
|
|
1837
2126
|
}
|
|
1838
2127
|
return fields.join("\n ");
|
|
1839
2128
|
}
|
|
2129
|
+
// ── Typed system-table query methods ─────────────────────────────────────
|
|
2130
|
+
/** Latest DApp fee state snapshot (credit_pool, total_settled, fee rates). */
|
|
2131
|
+
async getDappFeeState() {
|
|
2132
|
+
const result = await this.getAllTables("dubheDappFeeState", { first: 1 }).catch(
|
|
2133
|
+
() => null
|
|
2134
|
+
);
|
|
2135
|
+
return result?.edges?.[0]?.node ?? null;
|
|
2136
|
+
}
|
|
2137
|
+
/** Latest DApp revenue balance (USER_PAYS mode collected revenue). */
|
|
2138
|
+
async getDappRevenueState() {
|
|
2139
|
+
const result = await this.getAllTables("dubheDappRevenueState", { first: 1 }).catch(
|
|
2140
|
+
() => null
|
|
2141
|
+
);
|
|
2142
|
+
return result?.edges?.[0]?.node ?? null;
|
|
2143
|
+
}
|
|
2144
|
+
/** Latest DApp runtime state (admin, settlement mode, last event). */
|
|
2145
|
+
async getDappRuntimeState() {
|
|
2146
|
+
const result = await this.getAllTables("dubheDappRuntimeState", { first: 1 }).catch(
|
|
2147
|
+
() => null
|
|
2148
|
+
);
|
|
2149
|
+
return result?.edges?.[0]?.node ?? null;
|
|
2150
|
+
}
|
|
2151
|
+
/** Marketplace fee records (one row per listing sold). */
|
|
2152
|
+
async getDappMarketplaceFees(options) {
|
|
2153
|
+
return this.getAllTables("dubheDappMarketplaceFees", {
|
|
2154
|
+
first: options?.first ?? 20,
|
|
2155
|
+
after: options?.after,
|
|
2156
|
+
orderBy: [{ field: "updatedAtCheckpoint", direction: "DESC" }]
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
1840
2159
|
};
|
|
1841
2160
|
function createDubheGraphqlClient(config) {
|
|
1842
2161
|
return new DubheGraphqlClient(config);
|
|
@@ -1897,9 +2216,96 @@ function toSnakeCaseForEnum(str) {
|
|
|
1897
2216
|
}
|
|
1898
2217
|
return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "").toUpperCase();
|
|
1899
2218
|
}
|
|
2219
|
+
|
|
2220
|
+
// src/decoders.ts
|
|
2221
|
+
var ZERO_ADDRESS = "0x" + "0".repeat(64);
|
|
2222
|
+
function hexToBytes(hex) {
|
|
2223
|
+
const clean = hex.replace(/^0x/i, "");
|
|
2224
|
+
const pairs = clean.match(/../g) ?? [];
|
|
2225
|
+
return Uint8Array.from(pairs.map((b) => parseInt(b, 16)));
|
|
2226
|
+
}
|
|
2227
|
+
function readUIntLE(bytes, offset, width) {
|
|
2228
|
+
let n = 0n;
|
|
2229
|
+
for (let i = width - 1; i >= 0; i--) {
|
|
2230
|
+
n = n << 8n | BigInt(bytes[offset + i] ?? 0);
|
|
2231
|
+
}
|
|
2232
|
+
return n;
|
|
2233
|
+
}
|
|
2234
|
+
function readUleb(bytes, offset) {
|
|
2235
|
+
let value = 0;
|
|
2236
|
+
let shift = 0;
|
|
2237
|
+
let consumed = 0;
|
|
2238
|
+
for (; ; ) {
|
|
2239
|
+
const byte = bytes[offset + consumed] ?? 0;
|
|
2240
|
+
value |= (byte & 127) << shift;
|
|
2241
|
+
consumed++;
|
|
2242
|
+
if ((byte & 128) === 0)
|
|
2243
|
+
break;
|
|
2244
|
+
shift += 7;
|
|
2245
|
+
}
|
|
2246
|
+
return [value, consumed];
|
|
2247
|
+
}
|
|
2248
|
+
function decodeU8(hex) {
|
|
2249
|
+
return Number(readUIntLE(hexToBytes(hex), 0, 1));
|
|
2250
|
+
}
|
|
2251
|
+
function decodeU16(hex) {
|
|
2252
|
+
return Number(readUIntLE(hexToBytes(hex), 0, 2));
|
|
2253
|
+
}
|
|
2254
|
+
function decodeU32(hex) {
|
|
2255
|
+
return Number(readUIntLE(hexToBytes(hex), 0, 4));
|
|
2256
|
+
}
|
|
2257
|
+
function decodeU64(hex) {
|
|
2258
|
+
return readUIntLE(hexToBytes(hex), 0, 8);
|
|
2259
|
+
}
|
|
2260
|
+
function decodeU128(hex) {
|
|
2261
|
+
return readUIntLE(hexToBytes(hex), 0, 16);
|
|
2262
|
+
}
|
|
2263
|
+
function decodeBool(hex) {
|
|
2264
|
+
return (hexToBytes(hex)[0] ?? 0) !== 0;
|
|
2265
|
+
}
|
|
2266
|
+
function decodeAddress(hex) {
|
|
2267
|
+
const bytes = hexToBytes(hex);
|
|
2268
|
+
return "0x" + Array.from(bytes.slice(0, 32), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
2269
|
+
}
|
|
2270
|
+
function decodeVectorAddress(hex) {
|
|
2271
|
+
const bytes = hexToBytes(hex);
|
|
2272
|
+
const [len, consumed] = readUleb(bytes, 0);
|
|
2273
|
+
const out = [];
|
|
2274
|
+
for (let i = 0; i < len; i++) {
|
|
2275
|
+
const start = consumed + i * 32;
|
|
2276
|
+
out.push(
|
|
2277
|
+
"0x" + Array.from(bytes.slice(start, start + 32), (b) => b.toString(16).padStart(2, "0")).join("")
|
|
2278
|
+
);
|
|
2279
|
+
}
|
|
2280
|
+
return out;
|
|
2281
|
+
}
|
|
2282
|
+
function decodeString(hex) {
|
|
2283
|
+
const bytes = hexToBytes(hex);
|
|
2284
|
+
const [len, consumed] = readUleb(bytes, 0);
|
|
2285
|
+
return new TextDecoder().decode(bytes.slice(consumed, consumed + len));
|
|
2286
|
+
}
|
|
2287
|
+
function parseRecordData(recordDataRaw) {
|
|
2288
|
+
try {
|
|
2289
|
+
return JSON.parse(recordDataRaw);
|
|
2290
|
+
} catch {
|
|
2291
|
+
return [recordDataRaw];
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
1900
2294
|
export {
|
|
1901
2295
|
DubheGraphqlClient,
|
|
1902
2296
|
QueryBuilders,
|
|
1903
|
-
|
|
2297
|
+
ZERO_ADDRESS,
|
|
2298
|
+
createDubheGraphqlClient,
|
|
2299
|
+
decodeAddress,
|
|
2300
|
+
decodeBool,
|
|
2301
|
+
decodeString,
|
|
2302
|
+
decodeU128,
|
|
2303
|
+
decodeU16,
|
|
2304
|
+
decodeU32,
|
|
2305
|
+
decodeU64,
|
|
2306
|
+
decodeU8,
|
|
2307
|
+
decodeVectorAddress,
|
|
2308
|
+
hexToBytes,
|
|
2309
|
+
parseRecordData
|
|
1904
2310
|
};
|
|
1905
2311
|
//# sourceMappingURL=index.mjs.map
|