Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to NPM and GitHub #2

Merged
merged 6 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/ci-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ jobs:
- name: Run CI
run: bun run ci

- name: Prepare .npmrc for publishing
- name: Publish to NPM package registry
# https://github.com/oven-sh/bun/issues/1976
run: |
echo "@secretkeylabs:registry=https://registry.npmjs.org/" > .npmrc
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
echo "//registry.npmjs.org/:_authToken=$AUTH_TOKEN" >> .npmrc
bunx npm@latest publish --access=public --tag=latest
env:
NPM_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }}
AUTH_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }}

- name: Publish to NPM package registry
- name: Publish to GitHub package registry
# https://github.com/oven-sh/bun/issues/1976
run: bunx npm@latest publish --access=public --tag=latest
run: |
echo "@secretkeylabs:registry=https://npm.pkg.github.com/" > .npmrc
echo "//npm.pkg.github.com/:_authToken=$AUTH_TOKEN" >> .npmrc
bunx npm@latest publish --access=public --tag=latest
env:
AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 12 additions & 7 deletions .github/workflows/ci-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,27 @@ jobs:
name: Get commit sha
run: echo "SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Set publish version
- name: Set package version with commit sha
# https://github.com/oven-sh/bun/issues/1976
run: bunx npm@latest version --no-git-tag-version $CURRENT_VERSION-$SHA
env:
SHA: ${{ steps.sha.outputs.SHA }}
CURRENT_VERSION: ${{ steps.current-version.outputs.CURRENT_VERSION }}

- name: Prepare .npmrc for publishing
- name: Publish to NPM package registry
# https://github.com/oven-sh/bun/issues/1976
run: |
echo "@secretkeylabs:registry=https://registry.npmjs.org/" > .npmrc
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
echo "//registry.npmjs.org/:_authToken=$AUTH_TOKEN" >> .npmrc
bunx npm@latest publish --access=public
env:
NPM_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }}
AUTH_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }}

- name: Publish to NPM package registry
- name: Publish to GitHub package registry
# https://github.com/oven-sh/bun/issues/1976
run: bunx npm@latest publish --access=public --tag pr-$PR_NUMBER
run: |
echo "@secretkeylabs:registry=https://npm.pkg.github.com/" > .npmrc
echo "//npm.pkg.github.com/:_authToken=$AUTH_TOKEN" >> .npmrc
bunx npm@latest publish --access=public
env:
PR_NUMBER: ${{ github.event.number }}
AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@secretkeylabs/stacks-tools",
"version": "0.1.0",
"version": "0.2.0",
"type": "module",
"files": [
"dist"
Expand Down
38 changes: 28 additions & 10 deletions src/queries/get-signer-total-locked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,29 @@ import {
type SafeError,
} from "../utils/safe.js";

export type Args = {
export type Identifier =
| {
type: "address";
signerAddress: string;
}
| {
type: "publicKey";
signerPublicKey: string;
};

export type Args = { identifier: Identifier } & {
cycleNumber: number;
signerAddress: string;
} & ApiRequestOptions;

/**
* Return the total locked amount for a signer in a PoX cycle.
*/
export async function getSignerTotalLocked(
args: Args,
args: Args
): Promise<Result<bigint, SafeError<"SignerNotFound" | string>>> {
let totalLocked = 0n;

const { signerAddress, ...rest } = args;
const { identifier, ...rest } = args;

let hasMore = true;
let offset = 0;
Expand All @@ -32,7 +41,7 @@ export async function getSignerTotalLocked(
signersInCycle({
...rest,
limit,
}),
})
);

if (error) {
Expand All @@ -46,10 +55,18 @@ export async function getSignerTotalLocked(
}

for (const signer of data.results) {
if (signer.signer_address === signerAddress) {
totalLocked = BigInt(signer.stacked_amount);
found = true;
break;
if (identifier.type === "address") {
if (signer.signer_address === identifier.signerAddress) {
totalLocked = BigInt(signer.stacked_amount);
found = true;
break;
}
} else {
if (signer.signing_key === identifier.signerPublicKey) {
totalLocked = BigInt(signer.stacked_amount);
found = true;
break;
}
}
}

Expand All @@ -62,7 +79,8 @@ export async function getSignerTotalLocked(
name: "SignerNotFound",
message: "Signer not found.",
data: {
signerAddress,
identifier,
cycle: args.cycleNumber,
},
});
}
Expand Down
Loading