@kontor/kontor-sdk 1.0.0-alpha.27 → 1.0.0-alpha.29
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/exports/index.js.map +1 -1
- package/dist/cjs/sdk/accounts/hd-key-to-account.js +1 -0
- package/dist/cjs/sdk/accounts/hd-key-to-account.js.map +1 -1
- package/dist/cjs/sdk/accounts/mnemonic-to-account.js +2 -4
- package/dist/cjs/sdk/accounts/mnemonic-to-account.js.map +1 -1
- package/dist/cjs/sdk/accounts/private-key-to-account.js +3 -8
- package/dist/cjs/sdk/accounts/private-key-to-account.js.map +1 -1
- package/dist/cjs/sdk/accounts/to-local-account.js.map +1 -1
- package/dist/cjs/sdk/actions/get-contract.js +36 -16
- package/dist/cjs/sdk/actions/get-contract.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/build-compose-query.js +9 -12
- package/dist/cjs/sdk/actions/kontor/public/build-compose-query.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/build-instruction-query.js +13 -33
- package/dist/cjs/sdk/actions/kontor/public/build-instruction-query.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/call-compose.js +6 -4
- package/dist/cjs/sdk/actions/kontor/public/call-compose.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/call-view.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/inspect.js +1 -2
- package/dist/cjs/sdk/actions/kontor/public/inspect.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/proc-contract.js +5 -5
- package/dist/cjs/sdk/actions/kontor/public/proc-contract.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/view-contract.js +2 -1
- package/dist/cjs/sdk/actions/kontor/public/view-contract.js.map +1 -1
- package/dist/cjs/sdk/chains/definitions/signet.js +0 -1
- package/dist/cjs/sdk/chains/definitions/signet.js.map +1 -1
- package/dist/cjs/sdk/clients/decorators/kontor/public.js.map +1 -1
- package/dist/cjs/sdk/errors/chain.js +44 -0
- package/dist/cjs/sdk/errors/chain.js.map +1 -0
- package/dist/cjs/sdk/utils/chain/assert-current-chain.js +11 -0
- package/dist/cjs/sdk/utils/chain/assert-current-chain.js.map +1 -0
- package/dist/cjs/sdk/utils/kontor/build-compose-query.js +19 -0
- package/dist/cjs/sdk/utils/kontor/build-compose-query.js.map +1 -0
- package/dist/cjs/sdk/utils/kontor/build-instruction-query.js +36 -0
- package/dist/cjs/sdk/utils/kontor/build-instruction-query.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/codecs/bool.js +29 -0
- package/dist/cjs/sdk/utils/wit/codecs/bool.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/codecs/s64.js +57 -0
- package/dist/cjs/sdk/utils/wit/codecs/s64.js.map +1 -0
- package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js +134 -131
- package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
- package/dist/cjs/sdk/utils/wit/encode-wit-parameters.js +74 -26
- package/dist/cjs/sdk/utils/wit/encode-wit-parameters.js.map +1 -1
- package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
- package/dist/cjs/wit/wit-parser/core/errors/{splitParameters.js → split-parameters.js} +1 -1
- package/dist/cjs/wit/wit-parser/core/errors/split-parameters.js.map +1 -0
- package/dist/cjs/wit/wit-parser/core/utils.js +3 -3
- package/dist/cjs/wit/wit-parser/core/utils.js.map +1 -1
- package/dist/esm/exports/index.js +1 -1
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/sdk/accounts/hd-key-to-account.js +2 -5
- package/dist/esm/sdk/accounts/hd-key-to-account.js.map +1 -1
- package/dist/esm/sdk/accounts/mnemonic-to-account.js +2 -10
- package/dist/esm/sdk/accounts/mnemonic-to-account.js.map +1 -1
- package/dist/esm/sdk/accounts/private-key-to-account.js +3 -15
- package/dist/esm/sdk/accounts/private-key-to-account.js.map +1 -1
- package/dist/esm/sdk/accounts/to-local-account.js +0 -5
- package/dist/esm/sdk/accounts/to-local-account.js.map +1 -1
- package/dist/esm/sdk/actions/get-contract.js +37 -35
- package/dist/esm/sdk/actions/get-contract.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/build-compose-query.js +9 -13
- package/dist/esm/sdk/actions/kontor/public/build-compose-query.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/build-instruction-query.js +13 -36
- package/dist/esm/sdk/actions/kontor/public/build-instruction-query.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/call-compose.js +6 -4
- package/dist/esm/sdk/actions/kontor/public/call-compose.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/call-view.js +1 -0
- package/dist/esm/sdk/actions/kontor/public/call-view.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/inspect.js +9 -4
- package/dist/esm/sdk/actions/kontor/public/inspect.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/proc-contract.js +5 -6
- package/dist/esm/sdk/actions/kontor/public/proc-contract.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/view-contract.js +3 -5
- package/dist/esm/sdk/actions/kontor/public/view-contract.js.map +1 -1
- package/dist/esm/sdk/chains/definitions/signet.js +0 -1
- package/dist/esm/sdk/chains/definitions/signet.js.map +1 -1
- package/dist/esm/sdk/clients/decorators/kontor/public.js.map +1 -1
- package/dist/esm/sdk/errors/chain.js +37 -0
- package/dist/esm/sdk/errors/chain.js.map +1 -0
- package/dist/esm/sdk/utils/chain/assert-current-chain.js +8 -0
- package/dist/esm/sdk/utils/chain/assert-current-chain.js.map +1 -0
- package/dist/esm/sdk/utils/kontor/build-compose-query.js +16 -0
- package/dist/esm/sdk/utils/kontor/build-compose-query.js.map +1 -0
- package/dist/esm/sdk/utils/kontor/build-instruction-query.js +36 -0
- package/dist/esm/sdk/utils/kontor/build-instruction-query.js.map +1 -0
- package/dist/esm/sdk/utils/wit/codecs/bool.js +26 -0
- package/dist/esm/sdk/utils/wit/codecs/bool.js.map +1 -0
- package/dist/esm/sdk/utils/wit/codecs/s64.js +65 -0
- package/dist/esm/sdk/utils/wit/codecs/s64.js.map +1 -0
- package/dist/esm/sdk/utils/wit/decode-wit-parameter.js +155 -147
- package/dist/esm/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
- package/dist/esm/sdk/utils/wit/encode-wit-parameters.js +74 -72
- package/dist/esm/sdk/utils/wit/encode-wit-parameters.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/wit/wit-parser/core/errors/{splitParameters.js → split-parameters.js} +1 -1
- package/dist/esm/wit/wit-parser/core/errors/split-parameters.js.map +1 -0
- package/dist/esm/wit/wit-parser/core/utils.js +1 -1
- package/dist/esm/wit/wit-parser/core/utils.js.map +1 -1
- package/dist/types/exports/index.d.ts +1 -1
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/sdk/accounts/hd-key-to-account.d.ts +0 -5
- package/dist/types/sdk/accounts/hd-key-to-account.d.ts.map +1 -1
- package/dist/types/sdk/accounts/mnemonic-to-account.d.ts +1 -6
- package/dist/types/sdk/accounts/mnemonic-to-account.d.ts.map +1 -1
- package/dist/types/sdk/accounts/private-key-to-account.d.ts +5 -3
- package/dist/types/sdk/accounts/private-key-to-account.d.ts.map +1 -1
- package/dist/types/sdk/accounts/to-local-account.d.ts +0 -5
- package/dist/types/sdk/accounts/to-local-account.d.ts.map +1 -1
- package/dist/types/sdk/actions/get-contract.d.ts +28 -5
- package/dist/types/sdk/actions/get-contract.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/build-compose-query.d.ts +5 -5
- package/dist/types/sdk/actions/kontor/public/build-compose-query.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/build-instruction-query.d.ts +6 -6
- package/dist/types/sdk/actions/kontor/public/build-instruction-query.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/call-compose.d.ts +1 -1
- package/dist/types/sdk/actions/kontor/public/call-compose.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/call-view.d.ts +3 -3
- package/dist/types/sdk/actions/kontor/public/call-view.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/inspect.d.ts +3 -3
- package/dist/types/sdk/actions/kontor/public/inspect.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/proc-contract.d.ts +3 -3
- package/dist/types/sdk/actions/kontor/public/proc-contract.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/view-contract.d.ts +3 -3
- package/dist/types/sdk/actions/kontor/public/view-contract.d.ts.map +1 -1
- package/dist/types/sdk/chains/definitions/signet.d.ts +0 -1
- package/dist/types/sdk/chains/definitions/signet.d.ts.map +1 -1
- package/dist/types/sdk/clients/decorators/kontor/public.d.ts +6 -6
- package/dist/types/sdk/clients/decorators/kontor/public.d.ts.map +1 -1
- package/dist/types/sdk/errors/chain.d.ts +32 -0
- package/dist/types/sdk/errors/chain.d.ts.map +1 -0
- package/dist/types/sdk/types/chain.d.ts +0 -2
- package/dist/types/sdk/types/chain.d.ts.map +1 -1
- package/dist/types/sdk/types/contract.d.ts.map +1 -1
- package/dist/types/sdk/utils/chain/assert-current-chain.d.ts +10 -0
- package/dist/types/sdk/utils/chain/assert-current-chain.d.ts.map +1 -0
- package/dist/types/sdk/utils/kontor/build-compose-query.d.ts +13 -0
- package/dist/types/sdk/utils/kontor/build-compose-query.d.ts.map +1 -0
- package/dist/types/sdk/utils/kontor/build-instruction-query.d.ts +22 -0
- package/dist/types/sdk/utils/kontor/build-instruction-query.d.ts.map +1 -0
- package/dist/types/sdk/utils/wit/codecs/bool.d.ts +3 -0
- package/dist/types/sdk/utils/wit/codecs/bool.d.ts.map +1 -0
- package/dist/types/sdk/utils/wit/codecs/s64.d.ts +23 -0
- package/dist/types/sdk/utils/wit/codecs/s64.d.ts.map +1 -0
- package/dist/types/sdk/utils/wit/decode-wit-parameter.d.ts +12 -3
- package/dist/types/sdk/utils/wit/decode-wit-parameter.d.ts.map +1 -1
- package/dist/types/sdk/utils/wit/encode-wit-parameters.d.ts.map +1 -1
- package/dist/types/wit/type-utils.d.ts.map +1 -1
- package/dist/types/wit/utils.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/core/errors/{splitParameters.d.ts → split-parameters.d.ts} +1 -1
- package/dist/types/wit/wit-parser/core/errors/split-parameters.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/exports/index.ts +1 -1
- package/src/sdk/accounts/hd-key-to-account.ts +2 -5
- package/src/sdk/accounts/mnemonic-to-account.test.ts +7 -81
- package/src/sdk/accounts/mnemonic-to-account.ts +2 -11
- package/src/sdk/accounts/private-key-to-account.ts +10 -16
- package/src/sdk/accounts/to-local-account.ts +0 -5
- package/src/sdk/actions/get-contract.test-d.ts +10 -9
- package/src/sdk/actions/get-contract.test.ts +49 -0
- package/src/sdk/actions/get-contract.ts +312 -91
- package/src/sdk/actions/kontor/public/build-compose-query.ts +23 -25
- package/src/sdk/actions/kontor/public/build-instruction-query.ts +27 -53
- package/src/sdk/actions/kontor/public/call-compose.ts +8 -4
- package/src/sdk/actions/kontor/public/call-view.ts +5 -4
- package/src/sdk/actions/kontor/public/inspect.ts +20 -9
- package/src/sdk/actions/kontor/public/proc-contract.test.ts +1 -2
- package/src/sdk/actions/kontor/public/proc-contract.ts +21 -55
- package/src/sdk/actions/kontor/public/{view-contract.test-d.ts → view-contract.test.ts} +2 -2
- package/src/sdk/actions/kontor/public/view-contract.ts +10 -9
- package/src/sdk/chains/definitions/signet.ts +0 -1
- package/src/sdk/clients/base/create-rpc-client.test.ts +0 -1
- package/src/sdk/clients/create-public-client.test.ts +0 -1
- package/src/sdk/clients/decorators/kontor/public.ts +21 -12
- package/src/sdk/clients/kontor/create-public-client.test.ts +0 -7
- package/src/sdk/errors/chain.ts +64 -0
- package/src/sdk/test/e2e.test.ts +25 -1
- package/src/sdk/types/chain.ts +0 -2
- package/src/sdk/types/contract.ts +3 -14
- package/src/sdk/utils/chain/assert-current-chain.ts +28 -0
- package/src/sdk/utils/kontor/build-compose-query.ts +33 -0
- package/src/sdk/utils/kontor/build-instruction-query.ts +75 -0
- package/src/sdk/utils/wit/codecs/bool.ts +29 -0
- package/src/sdk/utils/wit/codecs/s64.ts +76 -0
- package/src/sdk/utils/wit/decode-wit-parameter.ts +167 -164
- package/src/sdk/utils/wit/encode-wit-parameters.ts +78 -75
- package/src/wit/type-utils.ts +0 -2
- package/src/wit/utils.ts +3 -6
- package/src/wit/wit-parser/core/utils.ts +1 -1
- package/dist/cjs/wit/wit-parser/core/errors/splitParameters.js.map +0 -1
- package/dist/esm/wit/wit-parser/core/errors/splitParameters.js.map +0 -1
- package/dist/types/wit/wit-parser/core/errors/splitParameters.d.ts.map +0 -1
- /package/src/wit/wit-parser/core/errors/{splitParameters.ts → split-parameters.ts} +0 -0
|
@@ -15,12 +15,23 @@ import type {
|
|
|
15
15
|
ContractFunctionName,
|
|
16
16
|
} from "../types/contract.js";
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
import { getKontorAction } from "../utils/get-action.js";
|
|
19
19
|
import {
|
|
20
|
+
viewContract,
|
|
20
21
|
// viewContract,
|
|
21
22
|
type ViewContractParameters,
|
|
22
23
|
type ViewContractReturnType,
|
|
23
24
|
} from "./kontor/public/view-contract.js";
|
|
25
|
+
import type { HttpTransport } from "../clients/transports/create-http-transport.js";
|
|
26
|
+
import type { Chain } from "../types/chain.js";
|
|
27
|
+
import type { Account } from "../accounts/types.js";
|
|
28
|
+
import type { KontorPublicClient } from "../clients/kontor/create-public-client.js";
|
|
29
|
+
import type { ResolvedRegister } from "../../wit/register.js";
|
|
30
|
+
import {
|
|
31
|
+
procContract,
|
|
32
|
+
type ProcContractParameters,
|
|
33
|
+
type ProcContractReturnType,
|
|
34
|
+
} from "./kontor/public/proc-contract.js";
|
|
24
35
|
|
|
25
36
|
// TODO: move to utils
|
|
26
37
|
function camelToKebab(str: string): string {
|
|
@@ -32,45 +43,29 @@ export type KebabToCamel<S extends string> =
|
|
|
32
43
|
? `${Head}${Capitalize<KebabToCamel<Tail>>}`
|
|
33
44
|
: S;
|
|
34
45
|
|
|
35
|
-
export type GetContractParameters<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
_args = WitParametersToPrimitiveTypes<witFunction["inputs"]>,
|
|
54
|
-
_options = Prettify<
|
|
55
|
-
UnionOmit<
|
|
56
|
-
ViewContractParameters<wit, functionName, args>,
|
|
57
|
-
"contractAddress" | "args" | "functionName"
|
|
58
|
-
>
|
|
59
|
-
>,
|
|
60
|
-
> = narrowable extends true
|
|
61
|
-
? (
|
|
62
|
-
...parameters: _args extends readonly []
|
|
63
|
-
? [options?: _options]
|
|
64
|
-
: [args: _args, options?: _options]
|
|
65
|
-
) => Promise<ViewContractReturnType<wit, functionName, args>>
|
|
66
|
-
: (
|
|
67
|
-
...parameters:
|
|
68
|
-
| [options?: _options]
|
|
69
|
-
| [args: readonly unknown[], options?: _options]
|
|
70
|
-
) => Promise<ViewContractReturnType>;
|
|
46
|
+
export type GetContractParameters<
|
|
47
|
+
transport extends HttpTransport = HttpTransport,
|
|
48
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
49
|
+
account extends Account | undefined = Account | undefined,
|
|
50
|
+
wit extends Wit | readonly unknown[] = Wit,
|
|
51
|
+
client extends KontorPublicClient<
|
|
52
|
+
transport,
|
|
53
|
+
chain,
|
|
54
|
+
account
|
|
55
|
+
> = KontorPublicClient<transport, chain, account>,
|
|
56
|
+
contractAddress extends
|
|
57
|
+
ResolvedRegister["contractAddress"] = ResolvedRegister["contractAddress"],
|
|
58
|
+
> = {
|
|
59
|
+
wit: wit;
|
|
60
|
+
contractAddress: contractAddress;
|
|
61
|
+
client: client;
|
|
62
|
+
};
|
|
71
63
|
|
|
72
64
|
export type GetContractReturnType<
|
|
73
65
|
wit extends Wit | readonly unknown[] = Wit,
|
|
66
|
+
client extends KontorPublicClient = KontorPublicClient,
|
|
67
|
+
contractAddress extends
|
|
68
|
+
ResolvedRegister["contractAddress"] = ResolvedRegister["contractAddress"],
|
|
74
69
|
_viewFunctionNames extends string = wit extends Wit
|
|
75
70
|
? Wit extends wit
|
|
76
71
|
? string
|
|
@@ -85,74 +80,300 @@ export type GetContractReturnType<
|
|
|
85
80
|
> = {
|
|
86
81
|
view: {
|
|
87
82
|
// K is the *original* wit function name ("cached-values")
|
|
88
|
-
[
|
|
83
|
+
[functionName in _viewFunctionNames as KebabToCamel<functionName>]: GetViewFunction<
|
|
89
84
|
_narrowable,
|
|
85
|
+
client["chain"],
|
|
90
86
|
wit,
|
|
91
87
|
// and we pass K directly into GetViewFunction
|
|
92
|
-
|
|
88
|
+
functionName extends ContractFunctionName<wit, "view">
|
|
89
|
+
? functionName
|
|
90
|
+
: never
|
|
93
91
|
>;
|
|
94
92
|
};
|
|
93
|
+
proc: {
|
|
94
|
+
// K is the *original* wit function name ("cached-values")
|
|
95
|
+
[functionName in _procFunctionNames as KebabToCamel<functionName>]: GetProcFunction<
|
|
96
|
+
_narrowable,
|
|
97
|
+
client["chain"],
|
|
98
|
+
client["account"],
|
|
99
|
+
wit,
|
|
100
|
+
// and we pass K directly into GetProcFunction
|
|
101
|
+
functionName extends ContractFunctionName<wit, "proc">
|
|
102
|
+
? functionName
|
|
103
|
+
: never
|
|
104
|
+
>;
|
|
105
|
+
};
|
|
106
|
+
contractAddress: contractAddress;
|
|
107
|
+
wit: wit;
|
|
95
108
|
};
|
|
96
109
|
|
|
97
|
-
|
|
98
|
-
wit
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
type ViewOptions<
|
|
111
|
+
wit extends Wit | readonly unknown[],
|
|
112
|
+
functionName extends ContractFunctionName<wit, "view">,
|
|
113
|
+
args extends ContractFunctionArgs<wit, "view", functionName>,
|
|
114
|
+
chain extends Chain | undefined,
|
|
115
|
+
chainOverride extends Chain | undefined,
|
|
116
|
+
> = Prettify<
|
|
117
|
+
UnionOmit<
|
|
118
|
+
ViewContractParameters<wit, functionName, args, chain, chainOverride>,
|
|
119
|
+
"wit" | "contractAddress" | "args" | "functionName"
|
|
120
|
+
>
|
|
121
|
+
>;
|
|
101
122
|
|
|
123
|
+
type OptTuple<chain extends Chain | undefined, O> = chain extends Chain
|
|
124
|
+
? [options?: O]
|
|
125
|
+
: [options: O];
|
|
126
|
+
|
|
127
|
+
export type GetViewFunction<
|
|
128
|
+
narrowable extends boolean,
|
|
129
|
+
chain extends Chain | undefined,
|
|
130
|
+
wit extends Wit | readonly unknown[],
|
|
131
|
+
functionName extends ContractFunctionName<wit, "view">,
|
|
132
|
+
args extends ContractFunctionArgs<
|
|
133
|
+
wit,
|
|
134
|
+
"view",
|
|
135
|
+
functionName
|
|
136
|
+
> = ContractFunctionArgs<wit, "view", functionName>,
|
|
137
|
+
witFunction extends WitFunction = wit extends Wit
|
|
138
|
+
? ExtractWitFunction<wit, functionName>
|
|
139
|
+
: WitFunction,
|
|
140
|
+
_args = WitParametersToPrimitiveTypes<witFunction["inputs"]>,
|
|
141
|
+
> = narrowable extends true
|
|
142
|
+
? <chainOverride extends Chain | undefined = undefined>(
|
|
143
|
+
...parameters: _args extends readonly []
|
|
144
|
+
? OptTuple<
|
|
145
|
+
chain,
|
|
146
|
+
ViewOptions<wit, functionName, args, chain, chainOverride>
|
|
147
|
+
>
|
|
148
|
+
: [
|
|
149
|
+
args: _args,
|
|
150
|
+
...options: OptTuple<
|
|
151
|
+
chain,
|
|
152
|
+
ViewOptions<wit, functionName, args, chain, chainOverride>
|
|
153
|
+
>,
|
|
154
|
+
]
|
|
155
|
+
) => Promise<ViewContractReturnType<wit, functionName, args>>
|
|
156
|
+
: <chainOverride extends Chain | undefined = undefined>(
|
|
157
|
+
...parameters:
|
|
158
|
+
| OptTuple<
|
|
159
|
+
chain,
|
|
160
|
+
ViewOptions<wit, functionName, args, chain, chainOverride>
|
|
161
|
+
>
|
|
162
|
+
| [
|
|
163
|
+
args: readonly unknown[],
|
|
164
|
+
...options: OptTuple<
|
|
165
|
+
chain,
|
|
166
|
+
ViewOptions<wit, functionName, args, chain, chainOverride>
|
|
167
|
+
>,
|
|
168
|
+
]
|
|
169
|
+
) => Promise<ViewContractReturnType>;
|
|
170
|
+
|
|
171
|
+
// export type GetViewFunction<
|
|
172
|
+
// narrowable extends boolean,
|
|
173
|
+
// chain extends Chain | undefined,
|
|
174
|
+
// wit extends Wit | readonly unknown[],
|
|
175
|
+
// functionName extends ContractFunctionName<wit, "view">,
|
|
176
|
+
// args extends ContractFunctionArgs<
|
|
177
|
+
// wit,
|
|
178
|
+
// "view",
|
|
179
|
+
// functionName
|
|
180
|
+
// > = ContractFunctionArgs<wit, "view", functionName>,
|
|
181
|
+
// witFunction extends WitFunction = wit extends Wit
|
|
182
|
+
// ? ExtractWitFunction<wit, functionName>
|
|
183
|
+
// : WitFunction,
|
|
184
|
+
// //
|
|
185
|
+
// _args = WitParametersToPrimitiveTypes<witFunction["inputs"]>,
|
|
186
|
+
// > = narrowable extends true
|
|
187
|
+
// ? <
|
|
188
|
+
// chainOverride extends Chain | undefined,
|
|
189
|
+
// options extends Prettify<
|
|
190
|
+
// UnionOmit<
|
|
191
|
+
// ViewContractParameters<wit, functionName, args, chain, chainOverride>,
|
|
192
|
+
// "wit" | "contractAddress" | "args" | "functionName"
|
|
193
|
+
// >
|
|
194
|
+
// >,
|
|
195
|
+
// >(
|
|
196
|
+
// ...parameters: _args extends readonly []
|
|
197
|
+
// ? chain extends Chain
|
|
198
|
+
// ? [options?: options]
|
|
199
|
+
// : [options: options]
|
|
200
|
+
// : [args: _args, options?: options]
|
|
201
|
+
// ) => Promise<ViewContractReturnType<wit, functionName, args>>
|
|
202
|
+
// : <
|
|
203
|
+
// chainOverride extends Chain | undefined,
|
|
204
|
+
// options extends Prettify<
|
|
205
|
+
// UnionOmit<
|
|
206
|
+
// ViewContractParameters<wit, functionName, args, chain, chainOverride>,
|
|
207
|
+
// "wit" | "contractAddress" | "args" | "functionName"
|
|
208
|
+
// >
|
|
209
|
+
// >,
|
|
210
|
+
// Rest extends unknown[] = [options: options],
|
|
211
|
+
// >(
|
|
212
|
+
// ...parameters: chain extends Chain
|
|
213
|
+
// ? [options?: options] | [args: readonly unknown[], ...parameters: Rest]
|
|
214
|
+
// : [options: options] | [args: readonly unknown[], ...parameters: Rest]
|
|
215
|
+
// ) => Promise<ViewContractReturnType>;
|
|
216
|
+
|
|
217
|
+
export type GetProcFunction<
|
|
218
|
+
narrowable extends boolean,
|
|
219
|
+
chain extends Chain | undefined,
|
|
220
|
+
account extends Account | undefined,
|
|
221
|
+
wit extends Wit | readonly unknown[],
|
|
222
|
+
functionName extends ContractFunctionName<wit, "proc">,
|
|
223
|
+
args extends ContractFunctionArgs<
|
|
224
|
+
wit,
|
|
225
|
+
"proc",
|
|
226
|
+
functionName
|
|
227
|
+
> = ContractFunctionArgs<wit, "proc", functionName>,
|
|
228
|
+
witFunction extends WitFunction = wit extends Wit
|
|
229
|
+
? ExtractWitFunction<wit, functionName>
|
|
230
|
+
: WitFunction,
|
|
231
|
+
//
|
|
232
|
+
_args = WitParametersToPrimitiveTypes<witFunction["inputs"]>,
|
|
233
|
+
> = narrowable extends true
|
|
234
|
+
? <
|
|
235
|
+
chainOverride extends Chain | undefined,
|
|
236
|
+
options extends Prettify<
|
|
237
|
+
UnionOmit<
|
|
238
|
+
ProcContractParameters<
|
|
239
|
+
wit,
|
|
240
|
+
functionName,
|
|
241
|
+
args,
|
|
242
|
+
chain,
|
|
243
|
+
account,
|
|
244
|
+
chainOverride
|
|
245
|
+
>,
|
|
246
|
+
"wit" | "contractAddress" | "args" | "functionName"
|
|
247
|
+
>
|
|
248
|
+
>,
|
|
249
|
+
>(
|
|
250
|
+
...parameters: _args extends readonly []
|
|
251
|
+
? [options: options]
|
|
252
|
+
: [args: _args, options: options]
|
|
253
|
+
) => Promise<ProcContractReturnType>
|
|
254
|
+
: <
|
|
255
|
+
chainOverride extends Chain | undefined,
|
|
256
|
+
options extends Prettify<
|
|
257
|
+
UnionOmit<
|
|
258
|
+
ProcContractParameters<
|
|
259
|
+
wit,
|
|
260
|
+
functionName,
|
|
261
|
+
args,
|
|
262
|
+
chain,
|
|
263
|
+
account,
|
|
264
|
+
chainOverride
|
|
265
|
+
>,
|
|
266
|
+
"contractAddress" | "args" | "functionName"
|
|
267
|
+
>
|
|
268
|
+
>,
|
|
269
|
+
Rest extends unknown[] = [options: options],
|
|
270
|
+
>(
|
|
271
|
+
...parameters:
|
|
272
|
+
| [options: options]
|
|
273
|
+
| [args: readonly unknown[], ...parameters: Rest]
|
|
274
|
+
) => Promise<ProcContractReturnType>;
|
|
275
|
+
|
|
276
|
+
export function getContract<
|
|
277
|
+
transport extends HttpTransport,
|
|
278
|
+
contractAddress extends ResolvedRegister["contractAddress"],
|
|
279
|
+
const wit extends Wit | readonly unknown[],
|
|
280
|
+
const client extends KontorPublicClient<transport, chain, account>,
|
|
281
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
282
|
+
account extends Account | undefined = Account | undefined,
|
|
283
|
+
>({
|
|
284
|
+
wit,
|
|
285
|
+
contractAddress,
|
|
286
|
+
client: client_,
|
|
287
|
+
}: GetContractParameters<
|
|
288
|
+
transport,
|
|
289
|
+
chain,
|
|
290
|
+
account,
|
|
291
|
+
wit,
|
|
292
|
+
client,
|
|
293
|
+
contractAddress
|
|
294
|
+
>): GetContractReturnType<wit, client, contractAddress> {
|
|
102
295
|
const contract: {
|
|
103
|
-
[_ in "wit" | "view"]?: unknown;
|
|
296
|
+
[_ in "wit" | "contractAddress" | "view" | "proc"]?: unknown;
|
|
104
297
|
} = {};
|
|
105
298
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
299
|
+
console.log("we are defining a proxy");
|
|
300
|
+
|
|
301
|
+
contract.view = new Proxy(
|
|
302
|
+
{},
|
|
303
|
+
{
|
|
304
|
+
get(_, functionName: string) {
|
|
305
|
+
const witFunctionName = camelToKebab(functionName);
|
|
306
|
+
|
|
307
|
+
return (
|
|
308
|
+
...parameters: [
|
|
309
|
+
args?: readonly unknown[] | undefined,
|
|
310
|
+
options?: UnionOmit<
|
|
311
|
+
ViewContractParameters,
|
|
312
|
+
"wit" | "contractAddress" | "functionName" | "args"
|
|
313
|
+
>,
|
|
314
|
+
]
|
|
315
|
+
) => {
|
|
316
|
+
const { args, options } = getFunctionParameters(parameters);
|
|
317
|
+
|
|
318
|
+
return getKontorAction(
|
|
319
|
+
client_,
|
|
320
|
+
viewContract,
|
|
321
|
+
"viewContract",
|
|
322
|
+
)({
|
|
323
|
+
wit,
|
|
324
|
+
functionName: witFunctionName,
|
|
325
|
+
contractAddress,
|
|
326
|
+
// address,
|
|
327
|
+
args,
|
|
328
|
+
...options,
|
|
329
|
+
} as ViewContractParameters);
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
contract.proc = new Proxy(
|
|
336
|
+
{},
|
|
337
|
+
{
|
|
338
|
+
get(_, functionName: string) {
|
|
339
|
+
const witFunctionName = camelToKebab(functionName);
|
|
340
|
+
|
|
341
|
+
return (
|
|
342
|
+
...parameters: [
|
|
343
|
+
args?: readonly unknown[] | undefined,
|
|
344
|
+
options?: UnionOmit<
|
|
345
|
+
ProcContractParameters,
|
|
346
|
+
"wit" | "contractAddress" | "functionName" | "args"
|
|
347
|
+
>,
|
|
348
|
+
]
|
|
349
|
+
) => {
|
|
350
|
+
const { args, options } = getFunctionParameters(parameters);
|
|
351
|
+
|
|
352
|
+
return getKontorAction(
|
|
353
|
+
client_,
|
|
354
|
+
procContract,
|
|
355
|
+
"procContract",
|
|
356
|
+
)({
|
|
357
|
+
wit,
|
|
358
|
+
functionName: witFunctionName,
|
|
359
|
+
contractAddress,
|
|
360
|
+
args,
|
|
361
|
+
|
|
362
|
+
...options,
|
|
363
|
+
} as any);
|
|
364
|
+
};
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
);
|
|
152
368
|
|
|
153
369
|
contract.wit = wit;
|
|
370
|
+
contract.contractAddress = contractAddress;
|
|
154
371
|
|
|
155
|
-
return contract as unknown as GetContractReturnType<
|
|
372
|
+
return contract as unknown as GetContractReturnType<
|
|
373
|
+
wit,
|
|
374
|
+
client,
|
|
375
|
+
contractAddress
|
|
376
|
+
>;
|
|
156
377
|
}
|
|
157
378
|
|
|
158
379
|
export function getFunctionParameters(
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// import type { ResolvedRegister } from "../../../../wit/register.js";
|
|
2
1
|
import type { KontorPublicClient } from "../../../clients/kontor/create-public-client.js";
|
|
3
2
|
import type { HttpTransport } from "../../../clients/transports/create-http-transport.js";
|
|
4
3
|
import type { Chain } from "../../../types/chain.js";
|
|
@@ -7,42 +6,40 @@ import { buildInstructionQuery } from "./build-instruction-query.js";
|
|
|
7
6
|
import { getKontorAction } from "../../../utils/get-action.js";
|
|
8
7
|
import type { ComposeQuery } from "@kontor/kontor-ts";
|
|
9
8
|
import type { Inst } from "../../../../sdk/types/kontor.js";
|
|
9
|
+
import type { GetAccountParameter } from "../../../../sdk/types/account.js";
|
|
10
10
|
|
|
11
|
+
import type { Account } from "../../../accounts/types.js";
|
|
12
|
+
import { parseAccount } from "../../../accounts/utils/parse-account.js";
|
|
11
13
|
export type BuildComposeQueryParameters<
|
|
12
|
-
|
|
14
|
+
account extends Account | undefined = Account | undefined,
|
|
15
|
+
accountOverride extends Account | [Address, XOnlyPubKey] | undefined =
|
|
16
|
+
| Account
|
|
17
|
+
| [Address, XOnlyPubKey]
|
|
18
|
+
| undefined,
|
|
13
19
|
> = {
|
|
14
20
|
instruction: Inst;
|
|
15
|
-
address?: Address;
|
|
16
|
-
xOnlyPubKey?: XOnlyPubKey; // TODO: maybe this should be wrapped in a single object
|
|
17
21
|
utxos: UtxoId[];
|
|
18
22
|
satsPerVByte: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
23
|
+
} & GetAccountParameter<account, accountOverride, true, true>;
|
|
21
24
|
export type BuildComposeQueryReturnType = ComposeQuery;
|
|
22
25
|
|
|
23
|
-
export
|
|
24
|
-
chain extends Chain | undefined
|
|
26
|
+
export function buildComposeQuery<
|
|
27
|
+
chain extends Chain | undefined,
|
|
28
|
+
account extends Account | undefined,
|
|
25
29
|
>(
|
|
26
30
|
client: KontorPublicClient<HttpTransport, chain>,
|
|
27
|
-
params: BuildComposeQueryParameters<
|
|
28
|
-
):
|
|
29
|
-
const account = client.account;
|
|
30
|
-
|
|
31
|
+
params: BuildComposeQueryParameters<account>,
|
|
32
|
+
): BuildComposeQueryReturnType {
|
|
31
33
|
const {
|
|
32
34
|
instruction: inst,
|
|
33
35
|
utxos,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
satsPerVByte,
|
|
37
|
+
account: account_ = client.account,
|
|
36
38
|
} = params;
|
|
37
39
|
|
|
38
|
-
if (!
|
|
39
|
-
// TODO: add custom error
|
|
40
|
-
throw new Error("x_only_public_key is required");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!address) {
|
|
40
|
+
if (!account_) {
|
|
44
41
|
// TODO: add custom error
|
|
45
|
-
throw new Error("
|
|
42
|
+
throw new Error("Account is required");
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
if (utxos.length === 0) {
|
|
@@ -50,20 +47,21 @@ export async function buildComposeQuery<
|
|
|
50
47
|
throw new Error("at least one funding UTXO is required");
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
const
|
|
50
|
+
const account = parseAccount(account_);
|
|
51
|
+
|
|
52
|
+
const instruction = getKontorAction(
|
|
54
53
|
client,
|
|
55
54
|
buildInstructionQuery,
|
|
56
55
|
"buildInstructionQuery",
|
|
57
56
|
)({
|
|
58
57
|
instruction: inst,
|
|
59
58
|
utxos,
|
|
60
|
-
|
|
61
|
-
address,
|
|
59
|
+
account,
|
|
62
60
|
});
|
|
63
61
|
|
|
64
62
|
return {
|
|
65
63
|
instructions: [instruction],
|
|
66
|
-
sat_per_vbyte:
|
|
64
|
+
sat_per_vbyte: satsPerVByte,
|
|
67
65
|
envelope: null,
|
|
68
66
|
};
|
|
69
67
|
}
|
|
@@ -2,17 +2,24 @@ import type { Inst, InstructionQuery } from "../../../types/kontor.js";
|
|
|
2
2
|
import type { KontorPublicClient } from "../../../clients/kontor/create-public-client.js";
|
|
3
3
|
import type { HttpTransport } from "../../../clients/transports/create-http-transport.js";
|
|
4
4
|
import type { Chain } from "../../../types/chain.js";
|
|
5
|
-
import type { Address,
|
|
5
|
+
import type { Address, XOnlyPubKey, UtxoId } from "../../../types/misc.js";
|
|
6
|
+
import type { Account } from "../../../../sdk/accounts/types.js";
|
|
7
|
+
import { buildInstructionQuery as buildInstructionQuery_ } from "../../../utils/kontor/build-instruction-query.js";
|
|
8
|
+
|
|
9
|
+
import { parseAccount } from "../../../../sdk/accounts/utils/parse-account.js";
|
|
10
|
+
import type { GetAccountParameter } from "../../../../sdk/types/account.js";
|
|
6
11
|
|
|
7
12
|
// If InstructionQuery already uses this Inst shape internally, you don't need to touch it.
|
|
8
13
|
// Otherwise you can make InstructionQuery generic over Inst and plug this in.
|
|
9
14
|
export type BuildInstructionQueryReturnType = InstructionQuery;
|
|
10
15
|
|
|
11
16
|
export type BuildInstructionQueryParameters<
|
|
12
|
-
|
|
17
|
+
account extends Account | undefined = Account | undefined,
|
|
18
|
+
accountOverride extends Account | [Address, XOnlyPubKey] | undefined =
|
|
19
|
+
| Account
|
|
20
|
+
| [Address, XOnlyPubKey]
|
|
21
|
+
| undefined,
|
|
13
22
|
> = {
|
|
14
|
-
address?: Address;
|
|
15
|
-
xOnlyPubKey?: XOnlyPubKey; // TODO: maybe this should be wrapped in a single object
|
|
16
23
|
utxos: UtxoId[];
|
|
17
24
|
/**
|
|
18
25
|
* The concrete instruction to send (Publish | Call | Issuance).
|
|
@@ -26,57 +33,25 @@ export type BuildInstructionQueryParameters<
|
|
|
26
33
|
* Optional chained instruction if you want to send two instructions atomically.
|
|
27
34
|
*/
|
|
28
35
|
chainedInstruction?: Inst | null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ------------------ helpers ------------------
|
|
32
|
-
|
|
33
|
-
function normalizeXOnly(pub: string): string {
|
|
34
|
-
if (!/^[0-9a-fA-F]{64}$/.test(pub)) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
"x_only_public_key must be 32-byte (64 hex chars) x-only pubkey",
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return pub.toLowerCase();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function normalizeUtxoId(u: UtxoId): string {
|
|
43
|
-
if (typeof u === "string") return u;
|
|
44
|
-
if (!u?.txid || typeof u.vout !== "number") {
|
|
45
|
-
throw new Error("funding UTXO must be 'txid:vout' or { txid, vout }");
|
|
46
|
-
}
|
|
47
|
-
return `${u.txid}:${u.vout}`;
|
|
48
|
-
}
|
|
36
|
+
} & GetAccountParameter<account, accountOverride, true, true>;
|
|
49
37
|
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// ------------------ main builder ------------------
|
|
55
|
-
|
|
56
|
-
export async function buildInstructionQuery<
|
|
57
|
-
chain extends Chain | undefined = Chain | undefined,
|
|
38
|
+
export function buildInstructionQuery<
|
|
39
|
+
chain extends Chain | undefined,
|
|
40
|
+
account extends Account | undefined,
|
|
58
41
|
>(
|
|
59
42
|
client: KontorPublicClient<HttpTransport, chain>,
|
|
60
|
-
params: BuildInstructionQueryParameters<
|
|
61
|
-
):
|
|
62
|
-
const account = client.account;
|
|
63
|
-
|
|
43
|
+
params: BuildInstructionQueryParameters<account>,
|
|
44
|
+
): BuildInstructionQueryReturnType {
|
|
64
45
|
const {
|
|
65
46
|
utxos,
|
|
66
47
|
instruction,
|
|
67
48
|
chainedInstruction = null,
|
|
68
|
-
|
|
69
|
-
xOnlyPubKey = account?.xOnlyPubKey,
|
|
49
|
+
account: account_ = client.account,
|
|
70
50
|
} = params;
|
|
71
51
|
|
|
72
|
-
if (!
|
|
52
|
+
if (!account_) {
|
|
73
53
|
// TODO: add custom error
|
|
74
|
-
throw new Error("
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!address) {
|
|
78
|
-
// TODO: add custom error
|
|
79
|
-
throw new Error("address is required");
|
|
54
|
+
throw new Error("Account is required");
|
|
80
55
|
}
|
|
81
56
|
|
|
82
57
|
if (utxos.length === 0) {
|
|
@@ -84,14 +59,13 @@ export async function buildInstructionQuery<
|
|
|
84
59
|
throw new Error("at least one funding UTXO is required");
|
|
85
60
|
}
|
|
86
61
|
|
|
87
|
-
const
|
|
88
|
-
const fundingIds = normalizeUtxoIds(utxos);
|
|
62
|
+
const account = parseAccount(account_);
|
|
89
63
|
|
|
90
|
-
return {
|
|
91
|
-
|
|
92
|
-
x_only_public_key: xOnly,
|
|
93
|
-
funding_utxo_ids: fundingIds.join(","),
|
|
64
|
+
return buildInstructionQuery_({
|
|
65
|
+
utxos,
|
|
94
66
|
instruction,
|
|
95
|
-
|
|
96
|
-
|
|
67
|
+
chainedInstruction,
|
|
68
|
+
address: account.address,
|
|
69
|
+
xOnlyPubKey: account.xOnlyPubKey,
|
|
70
|
+
});
|
|
97
71
|
}
|