@exodus/sui-api 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,71 +0,0 @@
1
- // Copyright (c) Mysten Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { JsonRpcError, SuiHTTPStatusError } from './errors.js'
5
-
6
- export const PACKAGE_VERSION = '1.36.1'
7
- export const TARGETED_RPC_VERSION = '1.55.0'
8
-
9
- /**
10
- * An object defining headers to be passed to the RPC server
11
- */
12
-
13
- export class SuiHTTPTransport {
14
- #requestId = 0
15
- #options
16
-
17
- constructor(options) {
18
- this.#options = options
19
- }
20
-
21
- fetch(input, init) {
22
- const fetchFn = this.#options.fetch ?? fetch
23
-
24
- if (!fetchFn) {
25
- throw new Error(
26
- 'The current environment does not support fetch, you can provide a fetch implementation in the options for SuiHTTPTransport.'
27
- )
28
- }
29
-
30
- return fetchFn(input, init)
31
- }
32
-
33
- async request(input) {
34
- this.#requestId += 1
35
-
36
- const res = await this.fetch(this.#options.rpc?.url ?? this.#options.url, {
37
- method: 'POST',
38
- signal: input.signal,
39
- headers: {
40
- 'Content-Type': 'application/json',
41
- 'Client-Sdk-Type': 'typescript',
42
- 'Client-Sdk-Version': PACKAGE_VERSION,
43
- 'Client-Target-Api-Version': TARGETED_RPC_VERSION,
44
- 'Client-Request-Method': input.method,
45
- ...this.#options.rpc?.headers,
46
- },
47
- body: JSON.stringify({
48
- jsonrpc: '2.0',
49
- id: this.#requestId,
50
- method: input.method,
51
- params: input.params,
52
- }),
53
- })
54
-
55
- if (!res.ok) {
56
- throw new SuiHTTPStatusError(
57
- `Unexpected status code: ${res.status}`,
58
- res.status,
59
- res.statusText
60
- )
61
- }
62
-
63
- const data = await res.json()
64
-
65
- if ('error' in data && data.error != null) {
66
- throw new JsonRpcError(data.error.message, data.error.code)
67
- }
68
-
69
- return data.result
70
- }
71
- }
@@ -1 +0,0 @@
1
- export { SuiClient } from './client.js'
@@ -1,90 +0,0 @@
1
- /* eslint-disable no-sequences */
2
- var __typeError = (msg) => {
3
- throw new TypeError(msg)
4
- }
5
-
6
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError('Cannot ' + msg)
7
- var __privateGet = (obj, member, getter) => (
8
- __accessCheck(obj, member, 'read from private field'),
9
- getter ? getter.call(obj) : member.get(obj)
10
- )
11
- var __privateAdd = (obj, member, value) =>
12
- member.has(obj)
13
- ? __typeError('Cannot add the same private member more than once')
14
- : member instanceof WeakSet
15
- ? member.add(obj)
16
- : member.set(obj, value)
17
- var __privateSet = (obj, member, value, setter) => (
18
- __accessCheck(obj, member, 'write to private field'),
19
- setter ? setter.call(obj, value) : member.set(obj, value),
20
- value
21
- )
22
- var _prefix, _cache
23
- const _ClientCache = class _ClientCache {
24
- constructor({ prefix, cache } = Object.create(null)) {
25
- __privateAdd(this, _prefix)
26
- __privateAdd(this, _cache)
27
- __privateSet(this, _prefix, prefix ?? [])
28
- __privateSet(this, _cache, cache ?? /* @__PURE__ */ new Map())
29
- }
30
-
31
- read(key, load) {
32
- const cacheKey = [__privateGet(this, _prefix), ...key].join(':')
33
- if (__privateGet(this, _cache).has(cacheKey)) {
34
- return __privateGet(this, _cache).get(cacheKey)
35
- }
36
-
37
- const result = load()
38
- __privateGet(this, _cache).set(cacheKey, result)
39
- if (typeof result === 'object' && result !== null && result.hasOwnProperty('then')) {
40
- return Promise.resolve(result)
41
- .then((v) => {
42
- __privateGet(this, _cache).set(cacheKey, v)
43
- return v
44
- })
45
- .catch((err) => {
46
- __privateGet(this, _cache).delete(cacheKey)
47
- throw err
48
- })
49
- }
50
-
51
- return result
52
- }
53
-
54
- readSync(key, load) {
55
- const cacheKey = [__privateGet(this, _prefix), ...key].join(':')
56
- if (__privateGet(this, _cache).has(cacheKey)) {
57
- return __privateGet(this, _cache).get(cacheKey)
58
- }
59
-
60
- const result = load()
61
- __privateGet(this, _cache).set(cacheKey, result)
62
- return result
63
- }
64
-
65
- clear(prefix) {
66
- const prefixKey = [...__privateGet(this, _prefix), ...(prefix ?? [])].join(':')
67
- if (!prefixKey) {
68
- __privateGet(this, _cache).clear()
69
- return
70
- }
71
-
72
- for (const key of __privateGet(this, _cache).keys()) {
73
- if (key.startsWith(prefixKey)) {
74
- __privateGet(this, _cache).delete(key)
75
- }
76
- }
77
- }
78
-
79
- scope(prefix) {
80
- return new _ClientCache({
81
- prefix: [...__privateGet(this, _prefix), ...(Array.isArray(prefix) ? prefix : [prefix])],
82
- cache: __privateGet(this, _cache),
83
- })
84
- }
85
- }
86
- _prefix = new WeakMap()
87
- _cache = new WeakMap()
88
- const ClientCache = _ClientCache
89
- export { ClientCache }
90
- // # sourceMappingURL=cache.js.map
@@ -1,27 +0,0 @@
1
- /* eslint-disable camelcase */
2
- import { ClientCache } from './cache.js'
3
-
4
- class Experimental_BaseClient {
5
- constructor({ network, base }) {
6
- this.network = network
7
- this.base = base ?? this
8
- this.cache = base?.cache ?? new ClientCache()
9
- }
10
-
11
- $extend(...registrations) {
12
- return Object.create(
13
- this,
14
- Object.fromEntries(
15
- registrations.map((registration) => {
16
- if ('experimental_asClientExtension' in registration) {
17
- const { name, register } = registration.experimental_asClientExtension()
18
- return [name, { value: register(this) }]
19
- }
20
-
21
- return [registration.name, { value: registration.register(this) }]
22
- })
23
- )
24
- )
25
- }
26
- }
27
- export { Experimental_BaseClient }
@@ -1,11 +0,0 @@
1
- /* eslint-disable camelcase */
2
-
3
- import { Experimental_BaseClient } from './client.js'
4
-
5
- class Experimental_CoreClient extends Experimental_BaseClient {
6
- constructor(options) {
7
- super(options)
8
- this.core = this
9
- }
10
- }
11
- export { Experimental_CoreClient }
@@ -1,106 +0,0 @@
1
- /* eslint-disable camelcase */
2
-
3
- import { vendorLib } from '@exodus/sui-lib'
4
-
5
- import { Experimental_CoreClient } from '../core.js'
6
- import { suiClientResolveTransactionPlugin } from './json-rpc-resolver.js'
7
-
8
- const { bcs } = vendorLib
9
-
10
- export class JSONRpcTransport extends Experimental_CoreClient {
11
- #jsonRpcClient
12
-
13
- constructor({ jsonRpcClient }) {
14
- super({ network: jsonRpcClient.network, base: jsonRpcClient })
15
- this.#jsonRpcClient = jsonRpcClient
16
- }
17
-
18
- async getCoins(options) {
19
- const coins = await this.#jsonRpcClient.getCoins({
20
- owner: options.address,
21
- coinType: options.coinType,
22
- limit: options.limit,
23
- cursor: options.cursor,
24
- signal: options.signal,
25
- })
26
-
27
- return {
28
- objects: coins.data.map((coin) => {
29
- return {
30
- id: coin.coinObjectId,
31
- version: coin.version,
32
- digest: coin.digest,
33
- balance: coin.balance,
34
- type: `0x2::coin::Coin<${coin.coinType}>`,
35
- content: Promise.resolve(
36
- Coin.serialize({
37
- id: coin.coinObjectId,
38
- balance: {
39
- value: coin.balance,
40
- },
41
- }).toBytes()
42
- ),
43
- owner: {
44
- $kind: 'ObjectOwner',
45
- ObjectOwner: options.address,
46
- },
47
- }
48
- }),
49
- hasNextPage: coins.hasNextPage,
50
- cursor: coins.nextCursor ?? null,
51
- }
52
- }
53
-
54
- async getBalance(options) {
55
- const balance = await this.#jsonRpcClient.getBalance({
56
- owner: options.address,
57
- coinType: options.coinType,
58
- signal: options.signal,
59
- })
60
-
61
- return {
62
- balance: {
63
- coinType: balance.coinType,
64
- balance: balance.totalBalance,
65
- },
66
- }
67
- }
68
-
69
- async getAllBalances(options) {
70
- const balances = await this.#jsonRpcClient.getAllBalances({
71
- owner: options.address,
72
- signal: options.signal,
73
- })
74
-
75
- return {
76
- balances: balances.map((balance) => ({
77
- coinType: balance.coinType,
78
- balance: balance.totalBalance,
79
- })),
80
- hasNextPage: false,
81
- cursor: null,
82
- }
83
- }
84
-
85
- async getReferenceGasPrice(options) {
86
- const referenceGasPrice = await this.#jsonRpcClient.getReferenceGasPrice({
87
- signal: options?.signal,
88
- })
89
- return {
90
- referenceGasPrice: String(referenceGasPrice),
91
- }
92
- }
93
-
94
- resolveTransactionPlugin() {
95
- return suiClientResolveTransactionPlugin(this.#jsonRpcClient)
96
- }
97
- }
98
-
99
- const Balance = bcs.struct('Balance', {
100
- value: bcs.u64(),
101
- })
102
-
103
- const Coin = bcs.struct('Coin', {
104
- id: bcs.Address,
105
- balance: Balance,
106
- })