Skip to content

Commit

Permalink
feat(SPV-1214): add admin contact filter to retreive contacts by xpub…
Browse files Browse the repository at this point in the history
…_id (#1122)
  • Loading branch information
jakubmkowalski authored Dec 19, 2024
1 parent ac1f076 commit 0044788
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 107 deletions.
5 changes: 3 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { HD, P2PKH, PrivateKey, Transaction } from '@bsv/sdk';
import {
AccessKeyFilter,
AdminAccessKeyFilter,
AdminContactFilter,
AdminPaymailFilter,
AdminUtxoFilter,
ContactFilter,
Expand Down Expand Up @@ -185,13 +186,13 @@ export class SpvWalletClient {
/**
* Admin only: Get a list of all contacts in the system, filtered by conditions, metadata and queryParams
*
* @param {ContactFilter} conditions Key value object to use to filter the documents
* @param {AdminContactFilter} conditions Key value object to use to filter the documents
* @param {Metadata} metadata Key value object to use to filter the documents by the metadata
* @param {OldQueryParams} params Database query parameters for page, page size and sorting
* @return {PageModel<OldContact>}
*/
async AdminGetContacts(
conditions: ContactFilter,
conditions: AdminContactFilter,
metadata: Metadata,
params: OldQueryParams,
): Promise<PageModel<OldContact>> {
Expand Down
214 changes: 109 additions & 105 deletions src/filters.ts
Original file line number Diff line number Diff line change
@@ -1,105 +1,109 @@
// TimeRange defines a range between two points in time.
export interface TimeRange {
from?: string; // from specifies the start time of the range. It's optional and can be nil.
to?: string; // to specifies the end time of the range. It's optional and can be nil
}

// ModelFilter is a common model filter that contains common fields for all model filters.
export interface ModelFilter {
includeDeleted?: boolean; // includeDeleted is a flag whether or not to include deleted items in the search results
createdRange?: TimeRange; // createdRange specifies the time range when a record was created.
updatedRange?: TimeRange; // updatedRange specifies the time range when a record was updated.
}

export interface AccessKeyFilter extends ModelFilter {
revokedRange?: TimeRange;
}

export interface AdminAccessKeyFilter extends AccessKeyFilter {
xpubId?: string;
}

export type ContactStatus = 'unconfirmed' | 'awaiting' | 'confirmed' | 'rejected';
export interface ContactFilter extends ModelFilter {
id?: string;
fullName?: string;
paymail?: string;
pubKey?: string;
status?: ContactStatus;
}

export interface DestinationFilter extends ModelFilter {
lockingScript?: string;
address?: string;
draftId?: string;
}

export interface AdminPaymailFilter extends ModelFilter {
id?: string;
xpubId?: string;
alias?: string;
domain?: string;
publicName?: string;
}

export type TransactionStatus =
| 'UNKNOWN'
| 'QUEUED'
| 'RECEIVED'
| 'STORED'
| 'ANNOUNCED_TO_NETWORK'
| 'REQUESTED_BY_NETWORK'
| 'SENT_TO_NETWORK'
| 'ACCEPTED_BY_NETWORK'
| 'SEEN_ON_NETWORK'
| 'MINED'
| 'SEEN_IN_ORPHAN_MEMPOOL'
| 'CONFIRMED'
| 'REJECTED';

export interface TransactionFilter extends ModelFilter {
id?: string;
hex?: string;
blockHash?: string;
blockHeight?: number;
fee?: number;
numberOfInputs?: number;
numberOfOutputs?: number;
draftId?: string;
totalValue?: number;

// status is typically of the type TransactionStatus. However, it can be any string to accommodate custom situations.
status?: TransactionStatus | string;
}

export type UtxoType =
| 'pubkey'
| 'pubkeyhash'
| 'nulldata'
| 'multisig'
| 'nonstandard'
| 'scripthash'
| 'metanet'
| 'token_stas'
| 'token_sensible';

export interface UtxoFilter extends ModelFilter {
transactionId?: string;
outputIndex?: number;
id?: string;
satoshis?: number;
scriptPubKey?: string;
type?: UtxoType;
draftId?: string;
reservedRange?: TimeRange;
spendingTxId?: string;
}

export interface AdminUtxoFilter extends UtxoFilter {
xpubId?: string;
}

export interface XpubFilter extends ModelFilter {
id?: string;
currentBalance?: number;
}
// TimeRange defines a range between two points in time.
export interface TimeRange {
from?: string; // from specifies the start time of the range. It's optional and can be nil.
to?: string; // to specifies the end time of the range. It's optional and can be nil
}

// ModelFilter is a common model filter that contains common fields for all model filters.
export interface ModelFilter {
includeDeleted?: boolean; // includeDeleted is a flag whether or not to include deleted items in the search results
createdRange?: TimeRange; // createdRange specifies the time range when a record was created.
updatedRange?: TimeRange; // updatedRange specifies the time range when a record was updated.
}

export interface AccessKeyFilter extends ModelFilter {
revokedRange?: TimeRange;
}

export interface AdminAccessKeyFilter extends AccessKeyFilter {
xpubId?: string;
}

export type ContactStatus = 'unconfirmed' | 'awaiting' | 'confirmed' | 'rejected';
export interface ContactFilter extends ModelFilter {
id?: string;
fullName?: string;
paymail?: string;
pubKey?: string;
status?: ContactStatus;
}

export interface DestinationFilter extends ModelFilter {
lockingScript?: string;
address?: string;
draftId?: string;
}

export interface AdminPaymailFilter extends ModelFilter {
id?: string;
xpubId?: string;
alias?: string;
domain?: string;
publicName?: string;
}

export type TransactionStatus =
| 'UNKNOWN'
| 'QUEUED'
| 'RECEIVED'
| 'STORED'
| 'ANNOUNCED_TO_NETWORK'
| 'REQUESTED_BY_NETWORK'
| 'SENT_TO_NETWORK'
| 'ACCEPTED_BY_NETWORK'
| 'SEEN_ON_NETWORK'
| 'MINED'
| 'SEEN_IN_ORPHAN_MEMPOOL'
| 'CONFIRMED'
| 'REJECTED';

export interface TransactionFilter extends ModelFilter {
id?: string;
hex?: string;
blockHash?: string;
blockHeight?: number;
fee?: number;
numberOfInputs?: number;
numberOfOutputs?: number;
draftId?: string;
totalValue?: number;

// status is typically of the type TransactionStatus. However, it can be any string to accommodate custom situations.
status?: TransactionStatus | string;
}

export type UtxoType =
| 'pubkey'
| 'pubkeyhash'
| 'nulldata'
| 'multisig'
| 'nonstandard'
| 'scripthash'
| 'metanet'
| 'token_stas'
| 'token_sensible';

export interface UtxoFilter extends ModelFilter {
transactionId?: string;
outputIndex?: number;
id?: string;
satoshis?: number;
scriptPubKey?: string;
type?: UtxoType;
draftId?: string;
reservedRange?: TimeRange;
spendingTxId?: string;
}

export interface AdminUtxoFilter extends UtxoFilter {
xpubId?: string;
}

export interface XpubFilter extends ModelFilter {
id?: string;
currentBalance?: number;
}

export interface AdminContactFilter extends ContactFilter {
xpubId?: string;
}

0 comments on commit 0044788

Please sign in to comment.