Skip to content

Commit

Permalink
upd: work in progress on introducing much stricter types
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyKhd committed Jan 5, 2025
1 parent 716a68d commit bb85a67
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-ordinals/src/actions/ordinals/rare-sats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default {
? addresses.taprootAddress
: derivedAddress;

const ordiscan = new API(runtime.getSetting("ORDISCAN_API_KEY"));
const ordiscan = new API();
const portfolio = await ordiscan.getRunesPortfolio(taprootAddress);

const balances = portfolio?.results;
Expand Down
2 changes: 0 additions & 2 deletions packages/plugin-ordinals/src/actions/runes/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ export default {
throw new Error(`Unable to determine divisibility of ${rune}`);
}

elizaLogger.info(JSON.stringify(runeInfo, mintBlock, tx));

const wallet: WalletProvider = await walletProvider.get(
runtime,
message,
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ordinals/src/actions/wallet/tx-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { WalletProvider, walletProvider } from "../../providers/wallet";
import { transactionHashTemplate } from "../../templates";
import { z } from "zod";
import { handleError } from "../../utils";
import { TBitcoinTxId } from "../../types";

export const transactionIdSchema = z.object({
txid: z.string().toLowerCase(),
Expand Down Expand Up @@ -46,7 +47,7 @@ export default {
template: transactionHashTemplate,
});

const content: { object: { txid?: string | null } } =
const content: { object: { txid?: TBitcoinTxId | null } } =
await generateObject({
runtime,
context,
Expand Down
6 changes: 0 additions & 6 deletions packages/plugin-ordinals/src/providers/ordinals.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/plugin-ordinals/src/providers/runes.ts

This file was deleted.

10 changes: 5 additions & 5 deletions packages/plugin-ordinals/src/providers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { HDKey } from "@scure/bip32";
import { wordlist } from "@scure/bip39/wordlists/english";
import mempoolJS from "@mempool/mempool.js";
import { MempoolReturn } from "@mempool/mempool.js/lib/interfaces";
import { IAccount } from "../types";
import { IAccount, TBitcoinTxId } from "../types";
import {
Tx,
TxStatus,
Expand Down Expand Up @@ -99,7 +99,7 @@ export class WalletProvider {
});
}

async getTransactionStatus(txid: string): Promise<TxStatus> {
async getTransactionStatus(txid: TBitcoinTxId): Promise<TxStatus> {
return await this.mempool.bitcoin.transactions.getTxStatus({ txid });
}

Expand All @@ -109,15 +109,15 @@ export class WalletProvider {
});
}

async lookupUtxo(txid: string): Promise<Tx> {
async lookupUtxo(txid: TBitcoinTxId): Promise<Tx> {
return await this.mempool.bitcoin.transactions.getTx({ txid });
}

async broadcastTransaction(txhex: string): Promise<string> {
async broadcastTransaction(txhex: string): Promise<TBitcoinTxId> {
const txid = await this.mempool.bitcoin.transactions.postTx({
txhex,
});
return txid as string;
return txid as TBitcoinTxId;
}

async getFeeRates(): Promise<FeesRecommended> {
Expand Down
21 changes: 21 additions & 0 deletions packages/plugin-ordinals/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type TBitcoinTxId = string & { readonly __brand: unique symbol } & { readonly length: 64 };

export interface IAccount {
nestedSegwitAddress: string;
taprootAddress: string;
Expand Down Expand Up @@ -54,3 +56,22 @@ export interface IRuneInfo {
timestamp: number;
};
}

export interface IRuneUtxo {
txid: TBitcoinTxId;
vout: number;
value: number;
block_height: number;
sat_ranges: any[];
runes: [
[
string,
{
amount: string;
divisibility: number;
symbol: string;
},
],
];
listing: (null | any)[];
}
13 changes: 9 additions & 4 deletions packages/plugin-ordinals/src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { elizaLogger } from "@elizaos/core";
import { IBalance, IRuneInfo } from "../types";
import { IBalance, IRuneInfo, IRuneUtxo } from "../types";

const HIRO_BASE_URL = "https://api.hiro.so";

Expand Down Expand Up @@ -34,11 +34,16 @@ class API {

async getRuneInfo(name: string): Promise<IRuneInfo> {
const nonSpacedName = name?.replaceAll("•", "");
return await fetcher(`${HIRO_BASE_URL}/runes/v1/etchings/${nonSpacedName}`);
return await fetcher(
`${HIRO_BASE_URL}/runes/v1/etchings/${nonSpacedName}`
);
}

async getRunesUtxos(address: string, runeName: string) {
return fetcher(
async getRunesUtxos(
address: string,
runeName: string
): Promise<IRuneUtxo[]> {
return await fetcher(
`https://api-3.xverse.app/v1/market/address/${address}/rune/${runeName}/utxos`
);
}
Expand Down

0 comments on commit bb85a67

Please sign in to comment.