Skip to content

Commit

Permalink
[Issue-118] Update interface address utxo
Browse files Browse the repository at this point in the history
  • Loading branch information
bluezdot committed Jun 12, 2024
1 parent 6a13367 commit a170a61
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { SWError } from '@subwallet/extension-base/background/errors/SWError';
import { _BEAR_TOKEN } from '@subwallet/extension-base/services/chain-service/constants';
import { BitcoinAddressSummaryInfo, BlockStreamBlock, BlockStreamFeeEstimates, BlockStreamTransactionDetail, BlockStreamTransactionStatus, BlockStreamUtxo, Brc20BalanceItem, Inscription, InscriptionFetchedData, RunesInfoByAddress, RunesInfoByAddressFetchedData, RuneTxs, RuneTxsResponse } from '@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/BlockStream/types';
import { BitcoinAddressSummaryInfo, BlockStreamBlock, BlockStreamFeeEstimates, BlockStreamTransactionDetail, BlockStreamTransactionStatus, Brc20BalanceItem, Inscription, InscriptionFetchedData, RunesInfoByAddress, RunesInfoByAddressFetchedData, RuneTxs, RuneTxsResponse, UpdateOpenBitUtxo } from '@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/BlockStream/types';
import { BitcoinApiStrategy, BitcoinTransactionEventMap } from '@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/types';
import { OBResponse } from '@subwallet/extension-base/services/chain-service/types';
import { HiroService } from '@subwallet/extension-base/services/hiro-service';
Expand Down Expand Up @@ -146,13 +146,13 @@ export class BlockStreamRequestStrategy extends BaseApiRequestStrategy implement
getUtxos (address: string): Promise<UtxoResponseItem[]> {
return this.addRequest<UtxoResponseItem[]>(async (): Promise<UtxoResponseItem[]> => {
const _rs = await getRequest(this.getUrl(`address/${address}/utxo`), undefined, this.headers);
const rs = await _rs.json() as OBResponse<BlockStreamUtxo[]>;
const rs = await _rs.json() as OBResponse<UpdateOpenBitUtxo>;

if (rs.status_code !== 200) {
throw new SWError('BlockStreamRequestStrategy.getUtxos', rs.message);
}

return rs.result;
return rs.result.utxoItems;
}, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ export interface Inscription {
// content: any
}

export interface UpdateOpenBitUtxo {
totalUtxo: number,
utxoItems: BlockStreamUtxo[]
}

export interface BlockStreamUtxo {
txid: string;
vout: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/src/services/hiro-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { BaseApiRequestContext } from '@subwallet/extension-base/strategy/api-re
import { getRequest } from '@subwallet/extension-base/strategy/api-request-strategy/utils';

const OPENBIT_URL = 'https://api.openbit.app';
const OPENBIT_URL_TEST = 'https://api-testnet.openbit.app/';
const OPENBIT_URL_TEST = 'https://api-testnet.openbit.app';

export class HiroService extends BaseApiRequestStrategy {
baseUrl: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/src/services/rune-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { BaseApiRequestContext } from '@subwallet/extension-base/strategy/api-re
import { getRequest } from '@subwallet/extension-base/strategy/api-request-strategy/utils';

const OPENBIT_URL = 'https://api.openbit.app';
const OPENBIT_URL_TEST = 'https://api-testnet.openbit.app/';
const OPENBIT_URL_TEST = 'https://api-testnet.openbit.app';

export class RunesService extends BaseApiRequestStrategy {
baseUrl: string;
Expand Down
42 changes: 25 additions & 17 deletions packages/extension-base/src/utils/bitcoin/utxo-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export function filterOutPendingTxsUtxos (utxos: UtxoResponseItem[]): UtxoRespon
}

export function filteredOutTxsUtxos (allTxsUtxos: UtxoResponseItem[], filteredOutTxsUtxos: UtxoResponseItem[]): UtxoResponseItem[] {
if (!filteredOutTxsUtxos.length) {
return allTxsUtxos;
}

const listFilterOut = filteredOutTxsUtxos.map((utxo) => {
return `${utxo.txid}:${utxo.vout}`;
});
Expand Down Expand Up @@ -213,21 +217,25 @@ export async function getRuneUtxos (bitcoinApi: _BitcoinApi, address: string) {
}

export async function getInscriptionUtxos (bitcoinApi: _BitcoinApi, address: string) {
const inscriptions = await bitcoinApi.api.getAddressInscriptions(address);

return inscriptions.map((inscription) => {
const [txid, vout] = inscription.output.split(':');

return {
txid,
vout: parseInt(vout),
status: {
confirmed: true, // not use in filter out inscription utxos
block_height: inscription.genesis_block_height,
block_hash: inscription.genesis_block_hash,
block_time: inscription.genesis_timestamp
},
value: parseInt(inscription.value)
} as UtxoResponseItem;
});
try {
const inscriptions = await bitcoinApi.api.getAddressInscriptions(address);

return inscriptions.map((inscription) => {
const [txid, vout] = inscription.output.split(':');

return {
txid,
vout: parseInt(vout),
status: {
confirmed: true, // not use in filter out inscription utxos
block_height: inscription.genesis_block_height,
block_hash: inscription.genesis_block_hash,
block_time: inscription.genesis_timestamp
},
value: parseInt(inscription.value)
} as UtxoResponseItem;
});
} catch (e) {
return [];
}
}

0 comments on commit a170a61

Please sign in to comment.