Skip to content

Commit

Permalink
docs: update stacking helper method tsdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Oct 30, 2023
1 parent 8e7c77b commit a4ca468
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/stacking/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ export function getErrorString(error: StackingErrors): string {
return 'Stacker must be delegating and not be directly stacking';
}
}

/**
* Converts a PoX address to a tuple (e.g. to be used in a Clarity contract call).
*
* @param poxAddress - The PoX bitcoin address to be converted.
* @returns The converted PoX address as a tuple of version and hashbytes.
*/
export function poxAddressToTuple(poxAddress: string) {
const { version, data } = decodeBtcAddress(poxAddress);
const versionBuff = bufferCV(bigIntToBytes(BigInt(version), 1));
Expand Down Expand Up @@ -278,11 +283,26 @@ function _poxAddressToBtcAddress_ClarityValue(
return _poxAddressToBtcAddress_Values(poxAddr.version, poxAddr.hashBytes, network);
}

/**
* Converts a PoX address to a Bitcoin address.
*
* @param version - The version of the PoX address (as a single number, not a Uint8array).
* @param hashBytes - The hash bytes of the PoX address.
* @param network - The network the PoX address is on.
* @returns The corresponding Bitcoin address.
*/
export function poxAddressToBtcAddress(
version: number,
hashBytes: Uint8Array,
network: StacksNetworkName
): string;
/**
* Converts a PoX address to a Bitcoin address.
*
* @param poxAddrClarityValue - The clarity tuple of the PoX address (version and hashbytes).
* @param network - The network the PoX address is on.
* @returns The corresponding Bitcoin address.
*/
export function poxAddressToBtcAddress(
poxAddrClarityValue: ClarityValue,
network: StacksNetworkName
Expand All @@ -292,6 +312,7 @@ export function poxAddressToBtcAddress(...args: any[]): string {
return _poxAddressToBtcAddress_ClarityValue(args[0], args[1]);
}

// todo: move unwrap to tx package and document
export function unwrap<T extends ClarityValue>(optional: OptionalCV<T>) {
if (optional.type === ClarityType.OptionalSome) return optional.value;
if (optional.type === ClarityType.OptionalNone) return undefined;
Expand All @@ -312,6 +333,10 @@ export function ensurePox2Activated(operationInfo: PoxOperationInfo) {
);
}

/**
* @internal
* Throws unless the given PoX address is a legacy address.
*/
export function ensureLegacyBtcAddressForPox1({
contract,
poxAddress,
Expand Down

0 comments on commit a4ca468

Please sign in to comment.