Skip to content

Commit

Permalink
fix(SDK): remove assumptions from getInscriptions and utxo RPC (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevzzsk authored Mar 21, 2024
1 parent da382af commit 1aadf2c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
16 changes: 3 additions & 13 deletions packages/sdk/src/inscription/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,12 @@ export async function publishCollection({
}

export async function mintFromCollection(options: MintFromCollectionOptions) {
if (!options.collectionOutpoint || !options.inscriptionIid || !options.destinationAddress) {
if (!options.collectionInscriptionId || !options.inscriptionIid || !options.destinationAddress) {
throw new OrditSDKError("Invalid options supplied.")
}

const [colTxId, colVOut] = options.collectionOutpoint.split(":").map((v, i) => {
if (i === 0) return v

const value = parseInt(v)
return isNaN(value) || (!value && value !== 0) ? false : value
}) as [string, number | false]

if (!colTxId || colVOut === false) {
throw new OrditSDKError("Invalid collection outpoint supplied.")
}
const datasource = options.datasource || new JsonRpcDatasource({ network: options.network })
const collection = await datasource.getInscription({ id: options.collectionOutpoint })
const collection = await datasource.getInscription({ id: options.collectionInscriptionId })
if (!collection) {
throw new OrditSDKError("Invalid collection")
}
Expand Down Expand Up @@ -167,7 +157,7 @@ export type MintFromCollectionOptions = Pick<GetWalletOptions, "safeMode"> & {
mediaContent: string
destinationAddress: string
changeAddress: string
collectionOutpoint: string
collectionInscriptionId: string
inscriptionIid: string
nonce: number
publisherIndex: number
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/instant-trade/InstantTradeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ export default class InstantTradeBuilder extends PSBTBuilder {
throw new OrditSDKError("Inscription not found")
}

const utxo = await this.datasource.getInscriptionUTXO({ id: this.inscription.genesis })
const utxo = await this.datasource.getInscriptionUTXO({ id: this.inscription.id })
if (!utxo) {
throw new OrditSDKError(`Unable to find UTXO: ${this.inscription.outpoint}`)
throw new OrditSDKError(`Unable to find UTXO: ${this.inscription.id}`)
}

this.postage = utxo.sats
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/instant-trade/InstantTradeSellerTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export default class InstantTradeSellerTxBuilder extends InstantTradeBuilder {
if (!this.inscription || !this.inscription.meta?.col) {
return
}

const collection = await this.datasource.getInscription({ id: this.inscription.meta.col as string })
const inscriptionId = `${this.inscription.meta.col}i0` // assumes that collection inscription is always minted as the first
const collection = await this.datasource.getInscription({ id: inscriptionId })
const royalty = collection.meta?.royalty
if (!royalty || !royalty.address || !royalty.pct) {
return
Expand Down
4 changes: 0 additions & 4 deletions packages/sdk/src/modules/JsonRpcDatasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export default class JsonRpcDatasource extends BaseDatasource {
throw new OrditSDKError("Invalid request")
}

id = id.includes(":") ? id.replace(":", "i") : !id.includes("i") ? `${id}i0` : id

let inscription = await rpc[this.network].call<Inscription>("Ordinals.GetInscription", { id }, rpc.id)
if (decodeMetadata) {
inscription = DatasourceUtility.transformInscriptions([inscription])[0]
Expand All @@ -56,8 +54,6 @@ export default class JsonRpcDatasource extends BaseDatasource {
throw new OrditSDKError("Invalid request")
}

id = id.includes(":") ? id.replace(":", "i") : !id.includes("i") ? `${id}i0` : id

return rpc[this.network].call<UTXO>("Ordinals.GetInscriptionUtxo", { id }, rpc.id)
}

Expand Down

0 comments on commit 1aadf2c

Please sign in to comment.