Skip to content

Commit

Permalink
chore: account for missing signer-key
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Jan 8, 2024
1 parent 100c09a commit bc6dd03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/stacking/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { PoxOperationPeriod, StackingErrors } from './constants';
import {
ensureLegacyBtcAddressForPox1,
ensurePox2Activated,
ensureSignerKeyForGtePox4,
ensureSignerKeyReadiness,
poxAddressToTuple,
unwrap,
unwrapMap,
Expand Down Expand Up @@ -684,7 +684,7 @@ export class StackingClient {
const contract = await this.getStackingContract(poxOperationInfo);

ensureLegacyBtcAddressForPox1({ contract, poxAddress });
ensureSignerKeyForGtePox4({ contract, signerKey });
ensureSignerKeyReadiness({ contract, signerKey });

const callOptions = this.getStackOptions({
contract,
Expand Down Expand Up @@ -720,7 +720,7 @@ export class StackingClient {
const poxOperationInfo = await this.getPoxOperationInfo(poxInfo);

ensurePox2Activated(poxOperationInfo);
ensureSignerKeyForGtePox4({ contract: poxInfo.contract_id, signerKey });
ensureSignerKeyReadiness({ contract: poxInfo.contract_id, signerKey });

const callOptions = this.getStackExtendOptions({
contract: poxInfo.contract_id,
Expand Down Expand Up @@ -821,7 +821,7 @@ export class StackingClient {
const contract = await this.getStackingContract(poxOperationInfo);

ensureLegacyBtcAddressForPox1({ contract, poxAddress });
ensureSignerKeyForGtePox4({ contract, signerKey });
ensureSignerKeyReadiness({ contract, signerKey });

const callOptions = this.getDelegateStackOptions({
contract,
Expand Down Expand Up @@ -858,7 +858,7 @@ export class StackingClient {
const poxInfo = await this.getPoxInfo();
const contract = poxInfo.contract_id;

ensureSignerKeyForGtePox4({ contract, signerKey });
ensureSignerKeyReadiness({ contract, signerKey });

const callOptions = this.getDelegateStackExtendOptions({
contract,
Expand Down
10 changes: 6 additions & 4 deletions packages/stacking/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,18 @@ export function ensureLegacyBtcAddressForPox1({

/**
* @internal
* Throws unless a signerKey is given for >= PoX-4.
* Throws unless a signerKey is given for >= PoX-4 or missing before.
*/
export function ensureSignerKeyForGtePox4({
export function ensureSignerKeyReadiness({
contract,
signerKey,
}: {
contract: string;
signerKey?: string;
}) {
if (signerKey) return;
if (/\.pox(-[2-3])?$/.test(contract)) return;
if (/\.pox(-[2-3])?$/.test(contract)) {
if (!signerKey) return;
throw new Error('PoX-1, PoX-2 and PoX-3 do not accept a signer-key (buff 33)');
}
throw new Error('PoX-4 requires a signer-key (buff 33) to stack');
}

0 comments on commit bc6dd03

Please sign in to comment.