@kontor/kontor-sdk 1.0.0-alpha.27 → 1.0.0-alpha.28
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/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/tsconfig.build.tsbuildinfo +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/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/sdk/actions/kontor/public/build-compose-query.d.ts +5 -3
- 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/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/wit/type-utils.d.ts.map +1 -1
- package/dist/types/wit/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/sdk/actions/kontor/public/build-compose-query.ts +23 -22
- 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 +21 -0
- package/src/sdk/types/chain.ts +0 -2
- 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/wit/type-utils.ts +0 -2
- package/src/wit/utils.ts +3 -6
|
@@ -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
|
}
|
|
@@ -34,7 +34,7 @@ export type CallComposeParameters<
|
|
|
34
34
|
| [Address, XOnlyPubKey]
|
|
35
35
|
| undefined,
|
|
36
36
|
> = CallComposeRequest &
|
|
37
|
-
GetAccountParameter<account, accountOverride,
|
|
37
|
+
GetAccountParameter<account, accountOverride, true, true> &
|
|
38
38
|
GetChainParameter<chain, chainOverride>;
|
|
39
39
|
|
|
40
40
|
// TODO: organize these types or just refernece direc
|
|
@@ -56,6 +56,7 @@ export async function callCompose<
|
|
|
56
56
|
): Promise<CallComposeReturnType> {
|
|
57
57
|
const {
|
|
58
58
|
account: account_ = client.account,
|
|
59
|
+
chain = client.chain,
|
|
59
60
|
utxos,
|
|
60
61
|
satsPerVByte,
|
|
61
62
|
instruction,
|
|
@@ -66,6 +67,10 @@ export async function callCompose<
|
|
|
66
67
|
throw new Error("Account is required");
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
if (!chain) {
|
|
71
|
+
throw new Error("Chain is required");
|
|
72
|
+
}
|
|
73
|
+
|
|
69
74
|
if (utxos.length === 0) {
|
|
70
75
|
// TODO: add custom error
|
|
71
76
|
throw new Error("at least one funding UTXO is required");
|
|
@@ -74,15 +79,14 @@ export async function callCompose<
|
|
|
74
79
|
//
|
|
75
80
|
const account = parseAccount(account_);
|
|
76
81
|
|
|
77
|
-
const composeCall =
|
|
82
|
+
const composeCall = getKontorAction(
|
|
78
83
|
client,
|
|
79
84
|
buildComposeQuery,
|
|
80
85
|
"buildComposeQuery",
|
|
81
86
|
)({
|
|
82
87
|
instruction,
|
|
83
88
|
utxos,
|
|
84
|
-
|
|
85
|
-
address: account.address,
|
|
89
|
+
account,
|
|
86
90
|
satsPerVByte,
|
|
87
91
|
});
|
|
88
92
|
|
|
@@ -5,15 +5,15 @@ import type {
|
|
|
5
5
|
import type { ResolvedRegister } from "../../../../wit/register.js";
|
|
6
6
|
import type { KontorPublicClient } from "../../../clients/kontor/create-public-client.js";
|
|
7
7
|
import type { HttpTransport } from "../../../clients/transports/create-http-transport.js";
|
|
8
|
-
import type { Chain } from "../../../types/chain.js";
|
|
8
|
+
import type { Chain, GetChainParameter } from "../../../types/chain.js";
|
|
9
9
|
|
|
10
10
|
export type CallViewParameters<
|
|
11
|
-
|
|
11
|
+
chain extends Chain | undefined = Chain,
|
|
12
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
|
12
13
|
> = {
|
|
13
14
|
contractAddress: ResolvedRegister["contractAddress"];
|
|
14
15
|
wave: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
16
|
+
} & GetChainParameter<chain, chainOverride>;
|
|
17
17
|
// TODO: refine this type
|
|
18
18
|
export type CallViewReturnType = ResultResponse<ViewResult>;
|
|
19
19
|
|
|
@@ -24,6 +24,7 @@ export async function callView<
|
|
|
24
24
|
params: CallViewParameters<chain>,
|
|
25
25
|
): Promise<CallViewReturnType> {
|
|
26
26
|
const { contractAddress, wave } = params;
|
|
27
|
+
// TODO: assert chain
|
|
27
28
|
|
|
28
29
|
try {
|
|
29
30
|
const response = await client.request({
|
|
@@ -5,19 +5,34 @@ import type {
|
|
|
5
5
|
} from "../../../types/kontor.js";
|
|
6
6
|
import type { KontorPublicClient } from "../../../clients/kontor/create-public-client.js";
|
|
7
7
|
import type { HttpTransport } from "../../../clients/transports/create-http-transport.js";
|
|
8
|
-
import type { Chain } from "../../../types/chain.js";
|
|
9
|
-
|
|
10
|
-
export type InspectParameters = TransactionHex;
|
|
8
|
+
import type { Chain, GetChainParameter } from "../../../types/chain.js";
|
|
9
|
+
// import { assertCurrentChain } from "../../../utils/chain/assert-current-chain.js";
|
|
11
10
|
|
|
11
|
+
export type InspectParameters<
|
|
12
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
13
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
|
14
|
+
> = TransactionHex & GetChainParameter<chain, chainOverride>;
|
|
12
15
|
export type InspectReturnType = ResultResponse<OpWithResult[]>;
|
|
13
16
|
|
|
14
17
|
export async function inspect<
|
|
15
18
|
chain extends Chain | undefined = Chain | undefined,
|
|
19
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
|
16
20
|
>(
|
|
17
21
|
client: KontorPublicClient<HttpTransport, chain>,
|
|
18
|
-
params: InspectParameters,
|
|
22
|
+
params: InspectParameters<chain, chainOverride>,
|
|
19
23
|
): Promise<InspectReturnType> {
|
|
20
|
-
const {
|
|
24
|
+
const {
|
|
25
|
+
hex,
|
|
26
|
+
// chain: chain_ = client.chain
|
|
27
|
+
} = params;
|
|
28
|
+
|
|
29
|
+
// TODO: chain assertions everywhere ( need to get current chain )
|
|
30
|
+
|
|
31
|
+
// assertCurrentChain({
|
|
32
|
+
// currentChain: client.chain,
|
|
33
|
+
// chain: chain_
|
|
34
|
+
// });
|
|
35
|
+
//
|
|
21
36
|
|
|
22
37
|
try {
|
|
23
38
|
const response = await client.request({
|
|
@@ -27,10 +42,6 @@ export async function inspect<
|
|
|
27
42
|
body: { hex: hex },
|
|
28
43
|
});
|
|
29
44
|
|
|
30
|
-
console.log("callView response:", response);
|
|
31
|
-
|
|
32
|
-
// TODO: fix CallViwewReturnType
|
|
33
|
-
// @ts-ignore
|
|
34
45
|
return response;
|
|
35
46
|
} catch (e) {
|
|
36
47
|
// TODO: augment error handling
|
|
@@ -31,13 +31,12 @@ test.skip("e2e", async () => {
|
|
|
31
31
|
"tb1pj2wrjsg0ksmmflec0myf3j7qnqm9myvk2pesqn7y8cqn6sgdg9ls9u6tar",
|
|
32
32
|
"2c7b730daa0036e8276cdd8fabe844b2dd324a6d227dd209663805189d03e51f",
|
|
33
33
|
],
|
|
34
|
+
chain: signet,
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
// proc contract action defined on client
|
|
37
38
|
// response is correctly typed
|
|
38
39
|
const res = await client.procContract({
|
|
39
|
-
account: client.account!,
|
|
40
|
-
chain: signet,
|
|
41
40
|
wit: wit,
|
|
42
41
|
// can also be injected
|
|
43
42
|
|
|
@@ -18,52 +18,6 @@ import {
|
|
|
18
18
|
} from "../../../utils/wit/encode-function-data.js";
|
|
19
19
|
import { callCompose, type CallComposeReturnType } from "./call-compose.js";
|
|
20
20
|
|
|
21
|
-
// export type WriteContractParameters<
|
|
22
|
-
// abi extends Abi | readonly unknown[] = Abi,
|
|
23
|
-
// functionName extends ContractFunctionName<
|
|
24
|
-
// abi,
|
|
25
|
-
// 'nonpayable' | 'payable'
|
|
26
|
-
// > = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
27
|
-
// args extends ContractFunctionArgs<
|
|
28
|
-
// abi,
|
|
29
|
-
// 'nonpayable' | 'payable',
|
|
30
|
-
// functionName
|
|
31
|
-
// > = ContractFunctionArgs<abi, 'nonpayable' | 'payable', functionName>,
|
|
32
|
-
// chain extends Chain | undefined = Chain | undefined,
|
|
33
|
-
// account extends Account | undefined = Account | undefined,
|
|
34
|
-
// chainOverride extends Chain | undefined = Chain | undefined,
|
|
35
|
-
// ///
|
|
36
|
-
// allFunctionNames = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
37
|
-
// derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
|
38
|
-
// > = ContractFunctionParameters<
|
|
39
|
-
// abi,
|
|
40
|
-
// 'nonpayable' | 'payable',
|
|
41
|
-
// functionName,
|
|
42
|
-
// args,
|
|
43
|
-
// false,
|
|
44
|
-
// allFunctionNames
|
|
45
|
-
// > &
|
|
46
|
-
// GetChainParameter<chain, chainOverride> &
|
|
47
|
-
// Prettify<
|
|
48
|
-
// GetAccountParameter<account, Account | Address, true, true> &
|
|
49
|
-
// GetMutabilityAwareValue<
|
|
50
|
-
// abi,
|
|
51
|
-
// 'nonpayable' | 'payable',
|
|
52
|
-
// functionName,
|
|
53
|
-
// FormattedTransactionRequest<derivedChain>['value'],
|
|
54
|
-
// args
|
|
55
|
-
// > & {
|
|
56
|
-
// /** Data to append to the end of the calldata. Useful for adding a ["domain" tag](https://opensea.notion.site/opensea/Seaport-Order-Attributions-ec2d69bf455041a5baa490941aad307f). */
|
|
57
|
-
// dataSuffix?: Hex | undefined
|
|
58
|
-
// }
|
|
59
|
-
// > &
|
|
60
|
-
// UnionEvaluate<
|
|
61
|
-
// UnionOmit<
|
|
62
|
-
// FormattedTransactionRequest<derivedChain>,
|
|
63
|
-
// 'data' | 'from' | 'to' | 'value'
|
|
64
|
-
// >
|
|
65
|
-
// >
|
|
66
|
-
|
|
67
21
|
export type ProcContractParameters<
|
|
68
22
|
wit extends Wit | readonly unknown[] = Wit,
|
|
69
23
|
functionName extends ContractFunctionName<wit, "proc"> = ContractFunctionName<
|
|
@@ -78,12 +32,16 @@ export type ProcContractParameters<
|
|
|
78
32
|
chain extends Chain | undefined = Chain | undefined,
|
|
79
33
|
account extends Account | undefined = Account | undefined,
|
|
80
34
|
chainOverride extends Chain | undefined = Chain | undefined,
|
|
35
|
+
accountOverride extends Account | [Address, XOnlyPubKey] | undefined =
|
|
36
|
+
| Account
|
|
37
|
+
| [Address, XOnlyPubKey]
|
|
38
|
+
| undefined,
|
|
81
39
|
> = ContractFunctionParameters<wit, "proc", functionName, args> & {
|
|
82
40
|
utxos: UtxoId[];
|
|
83
41
|
gas: bigint;
|
|
84
42
|
satsPerVByte: number;
|
|
85
43
|
} & GetChainParameter<chain, chainOverride> &
|
|
86
|
-
GetAccountParameter<account,
|
|
44
|
+
GetAccountParameter<account, accountOverride, true, true>;
|
|
87
45
|
|
|
88
46
|
export type ProcContractReturnType = CallComposeReturnType;
|
|
89
47
|
|
|
@@ -93,9 +51,18 @@ export async function procContract<
|
|
|
93
51
|
const wit extends Wit | readonly unknown[],
|
|
94
52
|
functionName extends ContractFunctionName<wit, "proc">,
|
|
95
53
|
const args extends ContractFunctionArgs<wit, "proc", functionName>,
|
|
54
|
+
account extends Account | undefined,
|
|
55
|
+
chainOverride extends Chain | undefined = undefined,
|
|
96
56
|
>(
|
|
97
57
|
client: KontorPublicClient<HttpTransport, chain>,
|
|
98
|
-
parameters: ProcContractParameters<
|
|
58
|
+
parameters: ProcContractParameters<
|
|
59
|
+
wit,
|
|
60
|
+
functionName,
|
|
61
|
+
args,
|
|
62
|
+
chain,
|
|
63
|
+
account,
|
|
64
|
+
chainOverride
|
|
65
|
+
>,
|
|
99
66
|
): Promise<ProcContractReturnType> {
|
|
100
67
|
const {
|
|
101
68
|
wit: wit,
|
|
@@ -111,13 +78,6 @@ export async function procContract<
|
|
|
111
78
|
...rest
|
|
112
79
|
} = parameters as ProcContractParameters;
|
|
113
80
|
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
const wave = encodeFunctionData({
|
|
116
|
-
wit: wit,
|
|
117
|
-
args,
|
|
118
|
-
functionName,
|
|
119
|
-
} as EncodeFunctionDataParameters);
|
|
120
|
-
|
|
121
81
|
if (!account_) {
|
|
122
82
|
// TODO: add custom error
|
|
123
83
|
throw new Error("account is required");
|
|
@@ -128,6 +88,12 @@ export async function procContract<
|
|
|
128
88
|
throw new Error("at least one funding UTXO is required");
|
|
129
89
|
}
|
|
130
90
|
|
|
91
|
+
const wave = encodeFunctionData({
|
|
92
|
+
wit: wit,
|
|
93
|
+
args,
|
|
94
|
+
functionName,
|
|
95
|
+
} as EncodeFunctionDataParameters);
|
|
96
|
+
|
|
131
97
|
try {
|
|
132
98
|
const response = await getKontorAction(
|
|
133
99
|
client,
|
|
@@ -4,16 +4,16 @@ import { parseWit } from "../../../../wit/wit-parser/parse-wit.js";
|
|
|
4
4
|
import { createPublicClient } from "../../../clients/kontor/create-public-client.js";
|
|
5
5
|
import { http } from "../../../clients/transports/http.js";
|
|
6
6
|
import { nativeToken } from "../../../contracts/wits.js";
|
|
7
|
+
import { signet } from "../../../chains/definitions/signet.js";
|
|
7
8
|
|
|
8
9
|
const wit = parseWit(nativeToken.raw);
|
|
9
10
|
|
|
10
11
|
test("e2e", async () => {
|
|
11
12
|
const client = createPublicClient({
|
|
12
13
|
transport: http("https://signet-staging.kontor.network:35000/api"),
|
|
14
|
+
chain: signet,
|
|
13
15
|
});
|
|
14
16
|
|
|
15
|
-
// view contract action defined on client
|
|
16
|
-
// response is correctly typed
|
|
17
17
|
const res = await client.viewContract({
|
|
18
18
|
wit: wit,
|
|
19
19
|
functionName: "balances", // functin name is only valid if it's got a view-context
|
|
@@ -2,7 +2,7 @@ import type { Wit } from "../../../../wit/wit.js";
|
|
|
2
2
|
import type { Prettify } from "../../../../wit/type-utils.js";
|
|
3
3
|
import type { KontorPublicClient } from "../../../clients/kontor/create-public-client.js";
|
|
4
4
|
import type { HttpTransport } from "../../../clients/transports/create-http-transport.js";
|
|
5
|
-
import type { Chain } from "../../../types/chain.js";
|
|
5
|
+
import type { Chain, GetChainParameter } from "../../../types/chain.js";
|
|
6
6
|
import type {
|
|
7
7
|
ContractFunctionArgs,
|
|
8
8
|
ContractFunctionName,
|
|
@@ -11,7 +11,6 @@ import type {
|
|
|
11
11
|
} from "../../../types/contract.js";
|
|
12
12
|
import { getKontorAction } from "../../../utils/get-action.js";
|
|
13
13
|
import { decodeFunctionResult } from "../../../utils/wit/decode-function-result.js";
|
|
14
|
-
// import { getAction } from "../../utils/getAction.js";
|
|
15
14
|
import {
|
|
16
15
|
encodeFunctionData,
|
|
17
16
|
type EncodeFunctionDataParameters,
|
|
@@ -29,7 +28,10 @@ export type ViewContractParameters<
|
|
|
29
28
|
"view",
|
|
30
29
|
functionName
|
|
31
30
|
> = ContractFunctionArgs<wit, "view", functionName>,
|
|
32
|
-
|
|
31
|
+
chain extends Chain | undefined = Chain,
|
|
32
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
|
33
|
+
> = ContractFunctionParameters<wit, "view", functionName, args> &
|
|
34
|
+
GetChainParameter<chain, chainOverride>;
|
|
33
35
|
|
|
34
36
|
export type ViewContractReturnType<
|
|
35
37
|
wit extends Wit | readonly unknown[] = Wit,
|
|
@@ -46,26 +48,24 @@ export type ViewContractReturnType<
|
|
|
46
48
|
> = Prettify<ContractFunctionReturnType<wit, "view", functionName, args>>;
|
|
47
49
|
|
|
48
50
|
export async function viewContract<
|
|
49
|
-
// chain exhttps://viem.sh/tends Chain | undefined,
|
|
50
51
|
chain extends Chain | undefined,
|
|
51
52
|
const wit extends Wit | readonly unknown[],
|
|
52
53
|
functionName extends ContractFunctionName<wit, "view">,
|
|
53
54
|
const args extends ContractFunctionArgs<wit, "view", functionName>,
|
|
54
55
|
>(
|
|
55
56
|
client: KontorPublicClient<HttpTransport, chain>,
|
|
56
|
-
parameters: ViewContractParameters<wit, functionName, args>,
|
|
57
|
+
parameters: ViewContractParameters<wit, functionName, args, chain>,
|
|
57
58
|
): Promise<ViewContractReturnType<wit, functionName, args>> {
|
|
58
59
|
const {
|
|
59
60
|
wit: wit,
|
|
60
61
|
contractAddress,
|
|
61
62
|
args,
|
|
62
63
|
functionName,
|
|
63
|
-
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
...rest
|
|
64
|
+
chain: chain_ = client.chain,
|
|
66
65
|
} = parameters as ViewContractParameters;
|
|
67
66
|
|
|
68
|
-
//
|
|
67
|
+
//TODO: assert chain ( or delegate to downstream call )
|
|
68
|
+
|
|
69
69
|
const wave = encodeFunctionData({
|
|
70
70
|
wit: wit,
|
|
71
71
|
args,
|
|
@@ -80,6 +80,7 @@ export async function viewContract<
|
|
|
80
80
|
)({
|
|
81
81
|
contractAddress: contractAddress,
|
|
82
82
|
wave: wave,
|
|
83
|
+
chain: chain_,
|
|
83
84
|
});
|
|
84
85
|
|
|
85
86
|
console.log(response.result.type);
|
|
@@ -59,35 +59,44 @@ export type KontorPublicActions<
|
|
|
59
59
|
const wit extends Wit | readonly unknown[],
|
|
60
60
|
functionName extends ContractFunctionName<wit, "view">,
|
|
61
61
|
const args extends ContractFunctionArgs<wit, "view", functionName>,
|
|
62
|
+
chainOverride extends Chain | undefined,
|
|
62
63
|
>(
|
|
63
|
-
args: ViewContractParameters<wit, functionName, args>,
|
|
64
|
+
args: ViewContractParameters<wit, functionName, args, chain, chainOverride>,
|
|
64
65
|
) => Promise<ViewContractReturnType<wit, functionName, args>>;
|
|
65
66
|
|
|
66
67
|
procContract: <
|
|
67
68
|
const wit extends Wit | readonly unknown[],
|
|
68
69
|
functionName extends ContractFunctionName<wit, "proc">,
|
|
69
70
|
const args extends ContractFunctionArgs<wit, "proc", functionName>,
|
|
71
|
+
chainOverride extends Chain | undefined,
|
|
70
72
|
>(
|
|
71
|
-
args: ProcContractParameters<
|
|
73
|
+
args: ProcContractParameters<
|
|
74
|
+
wit,
|
|
75
|
+
functionName,
|
|
76
|
+
args,
|
|
77
|
+
chain,
|
|
78
|
+
account,
|
|
79
|
+
chainOverride
|
|
80
|
+
>,
|
|
72
81
|
) => Promise<ProcContractReturnType>;
|
|
73
82
|
|
|
74
|
-
callView: <
|
|
75
|
-
args: CallViewParameters<chain>,
|
|
83
|
+
callView: <chainOverride extends Chain | undefined>(
|
|
84
|
+
args: CallViewParameters<chain, chainOverride>,
|
|
76
85
|
) => Promise<CallViewReturnType>;
|
|
77
86
|
|
|
78
|
-
buildInstructionQuery:
|
|
79
|
-
args: BuildInstructionQueryParameters<
|
|
80
|
-
) =>
|
|
87
|
+
buildInstructionQuery: (
|
|
88
|
+
args: BuildInstructionQueryParameters<account>,
|
|
89
|
+
) => BuildInstructionQueryReturnType;
|
|
81
90
|
|
|
82
|
-
buildComposeQuery:
|
|
83
|
-
args: BuildComposeQueryParameters<
|
|
84
|
-
) =>
|
|
91
|
+
buildComposeQuery: (
|
|
92
|
+
args: BuildComposeQueryParameters<account>,
|
|
93
|
+
) => BuildComposeQueryReturnType;
|
|
85
94
|
|
|
86
95
|
callCompose: <chainOverride extends Chain | undefined>(
|
|
87
96
|
args: CallComposeParameters<chain, account, chainOverride>,
|
|
88
97
|
) => Promise<CallComposeReturnType>;
|
|
89
|
-
inspect: <
|
|
90
|
-
args: InspectParameters,
|
|
98
|
+
inspect: <chainOverride extends Chain | undefined>(
|
|
99
|
+
args: InspectParameters<chain, chainOverride>,
|
|
91
100
|
) => Promise<InspectReturnType>;
|
|
92
101
|
};
|
|
93
102
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Chain } from "../types/chain.js";
|
|
2
|
+
|
|
3
|
+
import { BaseError } from "./base.js";
|
|
4
|
+
|
|
5
|
+
export type ChainMismatchErrorType = ChainMismatchError & {
|
|
6
|
+
name: "ChainMismatchError";
|
|
7
|
+
};
|
|
8
|
+
export class ChainMismatchError extends BaseError {
|
|
9
|
+
constructor({ chain, currentChain }: { chain: Chain; currentChain: Chain }) {
|
|
10
|
+
super(
|
|
11
|
+
`The current chain of the wallet (name: ${currentChain.name}) does not match the target chain for the transaction (name: ${chain.name}).`,
|
|
12
|
+
{
|
|
13
|
+
metaMessages: [
|
|
14
|
+
`Current Chain: ${currentChain.name}`,
|
|
15
|
+
`Expected Chain: ${chain.name}`,
|
|
16
|
+
],
|
|
17
|
+
name: "ChainMismatchError",
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type ChainNotFoundErrorType = ChainNotFoundError & {
|
|
24
|
+
name: "ChainNotFoundError";
|
|
25
|
+
};
|
|
26
|
+
export class ChainNotFoundError extends BaseError {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(
|
|
29
|
+
[
|
|
30
|
+
"No chain was provided to the request.",
|
|
31
|
+
"Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient.",
|
|
32
|
+
].join("\n"),
|
|
33
|
+
{
|
|
34
|
+
name: "ChainNotFoundError",
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ClientChainNotConfiguredErrorType =
|
|
41
|
+
ClientChainNotConfiguredError & {
|
|
42
|
+
name: "ClientChainNotConfiguredError";
|
|
43
|
+
};
|
|
44
|
+
export class ClientChainNotConfiguredError extends BaseError {
|
|
45
|
+
constructor() {
|
|
46
|
+
super("No chain was provided to the Client.", {
|
|
47
|
+
name: "ClientChainNotConfiguredError",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type InvalidChainIdErrorType = InvalidChainIdError & {
|
|
53
|
+
name: "InvalidChainIdError";
|
|
54
|
+
};
|
|
55
|
+
export class InvalidChainIdError extends BaseError {
|
|
56
|
+
constructor({ chainId }: { chainId?: number | undefined }) {
|
|
57
|
+
super(
|
|
58
|
+
typeof chainId === "number"
|
|
59
|
+
? `Chain ID "${chainId}" is invalid.`
|
|
60
|
+
: "Chain ID is invalid.",
|
|
61
|
+
{ name: "InvalidChainIdError" },
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/sdk/test/e2e.test.ts
CHANGED
|
@@ -140,6 +140,27 @@ test("e2e kontor wallet client", async () => {
|
|
|
140
140
|
satsPerVByte: 1,
|
|
141
141
|
});
|
|
142
142
|
|
|
143
|
+
// TODO: add separate tests for these
|
|
144
|
+
// const instructionQuery_ = kontorPublicClient.buildInstructionQuery({
|
|
145
|
+
// utxos: [
|
|
146
|
+
// "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
|
|
147
|
+
// ],
|
|
148
|
+
// instruction: Instruction.issuance(),
|
|
149
|
+
// });
|
|
150
|
+
//
|
|
151
|
+
// const composeQuery_ = kontorPublicClient.buildComposeQuery({
|
|
152
|
+
// utxos: [
|
|
153
|
+
// "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
|
|
154
|
+
// ],
|
|
155
|
+
//
|
|
156
|
+
// instruction: Instruction.issuance(),
|
|
157
|
+
// satsPerVByte: 1,
|
|
158
|
+
// });
|
|
159
|
+
// const x = await kontorPublicClient.callView({
|
|
160
|
+
// contractAddress: "token_0_0",
|
|
161
|
+
// wave: "balances()",
|
|
162
|
+
// });
|
|
163
|
+
|
|
143
164
|
const commit: Transaction = await kontorWalletClient.signCommit({
|
|
144
165
|
psbt: res.result.commit_psbt_hex,
|
|
145
166
|
});
|