Skip to content

Commit

Permalink
feat(solana-contrib): add shortenPubkey function
Browse files Browse the repository at this point in the history
  • Loading branch information
macalinao committed Oct 7, 2022
1 parent 030acd6 commit 9704b89
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/solana-contrib/src/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PublicKey } from "./publicKey";

export * from "@saberhq/option-utils";

const noop = () => {
Expand Down Expand Up @@ -60,3 +62,15 @@ export const valueAsPromise = async <T>(
}
return awaitable;
};

/**
* Shortens a pubkey.
* @param pubkey
* @returns
*/
export const shortenPubkey = (pubkey: PublicKey): string => {
const str = pubkey.toString();
return str.length > 20
? `${str.substring(0, 7)}.....${str.substring(str.length - 7, str.length)}`
: str;
};

0 comments on commit 9704b89

Please sign in to comment.