Skip to content

Commit 3234ea5

Browse files
committed
move resolver functions to name service and update interfaces
1 parent fc4b5b0 commit 3234ea5

File tree

9 files changed

+451
-564
lines changed

9 files changed

+451
-564
lines changed

lib/interfaces/auction.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,6 @@ export interface FetchAuctionUtxosResponse
8686
userUTXO: Utxo;
8787
}
8888

89-
/**
90-
* Parameters for retrieving all active auctions.
91-
*/
92-
export interface GetAuctionsParams
93-
{
94-
/**
95-
* The category of the auctions.
96-
*/
97-
category: string;
98-
/**
99-
* Contracts involved in the auctions.
100-
*/
101-
contracts: Record<string, Contract>;
102-
/**
103-
* Network provider for BCH network operations.
104-
*/
105-
networkProvider: NetworkProvider;
106-
/**
107-
* Electrum client for protocol events.
108-
*/
109-
electrumClient: ElectrumClient<ElectrumProtocolEvents>;
110-
}
111-
11289
/**
11390
* Response type for retrieving all active auctions.
11491
*/

lib/interfaces/name.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AddressType, Contract, NetworkProvider, Utxo } from 'cashscript';
1+
import type { Contract, Utxo } from 'cashscript';
22

33
/**
44
* Enum representing the various statuses a name can have.
@@ -56,21 +56,8 @@ export interface FetchClaimNameUtxosParams
5656
*/
5757
export interface GetNameParams
5858
{
59-
/** The category of the name. */
60-
category: string;
61-
/** The TLD of the name. */
62-
tld: string;
6359
/** The name of the name. */
6460
name: string;
65-
/** Additional options for the name contract. */
66-
options: {
67-
/** The type of address used. */
68-
addressType: AddressType;
69-
/** The network provider for blockchain interactions. */
70-
provider: NetworkProvider;
71-
};
72-
/** The contract instance for the registry. */
73-
registryContract: Contract;
7461
}
7562

7663
/**

lib/interfaces/records.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,8 @@ export interface CreateRecordsCoreParams
4646
*/
4747
export interface FetchRecordsParams
4848
{
49-
/** The category of the records. */
50-
category: string;
51-
/** The TLD of the name. */
52-
tld: string;
5349
/** The name associated with the records. */
5450
name: string;
55-
options: {
56-
/** The type of address used. */
57-
addressType: AddressType;
58-
/** The network provider for blockchain interactions. */
59-
provider: NetworkProvider;
60-
};
6151
}
6252

6353
/**

lib/interfaces/resolver.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import type { NetworkProvider } from 'cashscript';
2-
31
/**
42
* Interface for the request parameters of the lookupAddressCore function.
53
*/
64
export interface LookupAddressCoreParams
75
{
86
address: string;
9-
category: string;
10-
networkProvider: NetworkProvider;
117
}
128

139
/**
@@ -42,13 +38,8 @@ export interface LookupAddressParams
4238
export interface ResolveNameCoreParams
4339
{
4440
name: string;
45-
category: string;
46-
tld: string;
47-
options: any;
48-
electrumClient: any;
4941
useElectrum?: boolean;
5042
useChaingraph?: boolean;
51-
chaingraphUrl?: string;
5243
}
5344

5445
/**
@@ -59,7 +50,6 @@ export interface ResolveNameByElectrumParams
5950
baseHeight: number;
6051
token: any;
6152
ownerLockingBytecode: any;
62-
electrumClient: any;
6353
}
6454

6555
/**
@@ -68,6 +58,4 @@ export interface ResolveNameByElectrumParams
6858
export interface ResolveNameByChainGraphParams
6959
{
7060
token: any;
71-
chaingraphUrl: string;
72-
electrumClient: any;
7361
}

lib/managers/bitcann.manager.ts

Lines changed: 102 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,136 @@
1-
import type {
2-
AddressType,
3-
NetworkProvider,
4-
} from 'cashscript';
51
import {
62
Contract,
73
ElectrumNetworkProvider,
84
TransactionBuilder,
95
} from 'cashscript';
6+
import type {
7+
AddressType,
8+
NetworkProvider,
9+
} from 'cashscript';
10+
import { chaingraphURL } from '../config.js';
1011
import { NameService } from '../services/name.service.js';
1112
import { RegistryService } from '../services/registry.service.js';
1213
import { AuctionTransactionBuilder } from '../transactions/auction.builder.js';
1314
import { BidTransactionBuilder } from '../transactions/bid.builder.js';
1415
import { ClaimNameTransactionBuilder } from '../transactions/claim.builder.js';
15-
import { RecordsTransactionBuilder } from '../transactions/records.builder.js';
1616
import { PenalisationTransactionBuilder } from '../transactions/penalisation.builder.js';
17+
import { RecordsTransactionBuilder } from '../transactions/records.builder.js';
18+
import { AccumulationTransactionBuilder } from '../transactions/accumulation.builder.js';
19+
import { UtxoManager } from './utxo.manager.js';
1720
import {
1821
constructContracts,
1922
lookupAddressCore,
23+
resolveNameCore,
2024
} from '../util/index.js';
2125
import type {
2226
AccumulateParams,
2327
CreateAuctionParams,
2428
CreateBidParams,
29+
CreateClaimNameParams,
2530
CreateRecordsParams,
26-
NameInfo,
2731
GetAuctionsResponse,
2832
GetRecordsParams,
2933
LookupAddressParams,
3034
ManagerConfig,
35+
NameInfo,
3136
PastAuctionResponse,
3237
PenaliseDuplicateAuctionParams,
3338
PenaliseIllegalAuctionParams,
3439
PenalizeInvalidNameParams,
3540
ResolveNameParams,
36-
CreateClaimNameParams,
3741
} from '../interfaces/index.js';
3842
import { LookupAddressCoreResponse } from '../interfaces/resolver.js';
39-
import { resolveNameCore } from '../util/index.js';
40-
import { chaingraphURL } from '../config.js';
4143
import type { ParsedRecordsInterface } from '../util/parser.js';
42-
import { UtxoManager } from './utxo.manager.js';
43-
import { AccumulationTransactionBuilder } from '../transactions/accumulation.builder.js';
4444

4545

4646
export class BitcannManager
4747
{
48-
// Config to build the contracts in the BitCANN system.
49-
public category: string;
50-
public minStartingBid: number;
51-
public minBidIncreasePercentage: number;
52-
public inactivityExpiryTime: number;
53-
public minWaitTime: number;
54-
public tld: string;
55-
public creatorIncentiveAddress: string;
56-
public options: { provider: NetworkProvider; addressType: AddressType };
57-
58-
// Network provider to use for BCH network operations.
59-
public networkProvider: NetworkProvider;
60-
public chaingraphUrl: string;
61-
62-
// Contracts in the BitCANN system.
63-
public contracts: Record<string, Contract>;
64-
65-
public utxoManager: UtxoManager;
66-
public accumulationTransactionBuilder: AccumulationTransactionBuilder;
67-
public claimNameTransactionBuilder: ClaimNameTransactionBuilder;
68-
public auctionTransactionBuilder: AuctionTransactionBuilder;
69-
public bidTransactionBuilder: BidTransactionBuilder;
70-
public recordsTransactionBuilder: RecordsTransactionBuilder;
71-
public penalisationTransactionBuilder: PenalisationTransactionBuilder;
72-
73-
public nameService: NameService;
74-
public registryService: RegistryService;
48+
/**
49+
* The category of the name.
50+
*/
51+
private category: string;
52+
/**
53+
* The minimum starting bid for the name.
54+
*/
55+
private minStartingBid: number;
56+
/**
57+
* The minimum bid increase percentage for the name.
58+
*/
59+
private minBidIncreasePercentage: number;
60+
/**
61+
* The inactivity expiry time before the name can be considered expired.
62+
*/
63+
private inactivityExpiryTime: number;
64+
/**
65+
* The minimum wait time for the name.
66+
*/
67+
private minWaitTime: number;
68+
/**
69+
* The TLD of the name.
70+
*/
71+
private tld: string;
72+
/**
73+
* The creator incentive address for the protocol.
74+
*/
75+
private creatorIncentiveAddress: string;
76+
/**
77+
* The options for the name contract.
78+
*/
79+
private options: { provider: NetworkProvider; addressType: AddressType };
80+
/**
81+
* The network provider to use for BCH network operations.
82+
*/
83+
private networkProvider: NetworkProvider;
84+
/**
85+
* The Chaingraph URL to use for lookups.
86+
*/
87+
private chaingraphUrl: string;
88+
/**
89+
* The contracts in the BitCANN system.
90+
*/
91+
private contracts: Record<string, Contract>;
92+
/**
93+
* The UTXO manager for builders and
94+
*/
95+
private utxoManager: UtxoManager;
96+
/**
97+
* The builder for accumulation transactions.
98+
*/
99+
private accumulationTransactionBuilder: AccumulationTransactionBuilder;
100+
/**
101+
* The builder for claim name transactions.
102+
*/
103+
private claimNameTransactionBuilder: ClaimNameTransactionBuilder;
104+
/**
105+
* The builder for auction transactions.
106+
*/
107+
private auctionTransactionBuilder: AuctionTransactionBuilder;
108+
/**
109+
* The builder for bid transactions.
110+
*/
111+
private bidTransactionBuilder: BidTransactionBuilder;
112+
/**
113+
* The builder for records transactions.
114+
*/
115+
private recordsTransactionBuilder: RecordsTransactionBuilder;
116+
/**
117+
* The builder for penalisation transactions.
118+
*/
119+
private penalisationTransactionBuilder: PenalisationTransactionBuilder;
120+
/**
121+
* The service for registry operations.
122+
*/
123+
private registryService: RegistryService;
124+
/**
125+
* The service for name operations.
126+
*/
127+
private nameService: NameService;
75128

129+
/**
130+
* Constructs a new BitcannManager.
131+
*
132+
* @param {ManagerConfig} config - The configuration for the manager.
133+
*/
76134
constructor(config: ManagerConfig)
77135
{
78136
this.category = config.category;
@@ -168,6 +226,7 @@ export class BitcannManager
168226
this.category,
169227
this.tld,
170228
this.options,
229+
this.chaingraphUrl,
171230
);
172231

173232
this.registryService = new RegistryService(
@@ -193,14 +252,7 @@ export class BitcannManager
193252
*/
194253
public async getRecords({ name }: GetRecordsParams): Promise<ParsedRecordsInterface>
195254
{
196-
return this.nameService.fetchRecords({
197-
name,
198-
category: this.category,
199-
tld: this.tld,
200-
options: this.options,
201-
// @ts-ignore
202-
electrumClient: this.networkProvider.electrum,
203-
});
255+
return this.nameService.fetchRecords({ name });
204256
}
205257

206258
/**
@@ -210,13 +262,7 @@ export class BitcannManager
210262
*/
211263
public async getAuctions(): Promise<GetAuctionsResponse[]>
212264
{
213-
return this.registryService.getAuctions({
214-
category: this.category,
215-
networkProvider: this.networkProvider,
216-
contracts: this.contracts,
217-
// @ts-ignore
218-
electrumClient: this.networkProvider.electrum,
219-
});
265+
return this.registryService.getAuctions();
220266
}
221267

222268
/**
@@ -227,12 +273,7 @@ export class BitcannManager
227273
*/
228274
public async getHistory(): Promise<PastAuctionResponse[]>
229275
{
230-
return this.registryService.getPastAuctions({
231-
category: this.category,
232-
Factory: this.contracts.Factory,
233-
// @ts-ignore
234-
electrumClient: this.networkProvider.electrum,
235-
});
276+
return this.registryService.getPastAuctions();
236277
}
237278

238279
/**
@@ -243,13 +284,7 @@ export class BitcannManager
243284
*/
244285
public async getName(name: string): Promise<NameInfo>
245286
{
246-
return this.nameService.getName({
247-
name,
248-
category: this.category,
249-
tld: this.tld,
250-
options: this.options,
251-
registryContract: this.contracts.Registry,
252-
});
287+
return this.nameService.getName({ name });
253288
}
254289

255290
/**
@@ -273,6 +308,7 @@ export class BitcannManager
273308
options: this.options,
274309
// @ts-ignore
275310
electrumClient: this.networkProvider.electrum,
311+
chaingraphUrl: this.chaingraphUrl,
276312
useElectrum,
277313
useChaingraph,
278314
});

0 commit comments

Comments
 (0)