bump the Stacks JS SDK to the latest version.

This commit is contained in:
Kyle Fang
2024-11-28 05:21:15 +00:00
parent b8cbe159fc
commit dacad97ab4
6 changed files with 48 additions and 56 deletions

View File

@@ -59,7 +59,7 @@ const xlinkContracts = [
Example: Example:
```typescript ```typescript
import { callReadOnlyFunction } from "@stacks/transactions"; import { fetchReadOnlyFunction } from "@stacks/transactions";
import { tupleT, stringT } from "clarity-codegen"; import { tupleT, stringT } from "clarity-codegen";
import { AlexContracts } from "./generated/contracts_Alex"; import { AlexContracts } from "./generated/contracts_Alex";
@@ -76,7 +76,7 @@ const functionDescriptor = AlexContracts[contractName][readonlyFunctionName];
const clarityArgs = functionDescriptor.input.map((arg) => const clarityArgs = functionDescriptor.input.map((arg) =>
arg.type.encode(readonlyFunctionArgs[arg.name]) arg.type.encode(readonlyFunctionArgs[arg.name])
); );
const result = await callReadOnlyFunction({ const result = await fetchReadOnlyFunction({
contractName, contractName,
functionName: readonlyFunctionName, functionName: readonlyFunctionName,
functionArgs: clarityArgs, functionArgs: clarityArgs,

View File

@@ -1,6 +1,6 @@
{ {
"name": "clarity-codegen", "name": "clarity-codegen",
"version": "0.5.3", "version": "1.0.0-beta.1",
"main": "./lib/index.js", "main": "./lib/index.js",
"module": "./dist/index.js", "module": "./dist/index.js",
"types": "./dist/index.d.ts", "types": "./dist/index.d.ts",
@@ -34,7 +34,8 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@stacks/transactions": "^6.5.2", "@stacks/transactions": "^7.0.2",
"@stacks/common": "^7.0.2",
"@types/lodash": "^4.14.194", "@types/lodash": "^4.14.194",
"@types/node": "^20.1.5", "@types/node": "^20.1.5",
"@types/yargs": "^17.0.24", "@types/yargs": "^17.0.24",
@@ -49,6 +50,7 @@
"yqueue": "^1.0.1" "yqueue": "^1.0.1"
}, },
"peerDependencies": { "peerDependencies": {
"@stacks/transactions": "*" "@stacks/transactions": "^7.0.2",
"@stacks/common": "^7.0.2"
} }
} }

46
pnpm-lock.yaml generated
View File

@@ -24,9 +24,12 @@ importers:
specifier: ^1.0.1 specifier: ^1.0.1
version: 1.0.1 version: 1.0.1
devDependencies: devDependencies:
'@stacks/common':
specifier: ^7.0.2
version: 7.0.2
'@stacks/transactions': '@stacks/transactions':
specifier: ^6.5.2 specifier: ^7.0.2
version: 6.5.2 version: 7.0.2
'@types/lodash': '@types/lodash':
specifier: ^4.14.194 specifier: ^4.14.194
version: 4.14.194 version: 4.14.194
@@ -51,27 +54,21 @@ packages:
'@noble/secp256k1@1.7.1': '@noble/secp256k1@1.7.1':
resolution: {integrity: sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==} resolution: {integrity: sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==}
'@stacks/common@6.5.5': '@stacks/common@7.0.2':
resolution: {integrity: sha512-6v2AVHTTryvl1Govu5rmBXLywAyen2fU3doMCx/7Lk/tFLc4OjMEx4uf1wzpPx1zw/fwJnvoz74OrT/RSALDYw==} resolution: {integrity: sha512-+RSecHdkxOtswmE4tDDoZlYEuULpnTQVeDIG5eZ32opK8cFxf4EugAcK9CsIsHx/Se1yTEaQ21WGATmJGK84lQ==}
'@stacks/network@6.5.5': '@stacks/network@7.0.2':
resolution: {integrity: sha512-lw7+g6UhOpvWasMeRYMb2OGRKm9ptYkGt27Usg3Eo0z/pu20jZxvHXLBMdDQqxNQOOmwiG4FadICnwTlmnHaqw==} resolution: {integrity: sha512-XzHnoWqku/jRrTgMXhmh3c+I0O9vDH24KlhzGDZtBu+8CGGyHNPAZzGwvoUShonMXrXjEnfO9IYQwV5aJhfv6g==}
'@stacks/stacks-blockchain-api-types@7.1.10': '@stacks/stacks-blockchain-api-types@7.1.10':
resolution: {integrity: sha512-HGU8Z6YcGyebyKO1s1x5BXVu6dCojyhlKxoGTOzqElLiAB84eP8bs49PS+ttrBM0O7k02oXhDmi6cW3VcfS+/Q==} resolution: {integrity: sha512-HGU8Z6YcGyebyKO1s1x5BXVu6dCojyhlKxoGTOzqElLiAB84eP8bs49PS+ttrBM0O7k02oXhDmi6cW3VcfS+/Q==}
'@stacks/transactions@6.5.2': '@stacks/transactions@7.0.2':
resolution: {integrity: sha512-xL4XF4xSFFJ+VMzeahBenGdg1T+y0Q0fSNA09jz7knTnnXvdAzzC+RP59xzuIjrAY/IWYO3X1sf0MGm9IIhYOg==} resolution: {integrity: sha512-m2bvchqUeYv1ttXuC0EukW8UX4xBXTDcYb8bXmfI1RG89HXAvvCCgr5aiadU6zbutgoXvm8mquDt3nww0PO4Jg==}
'@types/bn.js@5.1.1':
resolution: {integrity: sha512-qNrYbZqMx0uJAfKnKclPh+dTwK33KfLHYqtyODwd5HnXOjnkhc4qgn3BrK6RWyGZm5+sIFE7Q7Vz6QQtJB7w7g==}
'@types/lodash@4.14.194': '@types/lodash@4.14.194':
resolution: {integrity: sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==} resolution: {integrity: sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==}
'@types/node@18.17.12':
resolution: {integrity: sha512-d6xjC9fJ/nSnfDeU0AMDsaJyb1iHsqCSOdi84w4u+SlN/UgQdY5tRhpMzaFYsI4mnpvgTivEaQd0yOUhAtOnEQ==}
'@types/node@20.1.5': '@types/node@20.1.5':
resolution: {integrity: sha512-IvGD1CD/nego63ySR7vrAKEX3AJTcmrAN2kn+/sDNLi1Ff5kBzDeEdqWDplK+0HAEoLYej137Sk0cUU8OLOlMg==} resolution: {integrity: sha512-IvGD1CD/nego63ySR7vrAKEX3AJTcmrAN2kn+/sDNLi1Ff5kBzDeEdqWDplK+0HAEoLYej137Sk0cUU8OLOlMg==}
@@ -234,39 +231,30 @@ snapshots:
'@noble/secp256k1@1.7.1': {} '@noble/secp256k1@1.7.1': {}
'@stacks/common@6.5.5': '@stacks/common@7.0.2': {}
dependencies:
'@types/bn.js': 5.1.1
'@types/node': 18.17.12
'@stacks/network@6.5.5': '@stacks/network@7.0.2':
dependencies: dependencies:
'@stacks/common': 6.5.5 '@stacks/common': 7.0.2
cross-fetch: 3.1.8 cross-fetch: 3.1.8
transitivePeerDependencies: transitivePeerDependencies:
- encoding - encoding
'@stacks/stacks-blockchain-api-types@7.1.10': {} '@stacks/stacks-blockchain-api-types@7.1.10': {}
'@stacks/transactions@6.5.2': '@stacks/transactions@7.0.2':
dependencies: dependencies:
'@noble/hashes': 1.1.5 '@noble/hashes': 1.1.5
'@noble/secp256k1': 1.7.1 '@noble/secp256k1': 1.7.1
'@stacks/common': 6.5.5 '@stacks/common': 7.0.2
'@stacks/network': 6.5.5 '@stacks/network': 7.0.2
c32check: 2.0.0 c32check: 2.0.0
lodash.clonedeep: 4.5.0 lodash.clonedeep: 4.5.0
transitivePeerDependencies: transitivePeerDependencies:
- encoding - encoding
'@types/bn.js@5.1.1':
dependencies:
'@types/node': 20.1.5
'@types/lodash@4.14.194': {} '@types/lodash@4.14.194': {}
'@types/node@18.17.12': {}
'@types/node@20.1.5': {} '@types/node@20.1.5': {}
'@types/yargs-parser@21.0.0': {} '@types/yargs-parser@21.0.0': {}

View File

@@ -1,13 +1,13 @@
import { import {
AnchorMode, AnchorMode,
ClarityValue, type ClarityValue,
FungiblePostCondition, type FungiblePostCondition,
PostCondition, type PostCondition,
PostConditionMode, PostConditionMode,
STXPostCondition, type StxPostCondition,
} from "@stacks/transactions"; } from "@stacks/transactions";
import { StringOnly } from "../utils/helpers"; import type { StringOnly } from "../utils/helpers";
import { import type {
ContractBaseType, ContractBaseType,
OpenCallFunctionDescriptor, OpenCallFunctionDescriptor,
ParameterObjOfDescriptor, ParameterObjOfDescriptor,
@@ -35,7 +35,7 @@ export type ComposeTxOptionsFn<Contracts extends ContractBaseType> = <
: never, : never,
options?: { options?: {
deployerAddress?: string; deployerAddress?: string;
postConditions?: (FungiblePostCondition | STXPostCondition)[]; postConditions?: (FungiblePostCondition | StxPostCondition)[];
} }
) => ContractCallOptions; ) => ContractCallOptions;
@@ -68,7 +68,7 @@ export const composeTxOptionsFactory =
const deployerAddress = const deployerAddress =
options.deployerAddress ?? factoryOptions.deployerAddress; options.deployerAddress ?? factoryOptions.deployerAddress;
if (deployerAddress == null) { if (deployerAddress == null) {
throw new Error(`[composeTxOptionsFactory] deployer address required`); throw new Error("[composeTxOptionsFactory] deployer address required");
} }
return { return {

View File

@@ -3,6 +3,7 @@ import {
ClarityType, ClarityType,
ClarityValue, ClarityValue,
} from "@stacks/transactions"; } from "@stacks/transactions";
import {hexToBytes} from '@stacks/common'
import { Decoder, Response, UnboxDecoder } from "./types"; import { Decoder, Response, UnboxDecoder } from "./types";
export class ClarityError extends Error { export class ClarityError extends Error {
@@ -32,21 +33,21 @@ export const principalResult: Decoder<string> = (result) => {
export const addressResult: Decoder<string> = (result) => { export const addressResult: Decoder<string> = (result) => {
if (result.type === ClarityType.PrincipalStandard) { if (result.type === ClarityType.PrincipalStandard) {
return addressToString(result.address); return result.value;
} }
throw new Error(`Expected principal, got ${result.type}`); throw new Error(`Expected principal, got ${result.type}`);
}; };
export const contractResult: Decoder<`${string}.${string}`> = (result) => { export const contractResult: Decoder<`${string}.${string}`> = (result) => {
if (result.type === ClarityType.PrincipalContract) { if (result.type === ClarityType.PrincipalContract) {
return `${addressToString(result.address)}.${result.contractName.content}`; return result.value;
} }
throw new Error(`Expected principal, got ${result.type}`); throw new Error(`Expected principal, got ${result.type}`);
}; };
export const intResult: Decoder<bigint> = (result) => { export const intResult: Decoder<bigint> = (result) => {
if (result.type === ClarityType.Int || result.type === ClarityType.UInt) { if (result.type === ClarityType.Int || result.type === ClarityType.UInt) {
return result.value; return BigInt(result.value);
} }
throw new Error(`Expected integer, got ${result.type}`); throw new Error(`Expected integer, got ${result.type}`);
}; };
@@ -56,14 +57,14 @@ export const stringResult: Decoder<string> = (result) => {
result.type === ClarityType.StringASCII || result.type === ClarityType.StringASCII ||
result.type === ClarityType.StringUTF8 result.type === ClarityType.StringUTF8
) { ) {
return result.data; return result.value;
} }
throw new Error(`Expected string, got ${result.type}`); throw new Error(`Expected string, got ${result.type}`);
}; };
export const bufferResult: Decoder<Uint8Array> = (result) => { export const bufferResult: Decoder<Uint8Array> = (result) => {
if (result.type === ClarityType.Buffer) { if (result.type === ClarityType.Buffer) {
return result.buffer; return hexToBytes(result.value);
} }
throw new Error(`Expected buffer, got ${result.type}`); throw new Error(`Expected buffer, got ${result.type}`);
}; };
@@ -73,7 +74,7 @@ export const defaultErrorDecoder: Decoder<Error> = (value: ClarityValue) => {
value.type === ClarityType.StringASCII || value.type === ClarityType.StringASCII ||
value.type === ClarityType.StringUTF8 value.type === ClarityType.StringUTF8
) { ) {
return new Error(value.data); return new Error(value.value);
} }
if (value.type === ClarityType.UInt || value.type === ClarityType.Int) { if (value.type === ClarityType.UInt || value.type === ClarityType.Int) {
return new ClarityError(Number(value.value)); return new ClarityError(Number(value.value));
@@ -110,7 +111,8 @@ export function optionalDecoder<T>(
return (value) => { return (value) => {
if (value.type === ClarityType.OptionalNone) { if (value.type === ClarityType.OptionalNone) {
return undefined; return undefined;
} else if (value.type === ClarityType.OptionalSome) { }
if (value.type === ClarityType.OptionalSome) {
return decoder(value.value); return decoder(value.value);
} }
return decoder(value); return decoder(value);
@@ -135,7 +137,7 @@ export function tupleDecoder<P extends Record<string, Decoder<any>>>(
} }
const result = {} as any; const result = {} as any;
for (const key of Object.keys(decorators)) { for (const key of Object.keys(decorators)) {
result[key] = decorators[key as keyof P]!(input.data[key]!); result[key] = decorators[key as keyof P]!(input.value[key]!);
} }
return result; return result;
}; };
@@ -144,7 +146,7 @@ export function tupleDecoder<P extends Record<string, Decoder<any>>>(
export function listDecoder<T>(decoder: Decoder<T>): Decoder<T[]> { export function listDecoder<T>(decoder: Decoder<T>): Decoder<T[]> {
return (value) => { return (value) => {
if (value.type === ClarityType.List) { if (value.type === ClarityType.List) {
return value.list.map(decoder); return value.value.map(decoder);
} }
throw new Error(`Expected list, got ${value.type}`); throw new Error(`Expected list, got ${value.type}`);
}; };

View File

@@ -1,13 +1,13 @@
import { callReadOnlyFunction } from "@stacks/transactions"; import { fetchCallReadOnlyFunction } from "@stacks/transactions";
import { StringOnly } from "../utils/helpers"; import type { StringOnly } from "../utils/helpers";
import { import type {
ContractBaseType, ContractBaseType,
ParameterObjOfDescriptor, ParameterObjOfDescriptor,
ReadonlyFunctionDescriptor, ReadonlyFunctionDescriptor,
ReturnTypeOfDescriptor, ReturnTypeOfDescriptor,
} from "./contractBase"; } from "./contractBase";
export type CallReadOnlyFunctionFn = typeof callReadOnlyFunction; export type CallReadOnlyFunctionFn = typeof fetchCallReadOnlyFunction;
export type ExecuteReadonlyCallFn<Contracts extends ContractBaseType> = < export type ExecuteReadonlyCallFn<Contracts extends ContractBaseType> = <
T extends StringOnly<keyof Contracts>, T extends StringOnly<keyof Contracts>,
@@ -66,7 +66,7 @@ export const executeReadonlyCallFactory =
const _callReadOnlyFunction = const _callReadOnlyFunction =
options.callReadOnlyFunction ?? options.callReadOnlyFunction ??
factoryOptions.callReadOnlyFunction ?? factoryOptions.callReadOnlyFunction ??
callReadOnlyFunction; fetchCallReadOnlyFunction;
const result = await _callReadOnlyFunction({ const result = await _callReadOnlyFunction({
contractName, contractName,