@stacks/clarinet-sdk-browser 3.25.0 → 4.0.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.
- package/README.md +1 -1
- package/dist/esm/browser/src/index.d.ts +1 -1
- package/dist/esm/browser/src/index.js.map +1 -1
- package/dist/esm/common/src/sdkProxy.d.ts +10 -18
- package/dist/esm/common/src/sdkProxy.js +15 -16
- package/dist/esm/common/src/sdkProxy.js.map +1 -1
- package/dist/esm/common/src/sdkProxyHelpers.d.ts +90 -1
- package/dist/esm/common/src/sdkProxyHelpers.js +62 -0
- package/dist/esm/common/src/sdkProxyHelpers.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ There are two ways to use the sdk in the browser:
|
|
|
29
29
|
```js
|
|
30
30
|
const simnet = await initSimnet();
|
|
31
31
|
await simnet.initEmptySession();
|
|
32
|
-
simnet.
|
|
32
|
+
simnet.execute("(+ 1 2)").result;
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
- With a clarinet project (ie: with a Clarinet.toml)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import init, { SDK } from "@stacks/clarinet-sdk-wasm-browser";
|
|
2
2
|
import { Simnet, getSessionProxy } from "./sdkProxy.js";
|
|
3
|
-
export { tx, type ClarityEvent, type ParsedTransactionResult, type DeployContractOptions, type Tx, type TransferSTX, } from "../../common/src/sdkProxyHelpers.js";
|
|
3
|
+
export { tx, type ClarityEvent, type ParsedTransactionResult, type BlockTransactionResult, type FailureKind, type BroadcastTransactionResult, type RawTransactionMetadata, type BroadcastTransaction, type DeployContractOptions, type Tx, type TransferSTX, } from "../../common/src/sdkProxyHelpers.js";
|
|
4
4
|
export { init, SDK, getSessionProxy, type Simnet };
|
|
5
5
|
export { defaultVfs, defaultFileStore } from "./defaultVfs.js";
|
|
6
6
|
export declare const initSimnet: (virtualFileSystem?: Function) => Promise<import("../../common/src/sdkProxy.js").ProxiedSimnet<SDK>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,GAAG,EAAE,MAAM,mCAAmC,CAAC;AAE9D,OAAO,EAAU,eAAe,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,0GAA0G;AAC1G,aAAa;AACb,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG;IACxB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,OAAO,EACL,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,GAAG,EAAE,MAAM,mCAAmC,CAAC;AAE9D,OAAO,EAAU,eAAe,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,0GAA0G;AAC1G,aAAa;AACb,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG;IACxB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,OAAO,EACL,EAAE,GAWH,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,EAAe,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,aAAa;AACb,UAAU,CAAC,GAAG,GAAG,UAAU,CAAC;AAE5B,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,iBAA4B,EAAE,EAAE;IAC/D,MAAM,IAAI,EAAE,CAAC;IACb,MAAM,GAAG,GAAG,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,UAAU,CAAC;IAC/D,OAAO,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,eAAe,EAAuB,CAAsB,CAAC;AAC9F,CAAC,CAAC"}
|
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import { type CallFn, type CallReadOnlyFn, type DeployContract, type Execute, type GetDataVar, type GetMapEntry, type MineBlock, type TransferSTX } from "./sdkProxyHelpers.js";
|
|
2
|
-
type WasmTransactionRes = {
|
|
3
|
-
result: string;
|
|
4
|
-
events: string;
|
|
5
|
-
costs: string;
|
|
6
|
-
performance?: string;
|
|
7
|
-
};
|
|
1
|
+
import { type SerializedTransactionResult, type SerializedBlockTransactionResult, type BroadcastTransaction, type CallFn, type CallReadOnlyFn, type DeployContract, type Execute, type GetDataVar, type GetMapEntry, type MineBlock, type TransferSTX } from "./sdkProxyHelpers.js";
|
|
8
2
|
type ProxySdk = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
broadcastTransaction(rawHex: string): string;
|
|
4
|
+
callReadOnlyFn(args: unknown): SerializedTransactionResult;
|
|
5
|
+
callPublicFn(args: unknown): SerializedTransactionResult;
|
|
6
|
+
callPrivateFn(args: unknown): SerializedTransactionResult;
|
|
7
|
+
deployContract(args: unknown): SerializedTransactionResult;
|
|
8
|
+
execute(snippet: string): SerializedTransactionResult;
|
|
14
9
|
getDataVar(contract: string, varName: string): string;
|
|
15
10
|
getMapEntry(contract: string, mapName: string, mapKey: Uint8Array): string;
|
|
16
|
-
mineBlock(txs: unknown[]):
|
|
17
|
-
|
|
18
|
-
transferSTX(args: unknown): WasmTransactionRes;
|
|
11
|
+
mineBlock(txs: unknown[]): SerializedBlockTransactionResult[];
|
|
12
|
+
transferSTX(args: unknown): SerializedTransactionResult;
|
|
19
13
|
};
|
|
20
|
-
/** @deprecated use `simnet.execute(command)` instead */
|
|
21
|
-
type RunSnippet<S extends ProxySdk> = S["runSnippet"];
|
|
22
14
|
export type ProxiedSimnet<S extends ProxySdk> = {
|
|
23
|
-
[K in keyof S]: K extends "callReadOnlyFn" ? CallReadOnlyFn : K extends "callPublicFn" | "callPrivateFn" ? CallFn : K extends "execute" ? Execute : K extends "
|
|
15
|
+
[K in keyof S]: K extends "broadcastTransaction" ? BroadcastTransaction : K extends "callReadOnlyFn" ? CallReadOnlyFn : K extends "callPublicFn" | "callPrivateFn" ? CallFn : K extends "execute" ? Execute : K extends "deployContract" ? DeployContract : K extends "transferSTX" ? TransferSTX : K extends "mineBlock" ? MineBlock : K extends "getDataVar" ? GetDataVar : K extends "getMapEntry" ? GetMapEntry : S[K];
|
|
24
16
|
};
|
|
25
17
|
type ProxyBindings<ContractOptions> = {
|
|
26
18
|
CallFnArgs: new (contract: string, method: string, args: Uint8Array[], sender: string, postConditions?: string[], postConditionMode?: string) => unknown;
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { Cl, serializeCVBytes } from "@stacks/transactions";
|
|
2
|
-
import {
|
|
3
|
-
function parseTxResponse(response) {
|
|
4
|
-
return {
|
|
5
|
-
result: Cl.deserialize(response.result),
|
|
6
|
-
events: parseEvents(response.events),
|
|
7
|
-
costs: parseCosts(response.costs),
|
|
8
|
-
performance: response.performance,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
2
|
+
import { parseBlockTransactionResult, getClarityVersionInputError, mineBlockWithValidatedVersions, parseTransactionResult, serializePostConditions, } from "./sdkProxyHelpers.js";
|
|
11
3
|
export function createSessionProxy(bindings) {
|
|
12
4
|
const { CallFnArgs, ContractOptions, DeployContractArgs, TransferSTXArgs } = bindings;
|
|
13
5
|
return {
|
|
@@ -17,33 +9,40 @@ export function createSessionProxy(bindings) {
|
|
|
17
9
|
const callFn = (contract, method, args, sender, options) => {
|
|
18
10
|
const { postConditions, postConditionMode } = serializePostConditions(options);
|
|
19
11
|
const response = sdk[prop](new CallFnArgs(contract, method, args.map(serializeCVBytes), sender, postConditions, postConditionMode));
|
|
20
|
-
return
|
|
12
|
+
return parseTransactionResult(response);
|
|
21
13
|
};
|
|
22
14
|
return callFn;
|
|
23
15
|
}
|
|
16
|
+
if (prop === "broadcastTransaction") {
|
|
17
|
+
const broadcast = (rawHex) => JSON.parse(sdk.broadcastTransaction(rawHex));
|
|
18
|
+
return broadcast;
|
|
19
|
+
}
|
|
24
20
|
if (prop === "execute") {
|
|
25
|
-
const execute = (snippet) =>
|
|
21
|
+
const execute = (snippet) => parseTransactionResult(sdk.execute(snippet));
|
|
26
22
|
return execute;
|
|
27
23
|
}
|
|
28
24
|
if (prop === "deployContract") {
|
|
29
25
|
const deployContract = (name, content, options, sender, postConditionOptions) => {
|
|
26
|
+
const error = getClarityVersionInputError(options?.clarityVersion);
|
|
27
|
+
if (error !== undefined)
|
|
28
|
+
throw new Error(error);
|
|
30
29
|
const rustOptions = options
|
|
31
30
|
? new ContractOptions(options.clarityVersion)
|
|
32
31
|
: new ContractOptions();
|
|
33
32
|
const { postConditions, postConditionMode } = serializePostConditions(postConditionOptions);
|
|
34
|
-
return
|
|
33
|
+
return parseTransactionResult(sdk.deployContract(new DeployContractArgs(name, content, rustOptions, sender, postConditions, postConditionMode)));
|
|
35
34
|
};
|
|
36
35
|
return deployContract;
|
|
37
36
|
}
|
|
38
37
|
if (prop === "transferSTX") {
|
|
39
38
|
const transferSTX = (amount, recipient, sender, options) => {
|
|
40
39
|
const { postConditions, postConditionMode } = serializePostConditions(options);
|
|
41
|
-
return
|
|
40
|
+
return parseTransactionResult(sdk.transferSTX(new TransferSTXArgs(BigInt(amount), recipient, sender, postConditions, postConditionMode)));
|
|
42
41
|
};
|
|
43
42
|
return transferSTX;
|
|
44
43
|
}
|
|
45
44
|
if (prop === "mineBlock") {
|
|
46
|
-
const mineBlock = (txs) => {
|
|
45
|
+
const mineBlock = (txs = []) => mineBlockWithValidatedVersions(txs, (txs) => {
|
|
47
46
|
const serializedTxs = txs.map((tx) => {
|
|
48
47
|
if (tx.callPublicFn) {
|
|
49
48
|
return {
|
|
@@ -66,8 +65,8 @@ export function createSessionProxy(bindings) {
|
|
|
66
65
|
}
|
|
67
66
|
return tx;
|
|
68
67
|
});
|
|
69
|
-
return sdk.mineBlock(serializedTxs).map(
|
|
70
|
-
};
|
|
68
|
+
return sdk.mineBlock(serializedTxs).map(parseBlockTransactionResult);
|
|
69
|
+
});
|
|
71
70
|
return mineBlock;
|
|
72
71
|
}
|
|
73
72
|
if (prop === "getDataVar") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkProxy.js","sourceRoot":"","sources":["../../../../../common/src/sdkProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"sdkProxy.js","sourceRoot":"","sources":["../../../../../common/src/sdkProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,8BAA8B,EAC9B,sBAAsB,EAGtB,uBAAuB,GAUxB,MAAM,sBAAsB,CAAC;AAgE9B,MAAM,UAAU,kBAAkB,CAChC,QAAwC;IAExC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,eAAe,EAAE,GAAG,QAAQ,CAAC;IAEtF,OAAO;QACL,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ;YACzB,MAAM,GAAG,GAAa,OAAO,CAAC;YAE9B,IAAI,IAAI,KAAK,gBAAgB,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,eAAe,EAAE,CAAC;gBACrF,MAAM,MAAM,GAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;oBACjE,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;oBAC/E,MAAM,QAAQ,GAAG,GA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B,CAAC;iCACvD;6BACF,CAAC;wBACJ,CAAC;wBACD,IAAI,EAAE,CAAC,cAAc,EAAE,CAAC;4BACtB,OAAO,EAAE,cAAc,EAAE,EAAE,GAAG,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC;wBACtD,CAAC;wBACD,OAAO,EAAE,CAAC;oBACZ,CAAC,CAAC,CAAC;oBACH,OAAO,GAAG,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;gBACvE,CAAC,CAAC,CAAC;gBACL,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC1B,MAAM,UAAU,GAAe,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACpF,OAAO,UAAU,CAAC;YACpB,CAAC;YAED,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;gBAC3B,MAAM,WAAW,GAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAC7D,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC/E,OAAO,WAAW,CAAC;YACrB,CAAC;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -26,6 +26,22 @@ export type ParsedTransactionResult = {
|
|
|
26
26
|
costs: ClarityCosts | null;
|
|
27
27
|
performance: string | undefined;
|
|
28
28
|
};
|
|
29
|
+
export type RawTransactionMetadata = {
|
|
30
|
+
txid: string;
|
|
31
|
+
fee: bigint;
|
|
32
|
+
nonce: bigint;
|
|
33
|
+
};
|
|
34
|
+
export type BroadcastTransactionResult = {
|
|
35
|
+
txid: string;
|
|
36
|
+
} | {
|
|
37
|
+
error: string;
|
|
38
|
+
reason: string;
|
|
39
|
+
reason_data?: Record<string, unknown>;
|
|
40
|
+
txid?: string;
|
|
41
|
+
};
|
|
42
|
+
/** Submit signed bytes to the mempool without executing or advancing the chain.
|
|
43
|
+
* Call `mineBlock()` to attempt inclusion; admission does not guarantee inclusion. */
|
|
44
|
+
export type BroadcastTransaction = (rawHex: string) => BroadcastTransactionResult;
|
|
29
45
|
/**
|
|
30
46
|
* Post-conditions to enforce on a simnet transaction.
|
|
31
47
|
*
|
|
@@ -48,13 +64,26 @@ export type CallReadOnlyFn = (contract: string, method: string, args: ClarityVal
|
|
|
48
64
|
export type DeployContractOptions = {
|
|
49
65
|
clarityVersion: ClarityVersion;
|
|
50
66
|
};
|
|
67
|
+
/** Deploy using the node's initialization rules. Success returns `(ok true)`,
|
|
68
|
+
* regardless of the initializer's final expression. */
|
|
51
69
|
export type DeployContract = (name: string, content: string, options: DeployContractOptions | null, sender: string, postConditionOptions?: PostConditionOptions) => ParsedTransactionResult;
|
|
70
|
+
/** Execute a native STX transfer. Invalid transfers (self-transfers, zero
|
|
71
|
+
* amounts and insufficient funds) throw without consuming a nonce. In
|
|
72
|
+
* `mineBlock`, they return a rejected outcome without consuming a
|
|
73
|
+
* nonce instead. */
|
|
52
74
|
export type TransferSTX = (amount: number | bigint, recipient: string, sender: string, options?: PostConditionOptions) => ParsedTransactionResult;
|
|
53
75
|
/**
|
|
54
76
|
* A transaction in a `mineBlock` batch. Post-conditions are already encoded,
|
|
55
77
|
* because the batch is handed to Wasm as plain JSON.
|
|
56
78
|
*/
|
|
57
79
|
export type Tx = {
|
|
80
|
+
broadcastTx: string;
|
|
81
|
+
callPublicFn?: never;
|
|
82
|
+
callPrivateFn?: never;
|
|
83
|
+
deployContract?: never;
|
|
84
|
+
transferSTX?: never;
|
|
85
|
+
} | {
|
|
86
|
+
broadcastTx?: never;
|
|
58
87
|
callPublicFn: {
|
|
59
88
|
contract: string;
|
|
60
89
|
method: string;
|
|
@@ -65,6 +94,7 @@ export type Tx = {
|
|
|
65
94
|
deployContract?: never;
|
|
66
95
|
transferSTX?: never;
|
|
67
96
|
} | {
|
|
97
|
+
broadcastTx?: never;
|
|
68
98
|
callPublicFn?: never;
|
|
69
99
|
callPrivateFn: {
|
|
70
100
|
contract: string;
|
|
@@ -75,6 +105,7 @@ export type Tx = {
|
|
|
75
105
|
deployContract?: never;
|
|
76
106
|
transferSTX?: never;
|
|
77
107
|
} | {
|
|
108
|
+
broadcastTx?: never;
|
|
78
109
|
callPublicFn?: never;
|
|
79
110
|
callPrivateFn?: never;
|
|
80
111
|
deployContract: {
|
|
@@ -85,6 +116,7 @@ export type Tx = {
|
|
|
85
116
|
} & SerializedPostConditions;
|
|
86
117
|
transferSTX?: never;
|
|
87
118
|
} | {
|
|
119
|
+
broadcastTx?: never;
|
|
88
120
|
callPublicFn?: never;
|
|
89
121
|
callPrivateFn?: never;
|
|
90
122
|
deployContract?: never;
|
|
@@ -94,6 +126,10 @@ export type Tx = {
|
|
|
94
126
|
sender: string;
|
|
95
127
|
} & SerializedPostConditions;
|
|
96
128
|
};
|
|
129
|
+
/** Check lossless u32 transport; Rust validates which Clarity versions are supported. */
|
|
130
|
+
export declare function getClarityVersionInputError(version: unknown): string | undefined;
|
|
131
|
+
/** Keep invalid versions as per-entry rejections, including when mining queued transactions. */
|
|
132
|
+
export declare function mineBlockWithValidatedVersions(txs: Tx[], mine: (txs: Tx[]) => BlockTransactionResult[]): BlockTransactionResult[];
|
|
97
133
|
export declare const tx: {
|
|
98
134
|
callPublicFn: (contract: string, method: string, args: ClarityValue[], sender: string, options?: PostConditionOptions) => Tx;
|
|
99
135
|
callPrivateFn: (contract: string, method: string, args: ClarityValue[], sender: string, options?: PostConditionOptions) => Tx;
|
|
@@ -102,7 +138,60 @@ export declare const tx: {
|
|
|
102
138
|
};
|
|
103
139
|
export declare function parseEvents(events: string): ClarityEvent[];
|
|
104
140
|
export declare function parseCosts(costs: string): ClarityCosts | null;
|
|
105
|
-
export type
|
|
141
|
+
export type FailureKind = "abort_by_response" | "abort_by_post_condition" | "runtime_error" | "analysis_error";
|
|
142
|
+
/** Signed entries carry their transaction metadata; convenience entries do not. */
|
|
143
|
+
export type MinedTransactionDetails = {
|
|
144
|
+
transaction?: RawTransactionMetadata | null;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* One outcome per selected queued transaction or explicit batch entry; rejected
|
|
148
|
+
* entries do not consume a nonce. Like a node's transaction receipt, an included
|
|
149
|
+
* failure's `execution` reports `(err none)`
|
|
150
|
+
* when execution produced no value, and post-condition aborts report the
|
|
151
|
+
* events they attempted, none of which were committed.
|
|
152
|
+
*/
|
|
153
|
+
export type BlockTransactionResult = MinedTransactionDetails & ({
|
|
154
|
+
status: "success";
|
|
155
|
+
execution: ParsedTransactionResult;
|
|
156
|
+
} | {
|
|
157
|
+
status: "included_failure";
|
|
158
|
+
kind: FailureKind;
|
|
159
|
+
error: string;
|
|
160
|
+
execution: ParsedTransactionResult;
|
|
161
|
+
} | {
|
|
162
|
+
status: "rejected";
|
|
163
|
+
error: string;
|
|
164
|
+
});
|
|
165
|
+
/** Advance one block and mine ready queued transactions, then explicit entries.
|
|
166
|
+
* Queued results precede explicit results, which retain input order. Rejections
|
|
167
|
+
* do not stop later entries; empty or entirely rejected batches still advance. */
|
|
168
|
+
export type MineBlock = (txs?: Array<Tx>) => BlockTransactionResult[];
|
|
169
|
+
export type SerializedTransactionResult = {
|
|
170
|
+
result: string;
|
|
171
|
+
events: string;
|
|
172
|
+
costs: string;
|
|
173
|
+
performance?: string;
|
|
174
|
+
};
|
|
175
|
+
export declare function parseTransactionResult(response: SerializedTransactionResult): ParsedTransactionResult;
|
|
176
|
+
export type SerializedBlockTransactionResult = {
|
|
177
|
+
transaction?: {
|
|
178
|
+
txid: string;
|
|
179
|
+
fee: string;
|
|
180
|
+
nonce: string;
|
|
181
|
+
} | null;
|
|
182
|
+
} & ({
|
|
183
|
+
status: "success";
|
|
184
|
+
execution: SerializedTransactionResult;
|
|
185
|
+
} | {
|
|
186
|
+
status: "included_failure";
|
|
187
|
+
kind: FailureKind;
|
|
188
|
+
error: string;
|
|
189
|
+
execution: SerializedTransactionResult;
|
|
190
|
+
} | {
|
|
191
|
+
status: "rejected";
|
|
192
|
+
error: string;
|
|
193
|
+
});
|
|
194
|
+
export declare function parseBlockTransactionResult(response: SerializedBlockTransactionResult): BlockTransactionResult;
|
|
106
195
|
export type Execute = (snippet: string) => ParsedTransactionResult;
|
|
107
196
|
export type GetDataVar = (contract: string, dataVar: string) => ClarityValue;
|
|
108
197
|
export type GetMapEntry = (contract: string, mapName: string, mapKey: ClarityValue) => ClarityValue;
|
|
@@ -24,6 +24,29 @@ export function serializePostConditions(options) {
|
|
|
24
24
|
}),
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
+
/** Check lossless u32 transport; Rust validates which Clarity versions are supported. */
|
|
28
|
+
export function getClarityVersionInputError(version) {
|
|
29
|
+
if (version === undefined)
|
|
30
|
+
return;
|
|
31
|
+
if (typeof version !== "number" ||
|
|
32
|
+
!Number.isInteger(version) ||
|
|
33
|
+
version < 0 ||
|
|
34
|
+
version > 0xffffffff) {
|
|
35
|
+
return "Invalid Clarity version: expected an unsigned 32-bit integer";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Keep invalid versions as per-entry rejections, including when mining queued transactions. */
|
|
39
|
+
export function mineBlockWithValidatedVersions(txs, mine) {
|
|
40
|
+
const errors = txs.map((entry) => getClarityVersionInputError(entry.deployContract?.options?.clarityVersion));
|
|
41
|
+
const valid = txs.filter((_, index) => errors[index] === undefined);
|
|
42
|
+
const results = mine(valid);
|
|
43
|
+
const queuedCount = results.length - valid.length;
|
|
44
|
+
let index = queuedCount;
|
|
45
|
+
return [
|
|
46
|
+
...results.slice(0, queuedCount),
|
|
47
|
+
...errors.map((error) => error === undefined ? results[index++] : { status: "rejected", error }),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
27
50
|
export const tx = {
|
|
28
51
|
callPublicFn: (contract, method, args, sender, options) => ({
|
|
29
52
|
callPublicFn: { contract, method, args, sender, ...serializePostConditions(options) },
|
|
@@ -89,4 +112,43 @@ export function parseCosts(costs) {
|
|
|
89
112
|
return null;
|
|
90
113
|
}
|
|
91
114
|
}
|
|
115
|
+
export function parseTransactionResult(response) {
|
|
116
|
+
return {
|
|
117
|
+
result: Cl.deserialize(response.result),
|
|
118
|
+
events: parseEvents(response.events),
|
|
119
|
+
costs: parseCosts(response.costs),
|
|
120
|
+
performance: response.performance ?? undefined,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export function parseBlockTransactionResult(response) {
|
|
124
|
+
const details = {};
|
|
125
|
+
if (response.transaction !== undefined) {
|
|
126
|
+
details.transaction =
|
|
127
|
+
response.transaction === null
|
|
128
|
+
? null
|
|
129
|
+
: {
|
|
130
|
+
txid: response.transaction.txid,
|
|
131
|
+
fee: BigInt(response.transaction.fee),
|
|
132
|
+
nonce: BigInt(response.transaction.nonce),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
switch (response.status) {
|
|
136
|
+
case "rejected":
|
|
137
|
+
return { ...details, status: "rejected", error: response.error };
|
|
138
|
+
case "success":
|
|
139
|
+
return {
|
|
140
|
+
...details,
|
|
141
|
+
status: "success",
|
|
142
|
+
execution: parseTransactionResult(response.execution),
|
|
143
|
+
};
|
|
144
|
+
case "included_failure":
|
|
145
|
+
return {
|
|
146
|
+
...details,
|
|
147
|
+
status: "included_failure",
|
|
148
|
+
kind: response.kind,
|
|
149
|
+
error: response.error,
|
|
150
|
+
execution: parseTransactionResult(response.execution),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
92
154
|
//# sourceMappingURL=sdkProxyHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkProxyHelpers.js","sourceRoot":"","sources":["../../../../../common/src/sdkProxyHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EAKF,iBAAiB,EAGjB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"sdkProxyHelpers.js","sourceRoot":"","sources":["../../../../../common/src/sdkProxyHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EAKF,iBAAiB,EAGjB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AA2D9B,MAAM,UAAU,uBAAuB,CAAC,OAA8B;IACpE,MAAM,UAAU,GAAG,OAAO,EAAE,cAAc,CAAC;IAC3C,MAAM,IAAI,GAAG,OAAO,EAAE,iBAAiB,CAAC;IAExC,8EAA8E;IAC9E,OAAO;QACL,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI;YAC9B,cAAc,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;gBACpC,IAAI,OAAO,EAAE,KAAK,QAAQ;oBAAE,OAAO,EAAE,CAAC;gBACtC,OAAO,OAAO,EAAE,CAAC,IAAI,KAAK,QAAQ;oBAChC,CAAC,CAAC,kBAAkB,CAAC,EAAmB,CAAC;oBACzC,CAAC,CAAC,0BAA0B,CAAC,EAAuB,CAAC,CAAC;YAC1D,CAAC,CAAC;SACH,CAAC;QACF,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI;YACxB,iBAAiB,EACf,IAAI,KAAK,iBAAiB,CAAC,KAAK;gBAC9B,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,IAAI,KAAK,iBAAiB,CAAC,IAAI;oBAC/B,CAAC,CAAC,MAAM;oBACR,CAAC,CAAC,IAAI,KAAK,iBAAiB,CAAC,UAAU;wBACrC,CAAC,CAAC,YAAY;wBACd,CAAC,CAAC,IAAI;SACf,CAAC;KACH,CAAC;AACJ,CAAC;AAsGD,yFAAyF;AACzF,MAAM,UAAU,2BAA2B,CAAC,OAAgB;IAC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C;IAE1C,MAAM,OAAO,GAA4B,EAAE,CAAC;IAC5C,IAAI,QAAQ,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,CAAC,WAAW;YACjB,QAAQ,CAAC,WAAW,KAAK,IAAI;gBAC3B,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC;oBACE,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,IAAI;oBAC/B,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC;oBACrC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC;iBAC1C,CAAC;IACV,CAAC;IACD,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;QACxB,KAAK,UAAU;YACb,OAAO,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;QACnE,KAAK,SAAS;YACZ,OAAO;gBACL,GAAG,OAAO;gBACV,MAAM,EAAE,SAAS;gBACjB,SAAS,EAAE,sBAAsB,CAAC,QAAQ,CAAC,SAAS,CAAC;aACtD,CAAC;QACJ,KAAK,kBAAkB;YACrB,OAAO;gBACL,GAAG,OAAO;gBACV,MAAM,EAAE,kBAAkB;gBAC1B,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,SAAS,EAAE,sBAAsB,CAAC,QAAQ,CAAC,SAAS,CAAC;aACtD,CAAC;IACN,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacks/clarinet-sdk-browser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"author": "Stacks Labs",
|
|
5
5
|
"description": "A SDK to interact with Clarity Smart Contracts in the browser",
|
|
6
6
|
"homepage": "https://stackslabs.com/clarinet",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"license": "GPL-3.0",
|
|
23
23
|
"readme": "./README.md",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@stacks/
|
|
26
|
-
"@stacks/
|
|
25
|
+
"@stacks/clarinet-sdk-wasm-browser": "4.0.0",
|
|
26
|
+
"@stacks/transactions": "7.6.0"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"clean": "rimraf dist",
|