Skip to content

Commit

Permalink
refactor: consolidate address types
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed May 30, 2024
1 parent bb79c82 commit 67e8982
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {
Cl,
ClarityAbi,
ContractIdString,
FeeEstimation,
StacksTransaction,
TxBroadcastResult,
Expand Down Expand Up @@ -100,7 +101,7 @@ export class StacksNodeApi {
* Fetch a contract's ABI
* @returns A promise that resolves to a ClarityAbi if the operation succeeds
*/
getAbi = async (contract: `${string}.${string}`): Promise<ClarityAbi> => {
getAbi = async (contract: ContractIdString): Promise<ClarityAbi> => {
const [contractAddress, contractName] = contract.split('.');
return getAbi({ contractAddress, contractName, api: this });
};
Expand Down Expand Up @@ -188,7 +189,7 @@ export class StacksNodeApi {
}

/** Gets the value of a data-var if it exists in the given contract */
async getDataVar(contract: `${string}.${string}`, dataVarName: string) {
async getDataVar(contract: ContractIdString, dataVarName: string) {
// todo: (contractAddress: string, contractName: string, dataVarName: string) overload?
// todo: cleanup address/contract identifies types
const contractPath = contract.replace('.', '/');
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { ContractIdString } from '@stacks/transactions';

export interface V2CoreInfoResponse {
burn_block_height: number;
stable_pox_consensus: string;
Expand All @@ -11,7 +13,7 @@ export interface CycleInfoResponse {
}

export interface ContractVersionResponse {
contract_id: `${string}.${string}`;
contract_id: ContractIdString;
activation_burnchain_block_height: number;
first_reward_cycle_id: number;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/transactions/src/pc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import {
/**
* ### `Pc.` Post Condition Builder
* @beta Interface may be subject to change in future releases.
* @param {AddressString | ContractIdString} principal The principal to check, which should/should-not be sending assets. A string in the format "address" or "address.contractId".
* @param {AddressString | ContractIdString} principal The principal to check, which should/should-not be sending assets. A string in the format `<address>` or `<contractAddress>.<contractName>`.
* @returns A partial post condition builder, which can be chained into a final post condition.
* @example
* ```
* import { Pc } from '@stacks/transactions';
* Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6').willSendEq(10000).ustx();
* Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.mycontract').willSendGte(2000).ft();
* ```
*/
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
Expand Down Expand Up @@ -218,6 +219,7 @@ class PartialPcFtWithCode {
* ⚠ Amount of fungible tokens is denoted in the smallest unit of the token
*/
ft(contractId: ContractIdString, tokenName: string) {
// todo: allow taking one arg (`Asset`) as well, overload
const [address, name] = parseContractId(contractId);
if (this.contractName) {
return makeContractFungiblePostCondition(
Expand Down

0 comments on commit 67e8982

Please sign in to comment.