Skip to content

Commit

Permalink
feat(sdk)!: upgrade JSON RPC source to Trinity (#68)
Browse files Browse the repository at this point in the history
* feat: add abstract class to define datasource base

* feat: add JSON RPC datasource class

* refactor: replace OrditApi w/ JsonRpc datasource

* refactor: move datasource to very top in inheritance chain

* feat: decouple utils to separate class

* refactor!: rename class to BaseDatasource and convert to abtract class

* refactor: integrate trinity

* refactor!: remove inscription & ordinals from UTXO

* refactor: update UTXO props

* feat: add getInscriptionUTXO RPC call

* refactor(sdk): improvements / clean up / remove deprecated fns (#69)

* feat: add abstract class to define datasource base

* refactor: replace OrditApi w/ JsonRpc datasource

* refasctor: move datasource to very top in inheritance chain

* feat: decouple utils to separate class

* refactor!: rename class to BaseDatasource and convert to abtract class

* chore: remove OrditApi

* chore: remove instant-buy & tx fns

* refactor: rename types

* chore!: remove deprecated fns

* feat: spread args for clarity of options on usage
  • Loading branch information
iamcrazycoder authored Oct 3, 2023
1 parent ed23fd6 commit 8e84fc2
Show file tree
Hide file tree
Showing 24 changed files with 105 additions and 1,086 deletions.
224 changes: 0 additions & 224 deletions packages/sdk/src/api/index.ts

This file was deleted.

26 changes: 11 additions & 15 deletions packages/sdk/src/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
import { Transaction as BTCTransaction } from "bitcoinjs-lib"

import { Network } from "../config/types"
import { Rarity } from "../inscription/types"
import { Transaction, UTXO } from "../transactions/types"
import { RequireAtLeastOne } from "../utils/types"

export interface FetchUnspentUTXOsOptions {
export interface GetUnspentsOptions {
address: string
network?: Network
type?: "all" | "spendable"
rarity?: Rarity[]
decodeMetadata?: boolean
sort?: "asc" | "desc"
limit?: number
next?: string | null
}

export interface FetchUnspentUTXOsResponse {
export interface GetUnspentsResponse {
totalUTXOs: number
spendableUTXOs: UTXO[]
unspendableUTXOs: UTXO[]
}

export interface FetchTxOptions {
export interface GetTxOptions {
txId: string
network?: Network
ordinals?: boolean
hex?: boolean
witness?: boolean
Expand All @@ -36,6 +32,10 @@ export interface FetchTxResponse {
rawTx?: BTCTransaction
}

export interface GetInscriptionUTXOOptions {
id: string
}

export type GetInscriptionsOptions = RequireAtLeastOne<{
creator?: string
owner?: string
Expand All @@ -47,32 +47,28 @@ export type GetInscriptionsOptions = RequireAtLeastOne<{
limit?: number
next?: string | null
decodeMetadata?: boolean
network?: Network
}

export interface FetchInscriptionOptions {
export interface GetInscriptionOptions {
id: string
network?: Network
decodeMetadata?: boolean
}

export interface RelayTxOptions {
export interface RelayOptions {
hex: string
maxFeeRate?: number
network?: Network
validate?: boolean
}

export interface FetchSpendablesOptions {
export interface GetSpendablesOptions {
address: string
value: number
type?: "all" | "spendable"
rarity?: Rarity[]
filter?: string[]
limit?: number
network?: Network
}

export interface GetBalanceOptions {
address: string
network?: Network
}
6 changes: 3 additions & 3 deletions packages/sdk/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ export const apiConfig = {
version: "0.0.0.10",
apis: {
mainnet: {
batter: "https://proto.ordit.io/",
batter: "https://mainnet.ordit.io/",
orderbook: "1H4vvBnr62YWQmvNSt8Z4pDw3Vcv1n5xz7",
ipfs: "http://ipfs-gateway.ordit.io/"
},
regtest: {
batter: "https://regtest-v2.ordit.io/",
batter: "https://regtest.ordit.io/",
orderbook: "bcrt1q2ys7qws8g072dqe3psp92pqz93ac6wmztexkh5",
ipfs: "http://ipfs-gateway.ordit.io/"
},
testnet: {
batter: "https://testnet-v2.ordit.io/",
batter: "https://testnet.ordit.io/",
orderbook: "tb1qfnw26753j7kqu3q099sd48htvtk5wm4e0enmru",
ipfs: "http://ipfs-gateway.ordit.io/"
}
Expand Down
3 changes: 0 additions & 3 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as addresses from "./addresses"
import * as api from "./api"
import * as metamask from "./browser-wallets/metamask"
import * as unisat from "./browser-wallets/unisat"
import * as xverse from "./browser-wallets/xverse"
Expand All @@ -13,7 +12,6 @@ import * as wallet from "./wallet"

export const ordit = {
config,
api,
addresses,
wallet,
keys,
Expand All @@ -27,7 +25,6 @@ export const ordit = {
}

export * from "./addresses"
export * from "./api"
export * as metamask from "./browser-wallets/metamask"
export * as unisat from "./browser-wallets/unisat"
export * as xverse from "./browser-wallets/xverse"
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/inscription/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function mintFromCollection(options: MintFromCollectionOptions) {
throw new Error("Invalid collection outpoint supplied.")
}
const datasource = options.datasource || new JsonRpcDatasource({ network: options.network })
const collection = await datasource.getInscription(options.collectionOutpoint)
const collection = await datasource.getInscription({ id: options.collectionOutpoint })
if (!collection) {
throw new Error("Invalid collection")
}
Expand Down
Loading

0 comments on commit 8e84fc2

Please sign in to comment.