@hashgraphonline/standards-sdk 0.1.160 → 0.1.162
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/cjs/hcs-14/index.d.ts +1 -0
- package/dist/cjs/hcs-14/index.d.ts.map +1 -1
- package/dist/cjs/hcs-14/resolvers/aid-dns-web-profile.d.ts +1 -0
- package/dist/cjs/hcs-14/resolvers/aid-dns-web-profile.d.ts.map +1 -1
- package/dist/cjs/hcs-14/resolvers/ans-dns-web-profile-utils.d.ts +23 -0
- package/dist/cjs/hcs-14/resolvers/ans-dns-web-profile-utils.d.ts.map +1 -0
- package/dist/cjs/hcs-14/resolvers/ans-dns-web-profile.d.ts +32 -0
- package/dist/cjs/hcs-14/resolvers/ans-dns-web-profile.d.ts.map +1 -0
- package/dist/cjs/hcs-14/resolvers/hcs-11-profile.d.ts +1 -0
- package/dist/cjs/hcs-14/resolvers/hcs-11-profile.d.ts.map +1 -1
- package/dist/cjs/hcs-14/resolvers/hiero.d.ts +1 -0
- package/dist/cjs/hcs-14/resolvers/hiero.d.ts.map +1 -1
- package/dist/cjs/hcs-14/resolvers/registry.d.ts +39 -1
- package/dist/cjs/hcs-14/resolvers/registry.d.ts.map +1 -1
- package/dist/cjs/hcs-14/resolvers/types.d.ts +52 -0
- package/dist/cjs/hcs-14/resolvers/types.d.ts.map +1 -1
- package/dist/cjs/hcs-14/resolvers/uaid-did-resolution-profile.d.ts +1 -0
- package/dist/cjs/hcs-14/resolvers/uaid-did-resolution-profile.d.ts.map +1 -1
- package/dist/cjs/hcs-14/resolvers/uaid-dns-web-profile.d.ts +1 -0
- package/dist/cjs/hcs-14/resolvers/uaid-dns-web-profile.d.ts.map +1 -1
- package/dist/cjs/hcs-14/sdk.d.ts +46 -13
- package/dist/cjs/hcs-14/sdk.d.ts.map +1 -1
- package/dist/cjs/standards-sdk.cjs +3 -3
- package/dist/cjs/standards-sdk.cjs.map +1 -1
- package/dist/es/hcs-14/index.d.ts +1 -0
- package/dist/es/hcs-14/index.d.ts.map +1 -1
- package/dist/es/hcs-14/resolvers/aid-dns-web-profile.d.ts +1 -0
- package/dist/es/hcs-14/resolvers/aid-dns-web-profile.d.ts.map +1 -1
- package/dist/es/hcs-14/resolvers/ans-dns-web-profile-utils.d.ts +23 -0
- package/dist/es/hcs-14/resolvers/ans-dns-web-profile-utils.d.ts.map +1 -0
- package/dist/es/hcs-14/resolvers/ans-dns-web-profile.d.ts +32 -0
- package/dist/es/hcs-14/resolvers/ans-dns-web-profile.d.ts.map +1 -0
- package/dist/es/hcs-14/resolvers/hcs-11-profile.d.ts +1 -0
- package/dist/es/hcs-14/resolvers/hcs-11-profile.d.ts.map +1 -1
- package/dist/es/hcs-14/resolvers/hiero.d.ts +1 -0
- package/dist/es/hcs-14/resolvers/hiero.d.ts.map +1 -1
- package/dist/es/hcs-14/resolvers/registry.d.ts +39 -1
- package/dist/es/hcs-14/resolvers/registry.d.ts.map +1 -1
- package/dist/es/hcs-14/resolvers/types.d.ts +52 -0
- package/dist/es/hcs-14/resolvers/types.d.ts.map +1 -1
- package/dist/es/hcs-14/resolvers/uaid-did-resolution-profile.d.ts +1 -0
- package/dist/es/hcs-14/resolvers/uaid-did-resolution-profile.d.ts.map +1 -1
- package/dist/es/hcs-14/resolvers/uaid-dns-web-profile.d.ts +1 -0
- package/dist/es/hcs-14/resolvers/uaid-dns-web-profile.d.ts.map +1 -1
- package/dist/es/hcs-14/sdk.d.ts +46 -13
- package/dist/es/hcs-14/sdk.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +97 -90
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es100.js +151 -43
- package/dist/es/standards-sdk.es100.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +114 -234
- package/dist/es/standards-sdk.es101.js.map +1 -1
- package/dist/es/standards-sdk.es102.js +43 -96
- package/dist/es/standards-sdk.es102.js.map +1 -1
- package/dist/es/standards-sdk.es103.js +244 -80
- package/dist/es/standards-sdk.es103.js.map +1 -1
- package/dist/es/standards-sdk.es104.js +101 -29
- package/dist/es/standards-sdk.es104.js.map +1 -1
- package/dist/es/standards-sdk.es105.js +94 -225
- package/dist/es/standards-sdk.es105.js.map +1 -1
- package/dist/es/standards-sdk.es106.js +29 -112
- package/dist/es/standards-sdk.es106.js.map +1 -1
- package/dist/es/standards-sdk.es107.js +224 -26
- package/dist/es/standards-sdk.es107.js.map +1 -1
- package/dist/es/standards-sdk.es108.js +109 -80
- package/dist/es/standards-sdk.es108.js.map +1 -1
- package/dist/es/standards-sdk.es109.js +29 -26
- package/dist/es/standards-sdk.es109.js.map +1 -1
- package/dist/es/standards-sdk.es11.js +1 -1
- package/dist/es/standards-sdk.es110.js +80 -248
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +28 -475
- package/dist/es/standards-sdk.es111.js.map +1 -1
- package/dist/es/standards-sdk.es112.js +244 -97
- package/dist/es/standards-sdk.es112.js.map +1 -1
- package/dist/es/standards-sdk.es113.js +451 -133
- package/dist/es/standards-sdk.es113.js.map +1 -1
- package/dist/es/standards-sdk.es114.js +98 -27
- package/dist/es/standards-sdk.es114.js.map +1 -1
- package/dist/es/standards-sdk.es115.js +156 -8
- package/dist/es/standards-sdk.es115.js.map +1 -1
- package/dist/es/standards-sdk.es116.js +31 -139
- package/dist/es/standards-sdk.es116.js.map +1 -1
- package/dist/es/standards-sdk.es117.js +10 -27
- package/dist/es/standards-sdk.es117.js.map +1 -1
- package/dist/es/standards-sdk.es118.js +139 -19
- package/dist/es/standards-sdk.es118.js.map +1 -1
- package/dist/es/standards-sdk.es119.js +27 -158
- package/dist/es/standards-sdk.es119.js.map +1 -1
- package/dist/es/standards-sdk.es12.js +1 -1
- package/dist/es/standards-sdk.es120.js +16 -197
- package/dist/es/standards-sdk.es120.js.map +1 -1
- package/dist/es/standards-sdk.es121.js +133 -763
- package/dist/es/standards-sdk.es121.js.map +1 -1
- package/dist/es/standards-sdk.es122.js +200 -10
- package/dist/es/standards-sdk.es122.js.map +1 -1
- package/dist/es/standards-sdk.es123.js +762 -539
- package/dist/es/standards-sdk.es123.js.map +1 -1
- package/dist/es/standards-sdk.es124.js +10 -599
- package/dist/es/standards-sdk.es124.js.map +1 -1
- package/dist/es/standards-sdk.es125.js +567 -13
- package/dist/es/standards-sdk.es125.js.map +1 -1
- package/dist/es/standards-sdk.es126.js +602 -2
- package/dist/es/standards-sdk.es126.js.map +1 -1
- package/dist/es/standards-sdk.es127.js +12 -86
- package/dist/es/standards-sdk.es127.js.map +1 -1
- package/dist/es/standards-sdk.es128.js +2 -40
- package/dist/es/standards-sdk.es128.js.map +1 -1
- package/dist/es/standards-sdk.es129.js +87 -2
- package/dist/es/standards-sdk.es129.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +1 -1
- package/dist/es/standards-sdk.es130.js +37 -232
- package/dist/es/standards-sdk.es130.js.map +1 -1
- package/dist/es/standards-sdk.es131.js +2 -1140
- package/dist/es/standards-sdk.es131.js.map +1 -1
- package/dist/es/standards-sdk.es132.js +213 -284
- package/dist/es/standards-sdk.es132.js.map +1 -1
- package/dist/es/standards-sdk.es133.js +1138 -420
- package/dist/es/standards-sdk.es133.js.map +1 -1
- package/dist/es/standards-sdk.es134.js +301 -350
- package/dist/es/standards-sdk.es134.js.map +1 -1
- package/dist/es/standards-sdk.es135.js +417 -1111
- package/dist/es/standards-sdk.es135.js.map +1 -1
- package/dist/es/standards-sdk.es136.js +348 -201
- package/dist/es/standards-sdk.es136.js.map +1 -1
- package/dist/es/standards-sdk.es137.js +1029 -1480
- package/dist/es/standards-sdk.es137.js.map +1 -1
- package/dist/es/standards-sdk.es138.js +207 -1254
- package/dist/es/standards-sdk.es138.js.map +1 -1
- package/dist/es/standards-sdk.es139.js +1564 -14
- package/dist/es/standards-sdk.es139.js.map +1 -1
- package/dist/es/standards-sdk.es14.js +1 -1
- package/dist/es/standards-sdk.es140.js +1253 -85
- package/dist/es/standards-sdk.es140.js.map +1 -1
- package/dist/es/standards-sdk.es141.js +15 -79
- package/dist/es/standards-sdk.es141.js.map +1 -1
- package/dist/es/standards-sdk.es142.js +83 -889
- package/dist/es/standards-sdk.es142.js.map +1 -1
- package/dist/es/standards-sdk.es143.js +73 -52
- package/dist/es/standards-sdk.es143.js.map +1 -1
- package/dist/es/standards-sdk.es144.js +877 -143
- package/dist/es/standards-sdk.es144.js.map +1 -1
- package/dist/es/standards-sdk.es145.js +60 -7
- package/dist/es/standards-sdk.es145.js.map +1 -1
- package/dist/es/standards-sdk.es146.js +138 -65
- package/dist/es/standards-sdk.es146.js.map +1 -1
- package/dist/es/standards-sdk.es147.js +7 -65
- package/dist/es/standards-sdk.es147.js.map +1 -1
- package/dist/es/standards-sdk.es148.js +86 -30
- package/dist/es/standards-sdk.es148.js.map +1 -1
- package/dist/es/standards-sdk.es149.js +65 -34
- package/dist/es/standards-sdk.es149.js.map +1 -1
- package/dist/es/standards-sdk.es15.js +1 -1
- package/dist/es/standards-sdk.es150.js +30 -41
- package/dist/es/standards-sdk.es150.js.map +1 -1
- package/dist/es/standards-sdk.es151.js +34 -138
- package/dist/es/standards-sdk.es151.js.map +1 -1
- package/dist/es/standards-sdk.es152.js +48 -42
- package/dist/es/standards-sdk.es152.js.map +1 -1
- package/dist/es/standards-sdk.es153.js +106 -12450
- package/dist/es/standards-sdk.es153.js.map +1 -1
- package/dist/es/standards-sdk.es154.js +38 -168
- package/dist/es/standards-sdk.es154.js.map +1 -1
- package/dist/es/standards-sdk.es155.js +12423 -263
- package/dist/es/standards-sdk.es155.js.map +1 -1
- package/dist/es/standards-sdk.es156.js +13 -342
- package/dist/es/standards-sdk.es156.js.map +1 -1
- package/dist/es/standards-sdk.es157.js +55 -452
- package/dist/es/standards-sdk.es157.js.map +1 -1
- package/dist/es/standards-sdk.es158.js +70 -317
- package/dist/es/standards-sdk.es158.js.map +1 -1
- package/dist/es/standards-sdk.es159.js +70 -65
- package/dist/es/standards-sdk.es159.js.map +1 -1
- package/dist/es/standards-sdk.es16.js +4 -4
- package/dist/es/standards-sdk.es160.js +197 -14
- package/dist/es/standards-sdk.es160.js.map +1 -1
- package/dist/es/standards-sdk.es161.js +60 -229
- package/dist/es/standards-sdk.es161.js.map +1 -1
- package/dist/es/standards-sdk.es162.js +237 -51
- package/dist/es/standards-sdk.es162.js.map +1 -1
- package/dist/es/standards-sdk.es163.js +160 -72
- package/dist/es/standards-sdk.es163.js.map +1 -1
- package/dist/es/standards-sdk.es164.js +312 -71
- package/dist/es/standards-sdk.es164.js.map +1 -1
- package/dist/es/standards-sdk.es165.js +337 -64
- package/dist/es/standards-sdk.es165.js.map +1 -1
- package/dist/es/standards-sdk.es166.js +436 -155
- package/dist/es/standards-sdk.es166.js.map +1 -1
- package/dist/es/standards-sdk.es167.js +319 -210
- package/dist/es/standards-sdk.es167.js.map +1 -1
- package/dist/es/standards-sdk.es168.js +68 -231
- package/dist/es/standards-sdk.es168.js.map +1 -1
- package/dist/es/standards-sdk.es169.js +154 -101
- package/dist/es/standards-sdk.es169.js.map +1 -1
- package/dist/es/standards-sdk.es170.js +200 -104
- package/dist/es/standards-sdk.es170.js.map +1 -1
- package/dist/es/standards-sdk.es171.js +225 -147
- package/dist/es/standards-sdk.es171.js.map +1 -1
- package/dist/es/standards-sdk.es172.js +100 -166
- package/dist/es/standards-sdk.es172.js.map +1 -1
- package/dist/es/standards-sdk.es173.js +110 -123
- package/dist/es/standards-sdk.es173.js.map +1 -1
- package/dist/es/standards-sdk.es174.js +122 -292
- package/dist/es/standards-sdk.es174.js.map +1 -1
- package/dist/es/standards-sdk.es175.js +166 -240
- package/dist/es/standards-sdk.es175.js.map +1 -1
- package/dist/es/standards-sdk.es176.js +125 -102
- package/dist/es/standards-sdk.es176.js.map +1 -1
- package/dist/es/standards-sdk.es177.js +334 -0
- package/dist/es/standards-sdk.es177.js.map +1 -0
- package/dist/es/standards-sdk.es178.js +262 -0
- package/dist/es/standards-sdk.es178.js.map +1 -0
- package/dist/es/standards-sdk.es179.js +119 -0
- package/dist/es/standards-sdk.es179.js.map +1 -0
- package/dist/es/standards-sdk.es18.js +11 -11
- package/dist/es/standards-sdk.es19.js +8 -8
- package/dist/es/standards-sdk.es2.js +2 -2
- package/dist/es/standards-sdk.es20.js +1 -1
- package/dist/es/standards-sdk.es21.js +1 -1
- package/dist/es/standards-sdk.es22.js +1 -1
- package/dist/es/standards-sdk.es23.js +1 -1
- package/dist/es/standards-sdk.es24.js +1 -1
- package/dist/es/standards-sdk.es25.js +1 -1
- package/dist/es/standards-sdk.es26.js +1 -1
- package/dist/es/standards-sdk.es27.js +11 -11
- package/dist/es/standards-sdk.es30.js +2 -2
- package/dist/es/standards-sdk.es31.js +4 -4
- package/dist/es/standards-sdk.es32.js +1 -1
- package/dist/es/standards-sdk.es35.js +5 -5
- package/dist/es/standards-sdk.es36.js +4 -4
- package/dist/es/standards-sdk.es37.js +2 -2
- package/dist/es/standards-sdk.es38.js +2 -2
- package/dist/es/standards-sdk.es39.js +1 -1
- package/dist/es/standards-sdk.es4.js +2 -2
- package/dist/es/standards-sdk.es40.js +1 -1
- package/dist/es/standards-sdk.es41.js +2 -2
- package/dist/es/standards-sdk.es46.js +1 -1
- package/dist/es/standards-sdk.es5.js +2 -2
- package/dist/es/standards-sdk.es51.js +1 -1
- package/dist/es/standards-sdk.es53.js +1 -1
- package/dist/es/standards-sdk.es56.js +2 -2
- package/dist/es/standards-sdk.es58.js +39 -231
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +328 -35
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es6.js +2 -2
- package/dist/es/standards-sdk.es60.js +33 -101
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es61.js +87 -156
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +126 -153
- package/dist/es/standards-sdk.es62.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +234 -81
- package/dist/es/standards-sdk.es63.js.map +1 -1
- package/dist/es/standards-sdk.es64.js +244 -39
- package/dist/es/standards-sdk.es64.js.map +1 -1
- package/dist/es/standards-sdk.es65.js +122 -247
- package/dist/es/standards-sdk.es65.js.map +1 -1
- package/dist/es/standards-sdk.es66.js +41 -28
- package/dist/es/standards-sdk.es66.js.map +1 -1
- package/dist/es/standards-sdk.es67.js +266 -90
- package/dist/es/standards-sdk.es67.js.map +1 -1
- package/dist/es/standards-sdk.es68.js +33 -3
- package/dist/es/standards-sdk.es68.js.map +1 -1
- package/dist/es/standards-sdk.es69.js +84 -89
- package/dist/es/standards-sdk.es69.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +1 -1
- package/dist/es/standards-sdk.es70.js +3 -99
- package/dist/es/standards-sdk.es70.js.map +1 -1
- package/dist/es/standards-sdk.es71.js +99 -17
- package/dist/es/standards-sdk.es71.js.map +1 -1
- package/dist/es/standards-sdk.es72.js +100 -77
- package/dist/es/standards-sdk.es72.js.map +1 -1
- package/dist/es/standards-sdk.es73.js +19 -458
- package/dist/es/standards-sdk.es73.js.map +1 -1
- package/dist/es/standards-sdk.es74.js +77 -324
- package/dist/es/standards-sdk.es74.js.map +1 -1
- package/dist/es/standards-sdk.es75.js +420 -170
- package/dist/es/standards-sdk.es75.js.map +1 -1
- package/dist/es/standards-sdk.es76.js +323 -71
- package/dist/es/standards-sdk.es76.js.map +1 -1
- package/dist/es/standards-sdk.es77.js +208 -71
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +67 -138
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +71 -69
- package/dist/es/standards-sdk.es79.js.map +1 -1
- package/dist/es/standards-sdk.es80.js +132 -393
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +44 -471
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +361 -322
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +495 -88
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +365 -125
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +88 -7
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +125 -47
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +6 -99
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +43 -344
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +73 -253
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es9.js +2 -2
- package/dist/es/standards-sdk.es90.js +340 -53
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +280 -48
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +54 -143
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +44 -62
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +140 -20
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +65 -23
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es96.js +26 -236
- package/dist/es/standards-sdk.es96.js.map +1 -1
- package/dist/es/standards-sdk.es97.js +23 -280
- package/dist/es/standards-sdk.es97.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +229 -146
- package/dist/es/standards-sdk.es98.js.map +1 -1
- package/dist/es/standards-sdk.es99.js +254 -117
- package/dist/es/standards-sdk.es99.js.map +1 -1
- package/package.json +8 -1
|
@@ -1,1570 +1,1119 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.logger = logger || new Logger({
|
|
16
|
-
level: "debug",
|
|
17
|
-
module: "MirrorNode"
|
|
18
|
-
});
|
|
19
|
-
this.isServerEnvironment = typeof window === "undefined";
|
|
20
|
-
if (config?.customUrl) {
|
|
21
|
-
this.logger.info(`Using custom mirror node URL: ${config.customUrl}`);
|
|
22
|
-
}
|
|
23
|
-
if (config?.apiKey) {
|
|
24
|
-
this.logger.info("Using API key for mirror node requests");
|
|
25
|
-
}
|
|
1
|
+
import { InscriptionSDK } from "./standards-sdk.es155.js";
|
|
2
|
+
import { Logger } from "./standards-sdk.es118.js";
|
|
3
|
+
import { ProgressReporter } from "./standards-sdk.es121.js";
|
|
4
|
+
import { TransactionParser } from "./standards-sdk.es123.js";
|
|
5
|
+
import { isBrowser } from "./standards-sdk.es131.js";
|
|
6
|
+
import { fileTypeFromBuffer } from "file-type";
|
|
7
|
+
import { validateQuoteParameters, getCachedQuote, getOrCreateSDK, cacheQuote } from "./standards-sdk.es138.js";
|
|
8
|
+
import { HederaMirrorNode } from "./standards-sdk.es139.js";
|
|
9
|
+
import { sleep } from "./standards-sdk.es128.js";
|
|
10
|
+
import { computeInscriptionCostSummary } from "./standards-sdk.es161.js";
|
|
11
|
+
let nodeModules = {};
|
|
12
|
+
const normalizeTransactionId = (txId) => {
|
|
13
|
+
if (!txId.includes("@")) {
|
|
14
|
+
return txId;
|
|
26
15
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.initialDelayMs = config.initialDelayMs ?? this.initialDelayMs;
|
|
34
|
-
this.maxDelayMs = config.maxDelayMs ?? this.maxDelayMs;
|
|
35
|
-
this.backoffFactor = config.backoffFactor ?? this.backoffFactor;
|
|
36
|
-
this.logger.info(
|
|
37
|
-
`Retry configuration updated: maxRetries=${this.maxRetries}, initialDelayMs=${this.initialDelayMs}, maxDelayMs=${this.maxDelayMs}, backoffFactor=${this.backoffFactor}`
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Updates the mirror node configuration.
|
|
42
|
-
* @param config The new mirror node configuration.
|
|
43
|
-
*/
|
|
44
|
-
configureMirrorNode(config) {
|
|
45
|
-
if (config.customUrl) {
|
|
46
|
-
this.baseUrl = config.customUrl;
|
|
47
|
-
this.logger.info(`Updated mirror node URL: ${config.customUrl}`);
|
|
48
|
-
}
|
|
49
|
-
if (config.apiKey) {
|
|
50
|
-
this.apiKey = config.apiKey;
|
|
51
|
-
this.logger.info("Updated API key for mirror node requests");
|
|
52
|
-
}
|
|
53
|
-
if (config.headers) {
|
|
54
|
-
this.customHeaders = { ...this.customHeaders, ...config.headers };
|
|
55
|
-
this.logger.info("Updated custom headers for mirror node requests");
|
|
56
|
-
}
|
|
16
|
+
const txParts = txId?.split("@");
|
|
17
|
+
return `${txParts[0]}-${txParts[1].replace(".", "-")}`;
|
|
18
|
+
};
|
|
19
|
+
async function loadNodeModules() {
|
|
20
|
+
if (isBrowser || nodeModules.readFileSync) {
|
|
21
|
+
return;
|
|
57
22
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
23
|
+
try {
|
|
24
|
+
const globalObj = typeof global !== "undefined" ? global : globalThis;
|
|
25
|
+
const req = globalObj.process?.mainModule?.require || globalObj.require;
|
|
26
|
+
if (typeof req === "function") {
|
|
27
|
+
const fs = req("fs");
|
|
28
|
+
const path = req("path");
|
|
29
|
+
nodeModules.readFileSync = fs.readFileSync;
|
|
30
|
+
nodeModules.basename = path.basename;
|
|
31
|
+
nodeModules.extname = path.extname;
|
|
32
|
+
} else {
|
|
33
|
+
throw new Error("require function not available");
|
|
34
|
+
}
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.warn(
|
|
37
|
+
"Node.js modules not available, file path operations will be disabled"
|
|
38
|
+
);
|
|
69
39
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
40
|
+
}
|
|
41
|
+
const COST_LOOKUP_ATTEMPTS = 3;
|
|
42
|
+
const COST_LOOKUP_DELAY_MS = 1e3;
|
|
43
|
+
const COST_LOGGER_MODULE = "InscriberCost";
|
|
44
|
+
async function convertFileToBase64(filePath) {
|
|
45
|
+
if (isBrowser) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"File path operations are not supported in browser environment. Use buffer input type instead."
|
|
48
|
+
);
|
|
77
49
|
}
|
|
78
|
-
|
|
79
|
-
|
|
50
|
+
await loadNodeModules();
|
|
51
|
+
if (!nodeModules.readFileSync || !nodeModules.basename || !nodeModules.extname) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
"Node.js file system modules are not available. Cannot read file from path."
|
|
54
|
+
);
|
|
80
55
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*/
|
|
87
|
-
async getPublicKey(accountId) {
|
|
88
|
-
this.logger.debug(`Getting public key for account ${accountId}`);
|
|
89
|
-
const accountInfo = await this.requestAccount(accountId);
|
|
56
|
+
try {
|
|
57
|
+
const buffer = nodeModules.readFileSync(filePath);
|
|
58
|
+
const base64 = buffer.toString("base64");
|
|
59
|
+
const fileName = nodeModules.basename(filePath);
|
|
60
|
+
let mimeType = "application/octet-stream";
|
|
90
61
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
);
|
|
62
|
+
const fileTypeResult = await fileTypeFromBuffer(buffer);
|
|
63
|
+
if (fileTypeResult) {
|
|
64
|
+
mimeType = fileTypeResult.mime;
|
|
95
65
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
66
|
+
} catch (error) {
|
|
67
|
+
const ext = nodeModules.extname(filePath).toLowerCase();
|
|
68
|
+
const mimeMap = {
|
|
69
|
+
".txt": "text/plain",
|
|
70
|
+
".json": "application/json",
|
|
71
|
+
".html": "text/html",
|
|
72
|
+
".css": "text/css",
|
|
73
|
+
".js": "application/javascript",
|
|
74
|
+
".png": "image/png",
|
|
75
|
+
".jpg": "image/jpeg",
|
|
76
|
+
".jpeg": "image/jpeg",
|
|
77
|
+
".gif": "image/gif",
|
|
78
|
+
".svg": "image/svg+xml",
|
|
79
|
+
".pdf": "application/pdf"
|
|
80
|
+
};
|
|
81
|
+
mimeType = mimeMap[ext] || "application/octet-stream";
|
|
102
82
|
}
|
|
83
|
+
return { base64, fileName, mimeType };
|
|
84
|
+
} catch (error) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`Failed to read file ${filePath}: ${error.message}`
|
|
87
|
+
);
|
|
103
88
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
);
|
|
116
|
-
if (accountInfo?.memo) {
|
|
117
|
-
return accountInfo.memo;
|
|
118
|
-
}
|
|
119
|
-
this.logger.warn(`No memo found for account ${accountId}`);
|
|
120
|
-
return null;
|
|
121
|
-
} catch (e) {
|
|
122
|
-
const error = e;
|
|
123
|
-
this.logger.error(
|
|
124
|
-
`Failed to get account memo for ${accountId} after retries: ${error.message}`
|
|
125
|
-
);
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
89
|
+
}
|
|
90
|
+
function normalizeClientConfig(cfg) {
|
|
91
|
+
return {
|
|
92
|
+
accountId: cfg.accountId,
|
|
93
|
+
privateKey: typeof cfg.privateKey === "string" ? cfg.privateKey : cfg.privateKey.toString(),
|
|
94
|
+
network: cfg.network
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function resolveConnectionMode(options) {
|
|
98
|
+
if (options.connectionMode) {
|
|
99
|
+
return options.connectionMode;
|
|
128
100
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
* @param topicId The ID of the topic to retrieve information for.
|
|
132
|
-
* @returns A promise that resolves to the topic information.
|
|
133
|
-
* @throws An error if the topic ID is invalid or the information cannot be retrieved.
|
|
134
|
-
*/
|
|
135
|
-
async getTopicInfo(topicId) {
|
|
136
|
-
try {
|
|
137
|
-
this.logger.debug(`Fetching topic info for ${topicId}`);
|
|
138
|
-
const data = await this._requestWithRetry(
|
|
139
|
-
`/api/v1/topics/${topicId}`
|
|
140
|
-
);
|
|
141
|
-
return data;
|
|
142
|
-
} catch (e) {
|
|
143
|
-
const error = e;
|
|
144
|
-
const logMessage = `Error retrieving topic information for ${topicId} after retries: ${error.message}`;
|
|
145
|
-
this.logger.error(logMessage);
|
|
146
|
-
throw new Error(logMessage);
|
|
147
|
-
}
|
|
101
|
+
if (typeof options.websocket === "boolean") {
|
|
102
|
+
return options.websocket ? "websocket" : "http";
|
|
148
103
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
104
|
+
return "websocket";
|
|
105
|
+
}
|
|
106
|
+
async function inscribe(input, clientConfig, options, existingSDK) {
|
|
107
|
+
const logger = Logger.getInstance({
|
|
108
|
+
module: "Inscriber",
|
|
109
|
+
...options.logging
|
|
110
|
+
});
|
|
111
|
+
const resolvedConnectionMode = resolveConnectionMode(options);
|
|
112
|
+
logger.info("Starting inscription process", {
|
|
113
|
+
type: input.type,
|
|
114
|
+
mode: options.mode || "file",
|
|
115
|
+
quoteOnly: options.quoteOnly || false,
|
|
116
|
+
...input.type === "url" ? { url: input.url } : {},
|
|
117
|
+
...input.type === "file" ? { path: input.path } : {},
|
|
118
|
+
...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
|
|
119
|
+
});
|
|
120
|
+
try {
|
|
121
|
+
if (options.quoteOnly) {
|
|
122
|
+
logger.debug("Quote-only mode requested, generating quote");
|
|
123
|
+
return await generateQuote(input, clientConfig, options, existingSDK);
|
|
124
|
+
}
|
|
125
|
+
if (options.mode === "hashinal" && options.metadata) {
|
|
126
|
+
validateHashinalMetadata(options.metadata, logger);
|
|
127
|
+
}
|
|
128
|
+
let sdk;
|
|
129
|
+
if (existingSDK) {
|
|
130
|
+
logger.debug("Using existing InscriptionSDK instance");
|
|
131
|
+
sdk = existingSDK;
|
|
132
|
+
} else if (options.apiKey) {
|
|
133
|
+
logger.debug("Initializing InscriptionSDK with API key");
|
|
134
|
+
sdk = new InscriptionSDK({
|
|
135
|
+
apiKey: options.apiKey,
|
|
136
|
+
network: clientConfig.network || "mainnet",
|
|
137
|
+
connectionMode: resolvedConnectionMode,
|
|
138
|
+
baseURL: options.baseURL
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
logger.debug("Initializing InscriptionSDK with server auth");
|
|
142
|
+
const normalized = normalizeClientConfig(clientConfig);
|
|
143
|
+
sdk = await InscriptionSDK.createWithAuth({
|
|
144
|
+
type: "server",
|
|
145
|
+
accountId: normalized.accountId,
|
|
146
|
+
privateKey: normalized.privateKey,
|
|
147
|
+
network: normalized.network || "mainnet",
|
|
148
|
+
connectionMode: resolvedConnectionMode,
|
|
149
|
+
baseUrl: options.baseURL
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
const baseRequest = {
|
|
153
|
+
holderId: clientConfig.accountId,
|
|
154
|
+
metadata: options.metadata || {},
|
|
155
|
+
tags: options.tags || [],
|
|
156
|
+
mode: options.mode || "file",
|
|
157
|
+
fileStandard: options.fileStandard,
|
|
158
|
+
chunkSize: options.chunkSize
|
|
159
|
+
};
|
|
160
|
+
let request;
|
|
161
|
+
switch (input.type) {
|
|
162
|
+
case "url":
|
|
163
|
+
request = {
|
|
164
|
+
...baseRequest,
|
|
165
|
+
file: {
|
|
166
|
+
type: "url",
|
|
167
|
+
url: input.url
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
break;
|
|
171
|
+
case "file": {
|
|
172
|
+
const fileData = await convertFileToBase64(input.path);
|
|
173
|
+
request = {
|
|
174
|
+
...baseRequest,
|
|
175
|
+
file: {
|
|
176
|
+
type: "base64",
|
|
177
|
+
base64: fileData.base64,
|
|
178
|
+
fileName: fileData.fileName,
|
|
179
|
+
mimeType: fileData.mimeType
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case "buffer":
|
|
185
|
+
request = {
|
|
186
|
+
...baseRequest,
|
|
187
|
+
file: {
|
|
188
|
+
type: "base64",
|
|
189
|
+
base64: Buffer.from(
|
|
190
|
+
input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
|
|
191
|
+
).toString("base64"),
|
|
192
|
+
fileName: input.fileName,
|
|
193
|
+
mimeType: input.mimeType
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
if (options.mode === "hashinal") {
|
|
199
|
+
request.metadataObject = options.metadata;
|
|
200
|
+
request.creator = options.metadata?.creator || clientConfig.accountId;
|
|
201
|
+
request.description = options.metadata?.description;
|
|
202
|
+
if (options.jsonFileURL) {
|
|
203
|
+
request.jsonFileURL = options.jsonFileURL;
|
|
204
|
+
}
|
|
164
205
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
206
|
+
logger.debug("Preparing to inscribe content", {
|
|
207
|
+
type: input.type,
|
|
208
|
+
mode: options.mode || "file",
|
|
209
|
+
holderId: clientConfig.accountId
|
|
210
|
+
});
|
|
211
|
+
const normalizedCfg = normalizeClientConfig(clientConfig);
|
|
212
|
+
const result = await sdk.inscribeAndExecute(
|
|
213
|
+
request,
|
|
214
|
+
normalizedCfg,
|
|
215
|
+
options.progressCallback
|
|
216
|
+
);
|
|
217
|
+
const rawJobId = result.jobId || result.tx_id || result.transactionId || "";
|
|
218
|
+
const rawTxId = result.transactionId || rawJobId || "";
|
|
219
|
+
const normalizedJobId = normalizeTransactionId(rawJobId);
|
|
220
|
+
const normalizedTxId = normalizeTransactionId(rawTxId);
|
|
221
|
+
const waitId = normalizeTransactionId(
|
|
222
|
+
normalizedJobId || normalizedTxId || rawJobId || result.jobId || ""
|
|
223
|
+
);
|
|
224
|
+
logger.info("Starting to inscribe.", {
|
|
225
|
+
type: input.type,
|
|
226
|
+
mode: options.mode || "file",
|
|
227
|
+
transactionId: result.jobId
|
|
228
|
+
});
|
|
229
|
+
if (options.waitForConfirmation) {
|
|
230
|
+
logger.debug("Waiting for inscription confirmation", {
|
|
231
|
+
transactionId: waitId,
|
|
232
|
+
maxAttempts: options.waitMaxAttempts,
|
|
233
|
+
intervalMs: options.waitIntervalMs
|
|
234
|
+
});
|
|
235
|
+
const inscription = await waitForInscriptionConfirmation(
|
|
236
|
+
sdk,
|
|
237
|
+
waitId,
|
|
238
|
+
options.waitMaxAttempts,
|
|
239
|
+
options.waitIntervalMs,
|
|
240
|
+
options.progressCallback
|
|
178
241
|
);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
242
|
+
logger.info("Inscription confirmation received", {
|
|
243
|
+
transactionId: result.jobId
|
|
244
|
+
});
|
|
245
|
+
return {
|
|
246
|
+
confirmed: true,
|
|
247
|
+
result: {
|
|
248
|
+
...result,
|
|
249
|
+
jobId: waitId,
|
|
250
|
+
transactionId: normalizedTxId
|
|
251
|
+
},
|
|
252
|
+
inscription,
|
|
253
|
+
sdk,
|
|
254
|
+
costSummary: await resolveInscriptionCost(
|
|
255
|
+
normalizedTxId,
|
|
256
|
+
clientConfig.network || "mainnet",
|
|
257
|
+
options.logging?.level
|
|
258
|
+
)
|
|
259
|
+
};
|
|
186
260
|
}
|
|
261
|
+
return {
|
|
262
|
+
confirmed: false,
|
|
263
|
+
result: {
|
|
264
|
+
...result,
|
|
265
|
+
jobId: waitId,
|
|
266
|
+
transactionId: normalizedTxId
|
|
267
|
+
},
|
|
268
|
+
sdk,
|
|
269
|
+
costSummary: await resolveInscriptionCost(
|
|
270
|
+
normalizedTxId,
|
|
271
|
+
clientConfig.network || "mainnet",
|
|
272
|
+
options.logging?.level
|
|
273
|
+
)
|
|
274
|
+
};
|
|
275
|
+
} catch (error) {
|
|
276
|
+
logger.error("Error during inscription process", error);
|
|
277
|
+
throw error;
|
|
187
278
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
279
|
+
}
|
|
280
|
+
async function resolveInscriptionCost(transactionId, network, level) {
|
|
281
|
+
const logger = Logger.getInstance({
|
|
282
|
+
module: COST_LOGGER_MODULE,
|
|
283
|
+
level: level ?? "info"
|
|
284
|
+
});
|
|
285
|
+
const mirrorNode = new HederaMirrorNode(network, logger);
|
|
286
|
+
const normalizedId = normalizeTransactionId(transactionId);
|
|
287
|
+
const payerAccountId = normalizedId.split("-")[0];
|
|
288
|
+
for (let attempt = 0; attempt < COST_LOOKUP_ATTEMPTS; attempt++) {
|
|
196
289
|
try {
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.logger.trace(`Token info found for ${tokenId}:`, data);
|
|
202
|
-
return data;
|
|
203
|
-
}
|
|
204
|
-
this.logger.warn(`No token info found for ${tokenId}`);
|
|
205
|
-
return null;
|
|
206
|
-
} catch (e) {
|
|
207
|
-
const error = e;
|
|
208
|
-
const logMessage = `Error fetching token info for ${tokenId}: ${error.message}`;
|
|
209
|
-
this.logger.error(logMessage);
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Retrieves messages for a given topic ID from the mirror node. Supports filtering by sequence number
|
|
215
|
-
* based on the OpenAPI specification.
|
|
216
|
-
* @param topicId The ID of the topic to retrieve messages for.
|
|
217
|
-
* @param options Optional filtering parameters.
|
|
218
|
-
* @returns A promise that resolves to the messages for the given topic.
|
|
219
|
-
*/
|
|
220
|
-
async getTopicMessages(topicId, options) {
|
|
221
|
-
this.logger.trace(
|
|
222
|
-
`Querying messages for topic ${topicId}${options ? " with filters" : ""}`
|
|
223
|
-
);
|
|
224
|
-
let endpoint = `/api/v1/topics/${topicId}/messages`;
|
|
225
|
-
const params = new URLSearchParams();
|
|
226
|
-
if (options) {
|
|
227
|
-
if (options.sequenceNumber !== void 0) {
|
|
228
|
-
const seqNum = typeof options.sequenceNumber === "number" ? options.sequenceNumber.toString() : options.sequenceNumber;
|
|
229
|
-
if (!seqNum.match(/^(gt|gte|lt|lte|eq|ne):/)) {
|
|
230
|
-
params.append("sequencenumber", `gt:${seqNum}`);
|
|
231
|
-
} else {
|
|
232
|
-
params.append("sequencenumber", seqNum);
|
|
290
|
+
const txn = await mirrorNode.getTransaction(normalizedId);
|
|
291
|
+
if (!txn) {
|
|
292
|
+
if (attempt < COST_LOOKUP_ATTEMPTS - 1) {
|
|
293
|
+
await sleep(COST_LOOKUP_DELAY_MS);
|
|
233
294
|
}
|
|
295
|
+
continue;
|
|
234
296
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const queryString = params.toString();
|
|
243
|
-
if (queryString) {
|
|
244
|
-
endpoint += `?${queryString}`;
|
|
245
|
-
}
|
|
246
|
-
const messages = [];
|
|
247
|
-
let nextEndpoint = endpoint;
|
|
248
|
-
while (nextEndpoint) {
|
|
249
|
-
try {
|
|
250
|
-
const data = await this._requestWithRetry(nextEndpoint);
|
|
251
|
-
if (data.messages && data.messages.length > 0) {
|
|
252
|
-
for (const message of data.messages) {
|
|
253
|
-
try {
|
|
254
|
-
if (!message.message) {
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
let messageContent;
|
|
258
|
-
try {
|
|
259
|
-
if (this.isServerEnvironment) {
|
|
260
|
-
messageContent = Buffer.from(
|
|
261
|
-
message.message,
|
|
262
|
-
"base64"
|
|
263
|
-
).toString("utf-8");
|
|
264
|
-
} else {
|
|
265
|
-
messageContent = new TextDecoder().decode(
|
|
266
|
-
Uint8Array.from(
|
|
267
|
-
atob(message.message),
|
|
268
|
-
(c) => c.charCodeAt(0)
|
|
269
|
-
)
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
} catch (error) {
|
|
273
|
-
const logMessage = `Error decoding message: ${error}`;
|
|
274
|
-
this.logger.error(logMessage);
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
let messageJson;
|
|
278
|
-
try {
|
|
279
|
-
messageJson = JSON.parse(messageContent);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
const logMessage = `Invalid JSON message content: ${messageContent}`;
|
|
282
|
-
this.logger.error(logMessage);
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
messageJson.sequence_number = message.sequence_number;
|
|
286
|
-
messages.push({
|
|
287
|
-
...messageJson,
|
|
288
|
-
consensus_timestamp: message.consensus_timestamp,
|
|
289
|
-
sequence_number: message.sequence_number,
|
|
290
|
-
running_hash: message.running_hash,
|
|
291
|
-
running_hash_version: message.running_hash_version,
|
|
292
|
-
topic_id: message.topic_id,
|
|
293
|
-
payer: message.payer_account_id,
|
|
294
|
-
created: new Date(Number(message.consensus_timestamp) * 1e3)
|
|
295
|
-
});
|
|
296
|
-
} catch (error) {
|
|
297
|
-
const logMessage = `Error processing message: ${error.message}`;
|
|
298
|
-
this.logger.error(logMessage);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
297
|
+
const computed = computeInscriptionCostSummary({
|
|
298
|
+
txn,
|
|
299
|
+
payerAccountId
|
|
300
|
+
});
|
|
301
|
+
if (!computed) {
|
|
302
|
+
if (attempt < COST_LOOKUP_ATTEMPTS - 1) {
|
|
303
|
+
await sleep(COST_LOOKUP_DELAY_MS);
|
|
301
304
|
}
|
|
302
|
-
|
|
303
|
-
} catch (e) {
|
|
304
|
-
const error = e;
|
|
305
|
-
const logMessage = `Error querying topic messages for topic ${topicId} (endpoint: ${nextEndpoint}) after retries: ${error.message}`;
|
|
306
|
-
this.logger.error(logMessage);
|
|
307
|
-
throw new Error(logMessage);
|
|
305
|
+
continue;
|
|
308
306
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
async requestAccount(accountId) {
|
|
319
|
-
try {
|
|
320
|
-
this.logger.debug(`Requesting account info for ${accountId}`);
|
|
321
|
-
const data = await this._requestWithRetry(
|
|
322
|
-
`/api/v1/accounts/${accountId}`
|
|
323
|
-
);
|
|
324
|
-
if (!data) {
|
|
325
|
-
throw new Error(
|
|
326
|
-
`No data received from mirror node for account: ${accountId}`
|
|
327
|
-
);
|
|
307
|
+
return computed.summary;
|
|
308
|
+
} catch (error) {
|
|
309
|
+
logger.warn("Unable to resolve inscription cost", {
|
|
310
|
+
transactionId: normalizedId,
|
|
311
|
+
attempt: attempt + 1,
|
|
312
|
+
error: error instanceof Error ? error.message : String(error)
|
|
313
|
+
});
|
|
314
|
+
if (attempt < COST_LOOKUP_ATTEMPTS - 1) {
|
|
315
|
+
await sleep(COST_LOOKUP_DELAY_MS);
|
|
328
316
|
}
|
|
329
|
-
return data;
|
|
330
|
-
} catch (e) {
|
|
331
|
-
const error = e;
|
|
332
|
-
const logMessage = `Failed to fetch account ${accountId} after retries: ${error.message}`;
|
|
333
|
-
this.logger.error(logMessage);
|
|
334
|
-
throw new Error(logMessage);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Checks if a user has access to a given key list.
|
|
339
|
-
* @param keyBytes The key list to check access for.
|
|
340
|
-
* @param userPublicKey The public key of the user to check access for.
|
|
341
|
-
* @returns A promise that resolves to true if the user has access, false otherwise.
|
|
342
|
-
*/
|
|
343
|
-
async checkKeyListAccess(keyBytes, userPublicKey) {
|
|
344
|
-
try {
|
|
345
|
-
const key = proto.Key.decode(keyBytes);
|
|
346
|
-
return this.evaluateKeyAccess(key, userPublicKey);
|
|
347
|
-
} catch (e) {
|
|
348
|
-
const error = e;
|
|
349
|
-
const logMessage = `Error decoding protobuf key: ${error.message}`;
|
|
350
|
-
this.logger.error(logMessage);
|
|
351
|
-
throw new Error(logMessage);
|
|
352
317
|
}
|
|
353
318
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
319
|
+
return void 0;
|
|
320
|
+
}
|
|
321
|
+
async function inscribeWithSigner(input, signer, options, existingSDK) {
|
|
322
|
+
const logger = Logger.getInstance({
|
|
323
|
+
module: "Inscriber",
|
|
324
|
+
...options.logging
|
|
325
|
+
});
|
|
326
|
+
const resolvedConnectionMode = resolveConnectionMode(options);
|
|
327
|
+
logger.info("Starting inscription process with signer", {
|
|
328
|
+
type: input.type,
|
|
329
|
+
mode: options.mode || "file",
|
|
330
|
+
quoteOnly: options.quoteOnly || false,
|
|
331
|
+
...input.type === "url" ? { url: input.url } : {},
|
|
332
|
+
...input.type === "file" ? { path: input.path } : {},
|
|
333
|
+
...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
|
|
334
|
+
});
|
|
335
|
+
try {
|
|
336
|
+
if (options.quoteOnly) {
|
|
337
|
+
logger.debug("Quote-only mode requested with signer, generating quote");
|
|
338
|
+
const clientConfig = {
|
|
339
|
+
accountId: signer.getAccountId().toString(),
|
|
340
|
+
privateKey: "",
|
|
341
|
+
network: options.network || "mainnet"
|
|
342
|
+
};
|
|
343
|
+
return await generateQuote(input, clientConfig, options, existingSDK);
|
|
344
|
+
}
|
|
345
|
+
if (options.mode === "hashinal" && options.metadata) {
|
|
346
|
+
validateHashinalMetadata(options.metadata, logger);
|
|
347
|
+
}
|
|
348
|
+
const accountId = signer.getAccountId().toString();
|
|
349
|
+
logger.debug("Using account ID from signer", { accountId });
|
|
350
|
+
let sdk;
|
|
351
|
+
if (existingSDK) {
|
|
352
|
+
logger.debug("Using existing InscriptionSDK instance");
|
|
353
|
+
sdk = existingSDK;
|
|
354
|
+
} else if (options.apiKey) {
|
|
355
|
+
logger.debug("Initializing InscriptionSDK with API key");
|
|
356
|
+
sdk = new InscriptionSDK({
|
|
357
|
+
apiKey: options.apiKey,
|
|
358
|
+
network: options.network || "mainnet",
|
|
359
|
+
connectionMode: resolvedConnectionMode,
|
|
360
|
+
baseURL: options.baseURL
|
|
361
|
+
});
|
|
362
|
+
} else {
|
|
363
|
+
logger.debug("Initializing InscriptionSDK with client auth (websocket)");
|
|
364
|
+
sdk = await InscriptionSDK.createWithAuth({
|
|
365
|
+
type: "client",
|
|
366
|
+
accountId,
|
|
367
|
+
signer,
|
|
368
|
+
network: options.network || "mainnet",
|
|
369
|
+
connectionMode: resolvedConnectionMode,
|
|
370
|
+
baseUrl: options.baseURL
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
const baseRequest = {
|
|
374
|
+
holderId: accountId,
|
|
375
|
+
metadata: options.metadata || {},
|
|
376
|
+
tags: options.tags || [],
|
|
377
|
+
mode: options.mode || "file",
|
|
378
|
+
fileStandard: options.fileStandard,
|
|
379
|
+
chunkSize: options.chunkSize
|
|
380
|
+
};
|
|
381
|
+
let request;
|
|
382
|
+
switch (input.type) {
|
|
383
|
+
case "url":
|
|
384
|
+
request = {
|
|
385
|
+
...baseRequest,
|
|
386
|
+
file: {
|
|
387
|
+
type: "url",
|
|
388
|
+
url: input.url
|
|
398
389
|
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
390
|
+
};
|
|
391
|
+
break;
|
|
392
|
+
case "file": {
|
|
393
|
+
const fileData = await convertFileToBase64(input.path);
|
|
394
|
+
request = {
|
|
395
|
+
...baseRequest,
|
|
396
|
+
file: {
|
|
397
|
+
type: "base64",
|
|
398
|
+
base64: fileData.base64,
|
|
399
|
+
fileName: fileData.fileName,
|
|
400
|
+
mimeType: fileData.mimeType
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
break;
|
|
404
404
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Retrieves information about a scheduled transaction
|
|
427
|
-
* @param scheduleId The ID of the scheduled transaction
|
|
428
|
-
* @returns A promise that resolves to the scheduled transaction information
|
|
429
|
-
*/
|
|
430
|
-
async getScheduleInfo(scheduleId) {
|
|
431
|
-
try {
|
|
432
|
-
this.logger.info(
|
|
433
|
-
`Getting information for scheduled transaction ${scheduleId}`
|
|
434
|
-
);
|
|
435
|
-
const data = await this._requestWithRetry(
|
|
436
|
-
`/api/v1/schedules/${scheduleId}`
|
|
437
|
-
);
|
|
438
|
-
if (data) {
|
|
439
|
-
return data;
|
|
405
|
+
case "buffer":
|
|
406
|
+
request = {
|
|
407
|
+
...baseRequest,
|
|
408
|
+
file: {
|
|
409
|
+
type: "base64",
|
|
410
|
+
base64: Buffer.from(
|
|
411
|
+
input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
|
|
412
|
+
).toString("base64"),
|
|
413
|
+
fileName: input.fileName,
|
|
414
|
+
mimeType: input.mimeType
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
if (options.mode === "hashinal") {
|
|
420
|
+
request.metadataObject = options.metadata;
|
|
421
|
+
request.creator = options.metadata?.creator || accountId;
|
|
422
|
+
request.description = options.metadata?.description;
|
|
423
|
+
if (options.jsonFileURL) {
|
|
424
|
+
request.jsonFileURL = options.jsonFileURL;
|
|
440
425
|
}
|
|
441
|
-
|
|
442
|
-
|
|
426
|
+
}
|
|
427
|
+
logger.debug("Starting inscription via startInscription (websocket)", {
|
|
428
|
+
type: input.type,
|
|
429
|
+
mode: options.mode || "file",
|
|
430
|
+
holderId: accountId,
|
|
431
|
+
usesStartInscription: true
|
|
432
|
+
});
|
|
433
|
+
const startResult = await sdk.startInscription({
|
|
434
|
+
...request,
|
|
435
|
+
holderId: accountId,
|
|
436
|
+
network: options.network || "mainnet"
|
|
437
|
+
});
|
|
438
|
+
const startTransactionIdRaw = typeof startResult?.tx_id === "string" && startResult.tx_id.trim() || typeof startResult?.jobId === "string" && (startResult.jobId || "").trim() || typeof startResult?.id === "string" && (startResult.id || "").trim() || "";
|
|
439
|
+
const waitId = normalizeTransactionId(startTransactionIdRaw);
|
|
440
|
+
if (!waitId) {
|
|
441
|
+
throw new Error("startInscription did not return a transaction id");
|
|
442
|
+
}
|
|
443
|
+
logger.info("about to start inscription", {
|
|
444
|
+
type: input.type,
|
|
445
|
+
mode: options.mode || "file",
|
|
446
|
+
jobId: waitId,
|
|
447
|
+
...startResult
|
|
448
|
+
});
|
|
449
|
+
if (typeof startResult?.transactionBytes === "string") {
|
|
450
|
+
logger.debug("Executing inscription transaction with signer from bytes");
|
|
451
|
+
await sdk.executeTransactionWithSigner(
|
|
452
|
+
startResult.transactionBytes,
|
|
453
|
+
signer
|
|
443
454
|
);
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
455
|
+
} else if (startResult?.transactionBytes?.type === "Buffer") {
|
|
456
|
+
logger.debug("Executing inscription transaction with signer from buffer");
|
|
457
|
+
await sdk.executeTransactionWithSigner(
|
|
458
|
+
Buffer.from(startResult.transactionBytes.data).toString("base64"),
|
|
459
|
+
signer
|
|
448
460
|
);
|
|
449
|
-
return null;
|
|
450
461
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
462
|
+
if (options.waitForConfirmation) {
|
|
463
|
+
logger.debug("Waiting for inscription confirmation (websocket)", {
|
|
464
|
+
jobId: waitId,
|
|
465
|
+
maxAttempts: options.waitMaxAttempts,
|
|
466
|
+
intervalMs: options.waitIntervalMs
|
|
467
|
+
});
|
|
468
|
+
const inscription = await waitForInscriptionConfirmation(
|
|
469
|
+
sdk,
|
|
470
|
+
waitId,
|
|
471
|
+
options.waitMaxAttempts,
|
|
472
|
+
options.waitIntervalMs,
|
|
473
|
+
options.progressCallback
|
|
461
474
|
);
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}
|
|
475
|
+
logger.info("Inscription confirmation received", {
|
|
476
|
+
jobId: waitId
|
|
477
|
+
});
|
|
466
478
|
return {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
479
|
+
confirmed: true,
|
|
480
|
+
result: {
|
|
481
|
+
jobId: waitId,
|
|
482
|
+
transactionId: waitId,
|
|
483
|
+
topic_id: startResult.topic_id,
|
|
484
|
+
status: startResult.status,
|
|
485
|
+
completed: startResult.completed
|
|
486
|
+
},
|
|
487
|
+
inscription,
|
|
488
|
+
sdk,
|
|
489
|
+
costSummary: await resolveInscriptionCost(
|
|
490
|
+
waitId,
|
|
491
|
+
options.network || "mainnet",
|
|
492
|
+
options.logging?.level
|
|
493
|
+
)
|
|
470
494
|
};
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
495
|
+
}
|
|
496
|
+
return {
|
|
497
|
+
confirmed: false,
|
|
498
|
+
result: {
|
|
499
|
+
jobId: waitId,
|
|
500
|
+
transactionId: waitId,
|
|
501
|
+
topic_id: startResult.topic_id,
|
|
502
|
+
status: startResult.status,
|
|
503
|
+
completed: startResult.completed
|
|
504
|
+
},
|
|
505
|
+
sdk,
|
|
506
|
+
costSummary: await resolveInscriptionCost(
|
|
507
|
+
waitId,
|
|
508
|
+
options.network || "mainnet",
|
|
509
|
+
options.logging?.level
|
|
510
|
+
)
|
|
511
|
+
};
|
|
512
|
+
} catch (error) {
|
|
513
|
+
logger.error("Error during inscription process", error);
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
async function retrieveInscription(transactionId, options) {
|
|
518
|
+
const logger = Logger.getInstance({
|
|
519
|
+
module: "Inscriber",
|
|
520
|
+
...options?.logging || {}
|
|
521
|
+
});
|
|
522
|
+
const formattedTransactionId = transactionId.includes("@") ? `${transactionId.split("@")[0]}-${transactionId.split("@")[1].replace(/\./g, "-")}` : transactionId;
|
|
523
|
+
logger.info("Retrieving inscription", {
|
|
524
|
+
originalTransactionId: transactionId,
|
|
525
|
+
formattedTransactionId
|
|
526
|
+
});
|
|
527
|
+
try {
|
|
528
|
+
let sdk;
|
|
529
|
+
if (options?.apiKey) {
|
|
530
|
+
logger.debug("Initializing InscriptionSDK with API key");
|
|
531
|
+
sdk = new InscriptionSDK({
|
|
532
|
+
apiKey: options.apiKey,
|
|
533
|
+
network: options.network || "mainnet",
|
|
534
|
+
baseURL: options.baseURL
|
|
535
|
+
});
|
|
536
|
+
} else if (options?.accountId && options?.privateKey) {
|
|
537
|
+
logger.debug("Initializing InscriptionSDK with server auth");
|
|
538
|
+
sdk = await InscriptionSDK.createWithAuth({
|
|
539
|
+
type: "server",
|
|
540
|
+
accountId: options.accountId,
|
|
541
|
+
privateKey: options.privateKey,
|
|
542
|
+
network: options.network || "mainnet",
|
|
543
|
+
baseUrl: options.baseURL
|
|
544
|
+
});
|
|
545
|
+
} else {
|
|
546
|
+
const error = new Error(
|
|
547
|
+
"Either API key or account ID and private key are required for retrieving inscriptions"
|
|
474
548
|
);
|
|
549
|
+
logger.error("Missing authentication credentials", {
|
|
550
|
+
hasApiKey: Boolean(options?.apiKey),
|
|
551
|
+
hasAccountId: Boolean(options?.accountId),
|
|
552
|
+
hasPrivateKey: Boolean(options?.privateKey)
|
|
553
|
+
});
|
|
475
554
|
throw error;
|
|
476
555
|
}
|
|
556
|
+
logger.debug("Initialized SDK for inscription retrieval", {
|
|
557
|
+
formattedTransactionId,
|
|
558
|
+
network: options.network || "mainnet"
|
|
559
|
+
});
|
|
560
|
+
const result = await sdk.retrieveInscription(formattedTransactionId);
|
|
561
|
+
logger.info("Successfully retrieved inscription", {
|
|
562
|
+
formattedTransactionId
|
|
563
|
+
});
|
|
564
|
+
return result;
|
|
565
|
+
} catch (error) {
|
|
566
|
+
logger.error("Error retrieving inscription", {
|
|
567
|
+
formattedTransactionId,
|
|
568
|
+
error
|
|
569
|
+
});
|
|
570
|
+
throw error;
|
|
477
571
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
this.logger.info(
|
|
486
|
-
`Getting transaction details for ID/hash: ${transactionIdOrHash}`
|
|
572
|
+
}
|
|
573
|
+
function validateHashinalMetadata(metadata, logger) {
|
|
574
|
+
const requiredFields = ["name", "creator", "description", "type"];
|
|
575
|
+
const missingFields = requiredFields.filter((field) => !metadata[field]);
|
|
576
|
+
if (missingFields.length > 0) {
|
|
577
|
+
const error = new Error(
|
|
578
|
+
`Missing required Hashinal metadata fields: ${missingFields.join(", ")}`
|
|
487
579
|
);
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
if (response?.transactions?.length > 0) {
|
|
491
|
-
this.logger.trace(
|
|
492
|
-
`Transaction details found for ${transactionIdOrHash}:`,
|
|
493
|
-
response.transactions[0]
|
|
494
|
-
);
|
|
495
|
-
return response.transactions[0];
|
|
496
|
-
}
|
|
497
|
-
this.logger.warn(
|
|
498
|
-
`No transaction details found for ${transactionIdOrHash} or unexpected response structure.`
|
|
499
|
-
);
|
|
500
|
-
return null;
|
|
501
|
-
} catch (e) {
|
|
502
|
-
const error = e;
|
|
503
|
-
this.logger.error(
|
|
504
|
-
`Failed to get transaction details for ${transactionIdOrHash} after retries: ${error.message}`
|
|
505
|
-
);
|
|
506
|
-
return null;
|
|
507
|
-
}
|
|
580
|
+
logger.error("Hashinal metadata validation failed", { missingFields });
|
|
581
|
+
throw error;
|
|
508
582
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
583
|
+
logger.debug("Hashinal metadata validation passed", {
|
|
584
|
+
name: metadata.name,
|
|
585
|
+
creator: metadata.creator,
|
|
586
|
+
description: metadata.description,
|
|
587
|
+
type: metadata.type,
|
|
588
|
+
hasAttributes: !!metadata.attributes,
|
|
589
|
+
hasProperties: !!metadata.properties
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
async function generateQuote(input, clientConfig, options, existingSDK) {
|
|
593
|
+
const logger = Logger.getInstance({
|
|
594
|
+
module: "Inscriber",
|
|
595
|
+
...options.logging
|
|
596
|
+
});
|
|
597
|
+
logger.info("Generating inscription quote", {
|
|
598
|
+
type: input.type,
|
|
599
|
+
mode: options.mode || "file",
|
|
600
|
+
...input.type === "url" ? { url: input.url } : {},
|
|
601
|
+
...input.type === "file" ? { path: input.path } : {},
|
|
602
|
+
...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
|
|
603
|
+
});
|
|
604
|
+
try {
|
|
605
|
+
validateQuoteParameters(input, clientConfig, options);
|
|
606
|
+
const cachedQuote = getCachedQuote(input, clientConfig, options);
|
|
607
|
+
if (cachedQuote) {
|
|
608
|
+
logger.debug("Returning cached quote");
|
|
609
|
+
return {
|
|
610
|
+
confirmed: false,
|
|
611
|
+
quote: true,
|
|
612
|
+
result: cachedQuote
|
|
528
613
|
};
|
|
529
614
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
);
|
|
542
|
-
throw error;
|
|
543
|
-
}
|
|
544
|
-
if (isLastAttempt) {
|
|
545
|
-
this.logger.error(
|
|
546
|
-
`Max retries (${this.maxRetries}) reached for ${url}. Last error: ${error.message}`
|
|
547
|
-
);
|
|
548
|
-
throw error;
|
|
549
|
-
}
|
|
550
|
-
this.logger.warn(
|
|
551
|
-
`Attempt ${attempt}/${this.maxRetries} failed for ${url}: ${error.message}. Retrying in ${delay}ms...`
|
|
552
|
-
);
|
|
553
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
554
|
-
delay = Math.min(delay * this.backoffFactor, this.maxDelayMs);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
throw new Error(
|
|
558
|
-
`Failed to fetch data from ${url} after ${this.maxRetries} attempts.`
|
|
559
|
-
);
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Private helper to make fetch requests with retry logic.
|
|
563
|
-
*/
|
|
564
|
-
async _fetchWithRetry(url, fetchOptions) {
|
|
565
|
-
let attempt = 0;
|
|
566
|
-
let delay = this.initialDelayMs;
|
|
567
|
-
const headers = {
|
|
568
|
-
...this.customHeaders
|
|
615
|
+
if (options.mode === "hashinal" && options.metadata) {
|
|
616
|
+
validateHashinalMetadata(options.metadata, logger);
|
|
617
|
+
}
|
|
618
|
+
const sdk = await getOrCreateSDK(clientConfig, options, existingSDK);
|
|
619
|
+
const baseRequest = {
|
|
620
|
+
holderId: clientConfig.accountId,
|
|
621
|
+
metadata: options.metadata || {},
|
|
622
|
+
tags: options.tags || [],
|
|
623
|
+
mode: options.mode || "file",
|
|
624
|
+
fileStandard: options.fileStandard,
|
|
625
|
+
chunkSize: options.chunkSize
|
|
569
626
|
};
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
627
|
+
let request;
|
|
628
|
+
switch (input.type) {
|
|
629
|
+
case "url":
|
|
630
|
+
request = {
|
|
631
|
+
...baseRequest,
|
|
632
|
+
file: {
|
|
633
|
+
type: "url",
|
|
634
|
+
url: input.url
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
break;
|
|
638
|
+
case "file": {
|
|
639
|
+
const fileData = await convertFileToBase64(input.path);
|
|
640
|
+
request = {
|
|
641
|
+
...baseRequest,
|
|
642
|
+
file: {
|
|
643
|
+
type: "base64",
|
|
644
|
+
base64: fileData.base64,
|
|
645
|
+
fileName: fileData.fileName,
|
|
646
|
+
mimeType: fileData.mimeType
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
break;
|
|
581
650
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
try {
|
|
593
|
-
const request = await fetch(url, options);
|
|
594
|
-
if (!request.ok) {
|
|
595
|
-
if (request.status >= 400 && request.status < 500 && request.status !== 429) {
|
|
596
|
-
this.logger.error(
|
|
597
|
-
`Client error for ${url} (status ${request.status}): ${request.statusText}. Not retrying.`
|
|
598
|
-
);
|
|
599
|
-
throw new Error(
|
|
600
|
-
`Fetch failed with status ${request.status}: ${request.statusText} for URL: ${url}`
|
|
601
|
-
);
|
|
651
|
+
case "buffer":
|
|
652
|
+
request = {
|
|
653
|
+
...baseRequest,
|
|
654
|
+
file: {
|
|
655
|
+
type: "base64",
|
|
656
|
+
base64: Buffer.from(
|
|
657
|
+
input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
|
|
658
|
+
).toString("base64"),
|
|
659
|
+
fileName: input.fileName,
|
|
660
|
+
mimeType: input.mimeType
|
|
602
661
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
this.logger.error(
|
|
613
|
-
`Max retries (${this.maxRetries}) reached for ${url}. Last error: ${error.message}`
|
|
614
|
-
);
|
|
615
|
-
throw error;
|
|
616
|
-
}
|
|
617
|
-
this.logger.warn(
|
|
618
|
-
`Attempt ${attempt}/${this.maxRetries} failed for ${url}: ${error.message}. Retrying in ${delay}ms...`
|
|
619
|
-
);
|
|
620
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
621
|
-
delay = Math.min(delay * this.backoffFactor, this.maxDelayMs);
|
|
662
|
+
};
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
if (options.mode === "hashinal") {
|
|
666
|
+
request.metadataObject = options.metadata;
|
|
667
|
+
request.creator = options.metadata?.creator || clientConfig.accountId;
|
|
668
|
+
request.description = options.metadata?.description;
|
|
669
|
+
if (options.jsonFileURL) {
|
|
670
|
+
request.jsonFileURL = options.jsonFileURL;
|
|
622
671
|
}
|
|
623
672
|
}
|
|
624
|
-
|
|
625
|
-
|
|
673
|
+
logger.debug("Calling inscription SDK startInscription for quote", {
|
|
674
|
+
type: input.type,
|
|
675
|
+
mode: options.mode || "file",
|
|
676
|
+
holderId: clientConfig.accountId
|
|
677
|
+
});
|
|
678
|
+
const inscriptionResponse = await sdk.startInscription(request);
|
|
679
|
+
logger.debug("Received inscription response for quote parsing", {
|
|
680
|
+
hasTransactionBytes: !!inscriptionResponse.transactionBytes,
|
|
681
|
+
bytesLength: inscriptionResponse.transactionBytes?.length || 0,
|
|
682
|
+
transactionBytesType: typeof inscriptionResponse.transactionBytes,
|
|
683
|
+
totalCost: inscriptionResponse.totalCost
|
|
684
|
+
});
|
|
685
|
+
const quote = await parseTransactionForQuote(
|
|
686
|
+
inscriptionResponse,
|
|
687
|
+
logger
|
|
626
688
|
);
|
|
689
|
+
cacheQuote(input, clientConfig, options, quote);
|
|
690
|
+
logger.info("Successfully generated inscription quote", {
|
|
691
|
+
totalCostHbar: quote.totalCostHbar
|
|
692
|
+
});
|
|
693
|
+
return {
|
|
694
|
+
confirmed: false,
|
|
695
|
+
quote: true,
|
|
696
|
+
result: quote
|
|
697
|
+
};
|
|
698
|
+
} catch (error) {
|
|
699
|
+
logger.error("Error generating inscription quote", error);
|
|
700
|
+
throw error;
|
|
627
701
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
}
|
|
678
|
-
if (options?.endTime) {
|
|
679
|
-
params.append("timestamp", `lt:${options.endTime}`);
|
|
680
|
-
}
|
|
681
|
-
if (options?.order) {
|
|
682
|
-
params.append("order", options.order);
|
|
683
|
-
}
|
|
684
|
-
const queryString = params.toString();
|
|
685
|
-
if (queryString) {
|
|
686
|
-
nextUrl += `?${queryString}`;
|
|
687
|
-
}
|
|
688
|
-
const messages = [];
|
|
689
|
-
let pagesFetched = 0;
|
|
690
|
-
const maxPages = 10;
|
|
691
|
-
try {
|
|
692
|
-
while (nextUrl && pagesFetched < maxPages) {
|
|
693
|
-
pagesFetched++;
|
|
694
|
-
const data = await this._requestWithRetry(nextUrl);
|
|
695
|
-
if (data.messages && data.messages.length > 0) {
|
|
696
|
-
for (const message of data.messages) {
|
|
697
|
-
try {
|
|
698
|
-
if (!message.message) {
|
|
699
|
-
continue;
|
|
700
|
-
}
|
|
701
|
-
let messageContent;
|
|
702
|
-
if (this.isServerEnvironment) {
|
|
703
|
-
messageContent = Buffer.from(
|
|
704
|
-
message.message,
|
|
705
|
-
"base64"
|
|
706
|
-
).toString("utf-8");
|
|
707
|
-
} else {
|
|
708
|
-
messageContent = new TextDecoder().decode(
|
|
709
|
-
Uint8Array.from(atob(message.message), (c) => c.charCodeAt(0))
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
|
-
let messageJson = {};
|
|
713
|
-
try {
|
|
714
|
-
messageJson = JSON.parse(messageContent);
|
|
715
|
-
} catch (parseError) {
|
|
716
|
-
this.logger.debug(
|
|
717
|
-
`Message content is not valid JSON, using raw: ${messageContent}`
|
|
718
|
-
);
|
|
719
|
-
messageJson = { raw_content: messageContent };
|
|
720
|
-
}
|
|
721
|
-
const parsedContent = messageJson;
|
|
722
|
-
const hcsMsg = {
|
|
723
|
-
...parsedContent,
|
|
724
|
-
consensus_timestamp: message.consensus_timestamp,
|
|
725
|
-
sequence_number: message.sequence_number,
|
|
726
|
-
payer_account_id: message.payer_account_id,
|
|
727
|
-
topic_id: message.topic_id,
|
|
728
|
-
running_hash: message.running_hash,
|
|
729
|
-
running_hash_version: message.running_hash_version,
|
|
730
|
-
chunk_info: message.chunk_info,
|
|
731
|
-
created: new Date(
|
|
732
|
-
Number(message.consensus_timestamp.split(".")[0]) * 1e3 + Number(message.consensus_timestamp.split(".")[1] || 0) / 1e6
|
|
733
|
-
),
|
|
734
|
-
payer: message.payer_account_id
|
|
735
|
-
};
|
|
736
|
-
messages.push(hcsMsg);
|
|
737
|
-
} catch (error) {
|
|
738
|
-
this.logger.error(
|
|
739
|
-
`Error processing individual message: ${error.message}`
|
|
740
|
-
);
|
|
702
|
+
}
|
|
703
|
+
async function parseTransactionForQuote(inscriptionResponse, logger) {
|
|
704
|
+
try {
|
|
705
|
+
let totalCostHbar = "0.001";
|
|
706
|
+
if (inscriptionResponse.totalCost && typeof inscriptionResponse.totalCost === "number") {
|
|
707
|
+
const hbarAmount = inscriptionResponse.totalCost / 1e8;
|
|
708
|
+
totalCostHbar = hbarAmount.toString();
|
|
709
|
+
logger.debug("Using totalCost from inscription response", {
|
|
710
|
+
totalCostTinybars: inscriptionResponse.totalCost,
|
|
711
|
+
totalCostHbar
|
|
712
|
+
});
|
|
713
|
+
} else if (inscriptionResponse.transactionBytes) {
|
|
714
|
+
logger.debug("Parsing transaction bytes for cost information");
|
|
715
|
+
try {
|
|
716
|
+
let transactionBytesString;
|
|
717
|
+
if (typeof inscriptionResponse.transactionBytes === "string") {
|
|
718
|
+
transactionBytesString = inscriptionResponse.transactionBytes;
|
|
719
|
+
} else if (inscriptionResponse.transactionBytes && typeof inscriptionResponse.transactionBytes === "object" && "data" in inscriptionResponse.transactionBytes) {
|
|
720
|
+
const buffer = Buffer.from(inscriptionResponse.transactionBytes.data);
|
|
721
|
+
transactionBytesString = buffer.toString("base64");
|
|
722
|
+
} else {
|
|
723
|
+
throw new Error("Invalid transactionBytes format");
|
|
724
|
+
}
|
|
725
|
+
logger.debug("About to parse transaction bytes", {
|
|
726
|
+
bytesLength: transactionBytesString.length,
|
|
727
|
+
bytesPreview: transactionBytesString.slice(0, 100)
|
|
728
|
+
});
|
|
729
|
+
const parsedTransaction = await TransactionParser.parseTransactionBytes(
|
|
730
|
+
transactionBytesString,
|
|
731
|
+
{ includeRaw: false }
|
|
732
|
+
);
|
|
733
|
+
logger.debug("Parsed transaction for quote", {
|
|
734
|
+
type: parsedTransaction.type,
|
|
735
|
+
hasTransfers: !!parsedTransaction.transfers,
|
|
736
|
+
transferCount: parsedTransaction.transfers?.length || 0,
|
|
737
|
+
transfers: parsedTransaction.transfers
|
|
738
|
+
});
|
|
739
|
+
let totalTransferAmount = 0;
|
|
740
|
+
if (parsedTransaction.transfers && parsedTransaction.transfers.length > 0) {
|
|
741
|
+
for (const transfer of parsedTransaction.transfers) {
|
|
742
|
+
const transferAmount = typeof transfer.amount === "string" ? parseFloat(transfer.amount) : transfer.amount;
|
|
743
|
+
if (transferAmount < 0) {
|
|
744
|
+
const amountHbar = Math.abs(transferAmount);
|
|
745
|
+
totalTransferAmount += amountHbar;
|
|
746
|
+
logger.debug("Found HBAR transfer", {
|
|
747
|
+
from: transfer.accountId,
|
|
748
|
+
to: "service",
|
|
749
|
+
amount: amountHbar
|
|
750
|
+
});
|
|
741
751
|
}
|
|
742
752
|
}
|
|
743
753
|
}
|
|
744
|
-
if (
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
this.logger.error(
|
|
751
|
-
`Error querying filtered topic messages for ${topicId}: ${error.message}`
|
|
752
|
-
);
|
|
753
|
-
return null;
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
/**
|
|
757
|
-
* Retrieves token balances for a given account ID.
|
|
758
|
-
* @param accountId The ID of the account.
|
|
759
|
-
* @param limit The maximum number of tokens to return.
|
|
760
|
-
* @returns A promise that resolves to an array of AccountTokenBalance or null.
|
|
761
|
-
*/
|
|
762
|
-
async getAccountTokens(accountId, limit = 100) {
|
|
763
|
-
this.logger.info(`Getting tokens for account ${accountId}`);
|
|
764
|
-
let allTokens = [];
|
|
765
|
-
let endpoint = `/api/v1/accounts/${accountId}/tokens?limit=${limit}`;
|
|
766
|
-
try {
|
|
767
|
-
for (let i = 0; i < 10 && endpoint; i++) {
|
|
768
|
-
const response = await this._requestWithRetry(endpoint);
|
|
769
|
-
if (response && response.tokens) {
|
|
770
|
-
allTokens = allTokens.concat(response.tokens);
|
|
754
|
+
if (totalTransferAmount > 0) {
|
|
755
|
+
totalCostHbar = totalTransferAmount.toString();
|
|
756
|
+
logger.debug("Using parsed transaction transfer amount", {
|
|
757
|
+
totalTransferAmount,
|
|
758
|
+
totalCostHbar
|
|
759
|
+
});
|
|
771
760
|
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
761
|
+
} catch (parseError) {
|
|
762
|
+
logger.warn(
|
|
763
|
+
"Could not parse transaction bytes, using totalCost fallback",
|
|
764
|
+
{
|
|
765
|
+
error: parseError,
|
|
766
|
+
errorMessage: parseError instanceof Error ? parseError.message : String(parseError)
|
|
776
767
|
}
|
|
777
|
-
|
|
778
|
-
}
|
|
768
|
+
);
|
|
779
769
|
}
|
|
780
|
-
return allTokens;
|
|
781
|
-
} catch (error) {
|
|
782
|
-
this.logger.error(
|
|
783
|
-
`Error fetching tokens for account ${accountId}: ${error.message}`
|
|
784
|
-
);
|
|
785
|
-
return null;
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Retrieves transaction details by consensus timestamp.
|
|
790
|
-
* @param timestamp The consensus timestamp of the transaction (e.g., "1629400000.000000000").
|
|
791
|
-
* @returns A promise that resolves to the transaction details or null.
|
|
792
|
-
*/
|
|
793
|
-
async getTransactionByTimestamp(timestamp) {
|
|
794
|
-
this.logger.info(`Getting transaction by timestamp: ${timestamp}`);
|
|
795
|
-
try {
|
|
796
|
-
const response = await this._requestWithRetry(`/api/v1/transactions?timestamp=${timestamp}&limit=1`);
|
|
797
|
-
return response.transactions;
|
|
798
|
-
} catch (error) {
|
|
799
|
-
this.logger.error(
|
|
800
|
-
`Error fetching transaction by timestamp ${timestamp}: ${error}`
|
|
801
|
-
);
|
|
802
|
-
return [];
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Retrieves NFTs for a given account ID, optionally filtered by token ID.
|
|
807
|
-
* @param accountId The ID of the account.
|
|
808
|
-
* @param tokenId Optional ID of the token to filter NFTs by.
|
|
809
|
-
* @param limit The maximum number of NFTs to return per page (API has its own max).
|
|
810
|
-
* @returns A promise that resolves to an array of NftDetail or null.
|
|
811
|
-
*/
|
|
812
|
-
async getAccountNfts(accountId, tokenId, limit = 100) {
|
|
813
|
-
this.logger.info(
|
|
814
|
-
`Getting NFTs for account ${accountId}${tokenId ? ` for token ${tokenId}` : ""}`
|
|
815
|
-
);
|
|
816
|
-
let allNfts = [];
|
|
817
|
-
let endpoint = `/api/v1/accounts/${accountId}/nfts?limit=${limit}`;
|
|
818
|
-
if (tokenId) {
|
|
819
|
-
endpoint += `&token.id=${tokenId}`;
|
|
820
770
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
let tokenUri = void 0;
|
|
827
|
-
if (nft.metadata) {
|
|
828
|
-
try {
|
|
829
|
-
if (this.isServerEnvironment) {
|
|
830
|
-
tokenUri = Buffer.from(nft.metadata, "base64").toString(
|
|
831
|
-
"utf-8"
|
|
832
|
-
);
|
|
833
|
-
} else {
|
|
834
|
-
tokenUri = new TextDecoder().decode(
|
|
835
|
-
Uint8Array.from(atob(nft.metadata), (c) => c.charCodeAt(0))
|
|
836
|
-
);
|
|
837
|
-
}
|
|
838
|
-
} catch (e) {
|
|
839
|
-
this.logger.warn(
|
|
840
|
-
`Failed to decode metadata for NFT ${nft.token_id} SN ${nft.serial_number}: ${e.message}`
|
|
841
|
-
);
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
return { ...nft, token_uri: tokenUri };
|
|
845
|
-
});
|
|
846
|
-
allNfts = allNfts.concat(nftsWithUri);
|
|
847
|
-
}
|
|
848
|
-
endpoint = response.links?.next || "";
|
|
849
|
-
if (!endpoint) break;
|
|
771
|
+
const transfers = [
|
|
772
|
+
{
|
|
773
|
+
to: "Inscription Service",
|
|
774
|
+
amount: totalCostHbar,
|
|
775
|
+
description: `Inscription fee (${totalCostHbar} HBAR)`
|
|
850
776
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
}
|
|
859
|
-
/**
|
|
860
|
-
* Validates NFT ownership by checking if a specific serial number of a token ID exists for an account.
|
|
861
|
-
* @param accountId The ID of the account.
|
|
862
|
-
* @param tokenId The ID of the NFT's token.
|
|
863
|
-
* @param serialNumber The serial number of the NFT.
|
|
864
|
-
* @returns A promise that resolves to the NftDetail if owned, or null otherwise.
|
|
865
|
-
*/
|
|
866
|
-
async validateNFTOwnership(accountId, tokenId, serialNumber) {
|
|
867
|
-
this.logger.info(
|
|
868
|
-
`Validating ownership of NFT ${tokenId} SN ${serialNumber} for account ${accountId}`
|
|
869
|
-
);
|
|
870
|
-
try {
|
|
871
|
-
const nfts = await this.getAccountNfts(accountId, tokenId);
|
|
872
|
-
if (nfts) {
|
|
873
|
-
const foundNft = nfts.find(
|
|
874
|
-
(nft) => nft.token_id === tokenId && nft.serial_number === serialNumber
|
|
875
|
-
);
|
|
876
|
-
return foundNft || null;
|
|
777
|
+
];
|
|
778
|
+
const validUntil = new Date(Date.now() + 15 * 60 * 1e3).toISOString();
|
|
779
|
+
const quote = {
|
|
780
|
+
totalCostHbar,
|
|
781
|
+
validUntil,
|
|
782
|
+
breakdown: {
|
|
783
|
+
transfers
|
|
877
784
|
}
|
|
878
|
-
return null;
|
|
879
|
-
} catch (error) {
|
|
880
|
-
this.logger.error(`Error validating NFT ownership: ${error.message}`);
|
|
881
|
-
return null;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
/**
|
|
885
|
-
* Performs a read-only query against a smart contract (eth_call like).
|
|
886
|
-
* @param contractIdOrAddress The contract ID (e.g., "0.0.123") or EVM address (e.g., "0x...").
|
|
887
|
-
* @param functionSelector The function selector and encoded parameters (e.g., "0xabcdef12...").
|
|
888
|
-
* @param payerAccountId The account ID of the payer (not strictly payer for read-only, but often required as 'from').
|
|
889
|
-
* @param estimate Whether this is an estimate call. Mirror node might not support this directly in /contracts/call for true estimation.
|
|
890
|
-
* @param block Block parameter, e.g., "latest", "pending", or block number.
|
|
891
|
-
* @param value The value in tinybars to send with the call (for payable view/pure functions, usually 0).
|
|
892
|
-
* @returns A promise that resolves to the contract call query response or null.
|
|
893
|
-
*/
|
|
894
|
-
async readSmartContractQuery(contractIdOrAddress, functionSelector, payerAccountId, options) {
|
|
895
|
-
this.logger.info(
|
|
896
|
-
`Reading smart contract ${contractIdOrAddress} with selector ${functionSelector}`
|
|
897
|
-
);
|
|
898
|
-
const toAddress = contractIdOrAddress.startsWith("0x") ? contractIdOrAddress : `0x${AccountId.fromString(contractIdOrAddress).toSolidityAddress()}`;
|
|
899
|
-
const fromAddress = payerAccountId.startsWith("0x") ? payerAccountId : `0x${AccountId.fromString(payerAccountId).toSolidityAddress()}`;
|
|
900
|
-
const body = {
|
|
901
|
-
block: options?.block || "latest",
|
|
902
|
-
data: functionSelector,
|
|
903
|
-
estimate: options?.estimate || false,
|
|
904
|
-
from: fromAddress,
|
|
905
|
-
to: toAddress,
|
|
906
|
-
gas: options?.gas,
|
|
907
|
-
gasPrice: options?.gasPrice,
|
|
908
|
-
value: options?.value || 0
|
|
909
785
|
};
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
786
|
+
logger.debug("Successfully parsed transaction for quote", {
|
|
787
|
+
totalCostHbar: quote.totalCostHbar,
|
|
788
|
+
transferCount: transfers.length,
|
|
789
|
+
hasTransactionBytes: !!inscriptionResponse.transactionBytes,
|
|
790
|
+
hasTotalCost: !!inscriptionResponse.totalCost
|
|
915
791
|
});
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
{
|
|
921
|
-
method: "POST",
|
|
922
|
-
body: JSON.stringify(body),
|
|
923
|
-
headers: {
|
|
924
|
-
"Content-Type": "application/json"
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
);
|
|
928
|
-
return response;
|
|
929
|
-
} catch (error) {
|
|
930
|
-
this.logger.error(
|
|
931
|
-
`Error reading smart contract ${contractIdOrAddress}: ${error.message}`
|
|
932
|
-
);
|
|
933
|
-
return null;
|
|
934
|
-
}
|
|
792
|
+
return quote;
|
|
793
|
+
} catch (error) {
|
|
794
|
+
logger.error("Error parsing transaction for quote", error);
|
|
795
|
+
throw error;
|
|
935
796
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
}
|
|
957
|
-
if (options?.serialNumber) {
|
|
958
|
-
params.append("serialnumber", options.serialNumber);
|
|
959
|
-
}
|
|
960
|
-
if (options?.tokenId) {
|
|
961
|
-
params.append("token.id", options.tokenId);
|
|
962
|
-
}
|
|
963
|
-
const queryString = params.toString();
|
|
964
|
-
if (queryString) {
|
|
965
|
-
endpoint += `?${queryString}`;
|
|
966
|
-
}
|
|
797
|
+
}
|
|
798
|
+
async function waitForInscriptionConfirmation(sdk, transactionId, maxAttempts = 450, intervalMs = 4e3, progressCallback) {
|
|
799
|
+
const logger = Logger.getInstance({ module: "Inscriber" });
|
|
800
|
+
const normalizedId = normalizeTransactionId(transactionId);
|
|
801
|
+
const progressReporter = new ProgressReporter({
|
|
802
|
+
module: "Inscriber",
|
|
803
|
+
logger,
|
|
804
|
+
callback: progressCallback
|
|
805
|
+
});
|
|
806
|
+
try {
|
|
807
|
+
logger.debug("Waiting for inscription confirmation", {
|
|
808
|
+
transactionId: normalizedId,
|
|
809
|
+
maxAttempts,
|
|
810
|
+
intervalMs
|
|
811
|
+
});
|
|
812
|
+
progressReporter.preparing("Preparing for inscription confirmation", 5, {
|
|
813
|
+
transactionId: normalizedId,
|
|
814
|
+
maxAttempts,
|
|
815
|
+
intervalMs
|
|
816
|
+
});
|
|
967
817
|
try {
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
818
|
+
const waitMethod = sdk.waitForInscription.bind(sdk);
|
|
819
|
+
const wrappedCallback = (data) => {
|
|
820
|
+
const stageRaw = data.stage || "confirming";
|
|
821
|
+
const allowedStages = [
|
|
822
|
+
"preparing",
|
|
823
|
+
"submitting",
|
|
824
|
+
"confirming",
|
|
825
|
+
"verifying",
|
|
826
|
+
"completed",
|
|
827
|
+
"failed"
|
|
828
|
+
];
|
|
829
|
+
const stage = allowedStages.includes(stageRaw) ? stageRaw : "confirming";
|
|
830
|
+
const message = data.message || "Processing inscription";
|
|
831
|
+
const percent = data.progressPercent || 50;
|
|
832
|
+
progressReporter.report({
|
|
833
|
+
stage,
|
|
834
|
+
message,
|
|
835
|
+
progressPercent: percent,
|
|
836
|
+
details: data.details
|
|
837
|
+
});
|
|
838
|
+
};
|
|
839
|
+
return await waitMethod(
|
|
840
|
+
normalizedId,
|
|
841
|
+
maxAttempts,
|
|
842
|
+
intervalMs,
|
|
843
|
+
true,
|
|
844
|
+
wrappedCallback
|
|
973
845
|
);
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
);
|
|
987
|
-
let endpoint = `/api/v1/accounts/${accountId}/airdrops/pending`;
|
|
988
|
-
const params = new URLSearchParams();
|
|
989
|
-
if (options?.limit) {
|
|
990
|
-
params.append("limit", options.limit.toString());
|
|
991
|
-
}
|
|
992
|
-
if (options?.order) {
|
|
993
|
-
params.append("order", options.order);
|
|
994
|
-
}
|
|
995
|
-
if (options?.senderId) {
|
|
996
|
-
params.append("sender.id", options.senderId);
|
|
997
|
-
}
|
|
998
|
-
if (options?.serialNumber) {
|
|
999
|
-
params.append("serialnumber", options.serialNumber);
|
|
1000
|
-
}
|
|
1001
|
-
if (options?.tokenId) {
|
|
1002
|
-
params.append("token.id", options.tokenId);
|
|
1003
|
-
}
|
|
1004
|
-
const queryString = params.toString();
|
|
1005
|
-
if (queryString) {
|
|
1006
|
-
endpoint += `?${queryString}`;
|
|
1007
|
-
}
|
|
1008
|
-
try {
|
|
1009
|
-
const response = await this._requestWithRetry(endpoint);
|
|
1010
|
-
return response.airdrops || [];
|
|
1011
|
-
} catch (error) {
|
|
1012
|
-
this.logger.error(
|
|
1013
|
-
`Error fetching pending token airdrops for account ${accountId}: ${error.message}`
|
|
846
|
+
} catch (e) {
|
|
847
|
+
logger.debug("Falling back to standard waitForInscription method", {
|
|
848
|
+
error: e
|
|
849
|
+
});
|
|
850
|
+
progressReporter.verifying("Verifying inscription status", 50, {
|
|
851
|
+
error: e
|
|
852
|
+
});
|
|
853
|
+
return await sdk.waitForInscription(
|
|
854
|
+
normalizedId,
|
|
855
|
+
maxAttempts,
|
|
856
|
+
intervalMs,
|
|
857
|
+
true
|
|
1014
858
|
);
|
|
1015
|
-
return null;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
/**
|
|
1019
|
-
* Retrieves blocks from the network.
|
|
1020
|
-
* @param options Optional parameters for filtering blocks.
|
|
1021
|
-
* @returns A promise that resolves to an array of Block or null.
|
|
1022
|
-
*/
|
|
1023
|
-
async getBlocks(options) {
|
|
1024
|
-
this.logger.info("Getting blocks from the network");
|
|
1025
|
-
let endpoint = `/api/v1/blocks`;
|
|
1026
|
-
const params = new URLSearchParams();
|
|
1027
|
-
if (options?.limit) {
|
|
1028
|
-
params.append("limit", options.limit.toString());
|
|
1029
|
-
}
|
|
1030
|
-
if (options?.order) {
|
|
1031
|
-
params.append("order", options.order);
|
|
1032
|
-
}
|
|
1033
|
-
if (options?.timestamp) {
|
|
1034
|
-
params.append("timestamp", options.timestamp);
|
|
1035
|
-
}
|
|
1036
|
-
if (options?.blockNumber) {
|
|
1037
|
-
params.append("block.number", options.blockNumber);
|
|
1038
|
-
}
|
|
1039
|
-
const queryString = params.toString();
|
|
1040
|
-
if (queryString) {
|
|
1041
|
-
endpoint += `?${queryString}`;
|
|
1042
|
-
}
|
|
1043
|
-
try {
|
|
1044
|
-
const response = await this._requestWithRetry(endpoint);
|
|
1045
|
-
return response.blocks || [];
|
|
1046
|
-
} catch (error) {
|
|
1047
|
-
this.logger.error(`Error fetching blocks: ${error.message}`);
|
|
1048
|
-
return null;
|
|
1049
859
|
}
|
|
860
|
+
} catch (error) {
|
|
861
|
+
logger.error("Error waiting for inscription confirmation", {
|
|
862
|
+
transactionId,
|
|
863
|
+
maxAttempts,
|
|
864
|
+
intervalMs,
|
|
865
|
+
error
|
|
866
|
+
});
|
|
867
|
+
progressReporter.failed("Inscription confirmation failed", {
|
|
868
|
+
transactionId,
|
|
869
|
+
error
|
|
870
|
+
});
|
|
871
|
+
throw error;
|
|
1050
872
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
);
|
|
1062
|
-
return response;
|
|
1063
|
-
} catch (error) {
|
|
1064
|
-
this.logger.error(
|
|
1065
|
-
`Error fetching block ${blockNumberOrHash}: ${error.message}`
|
|
1066
|
-
);
|
|
1067
|
-
return null;
|
|
1068
|
-
}
|
|
873
|
+
}
|
|
874
|
+
const DEFAULT_REGISTRY_BROKER_URL = "https://hol.org/registry/api/v1";
|
|
875
|
+
const DEFAULT_POLL_INTERVAL_MS = 2e3;
|
|
876
|
+
const DEFAULT_WAIT_TIMEOUT_MS = 12e4;
|
|
877
|
+
async function fetchRegistryBroker(url, options) {
|
|
878
|
+
const response = await fetch(url, options);
|
|
879
|
+
const body = await response.json().catch(() => ({}));
|
|
880
|
+
if (!response.ok) {
|
|
881
|
+
const errorMessage = typeof body === "object" && body && "error" in body ? String(body.error) : `HTTP ${response.status}`;
|
|
882
|
+
throw new Error(errorMessage);
|
|
1069
883
|
}
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
const response = await this._requestWithRetry(url);
|
|
1094
|
-
return response.contracts || [];
|
|
1095
|
-
} catch (error) {
|
|
1096
|
-
this.logger.error(`Error fetching contracts: ${error.message}`);
|
|
1097
|
-
return null;
|
|
1098
|
-
}
|
|
884
|
+
return body;
|
|
885
|
+
}
|
|
886
|
+
async function inscribeViaRegistryBroker(input, options = {}) {
|
|
887
|
+
const logger = Logger.getInstance({
|
|
888
|
+
module: "InscribeViaBroker",
|
|
889
|
+
...options.logging
|
|
890
|
+
});
|
|
891
|
+
const baseUrl = options.baseUrl ?? DEFAULT_REGISTRY_BROKER_URL;
|
|
892
|
+
const waitForConfirmation = options.waitForConfirmation ?? true;
|
|
893
|
+
const waitTimeoutMs = options.waitTimeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS;
|
|
894
|
+
const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
895
|
+
const headers = {
|
|
896
|
+
"Content-Type": "application/json",
|
|
897
|
+
Accept: "application/json"
|
|
898
|
+
};
|
|
899
|
+
if (options.ledgerApiKey) {
|
|
900
|
+
headers["x-api-key"] = options.ledgerApiKey;
|
|
901
|
+
} else if (options.apiKey) {
|
|
902
|
+
headers["x-api-key"] = options.apiKey;
|
|
903
|
+
} else {
|
|
904
|
+
throw new Error(
|
|
905
|
+
"Either ledgerApiKey or apiKey is required for Registry Broker inscription"
|
|
906
|
+
);
|
|
1099
907
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
const
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
908
|
+
logger.info("Starting inscription via Registry Broker", {
|
|
909
|
+
baseUrl,
|
|
910
|
+
inputType: input.type,
|
|
911
|
+
mode: options.mode ?? "file"
|
|
912
|
+
});
|
|
913
|
+
let base64Content;
|
|
914
|
+
let fileName;
|
|
915
|
+
let mimeType;
|
|
916
|
+
switch (input.type) {
|
|
917
|
+
case "url":
|
|
918
|
+
logger.debug("Creating job with URL input");
|
|
919
|
+
break;
|
|
920
|
+
case "file": {
|
|
921
|
+
const fileData = await convertFileToBase64(input.path);
|
|
922
|
+
base64Content = fileData.base64;
|
|
923
|
+
fileName = fileData.fileName;
|
|
924
|
+
mimeType = fileData.mimeType;
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
case "buffer":
|
|
928
|
+
base64Content = Buffer.from(
|
|
929
|
+
input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
|
|
930
|
+
).toString("base64");
|
|
931
|
+
fileName = input.fileName;
|
|
932
|
+
mimeType = input.mimeType;
|
|
933
|
+
break;
|
|
1121
934
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
if (
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1134
|
-
if (options?.blockHash) {
|
|
1135
|
-
params.append("block.hash", options.blockHash);
|
|
1136
|
-
}
|
|
1137
|
-
if (options?.blockNumber) {
|
|
1138
|
-
params.append("block.number", options.blockNumber);
|
|
1139
|
-
}
|
|
1140
|
-
if (options?.internal !== void 0) {
|
|
1141
|
-
params.append("internal", options.internal.toString());
|
|
1142
|
-
}
|
|
1143
|
-
if (options?.limit) {
|
|
1144
|
-
params.append("limit", options.limit.toString());
|
|
1145
|
-
}
|
|
1146
|
-
if (options?.order) {
|
|
1147
|
-
params.append("order", options.order);
|
|
1148
|
-
}
|
|
1149
|
-
if (options?.timestamp) {
|
|
1150
|
-
params.append("timestamp", options.timestamp);
|
|
1151
|
-
}
|
|
1152
|
-
if (options?.transactionIndex) {
|
|
1153
|
-
params.append("transaction.index", options.transactionIndex.toString());
|
|
1154
|
-
}
|
|
1155
|
-
const queryString = params.toString();
|
|
1156
|
-
if (queryString) {
|
|
1157
|
-
url += `?${queryString}`;
|
|
1158
|
-
}
|
|
1159
|
-
try {
|
|
1160
|
-
const response = await this._requestWithRetry(url);
|
|
1161
|
-
return response.results || [];
|
|
1162
|
-
} catch (error) {
|
|
1163
|
-
this.logger.error(`Error fetching contract results: ${error.message}`);
|
|
1164
|
-
return null;
|
|
935
|
+
const requestBody = {
|
|
936
|
+
inputType: input.type === "url" ? "url" : "base64",
|
|
937
|
+
mode: options.mode ?? "file"
|
|
938
|
+
};
|
|
939
|
+
if (input.type === "url") {
|
|
940
|
+
requestBody.url = input.url;
|
|
941
|
+
} else {
|
|
942
|
+
requestBody.base64 = base64Content;
|
|
943
|
+
requestBody.fileName = fileName;
|
|
944
|
+
if (mimeType) {
|
|
945
|
+
requestBody.mimeType = mimeType;
|
|
1165
946
|
}
|
|
1166
947
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
* @param transactionIdOrHash The transaction ID or hash.
|
|
1170
|
-
* @param nonce Optional nonce filter.
|
|
1171
|
-
* @returns A promise that resolves to a ContractResult or null.
|
|
1172
|
-
*/
|
|
1173
|
-
async getContractResult(transactionIdOrHash, nonce) {
|
|
1174
|
-
this.logger.info(`Getting contract result for ${transactionIdOrHash}`);
|
|
1175
|
-
let url = `/api/v1/contracts/results/${transactionIdOrHash}`;
|
|
1176
|
-
if (nonce !== void 0) {
|
|
1177
|
-
url += `?nonce=${nonce}`;
|
|
1178
|
-
}
|
|
1179
|
-
try {
|
|
1180
|
-
const response = await this._requestWithRetry(url);
|
|
1181
|
-
return response;
|
|
1182
|
-
} catch (error) {
|
|
1183
|
-
this.logger.error(
|
|
1184
|
-
`Error fetching contract result for ${transactionIdOrHash}: ${error.message}`
|
|
1185
|
-
);
|
|
1186
|
-
return null;
|
|
1187
|
-
}
|
|
948
|
+
if (options.metadata) {
|
|
949
|
+
requestBody.metadata = options.metadata;
|
|
1188
950
|
}
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
* @param contractIdOrAddress The contract ID or EVM address.
|
|
1192
|
-
* @param options Optional parameters for filtering.
|
|
1193
|
-
* @returns A promise that resolves to an array of ContractResult or null.
|
|
1194
|
-
*/
|
|
1195
|
-
async getContractResultsByContract(contractIdOrAddress, options) {
|
|
1196
|
-
this.logger.info(
|
|
1197
|
-
`Getting contract results for contract ${contractIdOrAddress}`
|
|
1198
|
-
);
|
|
1199
|
-
let url = `/api/v1/contracts/${contractIdOrAddress}/results`;
|
|
1200
|
-
const params = new URLSearchParams();
|
|
1201
|
-
if (options?.blockHash) {
|
|
1202
|
-
params.append("block.hash", options.blockHash);
|
|
1203
|
-
}
|
|
1204
|
-
if (options?.blockNumber) {
|
|
1205
|
-
params.append("block.number", options.blockNumber);
|
|
1206
|
-
}
|
|
1207
|
-
if (options?.from) {
|
|
1208
|
-
params.append("from", options.from);
|
|
1209
|
-
}
|
|
1210
|
-
if (options?.internal !== void 0) {
|
|
1211
|
-
params.append("internal", options.internal.toString());
|
|
1212
|
-
}
|
|
1213
|
-
if (options?.limit) {
|
|
1214
|
-
params.append("limit", options.limit.toString());
|
|
1215
|
-
}
|
|
1216
|
-
if (options?.order) {
|
|
1217
|
-
params.append("order", options.order);
|
|
1218
|
-
}
|
|
1219
|
-
if (options?.timestamp) {
|
|
1220
|
-
params.append("timestamp", options.timestamp);
|
|
1221
|
-
}
|
|
1222
|
-
if (options?.transactionIndex) {
|
|
1223
|
-
params.append("transaction.index", options.transactionIndex.toString());
|
|
1224
|
-
}
|
|
1225
|
-
const queryString = params.toString();
|
|
1226
|
-
if (queryString) {
|
|
1227
|
-
url += `?${queryString}`;
|
|
1228
|
-
}
|
|
1229
|
-
try {
|
|
1230
|
-
const response = await this._requestWithRetry(url);
|
|
1231
|
-
return response.results || [];
|
|
1232
|
-
} catch (error) {
|
|
1233
|
-
this.logger.error(
|
|
1234
|
-
`Error fetching contract results for ${contractIdOrAddress}: ${error.message}`
|
|
1235
|
-
);
|
|
1236
|
-
return null;
|
|
1237
|
-
}
|
|
951
|
+
if (options.tags) {
|
|
952
|
+
requestBody.tags = options.tags;
|
|
1238
953
|
}
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
* @param contractIdOrAddress The contract ID or EVM address.
|
|
1242
|
-
* @param options Optional parameters for filtering.
|
|
1243
|
-
* @returns A promise that resolves to an array of ContractState or null.
|
|
1244
|
-
*/
|
|
1245
|
-
async getContractState(contractIdOrAddress, options) {
|
|
1246
|
-
this.logger.info(`Getting contract state for ${contractIdOrAddress}`);
|
|
1247
|
-
let url = `/api/v1/contracts/${contractIdOrAddress}/state`;
|
|
1248
|
-
const params = new URLSearchParams();
|
|
1249
|
-
if (options?.limit) {
|
|
1250
|
-
params.append("limit", options.limit.toString());
|
|
1251
|
-
}
|
|
1252
|
-
if (options?.order) {
|
|
1253
|
-
params.append("order", options.order);
|
|
1254
|
-
}
|
|
1255
|
-
if (options?.slot) {
|
|
1256
|
-
params.append("slot", options.slot);
|
|
1257
|
-
}
|
|
1258
|
-
if (options?.timestamp) {
|
|
1259
|
-
params.append("timestamp", options.timestamp);
|
|
1260
|
-
}
|
|
1261
|
-
const queryString = params.toString();
|
|
1262
|
-
if (queryString) {
|
|
1263
|
-
url += `?${queryString}`;
|
|
1264
|
-
}
|
|
1265
|
-
try {
|
|
1266
|
-
const response = await this._requestWithRetry(url);
|
|
1267
|
-
return response.state || [];
|
|
1268
|
-
} catch (error) {
|
|
1269
|
-
this.logger.error(
|
|
1270
|
-
`Error fetching contract state for ${contractIdOrAddress}: ${error.message}`
|
|
1271
|
-
);
|
|
1272
|
-
return null;
|
|
1273
|
-
}
|
|
954
|
+
if (options.fileStandard) {
|
|
955
|
+
requestBody.fileStandard = options.fileStandard;
|
|
1274
956
|
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
* @param transactionIdOrHash The transaction ID or hash.
|
|
1278
|
-
* @param options Optional parameters for filtering.
|
|
1279
|
-
* @returns A promise that resolves to an array of ContractAction or null.
|
|
1280
|
-
*/
|
|
1281
|
-
async getContractActions(transactionIdOrHash, options) {
|
|
1282
|
-
this.logger.info(`Getting contract actions for ${transactionIdOrHash}`);
|
|
1283
|
-
let url = `/api/v1/contracts/results/${transactionIdOrHash}/actions`;
|
|
1284
|
-
const params = new URLSearchParams();
|
|
1285
|
-
if (options?.index) {
|
|
1286
|
-
params.append("index", options.index);
|
|
1287
|
-
}
|
|
1288
|
-
if (options?.limit) {
|
|
1289
|
-
params.append("limit", options.limit.toString());
|
|
1290
|
-
}
|
|
1291
|
-
if (options?.order) {
|
|
1292
|
-
params.append("order", options.order);
|
|
1293
|
-
}
|
|
1294
|
-
const queryString = params.toString();
|
|
1295
|
-
if (queryString) {
|
|
1296
|
-
url += `?${queryString}`;
|
|
1297
|
-
}
|
|
1298
|
-
try {
|
|
1299
|
-
const response = await this._requestWithRetry(url);
|
|
1300
|
-
return response.actions || [];
|
|
1301
|
-
} catch (error) {
|
|
1302
|
-
this.logger.error(
|
|
1303
|
-
`Error fetching contract actions for ${transactionIdOrHash}: ${error.message}`
|
|
1304
|
-
);
|
|
1305
|
-
return null;
|
|
1306
|
-
}
|
|
957
|
+
if (options.chunkSize) {
|
|
958
|
+
requestBody.chunkSize = options.chunkSize;
|
|
1307
959
|
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
}
|
|
1332
|
-
if (options?.topic1) {
|
|
1333
|
-
params.append("topic1", options.topic1);
|
|
1334
|
-
}
|
|
1335
|
-
if (options?.topic2) {
|
|
1336
|
-
params.append("topic2", options.topic2);
|
|
1337
|
-
}
|
|
1338
|
-
if (options?.topic3) {
|
|
1339
|
-
params.append("topic3", options.topic3);
|
|
1340
|
-
}
|
|
1341
|
-
if (options?.transactionHash) {
|
|
1342
|
-
params.append("transaction.hash", options.transactionHash);
|
|
1343
|
-
}
|
|
1344
|
-
const queryString = params.toString();
|
|
1345
|
-
if (queryString) {
|
|
1346
|
-
url += `?${queryString}`;
|
|
1347
|
-
}
|
|
1348
|
-
try {
|
|
1349
|
-
const response = await this._requestWithRetry(url);
|
|
1350
|
-
return response.logs || [];
|
|
1351
|
-
} catch (error) {
|
|
1352
|
-
this.logger.error(`Error fetching contract logs: ${error.message}`);
|
|
1353
|
-
return null;
|
|
1354
|
-
}
|
|
960
|
+
logger.debug("Creating inscription job");
|
|
961
|
+
const job = await fetchRegistryBroker(
|
|
962
|
+
`${baseUrl}/inscribe/content`,
|
|
963
|
+
{
|
|
964
|
+
method: "POST",
|
|
965
|
+
headers,
|
|
966
|
+
body: JSON.stringify(requestBody)
|
|
967
|
+
}
|
|
968
|
+
);
|
|
969
|
+
const jobId = job.jobId ?? job.id ?? "";
|
|
970
|
+
logger.info("Inscription job created", { jobId, status: job.status });
|
|
971
|
+
if (!waitForConfirmation) {
|
|
972
|
+
return {
|
|
973
|
+
confirmed: false,
|
|
974
|
+
jobId,
|
|
975
|
+
status: job.status,
|
|
976
|
+
credits: job.credits ?? job.quoteCredits,
|
|
977
|
+
usdCents: job.usdCents ?? job.quoteUsdCents,
|
|
978
|
+
sizeBytes: job.sizeBytes,
|
|
979
|
+
createdAt: job.createdAt,
|
|
980
|
+
updatedAt: job.updatedAt,
|
|
981
|
+
network: job.network
|
|
982
|
+
};
|
|
1355
983
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
this.logger.info(
|
|
1364
|
-
`Getting contract logs for contract ${contractIdOrAddress}`
|
|
984
|
+
logger.debug("Polling for job completion", { jobId, waitTimeoutMs });
|
|
985
|
+
const startTime = Date.now();
|
|
986
|
+
let lastStatus = "";
|
|
987
|
+
while (Date.now() - startTime < waitTimeoutMs) {
|
|
988
|
+
const currentJob = await fetchRegistryBroker(
|
|
989
|
+
`${baseUrl}/inscribe/content/${jobId}`,
|
|
990
|
+
{ method: "GET", headers }
|
|
1365
991
|
);
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
if (options?.topic3) {
|
|
1390
|
-
params.append("topic3", options.topic3);
|
|
1391
|
-
}
|
|
1392
|
-
const queryString = params.toString();
|
|
1393
|
-
if (queryString) {
|
|
1394
|
-
url += `?${queryString}`;
|
|
992
|
+
if (currentJob.status !== lastStatus) {
|
|
993
|
+
logger.debug("Job status update", { jobId, status: currentJob.status });
|
|
994
|
+
lastStatus = currentJob.status;
|
|
995
|
+
}
|
|
996
|
+
if (currentJob.status === "completed") {
|
|
997
|
+
logger.info("Inscription completed", {
|
|
998
|
+
jobId,
|
|
999
|
+
hrl: currentJob.hrl,
|
|
1000
|
+
topicId: currentJob.topicId
|
|
1001
|
+
});
|
|
1002
|
+
return {
|
|
1003
|
+
confirmed: true,
|
|
1004
|
+
jobId,
|
|
1005
|
+
status: currentJob.status,
|
|
1006
|
+
hrl: currentJob.hrl,
|
|
1007
|
+
topicId: currentJob.topicId,
|
|
1008
|
+
network: currentJob.network,
|
|
1009
|
+
credits: currentJob.credits ?? currentJob.quoteCredits,
|
|
1010
|
+
usdCents: currentJob.usdCents ?? currentJob.quoteUsdCents,
|
|
1011
|
+
sizeBytes: currentJob.sizeBytes,
|
|
1012
|
+
createdAt: currentJob.createdAt,
|
|
1013
|
+
updatedAt: currentJob.updatedAt
|
|
1014
|
+
};
|
|
1395
1015
|
}
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
return
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1016
|
+
if (currentJob.status === "failed") {
|
|
1017
|
+
logger.error("Inscription failed", { jobId, error: currentJob.error });
|
|
1018
|
+
return {
|
|
1019
|
+
confirmed: false,
|
|
1020
|
+
jobId,
|
|
1021
|
+
status: currentJob.status,
|
|
1022
|
+
error: currentJob.error ?? "Inscription failed",
|
|
1023
|
+
credits: currentJob.credits ?? currentJob.quoteCredits,
|
|
1024
|
+
createdAt: currentJob.createdAt,
|
|
1025
|
+
updatedAt: currentJob.updatedAt
|
|
1026
|
+
};
|
|
1404
1027
|
}
|
|
1028
|
+
await sleep(pollIntervalMs);
|
|
1405
1029
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1030
|
+
throw new Error(
|
|
1031
|
+
`Inscription job ${jobId} did not complete within ${waitTimeoutMs}ms`
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
async function getRegistryBrokerQuote(input, options = {}) {
|
|
1035
|
+
const logger = Logger.getInstance({
|
|
1036
|
+
module: "InscribeViaBroker",
|
|
1037
|
+
...options.logging
|
|
1038
|
+
});
|
|
1039
|
+
const baseUrl = options.baseUrl ?? DEFAULT_REGISTRY_BROKER_URL;
|
|
1040
|
+
const headers = {
|
|
1041
|
+
"Content-Type": "application/json",
|
|
1042
|
+
Accept: "application/json"
|
|
1043
|
+
};
|
|
1044
|
+
if (options.ledgerApiKey) {
|
|
1045
|
+
headers["x-api-key"] = options.ledgerApiKey;
|
|
1046
|
+
} else if (options.apiKey) {
|
|
1047
|
+
headers["x-api-key"] = options.apiKey;
|
|
1048
|
+
} else {
|
|
1049
|
+
throw new Error(
|
|
1050
|
+
"Either ledgerApiKey or apiKey is required for Registry Broker quotes"
|
|
1051
|
+
);
|
|
1424
1052
|
}
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
params.append("serialnumber", options.serialNumber);
|
|
1446
|
-
}
|
|
1447
|
-
const queryString = params.toString();
|
|
1448
|
-
if (queryString) {
|
|
1449
|
-
url += `?${queryString}`;
|
|
1450
|
-
}
|
|
1451
|
-
try {
|
|
1452
|
-
const response = await this._requestWithRetry(url);
|
|
1453
|
-
return response.nfts || [];
|
|
1454
|
-
} catch (error) {
|
|
1455
|
-
this.logger.error(
|
|
1456
|
-
`Error fetching NFTs for token ${tokenId}: ${error.message}`
|
|
1457
|
-
);
|
|
1458
|
-
return null;
|
|
1459
|
-
}
|
|
1053
|
+
let base64Content;
|
|
1054
|
+
let fileName;
|
|
1055
|
+
let mimeType;
|
|
1056
|
+
switch (input.type) {
|
|
1057
|
+
case "url":
|
|
1058
|
+
break;
|
|
1059
|
+
case "file": {
|
|
1060
|
+
const fileData = await convertFileToBase64(input.path);
|
|
1061
|
+
base64Content = fileData.base64;
|
|
1062
|
+
fileName = fileData.fileName;
|
|
1063
|
+
mimeType = fileData.mimeType;
|
|
1064
|
+
break;
|
|
1065
|
+
}
|
|
1066
|
+
case "buffer":
|
|
1067
|
+
base64Content = Buffer.from(
|
|
1068
|
+
input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
|
|
1069
|
+
).toString("base64");
|
|
1070
|
+
fileName = input.fileName;
|
|
1071
|
+
mimeType = input.mimeType;
|
|
1072
|
+
break;
|
|
1460
1073
|
}
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
this.logger.error(`Error fetching network info: ${error.message}`);
|
|
1473
|
-
return null;
|
|
1074
|
+
const requestBody = {
|
|
1075
|
+
inputType: input.type === "url" ? "url" : "base64",
|
|
1076
|
+
mode: options.mode ?? "file"
|
|
1077
|
+
};
|
|
1078
|
+
if (input.type === "url") {
|
|
1079
|
+
requestBody.url = input.url;
|
|
1080
|
+
} else {
|
|
1081
|
+
requestBody.base64 = base64Content;
|
|
1082
|
+
requestBody.fileName = fileName;
|
|
1083
|
+
if (mimeType) {
|
|
1084
|
+
requestBody.mimeType = mimeType;
|
|
1474
1085
|
}
|
|
1475
1086
|
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
* @param timestamp Optional timestamp for historical fees.
|
|
1479
|
-
* @returns A promise that resolves to NetworkFees or null.
|
|
1480
|
-
*/
|
|
1481
|
-
async getNetworkFees(timestamp) {
|
|
1482
|
-
this.logger.info("Getting network fees");
|
|
1483
|
-
let url = `/api/v1/network/fees`;
|
|
1484
|
-
if (timestamp) {
|
|
1485
|
-
url += `?timestamp=${timestamp}`;
|
|
1486
|
-
}
|
|
1487
|
-
try {
|
|
1488
|
-
const response = await this._requestWithRetry(url);
|
|
1489
|
-
return response;
|
|
1490
|
-
} catch (error) {
|
|
1491
|
-
this.logger.error(`Error fetching network fees: ${error.message}`);
|
|
1492
|
-
return null;
|
|
1493
|
-
}
|
|
1087
|
+
if (options.metadata) {
|
|
1088
|
+
requestBody.metadata = options.metadata;
|
|
1494
1089
|
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
* @param timestamp Optional timestamp for historical supply data.
|
|
1498
|
-
* @returns A promise that resolves to NetworkSupply or null.
|
|
1499
|
-
*/
|
|
1500
|
-
async getNetworkSupply(timestamp) {
|
|
1501
|
-
this.logger.info("Getting network supply");
|
|
1502
|
-
let url = `/api/v1/network/supply`;
|
|
1503
|
-
if (timestamp) {
|
|
1504
|
-
url += `?timestamp=${timestamp}`;
|
|
1505
|
-
}
|
|
1506
|
-
try {
|
|
1507
|
-
const response = await this._requestWithRetry(url);
|
|
1508
|
-
return response;
|
|
1509
|
-
} catch (error) {
|
|
1510
|
-
this.logger.error(`Error fetching network supply: ${error.message}`);
|
|
1511
|
-
return null;
|
|
1512
|
-
}
|
|
1090
|
+
if (options.tags) {
|
|
1091
|
+
requestBody.tags = options.tags;
|
|
1513
1092
|
}
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
* @param timestamp Optional timestamp for historical stake data.
|
|
1517
|
-
* @returns A promise that resolves to NetworkStake or null.
|
|
1518
|
-
*/
|
|
1519
|
-
async getNetworkStake(timestamp) {
|
|
1520
|
-
this.logger.info("Getting network stake");
|
|
1521
|
-
let url = `/api/v1/network/stake`;
|
|
1522
|
-
if (timestamp) {
|
|
1523
|
-
url += `?timestamp=${timestamp}`;
|
|
1524
|
-
}
|
|
1525
|
-
try {
|
|
1526
|
-
const response = await this._requestWithRetry(url);
|
|
1527
|
-
return response;
|
|
1528
|
-
} catch (error) {
|
|
1529
|
-
this.logger.error(`Error fetching network stake: ${error.message}`);
|
|
1530
|
-
return null;
|
|
1531
|
-
}
|
|
1093
|
+
if (options.fileStandard) {
|
|
1094
|
+
requestBody.fileStandard = options.fileStandard;
|
|
1532
1095
|
}
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
* @param transactionIdOrHash The transaction ID or hash.
|
|
1536
|
-
* @param options Optional parameters for trace details.
|
|
1537
|
-
* @returns A promise that resolves to an OpcodesResponse or null.
|
|
1538
|
-
*/
|
|
1539
|
-
async getOpcodeTraces(transactionIdOrHash, options) {
|
|
1540
|
-
this.logger.info(`Getting opcode traces for ${transactionIdOrHash}`);
|
|
1541
|
-
let url = `/api/v1/contracts/results/${transactionIdOrHash}/opcodes`;
|
|
1542
|
-
const params = new URLSearchParams();
|
|
1543
|
-
if (options?.stack !== void 0) {
|
|
1544
|
-
params.append("stack", options.stack.toString());
|
|
1545
|
-
}
|
|
1546
|
-
if (options?.memory !== void 0) {
|
|
1547
|
-
params.append("memory", options.memory.toString());
|
|
1548
|
-
}
|
|
1549
|
-
if (options?.storage !== void 0) {
|
|
1550
|
-
params.append("storage", options.storage.toString());
|
|
1551
|
-
}
|
|
1552
|
-
const queryString = params.toString();
|
|
1553
|
-
if (queryString) {
|
|
1554
|
-
url += `?${queryString}`;
|
|
1555
|
-
}
|
|
1556
|
-
try {
|
|
1557
|
-
const response = await this._requestWithRetry(url);
|
|
1558
|
-
return response;
|
|
1559
|
-
} catch (error) {
|
|
1560
|
-
this.logger.error(
|
|
1561
|
-
`Error fetching opcode traces for ${transactionIdOrHash}: ${error.message}`
|
|
1562
|
-
);
|
|
1563
|
-
return null;
|
|
1564
|
-
}
|
|
1096
|
+
if (options.chunkSize) {
|
|
1097
|
+
requestBody.chunkSize = options.chunkSize;
|
|
1565
1098
|
}
|
|
1099
|
+
logger.debug("Getting inscription quote from Registry Broker");
|
|
1100
|
+
return fetchRegistryBroker(
|
|
1101
|
+
`${baseUrl}/inscribe/content/quote`,
|
|
1102
|
+
{
|
|
1103
|
+
method: "POST",
|
|
1104
|
+
headers,
|
|
1105
|
+
body: JSON.stringify(requestBody)
|
|
1106
|
+
}
|
|
1107
|
+
);
|
|
1566
1108
|
}
|
|
1567
1109
|
export {
|
|
1568
|
-
|
|
1110
|
+
generateQuote,
|
|
1111
|
+
getRegistryBrokerQuote,
|
|
1112
|
+
inscribe,
|
|
1113
|
+
inscribeViaRegistryBroker,
|
|
1114
|
+
inscribeWithSigner,
|
|
1115
|
+
normalizeTransactionId,
|
|
1116
|
+
retrieveInscription,
|
|
1117
|
+
waitForInscriptionConfirmation
|
|
1569
1118
|
};
|
|
1570
1119
|
//# sourceMappingURL=standards-sdk.es137.js.map
|