@arkiv-network/sdk 0.7.0-dev.1 → 0.8.0-advanced.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -16
- package/dist/actions/advanced/index.cjs +13 -0
- package/dist/actions/advanced/index.d.cts +8 -0
- package/dist/actions/advanced/index.d.ts +9 -0
- package/dist/actions/advanced/index.js +9 -0
- package/dist/advanced-8ZPTmmaN.js +598 -0
- package/dist/advanced-8ZPTmmaN.js.map +1 -0
- package/dist/advanced-fPImL6lW.cjs +656 -0
- package/dist/arkivTransactions-D74gERHG.d.cts +571 -0
- package/dist/arkivTransactions-D74gERHG.d.cts.map +1 -0
- package/dist/arkivTransactions-NtGD6uk5.d.ts +571 -0
- package/dist/arkivTransactions-NtGD6uk5.d.ts.map +1 -0
- package/dist/attr/index.cjs +35 -0
- package/dist/attr/index.d.cts +2 -0
- package/dist/attr/index.d.ts +3 -0
- package/dist/attr/index.js +4 -0
- package/dist/attributes-BhY5DwJp.js +809 -0
- package/dist/attributes-BhY5DwJp.js.map +1 -0
- package/dist/attributes-Df9IsCVs.cjs +1029 -0
- package/dist/chains/index.cjs +2 -3
- package/dist/chains/index.d.cts +22 -60
- package/dist/chains/index.d.cts.map +1 -1
- package/dist/chains/index.d.ts +22 -60
- package/dist/chains/index.d.ts.map +1 -1
- package/dist/chains/index.js +2 -2
- package/dist/chains-BJrZs6sG.js +57 -0
- package/dist/chains-BJrZs6sG.js.map +1 -0
- package/dist/chains-BYRTTipa.cjs +73 -0
- package/dist/codec-Car3KkFF.d.ts +102 -0
- package/dist/codec-Car3KkFF.d.ts.map +1 -0
- package/dist/entity/index.cjs +20 -0
- package/dist/entity/index.d.cts +4 -0
- package/dist/entity/index.d.ts +5 -0
- package/dist/entity/index.js +7 -0
- package/dist/entity-B00Li04j.cjs +71 -0
- package/dist/entity-B7G8q_Eo.cjs +0 -0
- package/dist/entity-BYQR1uoe.js +67 -0
- package/dist/entity-BYQR1uoe.js.map +1 -0
- package/dist/entity-CD_qFF2M.js +0 -0
- package/dist/errors-BVbjKVMN.cjs +56 -0
- package/dist/errors-LTe7bOYS.js +33 -0
- package/dist/errors-LTe7bOYS.js.map +1 -0
- package/dist/expiry-BELY2Kpw.cjs +135 -0
- package/dist/expiry-BjpxZZQU.js +95 -0
- package/dist/expiry-BjpxZZQU.js.map +1 -0
- package/dist/expiry-DRV29F1r.d.cts +79 -0
- package/dist/expiry-DRV29F1r.d.cts.map +1 -0
- package/dist/expiry-nDbCgZX4.d.ts +79 -0
- package/dist/expiry-nDbCgZX4.d.ts.map +1 -0
- package/dist/flags-5dTNRnow.d.ts +41 -0
- package/dist/flags-5dTNRnow.d.ts.map +1 -0
- package/dist/flags-CRjPpoh3.d.cts +41 -0
- package/dist/flags-CRjPpoh3.d.cts.map +1 -0
- package/dist/flags-DFBs2J94.js +33 -0
- package/dist/flags-DFBs2J94.js.map +1 -0
- package/dist/flags-kr276q6i.cjs +43 -0
- package/dist/index-B5j76711.d.ts +184 -0
- package/dist/index-B5j76711.d.ts.map +1 -0
- package/dist/index-BF7Mq9Is.d.cts +280 -0
- package/dist/index-BF7Mq9Is.d.cts.map +1 -0
- package/dist/index-CA4V7Pdh.d.cts +167 -0
- package/dist/index-CA4V7Pdh.d.cts.map +1 -0
- package/dist/index-CV5zCdpa.d.cts +417 -0
- package/dist/index-CV5zCdpa.d.cts.map +1 -0
- package/dist/index-DHDud2hC.d.ts +280 -0
- package/dist/index-DHDud2hC.d.ts.map +1 -0
- package/dist/index-DvYvrkdk.d.ts +320 -0
- package/dist/index-DvYvrkdk.d.ts.map +1 -0
- package/dist/index-EeUO0nnJ.d.cts +184 -0
- package/dist/index-EeUO0nnJ.d.cts.map +1 -0
- package/dist/index-fX_XyqLp.d.ts +167 -0
- package/dist/index-fX_XyqLp.d.ts.map +1 -0
- package/dist/index.cjs +411 -405
- package/dist/index.d.cts +360 -209
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +361 -209
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +342 -387
- package/dist/index.js.map +1 -1
- package/dist/key-D1Bh7MF0.js +70 -0
- package/dist/key-D1Bh7MF0.js.map +1 -0
- package/dist/key-WKhXnXuU.cjs +98 -0
- package/dist/logger-CVpvU8ik.js +153 -0
- package/dist/logger-CVpvU8ik.js.map +1 -0
- package/dist/logger-Cr15lPAQ.cjs +188 -0
- package/dist/payload-BNoud2KZ.d.cts +94 -0
- package/dist/payload-BNoud2KZ.d.cts.map +1 -0
- package/dist/payload-Bz6651ax.js +67 -0
- package/dist/payload-Bz6651ax.js.map +1 -0
- package/dist/payload-CcUj85ys.d.ts +94 -0
- package/dist/payload-CcUj85ys.d.ts.map +1 -0
- package/dist/payload-KC14SDlN.cjs +83 -0
- package/dist/query/index.cjs +26 -150
- package/dist/query/index.d.cts +5 -3
- package/dist/query/index.d.ts +6 -3
- package/dist/query/index.js +8 -138
- package/dist/queryBuilder-DM6AWCBa.js +820 -0
- package/dist/queryBuilder-DM6AWCBa.js.map +1 -0
- package/dist/queryBuilder-DbUMEZln.cjs +944 -0
- package/dist/selection-C4UhsMOO.d.ts +434 -0
- package/dist/selection-C4UhsMOO.d.ts.map +1 -0
- package/dist/selection-DPg0uyJf.d.cts +433 -0
- package/dist/selection-DPg0uyJf.d.cts.map +1 -0
- package/dist/types/index.cjs +3 -3
- package/dist/types/index.d.cts +7 -2
- package/dist/types/index.d.ts +8 -2
- package/dist/types/index.js +3 -3
- package/dist/types-Bu_ZwMbZ.js +0 -0
- package/dist/types-NRqymi6S.cjs +0 -0
- package/dist/utils/index.cjs +4 -17
- package/dist/utils/index.d.cts +3 -17
- package/dist/utils/index.d.ts +3 -17
- package/dist/utils/index.js +4 -18
- package/package.json +26 -5
- package/src/actions/advanced/advanced.test.ts +258 -0
- package/src/actions/advanced/buildMutation.ts +104 -0
- package/src/actions/advanced/getMutationResult.ts +112 -0
- package/src/actions/advanced/index.ts +21 -0
- package/src/actions/advanced/pingTransaction.ts +43 -0
- package/src/actions/advanced/sendMutation.ts +59 -0
- package/src/actions/public/getEntity.ts +27 -43
- package/src/actions/public/getEntityNonce.ts +30 -0
- package/src/actions/public/predictEntityKeys.test.ts +143 -0
- package/src/actions/public/predictEntityKeys.ts +138 -0
- package/src/actions/public/query.ts +35 -67
- package/src/actions/public/watchEntityEvents.test.ts +414 -0
- package/src/actions/public/watchEntityEvents.ts +225 -0
- package/src/actions/wallet/changeOwnership.ts +2 -2
- package/src/actions/wallet/createEntity.ts +99 -24
- package/src/actions/wallet/extendEntity.ts +37 -13
- package/src/actions/wallet/mutateEntities.test.ts +76 -0
- package/src/actions/wallet/mutateEntities.ts +16 -33
- package/src/actions/wallet/patchEntity.ts +90 -0
- package/src/attr/attributes.test.ts +120 -0
- package/src/attr/attributes.ts +190 -0
- package/src/attr/codec.test.ts +162 -0
- package/src/attr/codec.ts +220 -0
- package/src/attr/decimal.ts +86 -0
- package/src/attr/errors.ts +145 -0
- package/src/attr/index.ts +50 -0
- package/src/attr/names.ts +106 -0
- package/src/attr/types.ts +150 -0
- package/src/attr/values.test.ts +271 -0
- package/src/attr/values.ts +502 -0
- package/src/chains/cheesecake.ts +22 -0
- package/src/chains/index.ts +1 -2
- package/src/clients/createPublicClient.test.ts +3 -5
- package/src/clients/createPublicClient.ts +5 -4
- package/src/clients/createWalletClient.test.ts +2 -2
- package/src/clients/createWalletClient.ts +13 -7
- package/src/clients/decorators/arkivAdvanced.ts +144 -0
- package/src/clients/decorators/arkivPublic.ts +172 -139
- package/src/clients/decorators/arkivWallet.ts +101 -94
- package/src/entity/create.test.ts +184 -0
- package/src/entity/errors.ts +38 -0
- package/src/entity/events.ts +16 -0
- package/src/entity/expiry.test.ts +195 -0
- package/src/entity/expiry.ts +181 -0
- package/src/entity/flags.ts +65 -0
- package/src/entity/index.ts +15 -0
- package/src/entity/key.ts +68 -0
- package/src/entity/operations.ts +134 -0
- package/src/entity/params.ts +15 -0
- package/src/errors.ts +26 -49
- package/src/index.ts +19 -0
- package/src/query/engine.ts +68 -137
- package/src/query/errors.ts +151 -0
- package/src/query/expression.test.ts +286 -0
- package/src/query/expression.ts +493 -0
- package/src/query/index.ts +40 -4
- package/src/query/injection.test.ts +151 -0
- package/src/query/queryBuilder.test.ts +342 -637
- package/src/query/queryBuilder.ts +133 -359
- package/src/query/queryResult.ts +54 -51
- package/src/query/selection.test.ts +48 -98
- package/src/query/selection.ts +77 -65
- package/src/types/entity.test.ts +44 -155
- package/src/types/entity.ts +60 -52
- package/src/types/events.ts +59 -16
- package/src/types/index.ts +20 -17
- package/src/types/rpcSchema.ts +69 -37
- package/src/utils/arkivTransactions.test.ts +600 -155
- package/src/utils/arkivTransactions.ts +350 -219
- package/src/utils/chains.test.ts +21 -24
- package/src/utils/compression.ts +1 -1
- package/src/utils/entities.test.ts +62 -0
- package/src/utils/entities.ts +109 -37
- package/src/utils/expirationTime.ts +114 -10
- package/src/utils/logger.ts +2 -2
- package/src/utils/revert.test.ts +99 -0
- package/src/utils/revert.ts +145 -0
- package/dist/chains-BifaY04V.cjs +0 -108
- package/dist/chains-CrtkVbBh.js +0 -86
- package/dist/chains-CrtkVbBh.js.map +0 -1
- package/dist/consts-Bz0LZQZY.js +0 -7
- package/dist/consts-Bz0LZQZY.js.map +0 -1
- package/dist/consts-CxT1-RXU.cjs +0 -18
- package/dist/entity-BhSXaB23.cjs +0 -81
- package/dist/entity-CN41IOrq.d.cts +0 -401
- package/dist/entity-CN41IOrq.d.cts.map +0 -1
- package/dist/entity-DGfVyB-a.js +0 -71
- package/dist/entity-DGfVyB-a.js.map +0 -1
- package/dist/entity-NnEVlePN.d.ts +0 -401
- package/dist/entity-NnEVlePN.d.ts.map +0 -1
- package/dist/index-ClkpS6s_.d.ts +0 -481
- package/dist/index-ClkpS6s_.d.ts.map +0 -1
- package/dist/index-w4qop0Pe.d.cts +0 -481
- package/dist/index-w4qop0Pe.d.cts.map +0 -1
- package/dist/payload-BpNUPOnY.js +0 -13
- package/dist/payload-BpNUPOnY.js.map +0 -1
- package/dist/payload-C2KHOUoj.d.ts +0 -6
- package/dist/payload-C2KHOUoj.d.ts.map +0 -1
- package/dist/payload-CJN8fTvX.d.cts +0 -6
- package/dist/payload-CJN8fTvX.d.cts.map +0 -1
- package/dist/payload-D8YLKcJj.cjs +0 -23
- package/dist/query/index.js.map +0 -1
- package/dist/queryBuilder-BE_XhLLa.js +0 -735
- package/dist/queryBuilder-BE_XhLLa.js.map +0 -1
- package/dist/queryBuilder-J37buGCi.cjs +0 -865
- package/dist/utils/index.d.cts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/src/actions/public/buildQuery.ts +0 -10
- package/src/actions/public/subscribeEntityEvents.ts +0 -93
- package/src/actions/wallet/updateEntity.ts +0 -59
- package/src/chains/braga.ts +0 -26
- package/src/chains/kaolin.ts +0 -29
- package/src/query/engine.test.ts +0 -571
- package/src/query/predicate.test.ts +0 -461
- package/src/query/predicate.ts +0 -144
- package/src/query/queryResult.test.ts +0 -270
- package/src/query/selectQueryBuilder.test.ts +0 -213
- package/src/types/attributes.ts +0 -28
- package/src/utils/validation.test.ts +0 -106
- package/src/utils/validation.ts +0 -80
- /package/dist/{types-Ci4BRClw.js → attr-DlmErkvR.cjs} +0 -0
- /package/dist/{types-a8gm_IaQ.cjs → attr-GcQKatub.js} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
const require_chains = require('./chains-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
require('./
|
|
6
|
-
const
|
|
1
|
+
const require_chains = require('./chains-BYRTTipa.cjs');
|
|
2
|
+
const require_expiry = require('./expiry-BELY2Kpw.cjs');
|
|
3
|
+
const require_advanced = require('./advanced-fPImL6lW.cjs');
|
|
4
|
+
const require_attributes = require('./attributes-Df9IsCVs.cjs');
|
|
5
|
+
const require_key = require('./key-WKhXnXuU.cjs');
|
|
6
|
+
const require_errors = require('./errors-BVbjKVMN.cjs');
|
|
7
|
+
const require_flags = require('./flags-kr276q6i.cjs');
|
|
8
|
+
const require_logger = require('./logger-Cr15lPAQ.cjs');
|
|
9
|
+
require('./attr-DlmErkvR.cjs');
|
|
10
|
+
const require_entity = require('./entity-B00Li04j.cjs');
|
|
11
|
+
const require_queryBuilder = require('./queryBuilder-DbUMEZln.cjs');
|
|
12
|
+
require('./entity-B7G8q_Eo.cjs');
|
|
13
|
+
require('./types-NRqymi6S.cjs');
|
|
14
|
+
const require_payload = require('./payload-KC14SDlN.cjs');
|
|
7
15
|
let viem = require("viem");
|
|
16
|
+
let viem_actions = require("viem/actions");
|
|
8
17
|
|
|
9
18
|
//#region src/actions/public/getBlockTiming.ts
|
|
10
|
-
const logger$8 =
|
|
19
|
+
const logger$8 = require_logger.getLogger("actions:public:get-block-timing");
|
|
11
20
|
async function getBlockTiming(client) {
|
|
12
21
|
const blockTiming = await client.request({
|
|
13
22
|
method: "arkiv_getBlockTiming",
|
|
@@ -23,33 +32,26 @@ async function getBlockTiming(client) {
|
|
|
23
32
|
|
|
24
33
|
//#endregion
|
|
25
34
|
//#region src/actions/public/getEntity.ts
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
expiration: true,
|
|
43
|
-
owner: true,
|
|
44
|
-
creator: true,
|
|
45
|
-
createdAtBlock: true,
|
|
46
|
-
lastModifiedAtBlock: true,
|
|
47
|
-
transactionIndexInBlock: true,
|
|
48
|
-
operationIndexInTransaction: true
|
|
49
|
-
} }]
|
|
35
|
+
/**
|
|
36
|
+
* Reads one entity by key, with every field selected.
|
|
37
|
+
*
|
|
38
|
+
* Returns a {@link FullEntity} rather than an {@link Entity}: the selection is fixed at `"*"`, so
|
|
39
|
+
* every field is populated and none of them needs a `?` at the call site. The bare `Entity` type
|
|
40
|
+
* has every field optional because a `select()` result carries only what it asked for.
|
|
41
|
+
*
|
|
42
|
+
* @throws {InvalidValueError} If the key is not 32 bytes.
|
|
43
|
+
* @throws {NoEntityFoundError} If no live entity has that key — it never existed, or it was
|
|
44
|
+
* deleted or has expired.
|
|
45
|
+
*/
|
|
46
|
+
async function getEntity(client, entityKey) {
|
|
47
|
+
const { entities } = await require_queryBuilder.runQuery(client, {
|
|
48
|
+
query: require_queryBuilder.eq("$key", require_attributes.key(entityKey)).toString(),
|
|
49
|
+
select: require_queryBuilder.toRpcSelect("*"),
|
|
50
|
+
limit: 1
|
|
50
51
|
});
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
const entity = entities[0];
|
|
53
|
+
if (entity === void 0) throw new require_logger.NoEntityFoundError(entityKey);
|
|
54
|
+
return entity;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
//#endregion
|
|
@@ -62,355 +64,294 @@ async function getEntityCount(client) {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
//#endregion
|
|
65
|
-
//#region src/actions/public/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
type: order.type,
|
|
85
|
-
desc: order.desc === "desc"
|
|
86
|
-
})) },
|
|
87
|
-
...queryOptions?.resultsPerPage !== void 0 && { resultsPerPage: (0, viem.numberToHex)(queryOptions.resultsPerPage) },
|
|
88
|
-
...queryOptions?.cursor !== void 0 && { cursor: queryOptions?.cursor }
|
|
89
|
-
};
|
|
90
|
-
const result = await client.request({
|
|
91
|
-
method: "arkiv_query",
|
|
92
|
-
params: [query$1, rpcQueryOptions]
|
|
67
|
+
//#region src/actions/public/getEntityNonce.ts
|
|
68
|
+
const logger$7 = require_logger.getLogger("actions:public:get-entity-nonce");
|
|
69
|
+
/**
|
|
70
|
+
* Reads an owner's entity-minting nonce — how many entities that account has created.
|
|
71
|
+
*
|
|
72
|
+
* This is not the account's transaction nonce. The engine keeps a separate counter per creator and
|
|
73
|
+
* mixes it into every key it mints, which is what makes two identical creates from one account land
|
|
74
|
+
* on different keys.
|
|
75
|
+
*
|
|
76
|
+
* @param owner - The account whose nonce to read.
|
|
77
|
+
* @returns The number of entities `owner` has created so far, which is the nonce its next create
|
|
78
|
+
* will use.
|
|
79
|
+
*/
|
|
80
|
+
async function getEntityNonce(client, owner) {
|
|
81
|
+
const nonce = await (0, viem_actions.readContract)(client, {
|
|
82
|
+
address: require_expiry.ARKIV_ADDRESS,
|
|
83
|
+
abi: require_advanced.ENTITY_NONCE_ABI,
|
|
84
|
+
functionName: "entityNonce",
|
|
85
|
+
args: [owner]
|
|
93
86
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
cursor: result.cursor,
|
|
97
|
-
blockNumber: BigInt(result.blockNumber)
|
|
98
|
-
};
|
|
87
|
+
logger$7("entity nonce of %s is %s", owner, nonce);
|
|
88
|
+
return nonce;
|
|
99
89
|
}
|
|
100
90
|
|
|
101
91
|
//#endregion
|
|
102
|
-
//#region src/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
function encodeMime128(contentType) {
|
|
153
|
-
return { data: contentType ? encodeBytes128((0, viem.stringToBytes)(contentType)) : EMPTY_BYTES128 };
|
|
92
|
+
//#region src/actions/public/predictEntityKeys.ts
|
|
93
|
+
/**
|
|
94
|
+
* Works out the keys an account's next creates will be given, before sending them.
|
|
95
|
+
*
|
|
96
|
+
* A key is `keccak256(chainId ++ registry ++ owner ++ nonce ++ salt)`. Everything but the nonce is
|
|
97
|
+
* known to the caller, and the nonce is read here — so a batch can reference a key it is about to
|
|
98
|
+
* mint, storing it as a `key` attribute on a sibling entity created in the same transaction.
|
|
99
|
+
*
|
|
100
|
+
* Each key arrives paired with its salt, and the create must be given that salt: a create left to
|
|
101
|
+
* pick its own salt picks a random one, which mints a different key.
|
|
102
|
+
*
|
|
103
|
+
* The prediction is valid only while nothing else from this owner is in flight. Every create that
|
|
104
|
+
* lands first takes the nonce with it and moves these keys. For a key you can rely on
|
|
105
|
+
* unconditionally, read it back from the create instead — `createEntity` and `mutateEntities`
|
|
106
|
+
* report the keys the engine actually minted.
|
|
107
|
+
*
|
|
108
|
+
* @param parameters - Owner, and either a count or the salts. {@link PredictEntityKeysParameters}
|
|
109
|
+
* @returns One `{ key, salt }` pair per create, in batch order. {@link PredictEntityKeysReturnType}
|
|
110
|
+
*
|
|
111
|
+
* @example A batch whose second entity points at its first.
|
|
112
|
+
* import { key } from "@arkiv-network/sdk/attr"
|
|
113
|
+
*
|
|
114
|
+
* const [parent, child] = await client.predictEntityKeys({ owner: account.address, count: 2 })
|
|
115
|
+
* await wallet.mutateEntities({
|
|
116
|
+
* creates: [
|
|
117
|
+
* { payload, contentType, expires, salt: parent.salt },
|
|
118
|
+
* {
|
|
119
|
+
* payload,
|
|
120
|
+
* contentType,
|
|
121
|
+
* expires,
|
|
122
|
+
* salt: child.salt,
|
|
123
|
+
* attributes: { parent: key(parent.key) },
|
|
124
|
+
* },
|
|
125
|
+
* ],
|
|
126
|
+
* })
|
|
127
|
+
*/
|
|
128
|
+
async function predictEntityKeys(client, { owner, count, salts }) {
|
|
129
|
+
const resolvedSalts = resolveSalts(count, salts);
|
|
130
|
+
const chainId = client.chain?.id ?? await (0, viem_actions.getChainId)(client);
|
|
131
|
+
const nonce = await getEntityNonce(client, owner);
|
|
132
|
+
return resolvedSalts.map((salt, index) => ({
|
|
133
|
+
key: require_key.predictEntityKey({
|
|
134
|
+
owner,
|
|
135
|
+
nonce: nonce + BigInt(index),
|
|
136
|
+
salt,
|
|
137
|
+
chainId
|
|
138
|
+
}),
|
|
139
|
+
salt
|
|
140
|
+
}));
|
|
154
141
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
name,
|
|
161
|
-
valueType: require_queryBuilder.RpcAttributeValueType.EntityKey,
|
|
162
|
-
value: [
|
|
163
|
-
(0, viem.toHex)((0, viem.toBytes)(attr.value), { size: 32 }),
|
|
164
|
-
ZERO_32,
|
|
165
|
-
ZERO_32,
|
|
166
|
-
ZERO_32
|
|
167
|
-
]
|
|
168
|
-
};
|
|
169
|
-
return {
|
|
170
|
-
name,
|
|
171
|
-
valueType: require_queryBuilder.RpcAttributeValueType.String,
|
|
172
|
-
value: encodeBytes128((0, viem.stringToBytes)(attr.value))
|
|
173
|
-
};
|
|
142
|
+
/** The salts to derive from: the ones given, or `count` fresh random ones. */
|
|
143
|
+
function resolveSalts(count, salts) {
|
|
144
|
+
if (salts !== void 0) {
|
|
145
|
+
if (salts.length === 0) throw new Error("predictEntityKeys: `salts` is empty — there is nothing to predict");
|
|
146
|
+
return salts.map(require_key.validateSalt);
|
|
174
147
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
value: [
|
|
179
|
-
(0, viem.toHex)(BigInt(attr.value), { size: 32 }),
|
|
180
|
-
ZERO_32,
|
|
181
|
-
ZERO_32,
|
|
182
|
-
ZERO_32
|
|
183
|
-
]
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function encodeAttributes(attrs) {
|
|
187
|
-
const encoded = attrs.map((attr) => ({
|
|
188
|
-
key: attr.key,
|
|
189
|
-
...encodeAttribute(attr)
|
|
190
|
-
})).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
191
|
-
for (let i = 1; i < encoded.length; i++) if (encoded[i].name === encoded[i - 1].name) throw new require_queryBuilder.DuplicateAttributeError(encoded[i].key);
|
|
192
|
-
return encoded.map(({ key: _,...attr }) => attr);
|
|
193
|
-
}
|
|
194
|
-
function toBTL(expiresIn) {
|
|
195
|
-
require_queryBuilder.validateExpiresIn(expiresIn);
|
|
196
|
-
return Math.ceil(expiresIn / require_consts.BLOCK_TIME);
|
|
148
|
+
if (count === void 0) throw new Error("predictEntityKeys: pass either `count` or `salts`");
|
|
149
|
+
if (!Number.isInteger(count) || count <= 0) throw new Error(`predictEntityKeys: \`count\` must be a positive whole number, got ${count}`);
|
|
150
|
+
return Array.from({ length: count }, () => require_key.randomSalt());
|
|
197
151
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
address: require_consts.ARKIV_ADDRESS,
|
|
219
|
-
abi: ENTITY_NONCE_ABI,
|
|
220
|
-
functionName: "nonces",
|
|
221
|
-
args: [owner]
|
|
222
|
-
})) : 0n;
|
|
223
|
-
const createdEntityKeys = (creates ?? []).map((_, i) => deriveEntityKey(client.chain.id, owner, ownerNonce + BigInt(i)));
|
|
224
|
-
for (const item of creates ?? []) validateContentType(item.contentType);
|
|
225
|
-
for (const item of updates ?? []) validateContentType(item.contentType);
|
|
226
|
-
const operations = [
|
|
227
|
-
...(creates ?? []).map((item, i) => ({
|
|
228
|
-
operationType: require_entity.EntityOperationType.Create,
|
|
229
|
-
entityKey: createdEntityKeys[i],
|
|
230
|
-
payload: (0, viem.toHex)(item.payload),
|
|
231
|
-
contentType: encodeMime128(item.contentType),
|
|
232
|
-
attributes: encodeAttributes(item.attributes),
|
|
233
|
-
expiresIn: toBTL(item.expiresIn),
|
|
234
|
-
newOwner: ZERO_ADDRESS
|
|
235
|
-
})),
|
|
236
|
-
...(updates ?? []).map((item) => ({
|
|
237
|
-
operationType: require_entity.EntityOperationType.Update,
|
|
238
|
-
entityKey: item.entityKey,
|
|
239
|
-
payload: (0, viem.toHex)(item.payload),
|
|
240
|
-
contentType: encodeMime128(item.contentType),
|
|
241
|
-
attributes: encodeAttributes(item.attributes),
|
|
242
|
-
expiresIn: 0,
|
|
243
|
-
newOwner: ZERO_ADDRESS
|
|
244
|
-
})),
|
|
245
|
-
...(deletes ?? []).map((item) => ({
|
|
246
|
-
operationType: require_entity.EntityOperationType.Delete,
|
|
247
|
-
entityKey: item.entityKey,
|
|
248
|
-
payload: "0x",
|
|
249
|
-
contentType: encodeMime128(""),
|
|
250
|
-
attributes: [],
|
|
251
|
-
expiresIn: 0,
|
|
252
|
-
newOwner: ZERO_ADDRESS
|
|
253
|
-
})),
|
|
254
|
-
...(extensions ?? []).map((item) => ({
|
|
255
|
-
operationType: require_entity.EntityOperationType.Extend,
|
|
256
|
-
entityKey: item.entityKey,
|
|
257
|
-
payload: "0x",
|
|
258
|
-
contentType: encodeMime128(""),
|
|
259
|
-
attributes: [],
|
|
260
|
-
expiresIn: toBTL(item.expiresIn),
|
|
261
|
-
newOwner: ZERO_ADDRESS
|
|
262
|
-
})),
|
|
263
|
-
...(ownershipChanges ?? []).map((item) => ({
|
|
264
|
-
operationType: require_entity.EntityOperationType.Transfer,
|
|
265
|
-
entityKey: item.entityKey,
|
|
266
|
-
payload: "0x",
|
|
267
|
-
contentType: encodeMime128(""),
|
|
268
|
-
attributes: [],
|
|
269
|
-
expiresIn: 0,
|
|
270
|
-
newOwner: item.newOwner
|
|
271
|
-
}))
|
|
272
|
-
];
|
|
273
|
-
logger$7("Sending execute with %d operations %s", operations.length, JSON.stringify(operations));
|
|
274
|
-
try {
|
|
275
|
-
const txHash = await walletClient.writeContract({
|
|
276
|
-
address: require_consts.ARKIV_ADDRESS,
|
|
277
|
-
abi: EXECUTE_ABI,
|
|
278
|
-
functionName: "execute",
|
|
279
|
-
args: [operations],
|
|
280
|
-
account: client.account,
|
|
281
|
-
chain: client.chain,
|
|
282
|
-
...txParams
|
|
283
|
-
});
|
|
284
|
-
const receipt = await walletClient.waitForTransactionReceipt({ hash: txHash });
|
|
285
|
-
logger$7("Tx receipt %o", receipt);
|
|
286
|
-
if (receipt.status === "reverted") {
|
|
287
|
-
try {
|
|
288
|
-
await walletClient.simulateContract({
|
|
289
|
-
address: require_consts.ARKIV_ADDRESS,
|
|
290
|
-
abi: EXECUTE_ABI,
|
|
291
|
-
functionName: "execute",
|
|
292
|
-
args: [operations],
|
|
293
|
-
account: client.account,
|
|
294
|
-
chain: client.chain
|
|
295
|
-
});
|
|
296
|
-
} catch (err) {
|
|
297
|
-
const error = err;
|
|
298
|
-
const reason = error.shortMessage ?? error.cause?.details ?? "No reason provided by backend.";
|
|
299
|
-
throw new require_queryBuilder.EntityMutationError(`Transaction ${receipt.transactionHash} reverted. Reason: ${reason}`);
|
|
300
|
-
}
|
|
301
|
-
throw new require_queryBuilder.EntityMutationError(`Transaction ${receipt.transactionHash} reverted. No reason provided by backend.`);
|
|
302
|
-
}
|
|
303
|
-
return {
|
|
304
|
-
receipt,
|
|
305
|
-
createdEntityKeys
|
|
306
|
-
};
|
|
307
|
-
} catch (error) {
|
|
308
|
-
let message = "Transaction failed";
|
|
309
|
-
if (error instanceof viem.TransactionExecutionError) message += `: ${error.details}`;
|
|
310
|
-
else if (error instanceof viem.ContractFunctionExecutionError) {
|
|
311
|
-
logger$7("Contract function execution error data:", error.shortMessage);
|
|
312
|
-
if (error.cause instanceof viem.ContractFunctionRevertedError) message += `: ${error.cause.message}`;
|
|
313
|
-
else message += ": Execution error without revert data";
|
|
314
|
-
} else if (error instanceof require_queryBuilder.EntityMutationError) throw error;
|
|
315
|
-
throw new require_queryBuilder.EntityMutationError(message);
|
|
316
|
-
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/actions/public/query.ts
|
|
155
|
+
/**
|
|
156
|
+
* Runs a single query and returns one page, with no builder in between.
|
|
157
|
+
*
|
|
158
|
+
* Takes either an {@link Expression} or a raw query string. The string form is an escape hatch for
|
|
159
|
+
* a query built elsewhere — it goes to the node exactly as written, with none of the name, type or
|
|
160
|
+
* operator checks the expression combinators apply.
|
|
161
|
+
*
|
|
162
|
+
* @throws {QueryError} If the node rejects the query.
|
|
163
|
+
*/
|
|
164
|
+
function query(client, query$1, options = {}) {
|
|
165
|
+
return require_queryBuilder.runQuery(client, {
|
|
166
|
+
query: query$1.toString(),
|
|
167
|
+
select: require_queryBuilder.toRpcSelect(options.select),
|
|
168
|
+
limit: options.limit,
|
|
169
|
+
cursor: options.cursor,
|
|
170
|
+
atBlock: options.atBlock
|
|
171
|
+
});
|
|
317
172
|
}
|
|
318
173
|
|
|
319
174
|
//#endregion
|
|
320
|
-
//#region src/actions/public/
|
|
321
|
-
const logger$6 =
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
175
|
+
//#region src/actions/public/watchEntityEvents.ts
|
|
176
|
+
const logger$6 = require_logger.getLogger("actions:public:watch-entity-events");
|
|
177
|
+
/**
|
|
178
|
+
* How often to poll, when the caller does not say.
|
|
179
|
+
*
|
|
180
|
+
* Half a block: fast enough that an event is never a whole block stale, slow enough not to hammer
|
|
181
|
+
* the node. viem's own default is derived from a 12-second Ethereum block and is far too slow here.
|
|
182
|
+
*/
|
|
183
|
+
const DEFAULT_POLLING_INTERVAL = require_expiry.BLOCK_TIME * 1e3 / 2;
|
|
184
|
+
/**
|
|
185
|
+
* Watches entity events, calling the handlers you pass as they arrive.
|
|
186
|
+
*
|
|
187
|
+
* Every event here is decoded from a log the Arkiv operation address emitted, and carries the
|
|
188
|
+
* block, transaction and log index it came from — so consuming them in order replays exactly what
|
|
189
|
+
* the engine did.
|
|
190
|
+
*
|
|
191
|
+
* @param parameters - Handlers and options. {@link WatchEntityEventsParameters}
|
|
192
|
+
* @returns A function that stops the watcher.
|
|
193
|
+
*
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* import { createPublicClient } from "@arkiv-network/sdk"
|
|
197
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
198
|
+
* import { http } from "viem"
|
|
199
|
+
*
|
|
200
|
+
* const client = createPublicClient({ chain: cheesecake, transport: http() })
|
|
201
|
+
*
|
|
202
|
+
* const unwatch = client.watchEntityEvents({
|
|
203
|
+
* onEntityCreated: ({ entityKey, owner, expiresAt }) =>
|
|
204
|
+
* console.log("created", entityKey, "by", owner, "until block", expiresAt),
|
|
205
|
+
* onEntityDeleted: ({ entityKey }) => console.log("deleted", entityKey),
|
|
206
|
+
* onError: (error) => console.error(error),
|
|
207
|
+
* })
|
|
208
|
+
*
|
|
209
|
+
* unwatch()
|
|
210
|
+
*/
|
|
211
|
+
function watchEntityEvents(client, parameters) {
|
|
212
|
+
const { onEntityCreated, onEntityPatched, onExpiryExtended, onOwnershipTransferred, onEntityDeleted, onEvent, onError, fromBlock, pollingInterval = DEFAULT_POLLING_INTERVAL } = parameters;
|
|
213
|
+
const publicClient = client;
|
|
214
|
+
const reportError = onError ?? logToConsole;
|
|
215
|
+
function emit(event) {
|
|
216
|
+
deliver(onEvent, event);
|
|
217
|
+
switch (event.type) {
|
|
218
|
+
case "EntityCreated":
|
|
219
|
+
deliver(onEntityCreated, event);
|
|
220
|
+
break;
|
|
221
|
+
case "EntityPatched":
|
|
222
|
+
deliver(onEntityPatched, event);
|
|
223
|
+
break;
|
|
224
|
+
case "ExpiryExtended":
|
|
225
|
+
deliver(onExpiryExtended, event);
|
|
226
|
+
break;
|
|
227
|
+
case "OwnershipTransferred":
|
|
228
|
+
deliver(onOwnershipTransferred, event);
|
|
229
|
+
break;
|
|
230
|
+
case "EntityDeleted":
|
|
231
|
+
deliver(onEntityDeleted, event);
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Runs one handler, keeping its failure to itself.
|
|
237
|
+
*
|
|
238
|
+
* A handler that throws is the consumer's problem, not the watcher's: letting it escape would
|
|
239
|
+
* reject the poll, drop the rest of the batch, and take down every other handler with it.
|
|
240
|
+
*/
|
|
241
|
+
function deliver(handler, event) {
|
|
242
|
+
if (handler === void 0) return;
|
|
243
|
+
try {
|
|
244
|
+
handler(event);
|
|
245
|
+
} catch (error) {
|
|
246
|
+
reportError(asError(error));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return publicClient.watchEvent({
|
|
250
|
+
address: require_expiry.ARKIV_ADDRESS,
|
|
251
|
+
events: require_key.ENTITY_EVENTS_ABI,
|
|
252
|
+
pollingInterval,
|
|
253
|
+
...fromBlock !== void 0 && { fromBlock },
|
|
328
254
|
onLogs: (logs) => {
|
|
329
|
-
logger$6("logs
|
|
255
|
+
logger$6("logs %o", logs);
|
|
330
256
|
for (const log of logs) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
case require_entity.EntityOperationType.Create:
|
|
344
|
-
onEntityCreated?.({
|
|
345
|
-
entityKey,
|
|
346
|
-
owner,
|
|
347
|
-
expiresAt,
|
|
348
|
-
entityHash
|
|
349
|
-
});
|
|
350
|
-
break;
|
|
351
|
-
case require_entity.EntityOperationType.Update:
|
|
352
|
-
onEntityUpdated?.({
|
|
353
|
-
entityKey,
|
|
354
|
-
owner,
|
|
355
|
-
expiresAt,
|
|
356
|
-
entityHash
|
|
357
|
-
});
|
|
358
|
-
break;
|
|
359
|
-
case require_entity.EntityOperationType.Extend:
|
|
360
|
-
onEntityExpiresInExtended?.({
|
|
361
|
-
entityKey,
|
|
362
|
-
owner,
|
|
363
|
-
expiresAt,
|
|
364
|
-
entityHash
|
|
365
|
-
});
|
|
366
|
-
break;
|
|
367
|
-
case require_entity.EntityOperationType.Transfer:
|
|
368
|
-
onEntityOwnerChanged?.({
|
|
369
|
-
entityKey,
|
|
370
|
-
owner,
|
|
371
|
-
entityHash
|
|
372
|
-
});
|
|
373
|
-
break;
|
|
374
|
-
case require_entity.EntityOperationType.Delete:
|
|
375
|
-
onEntityDeleted?.({
|
|
376
|
-
entityKey,
|
|
377
|
-
owner
|
|
378
|
-
});
|
|
379
|
-
break;
|
|
380
|
-
default:
|
|
381
|
-
onEntityExpired?.({
|
|
382
|
-
entityKey,
|
|
383
|
-
owner
|
|
384
|
-
});
|
|
385
|
-
break;
|
|
257
|
+
if (log.blockNumber === null || log.transactionHash === null || log.logIndex === null) continue;
|
|
258
|
+
const context = {
|
|
259
|
+
blockNumber: log.blockNumber,
|
|
260
|
+
transactionHash: log.transactionHash,
|
|
261
|
+
logIndex: log.logIndex
|
|
262
|
+
};
|
|
263
|
+
let event;
|
|
264
|
+
try {
|
|
265
|
+
event = toEntityEvent(log.topics, log.data, context);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
reportError(asError(error));
|
|
268
|
+
continue;
|
|
386
269
|
}
|
|
270
|
+
emit(event);
|
|
387
271
|
}
|
|
388
272
|
},
|
|
389
|
-
onError: (error) =>
|
|
390
|
-
console.error("error from subscribeEntityEvents", error);
|
|
391
|
-
onError?.(error);
|
|
392
|
-
}
|
|
273
|
+
onError: (error) => reportError(error)
|
|
393
274
|
});
|
|
394
275
|
}
|
|
276
|
+
/** The fallback when no `onError` was given — see {@link WatchEntityEventsParameters.onError}. */
|
|
277
|
+
function logToConsole(error) {
|
|
278
|
+
console.error("watchEntityEvents error", error);
|
|
279
|
+
}
|
|
280
|
+
/** Handlers take an `Error`, and a `throw` can be anything. */
|
|
281
|
+
function asError(error) {
|
|
282
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Decodes one log into the {@link EntityEvent} it carries.
|
|
286
|
+
*
|
|
287
|
+
* @throws If the log does not decode against {@link ENTITY_EVENTS_ABI}.
|
|
288
|
+
*/
|
|
289
|
+
function toEntityEvent(topics, data, context) {
|
|
290
|
+
const decoded = (0, viem.decodeEventLog)({
|
|
291
|
+
abi: require_key.ENTITY_EVENTS_ABI,
|
|
292
|
+
topics,
|
|
293
|
+
data
|
|
294
|
+
});
|
|
295
|
+
switch (decoded.eventName) {
|
|
296
|
+
case "EntityCreated": return {
|
|
297
|
+
type: "EntityCreated",
|
|
298
|
+
...context,
|
|
299
|
+
...decoded.args,
|
|
300
|
+
creationFlags: require_flags.decodeCreationFlags(decoded.args.creationFlags)
|
|
301
|
+
};
|
|
302
|
+
case "EntityPatched": return {
|
|
303
|
+
type: "EntityPatched",
|
|
304
|
+
...context,
|
|
305
|
+
...decoded.args
|
|
306
|
+
};
|
|
307
|
+
case "ExpiryExtended": return {
|
|
308
|
+
type: "ExpiryExtended",
|
|
309
|
+
...context,
|
|
310
|
+
...decoded.args
|
|
311
|
+
};
|
|
312
|
+
case "OwnershipTransferred": return {
|
|
313
|
+
type: "OwnershipTransferred",
|
|
314
|
+
...context,
|
|
315
|
+
...decoded.args
|
|
316
|
+
};
|
|
317
|
+
case "EntityDeleted": return {
|
|
318
|
+
type: "EntityDeleted",
|
|
319
|
+
...context,
|
|
320
|
+
...decoded.args
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/clients/decorators/arkivAdvanced.ts
|
|
327
|
+
function publicAdvancedActions(client) {
|
|
328
|
+
return {
|
|
329
|
+
pingTransaction: (txHash) => require_advanced.pingTransaction(client, txHash),
|
|
330
|
+
getMutationResult: (txHash) => require_advanced.getMutationResult(client, txHash),
|
|
331
|
+
decodeMutationResult: (receipt) => require_advanced.decodeMutationResult(receipt)
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function walletAdvancedActions(client) {
|
|
335
|
+
return {
|
|
336
|
+
...publicAdvancedActions(client),
|
|
337
|
+
buildMutation: (data, options) => require_advanced.buildMutation(client, data, options),
|
|
338
|
+
sendMutation: (data, options) => require_advanced.sendMutation(client, data, options)
|
|
339
|
+
};
|
|
340
|
+
}
|
|
395
341
|
|
|
396
342
|
//#endregion
|
|
397
343
|
//#region src/clients/decorators/arkivPublic.ts
|
|
398
344
|
function publicArkivActions(client) {
|
|
399
345
|
return {
|
|
400
|
-
getEntity: (key) => getEntity(client, key),
|
|
346
|
+
getEntity: (key$1) => getEntity(client, key$1),
|
|
401
347
|
query: (rawQuery, queryOptions) => query(client, rawQuery, queryOptions),
|
|
402
|
-
buildQuery: () => new require_queryBuilder.QueryBuilder(client),
|
|
403
348
|
select: (selection) => new require_queryBuilder.SelectQueryBuilder(client, selection),
|
|
404
349
|
getBlockTiming: () => getBlockTiming(client),
|
|
405
350
|
getEntityCount: () => getEntityCount(client),
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
onEntityDeleted,
|
|
411
|
-
onEntityExpired,
|
|
412
|
-
onEntityExpiresInExtended
|
|
413
|
-
}, pollingInterval, fromBlock)
|
|
351
|
+
getEntityNonce: (owner) => getEntityNonce(client, owner),
|
|
352
|
+
predictEntityKeys: (parameters) => predictEntityKeys(client, parameters),
|
|
353
|
+
watchEntityEvents: (parameters) => watchEntityEvents(client, parameters),
|
|
354
|
+
advanced: publicAdvancedActions(client)
|
|
414
355
|
};
|
|
415
356
|
}
|
|
416
357
|
|
|
@@ -421,35 +362,36 @@ function publicArkivActions(client) {
|
|
|
421
362
|
*
|
|
422
363
|
* - Docs: https://docs.arkiv.network/ts-sdk/clients/public
|
|
423
364
|
*
|
|
424
|
-
* A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.arkiv.network/json-rpc/), and [
|
|
365
|
+
* A Public Client is an interface to "public" [Ethereum JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/), [Arkiv JSON-RPC API](https://docs.arkiv.network/json-rpc/), and [Cheesecake JSON-RPC API](https://rpc.cheesecake.db-chain.devnet.gobas.me) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
|
|
425
366
|
*
|
|
426
367
|
* @param parameters - Configuration object for the public client (chain, transport, etc.)
|
|
427
368
|
* @returns A Arkiv Public Client. {@link PublicArkivClient}
|
|
428
369
|
*
|
|
429
370
|
* @example
|
|
430
|
-
* import { createPublicClient
|
|
431
|
-
* import {
|
|
371
|
+
* import { createPublicClient } from "@arkiv-network/sdk"
|
|
372
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
373
|
+
* import { http } from "viem"
|
|
432
374
|
*
|
|
433
375
|
* const client = createPublicClient({
|
|
434
|
-
* chain:
|
|
376
|
+
* chain: cheesecake,
|
|
435
377
|
* transport: http(),
|
|
436
378
|
* })
|
|
437
379
|
*/
|
|
438
380
|
function createPublicClient(parameters) {
|
|
439
|
-
const { key = "public", name = "Public Client" } = parameters;
|
|
381
|
+
const { key: key$1 = "public", name = "Public Client" } = parameters;
|
|
440
382
|
return (0, viem.createClient)({
|
|
441
383
|
...parameters,
|
|
442
|
-
key,
|
|
384
|
+
key: key$1,
|
|
443
385
|
name
|
|
444
386
|
}).extend(viem.publicActions).extend(publicArkivActions);
|
|
445
387
|
}
|
|
446
388
|
|
|
447
389
|
//#endregion
|
|
448
390
|
//#region src/actions/wallet/changeOwnership.ts
|
|
449
|
-
const logger$5 =
|
|
391
|
+
const logger$5 = require_logger.getLogger("actions:wallet:change-ownership");
|
|
450
392
|
async function changeOwnership(client, data, txParams) {
|
|
451
393
|
logger$5("changeOwnership %o", data);
|
|
452
|
-
const { receipt } = await sendArkivTransaction(client, { ownershipChanges: [data] }, txParams);
|
|
394
|
+
const { receipt } = await require_advanced.sendArkivTransaction(client, { ownershipChanges: [data] }, txParams);
|
|
453
395
|
logger$5("Receipt from changeOwnership %o", receipt);
|
|
454
396
|
return {
|
|
455
397
|
txHash: receipt.transactionHash,
|
|
@@ -459,23 +401,27 @@ async function changeOwnership(client, data, txParams) {
|
|
|
459
401
|
|
|
460
402
|
//#endregion
|
|
461
403
|
//#region src/actions/wallet/createEntity.ts
|
|
462
|
-
const logger$4 =
|
|
404
|
+
const logger$4 = require_logger.getLogger("actions:wallet:create-entity");
|
|
463
405
|
async function createEntity(client, data, txParams) {
|
|
464
406
|
logger$4("createEntity %o", data);
|
|
465
|
-
const { receipt, createdEntityKeys } = await sendArkivTransaction(client, { creates: [data] }, txParams);
|
|
407
|
+
const { receipt, createdEntityKeys, createdExpiries } = await require_advanced.sendArkivTransaction(client, { creates: [data] }, txParams);
|
|
466
408
|
logger$4("Receipt from createEntity %o", receipt);
|
|
409
|
+
const [entityKey] = createdEntityKeys;
|
|
410
|
+
const [expiresAt] = createdExpiries;
|
|
411
|
+
if (entityKey === void 0 || expiresAt === void 0) throw new require_logger.EntityMutationError(`Transaction ${receipt.transactionHash} succeeded, but the receipt did not carry the expected entity key or expiry.`);
|
|
467
412
|
return {
|
|
468
413
|
txHash: receipt.transactionHash,
|
|
469
|
-
entityKey
|
|
414
|
+
entityKey,
|
|
415
|
+
expiresAt
|
|
470
416
|
};
|
|
471
417
|
}
|
|
472
418
|
|
|
473
419
|
//#endregion
|
|
474
420
|
//#region src/actions/wallet/deleteEntity.ts
|
|
475
|
-
const logger$3 =
|
|
421
|
+
const logger$3 = require_logger.getLogger("actions:wallet:delete-entity");
|
|
476
422
|
async function deleteEntity(client, data, txParams) {
|
|
477
423
|
logger$3("deleteEntity %o", data);
|
|
478
|
-
const { receipt } = await sendArkivTransaction(client, { deletes: [data] }, txParams);
|
|
424
|
+
const { receipt } = await require_advanced.sendArkivTransaction(client, { deletes: [data] }, txParams);
|
|
479
425
|
logger$3("Receipt from deleteEntity %o", receipt);
|
|
480
426
|
return {
|
|
481
427
|
txHash: receipt.transactionHash,
|
|
@@ -485,28 +431,30 @@ async function deleteEntity(client, data, txParams) {
|
|
|
485
431
|
|
|
486
432
|
//#endregion
|
|
487
433
|
//#region src/actions/wallet/extendEntity.ts
|
|
488
|
-
const logger$2 =
|
|
434
|
+
const logger$2 = require_logger.getLogger("actions:wallet:extend-entity");
|
|
489
435
|
async function extendEntity(client, data, txParams) {
|
|
490
436
|
logger$2("extendEntity %o", data);
|
|
491
|
-
const { receipt } = await sendArkivTransaction(client, { extensions: [data] }, txParams);
|
|
437
|
+
const { receipt, extendedExpiries } = await require_advanced.sendArkivTransaction(client, { extensions: [data] }, txParams);
|
|
492
438
|
logger$2("Receipt from extendEntity %o", receipt);
|
|
439
|
+
const [expiresAt] = extendedExpiries;
|
|
440
|
+
if (expiresAt === void 0) throw new require_logger.EntityMutationError(`Transaction ${receipt.transactionHash} succeeded, but the receipt did not carry the expected entity expiry.`);
|
|
493
441
|
return {
|
|
494
442
|
txHash: receipt.transactionHash,
|
|
495
|
-
entityKey: data.entityKey
|
|
443
|
+
entityKey: data.entityKey,
|
|
444
|
+
expiresAt
|
|
496
445
|
};
|
|
497
446
|
}
|
|
498
447
|
|
|
499
448
|
//#endregion
|
|
500
449
|
//#region src/actions/wallet/mutateEntities.ts
|
|
501
|
-
const logger$1 =
|
|
450
|
+
const logger$1 = require_logger.getLogger("actions:wallet:mutate-entities");
|
|
502
451
|
async function mutateEntities(client, data, txParams) {
|
|
503
|
-
|
|
504
|
-
const { receipt, createdEntityKeys } = await sendArkivTransaction(client, data, txParams);
|
|
452
|
+
const { receipt, createdEntityKeys } = await require_advanced.sendArkivTransaction(client, data, txParams);
|
|
505
453
|
logger$1("Receipt from mutateEntities %o", receipt);
|
|
506
454
|
return {
|
|
507
455
|
txHash: receipt.transactionHash,
|
|
508
456
|
createdEntities: createdEntityKeys,
|
|
509
|
-
|
|
457
|
+
patchedEntities: (data.patches ?? []).map((p) => p.entityKey),
|
|
510
458
|
deletedEntities: (data.deletes ?? []).map((d) => d.entityKey),
|
|
511
459
|
extendedEntities: (data.extensions ?? []).map((e) => e.entityKey),
|
|
512
460
|
ownershipChanges: (data.ownershipChanges ?? []).map((o) => o.entityKey)
|
|
@@ -514,12 +462,12 @@ async function mutateEntities(client, data, txParams) {
|
|
|
514
462
|
}
|
|
515
463
|
|
|
516
464
|
//#endregion
|
|
517
|
-
//#region src/actions/wallet/
|
|
518
|
-
const logger =
|
|
519
|
-
async function
|
|
520
|
-
logger("
|
|
521
|
-
const { receipt } = await sendArkivTransaction(client, {
|
|
522
|
-
logger("Receipt from
|
|
465
|
+
//#region src/actions/wallet/patchEntity.ts
|
|
466
|
+
const logger = require_logger.getLogger("actions:wallet:patch-entity");
|
|
467
|
+
async function patchEntity(client, data, txParams) {
|
|
468
|
+
logger("patchEntity %o", data);
|
|
469
|
+
const { receipt } = await require_advanced.sendArkivTransaction(client, { patches: [data] }, txParams);
|
|
470
|
+
logger("Receipt from patchEntity %o", receipt);
|
|
523
471
|
return {
|
|
524
472
|
txHash: receipt.transactionHash,
|
|
525
473
|
entityKey: data.entityKey
|
|
@@ -531,47 +479,54 @@ async function updateEntity(client, data, txParams) {
|
|
|
531
479
|
function walletArkivActions(client) {
|
|
532
480
|
return {
|
|
533
481
|
createEntity: (data, txParams) => createEntity(client, data, txParams),
|
|
534
|
-
|
|
482
|
+
patchEntity: (data, txParams) => patchEntity(client, data, txParams),
|
|
535
483
|
deleteEntity: (data, txParams) => deleteEntity(client, data, txParams),
|
|
536
484
|
extendEntity: (data, txParams) => extendEntity(client, data, txParams),
|
|
537
485
|
changeOwnership: (data, txParams) => changeOwnership(client, data, txParams),
|
|
538
|
-
mutateEntities: (data, txParams) => mutateEntities(client, data, txParams)
|
|
486
|
+
mutateEntities: (data, txParams) => mutateEntities(client, data, txParams),
|
|
487
|
+
advanced: walletAdvancedActions(client)
|
|
539
488
|
};
|
|
540
489
|
}
|
|
541
490
|
|
|
542
491
|
//#endregion
|
|
543
492
|
//#region src/clients/createWalletClient.ts
|
|
544
493
|
/**
|
|
545
|
-
* Creates a
|
|
494
|
+
* Creates a Wallet Client with a given [Transport](https://viem.sh/docs/clients/intro) configured
|
|
495
|
+
* for a [Chain](https://viem.sh/docs/clients/chains) and an account.
|
|
546
496
|
*
|
|
547
|
-
* - Docs: https://docs.arkiv.network/ts-sdk/clients/
|
|
497
|
+
* - Docs: https://docs.arkiv.network/ts-sdk/clients/wallet
|
|
548
498
|
*
|
|
549
|
-
* A
|
|
499
|
+
* A Wallet Client signs and sends transactions, so it carries an `account` and exposes everything
|
|
500
|
+
* that mutates state — `createEntity`, `patchEntity`, `deleteEntity`, `extendEntity`,
|
|
501
|
+
* `changeOwnership` and `mutateEntities` — on top of the read actions a Public Client has.
|
|
550
502
|
*
|
|
551
503
|
* @param parameters - Configuration object for the wallet client (chain, transport, account, etc.)
|
|
552
504
|
* @returns A Arkiv Wallet Client. {@link WalletArkivClient}
|
|
553
505
|
*
|
|
554
506
|
* @example
|
|
555
|
-
* import {
|
|
556
|
-
* import {
|
|
507
|
+
* import { createWalletClient } from "@arkiv-network/sdk"
|
|
508
|
+
* import { cheesecake } from "@arkiv-network/sdk/chains"
|
|
509
|
+
* import { http } from "viem"
|
|
510
|
+
* import { privateKeyToAccount } from "viem/accounts"
|
|
557
511
|
*
|
|
558
|
-
* const client =
|
|
559
|
-
* chain:
|
|
512
|
+
* const client = createWalletClient({
|
|
513
|
+
* chain: cheesecake,
|
|
560
514
|
* transport: http(),
|
|
515
|
+
* account: privateKeyToAccount("0x..."),
|
|
561
516
|
* })
|
|
562
517
|
*/
|
|
563
518
|
function createWalletClient(parameters) {
|
|
564
|
-
const { key = "wallet", name = "Wallet Client" } = parameters;
|
|
519
|
+
const { key: key$1 = "wallet", name = "Wallet Client" } = parameters;
|
|
565
520
|
return (0, viem.createClient)({
|
|
566
521
|
...parameters,
|
|
567
|
-
key,
|
|
522
|
+
key: key$1,
|
|
568
523
|
name
|
|
569
524
|
}).extend(viem.publicActions).extend(viem.walletActions).extend(walletArkivActions);
|
|
570
525
|
}
|
|
571
526
|
|
|
572
527
|
//#endregion
|
|
573
528
|
//#region src/utils/chains.ts
|
|
574
|
-
const chainMap = new Map(Object.entries(require_chains.chains_exports).map(([key, value]) => [key.toLowerCase(), value]));
|
|
529
|
+
const chainMap = new Map(Object.entries(require_chains.chains_exports).map(([key$1, value]) => [key$1.toLowerCase(), value]));
|
|
575
530
|
/**
|
|
576
531
|
* Get a chain from its name
|
|
577
532
|
* @param name - The name of the chain, case insensitive
|
|
@@ -585,18 +540,69 @@ function chainFromName(name) {
|
|
|
585
540
|
}
|
|
586
541
|
|
|
587
542
|
//#endregion
|
|
588
|
-
exports.
|
|
589
|
-
exports.
|
|
590
|
-
exports.
|
|
591
|
-
exports.
|
|
592
|
-
exports.
|
|
593
|
-
exports.
|
|
594
|
-
exports.
|
|
595
|
-
exports.
|
|
596
|
-
exports.
|
|
597
|
-
exports.
|
|
543
|
+
exports.ConflictingMutationError = require_attributes.ConflictingMutationError;
|
|
544
|
+
exports.DECIMAL_SCALE = require_attributes.DECIMAL_SCALE;
|
|
545
|
+
exports.DECIMAL_UNIT = require_attributes.DECIMAL_UNIT;
|
|
546
|
+
exports.ENTITY_EVENTS_ABI = require_key.ENTITY_EVENTS_ABI;
|
|
547
|
+
exports.EmptyPatchError = require_logger.EmptyPatchError;
|
|
548
|
+
exports.Entity = require_entity.Entity;
|
|
549
|
+
exports.EntityMutationError = require_logger.EntityMutationError;
|
|
550
|
+
exports.ExpirationTime = require_payload.ExpirationTime;
|
|
551
|
+
exports.I32_MAX = require_attributes.I32_MAX;
|
|
552
|
+
exports.I32_MIN = require_attributes.I32_MIN;
|
|
553
|
+
exports.InvalidAttributeNameError = require_attributes.InvalidAttributeNameError;
|
|
554
|
+
exports.InvalidContentTypeError = require_logger.InvalidContentTypeError;
|
|
555
|
+
exports.InvalidCreationFlagsError = require_errors.InvalidCreationFlagsError;
|
|
556
|
+
exports.InvalidExpiryError = require_errors.InvalidExpiryError;
|
|
557
|
+
exports.InvalidSaltError = require_errors.InvalidSaltError;
|
|
558
|
+
exports.InvalidValueError = require_attributes.InvalidValueError;
|
|
559
|
+
exports.MAX_ATTRIBUTES = require_attributes.MAX_ATTRIBUTES;
|
|
560
|
+
exports.MAX_EXPIRES_AT = require_expiry.MAX_EXPIRES_AT;
|
|
561
|
+
exports.MAX_NAME_BYTES = require_attributes.MAX_NAME_BYTES;
|
|
562
|
+
exports.MAX_PAYLOAD_BYTES = require_attributes.MAX_PAYLOAD_BYTES;
|
|
563
|
+
exports.MAX_SALT = require_key.MAX_SALT;
|
|
564
|
+
exports.MAX_STRING_BYTES = require_attributes.MAX_STRING_BYTES;
|
|
565
|
+
exports.MissingValueError = require_attributes.MissingValueError;
|
|
566
|
+
exports.NoEntityFoundError = require_logger.NoEntityFoundError;
|
|
567
|
+
exports.NoMoreResultsError = require_logger.NoMoreResultsError;
|
|
568
|
+
exports.NoRandomSourceError = require_errors.NoRandomSourceError;
|
|
569
|
+
exports.OperationType = require_expiry.OperationType;
|
|
570
|
+
exports.TooManyAttributesError = require_attributes.TooManyAttributesError;
|
|
571
|
+
exports.U256_MAX = require_attributes.U256_MAX;
|
|
572
|
+
exports.U64_MAX = require_attributes.U64_MAX;
|
|
573
|
+
exports.UnknownAttributeTypeError = require_attributes.UnknownAttributeTypeError;
|
|
574
|
+
exports.UntypedValueError = require_attributes.UntypedValueError;
|
|
575
|
+
exports.addr = require_attributes.addr;
|
|
576
|
+
exports.bool = require_attributes.bool;
|
|
577
|
+
exports.buildEntityOperations = require_advanced.buildEntityOperations;
|
|
578
|
+
exports.buildMutation = require_advanced.buildMutation;
|
|
579
|
+
exports.bytes32 = require_attributes.bytes32;
|
|
598
580
|
exports.chainFromName = chainFromName;
|
|
581
|
+
exports.collectMutationEvents = require_advanced.collectMutationEvents;
|
|
599
582
|
exports.createPublicClient = createPublicClient;
|
|
600
583
|
exports.createWalletClient = createWalletClient;
|
|
584
|
+
exports.dec = require_attributes.dec;
|
|
585
|
+
exports.decFromUnits = require_attributes.decFromUnits;
|
|
586
|
+
exports.decUnits = require_attributes.decUnits;
|
|
587
|
+
exports.decodeCreationFlags = require_flags.decodeCreationFlags;
|
|
588
|
+
exports.decodeMutationResult = require_advanced.decodeMutationResult;
|
|
589
|
+
exports.encodeCreationFlags = require_flags.encodeCreationFlags;
|
|
590
|
+
exports.getMutationResult = require_advanced.getMutationResult;
|
|
591
|
+
exports.i32 = require_attributes.i32;
|
|
592
|
+
exports.isArkivValue = require_attributes.isArkivValue;
|
|
593
|
+
exports.isValidAttributeName = require_attributes.isValidAttributeName;
|
|
601
594
|
exports.jsonToPayload = require_payload.jsonToPayload;
|
|
602
|
-
exports.
|
|
595
|
+
exports.key = require_attributes.key;
|
|
596
|
+
exports.mutationNeedsBlockNumber = require_advanced.mutationNeedsBlockNumber;
|
|
597
|
+
exports.pingTransaction = require_advanced.pingTransaction;
|
|
598
|
+
exports.predictEntityKey = require_key.predictEntityKey;
|
|
599
|
+
exports.randomSalt = require_key.randomSalt;
|
|
600
|
+
exports.resolveExpiry = require_expiry.resolveExpiry;
|
|
601
|
+
exports.sendMutation = require_advanced.sendMutation;
|
|
602
|
+
exports.str = require_attributes.str;
|
|
603
|
+
exports.stringToPayload = require_payload.stringToPayload;
|
|
604
|
+
exports.toBlocks = require_expiry.toBlocks;
|
|
605
|
+
exports.toValue = require_attributes.toValue;
|
|
606
|
+
exports.u256 = require_attributes.u256;
|
|
607
|
+
exports.u64 = require_attributes.u64;
|
|
608
|
+
exports.validateAttributeName = require_attributes.validateAttributeName;
|