mirror of
https://github.com/mempool/mempool.git
synced 2025-01-18 21:32:55 +01:00
Clean up etches fetching logic
This commit is contained in:
parent
040c067aac
commit
177bbc83f3
@ -19,15 +19,12 @@ export class OrdApiService {
|
|||||||
decodeRunestone$(tx: Transaction): Observable<{ runestone: Runestone, runeInfo: { [id: string]: { etching: Etching; txid: string; } } }> {
|
decodeRunestone$(tx: Transaction): Observable<{ runestone: Runestone, runeInfo: { [id: string]: { etching: Etching; txid: string; } } }> {
|
||||||
const runestone = decipherRunestone(tx);
|
const runestone = decipherRunestone(tx);
|
||||||
const runeInfo: { [id: string]: { etching: Etching; txid: string; } } = {};
|
const runeInfo: { [id: string]: { etching: Etching; txid: string; } } = {};
|
||||||
const runesToFetch: Set<string> = new Set();
|
|
||||||
|
|
||||||
if (runestone) {
|
if (runestone) {
|
||||||
|
const runesToFetch: Set<string> = new Set();
|
||||||
|
|
||||||
if (runestone.mint) {
|
if (runestone.mint) {
|
||||||
if (runestone.mint.toString() === '1:0') {
|
runesToFetch.add(runestone.mint.toString());
|
||||||
runeInfo[runestone.mint.toString()] = { etching: UNCOMMON_GOODS, txid: '0000000000000000000000000000000000000000000000000000000000000000' };
|
|
||||||
} else {
|
|
||||||
runesToFetch.add(runestone.mint.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runestone.edicts.length) {
|
if (runestone.edicts.length) {
|
||||||
@ -37,18 +34,15 @@ export class OrdApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (runesToFetch.size) {
|
if (runesToFetch.size) {
|
||||||
const runeEtchingObservables = Array.from(runesToFetch).map(runeId => {
|
const runeEtchingObservables = Array.from(runesToFetch).map(runeId => this.getEtchingFromRuneId$(runeId));
|
||||||
return this.getEtchingFromRuneId$(runeId).pipe(
|
|
||||||
tap(etching => {
|
|
||||||
if (etching) {
|
|
||||||
runeInfo[runeId] = etching;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return forkJoin(runeEtchingObservables).pipe(
|
return forkJoin(runeEtchingObservables).pipe(
|
||||||
map(() => {
|
map((etchings) => {
|
||||||
|
etchings.forEach((el) => {
|
||||||
|
if (el) {
|
||||||
|
runeInfo[el.runeId] = { etching: el.etching, txid: el.txid };
|
||||||
|
}
|
||||||
|
});
|
||||||
return { runestone: runestone, runeInfo };
|
return { runestone: runestone, runeInfo };
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -60,24 +54,27 @@ export class OrdApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get etching from runeId by looking up the transaction that etched the rune
|
// Get etching from runeId by looking up the transaction that etched the rune
|
||||||
getEtchingFromRuneId$(runeId: string): Observable<{ etching: Etching; txid: string; }> {
|
getEtchingFromRuneId$(runeId: string): Observable<{ runeId: string; etching: Etching; txid: string; }> {
|
||||||
const [blockNumber, txIndex] = runeId.split(':');
|
if (runeId === '1:0') {
|
||||||
|
return of({ runeId, etching: UNCOMMON_GOODS, txid: '0000000000000000000000000000000000000000000000000000000000000000' });
|
||||||
return this.electrsApiService.getBlockHashFromHeight$(parseInt(blockNumber)).pipe(
|
} else {
|
||||||
switchMap(blockHash => this.electrsApiService.getBlockTxId$(blockHash, parseInt(txIndex))),
|
const [blockNumber, txIndex] = runeId.split(':');
|
||||||
switchMap(txId => this.electrsApiService.getTransaction$(txId)),
|
return this.electrsApiService.getBlockHashFromHeight$(parseInt(blockNumber)).pipe(
|
||||||
switchMap(tx => {
|
switchMap(blockHash => this.electrsApiService.getBlockTxId$(blockHash, parseInt(txIndex))),
|
||||||
const runestone = decipherRunestone(tx);
|
switchMap(txId => this.electrsApiService.getTransaction$(txId)),
|
||||||
if (runestone) {
|
switchMap(tx => {
|
||||||
const etching = runestone.etching;
|
const runestone = decipherRunestone(tx);
|
||||||
if (etching) {
|
if (runestone) {
|
||||||
return of({ etching, txid: tx.txid });
|
const etching = runestone.etching;
|
||||||
|
if (etching) {
|
||||||
|
return of({ runeId, etching, txid: tx.txid });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return of(null);
|
||||||
return of(null);
|
}),
|
||||||
}),
|
catchError(() => of(null))
|
||||||
catchError(() => of(null))
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
decodeInscriptions(witness: string): Inscription[] | null {
|
decodeInscriptions(witness: string): Inscription[] | null {
|
||||||
|
Loading…
Reference in New Issue
Block a user