Skip to content

Commit 3005b76

Browse files
committed
fix all interfaces and params
1 parent eec2f0d commit 3005b76

22 files changed

+531
-215
lines changed

lib/errors.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,16 @@ export class ThreadWithTokenUTXONotFoundError extends Error
209209
super(message);
210210
}
211211
}
212+
213+
/**
214+
* Error thrown when a previous bidder address is invalid.
215+
*/
216+
export class InvalidPrevBidderAddressError extends Error
217+
{
218+
constructor()
219+
{
220+
const message = 'The previous bidder address is invalid';
221+
222+
super(message);
223+
}
224+
}

lib/functions/accumulation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TransactionBuilder } from 'cashscript';
22
import { adjustLastOutputForFee, getAuthorizedContractUtxo, getRegistrationUtxo, getThreadUtxo } from '../util/index.js';
33
import { UserUTXONotFoundError } from '../errors.js';
44
import { createPlaceholderUnlocker, getThreadWithTokenUtxo } from '../util/utxo.js';
5-
import { FetchAccumulationUtxosResponse, FetchAccumulationUtxosParams, AccumulateParams } from '../interfaces/index.js';
5+
import { FetchAccumulationUtxosResponse, FetchAccumulationUtxosParams, AccumulateCoreParams } from '../interfaces/index.js';
66

77

88
/**
@@ -77,7 +77,7 @@ export const accumulate = async ({
7777
accumulatorContract,
7878
utxos,
7979
address,
80-
}: AccumulateParams): Promise<TransactionBuilder> =>
80+
}: AccumulateCoreParams): Promise<TransactionBuilder> =>
8181
{
8282
const { threadNFTUTXO, registrationCounterUTXO, authorizedContractUTXO, threadWithTokenUTXO, userUTXO } = utxos;
8383

lib/functions/claim-domain.ts

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
getThreadUtxo,
1414
validateName,
1515
} from '../util/index.js';
16-
import type { FetchClaimDomainUtxosParams, CreateClaimDomainTransactionParams } from '../interfaces/index.js';
16+
import type { FetchClaimDomainUtxosParams, CreateClaimDomainParams, FetchClaimDomainUtxosResponse } from '../interfaces/index.js';
17+
import { InvalidPrevBidderAddressError } from '../errors.js';
18+
1719

1820
/**
1921
* Fetches UTXOs required for claiming a domain.
@@ -24,15 +26,15 @@ import type { FetchClaimDomainUtxosParams, CreateClaimDomainTransactionParams }
2426
* @param {Contract} params.domainFactoryContract - The domain factory contract instance.
2527
* @param {string} params.name - The name of the domain.
2628
* @param {NetworkProvider} params.networkProvider - The network provider for blockchain interactions.
27-
* @returns {Promise<Object>} A promise that resolves to an object containing the necessary UTXOs.
29+
* @returns {Promise<FetchClaimDomainUtxosResponse>} A promise that resolves to an object containing the necessary UTXOs.
2830
*/
2931
export const fetchClaimDomainUtxos = async ({
3032
category,
3133
registryContract,
3234
domainFactoryContract,
3335
name,
3436
networkProvider,
35-
}: FetchClaimDomainUtxosParams): Promise<any> =>
37+
}: FetchClaimDomainUtxosParams): Promise<FetchClaimDomainUtxosResponse> =>
3638
{
3739
const [ registryUtxos, domainFactoryUtxos ] = await Promise.all([
3840
networkProvider.getUtxos(registryContract.address),
@@ -75,58 +77,50 @@ export const fetchClaimDomainUtxos = async ({
7577
* and contracts. It ensures the domain name is valid, fetches necessary UTXOs if not provided,
7678
* and builds a transaction with multiple inputs and outputs to facilitate the domain claim process.
7779
*
78-
* @param {CreateClaimDomainTransactionParams} params - The parameters required to create the claim domain transaction.
80+
* @param {CreateClaimDomainParams} params - The parameters required to create the claim domain transaction.
7981
* @param {string} params.category - The category of the domain.
8082
* @param {Contract} params.registryContract - The registry contract instance.
8183
* @param {Contract} params.domainFactoryContract - The domain factory contract instance.
8284
* @param {number} params.inactivityExpiryTime - The inactivity expiry time for the domain.
8385
* @param {number} params.maxPlatformFeePercentage - The maximum platform fee percentage.
8486
* @param {number} params.minWaitTime - The minimum wait time for the transaction.
8587
* @param {string} params.name - The name of the domain.
86-
* @param {NetworkProvider} params.networkProvider - The network provider for blockchain interactions.
87-
* @param {any} params.options - Additional options for the domain contract.
88+
* @param {object} params.options - Additional options for the domain contract.
8889
* @param {string} [params.platformFeeAddress] - The address to receive the platform fee, if specified.
89-
* @param {any} [params.utxos] - The UTXOs to be used in the transaction, if already available.
90+
* @param {FetchClaimDomainUtxosResponse} [params.utxos] - The UTXOs to be used in the transaction, if already available.
9091
* @returns {Promise<TransactionBuilder>} A promise that resolves to the transaction builder.
9192
* @throws {InvalidNameError} If the domain name is invalid.
92-
* @throws {Error} If the previous bidder address is invalid.
93+
* @throws {InvalidPrevBidderAddressError} If the previous bidder address is invalid.
9394
*/
94-
export const createClaimDomainTransaction = async ({
95+
export const createClaimDomainTransactionCore = async ({
9596
category,
9697
registryContract,
9798
domainFactoryContract,
9899
inactivityExpiryTime,
99100
maxPlatformFeePercentage,
100101
minWaitTime,
101102
name,
102-
networkProvider,
103103
options,
104104
platformFeeAddress,
105105
utxos,
106-
}: CreateClaimDomainTransactionParams): Promise<TransactionBuilder> =>
106+
}: CreateClaimDomainParams): Promise<TransactionBuilder> =>
107107
{
108108
validateName(name);
109109
const { nameBin } = convertNameToBinaryAndHex(name);
110110

111-
if(!utxos)
112-
{
113-
utxos = await fetchClaimDomainUtxos({
114-
category,
115-
registryContract,
116-
domainFactoryContract,
117-
name,
118-
networkProvider,
119-
});
120-
}
121111
const { threadNFTUTXO, authorizedContractUTXO, domainMintingUTXO, runningAuctionUTXO } = utxos;
122112

123113
const bidderPKH = runningAuctionUTXO.token?.nft?.commitment.slice(0, 40);
114+
if(!bidderPKH)
115+
{
116+
throw new InvalidPrevBidderAddressError();
117+
}
124118
const bidderLockingBytecode = convertPkhToLockingBytecode(bidderPKH);
125119
const bidderAddressResult = lockingBytecodeToCashAddress({ bytecode: bidderLockingBytecode });
126120

127121
if(typeof bidderAddressResult !== 'object' || !bidderAddressResult.address)
128122
{
129-
throw new Error('Invalid prev bidder address');
123+
throw new InvalidPrevBidderAddressError();
130124
}
131125

132126
const bidderAddress = bidderAddressResult.address;
@@ -140,7 +134,7 @@ export const createClaimDomainTransaction = async ({
140134

141135
const registrationId = createRegistrationId(runningAuctionUTXO);
142136

143-
const transaction = await new TransactionBuilder({ provider: networkProvider })
137+
const transaction = await new TransactionBuilder({ provider: options.provider })
144138
.addInput(threadNFTUTXO, registryContract.unlock.call())
145139
.addInput(authorizedContractUTXO, domainFactoryContract.unlock.call())
146140
.addInput(domainMintingUTXO, registryContract.unlock.call())
@@ -149,11 +143,11 @@ export const createClaimDomainTransaction = async ({
149143
to: registryContract.tokenAddress,
150144
amount: threadNFTUTXO.satoshis,
151145
token: {
152-
category: threadNFTUTXO.token.category,
153-
amount: threadNFTUTXO.token.amount + runningAuctionUTXO.token.amount,
146+
category: threadNFTUTXO.token!.category,
147+
amount: threadNFTUTXO.token!.amount + runningAuctionUTXO.token!.amount,
154148
nft: {
155-
capability: threadNFTUTXO.token.nft.capability,
156-
commitment: threadNFTUTXO.token.nft.commitment,
149+
capability: threadNFTUTXO.token!.nft!.capability,
150+
commitment: threadNFTUTXO.token!.nft!.commitment,
157151
},
158152
},
159153
})
@@ -165,19 +159,19 @@ export const createClaimDomainTransaction = async ({
165159
to: registryContract.tokenAddress,
166160
amount: domainMintingUTXO.satoshis,
167161
token: {
168-
category: domainMintingUTXO.token.category,
169-
amount: domainMintingUTXO.token.amount,
162+
category: domainMintingUTXO.token!.category,
163+
amount: domainMintingUTXO.token!.amount,
170164
nft: {
171-
capability: domainMintingUTXO.token.nft.capability,
172-
commitment: domainMintingUTXO.token.nft.commitment,
165+
capability: domainMintingUTXO.token!.nft!.capability,
166+
commitment: domainMintingUTXO.token!.nft!.commitment,
173167
},
174168
},
175169
})
176170
.addOutput({
177171
to: domainContract.tokenAddress,
178172
amount: BigInt(1000),
179173
token: {
180-
category: domainMintingUTXO.token.category,
174+
category: domainMintingUTXO.token!.category,
181175
amount: BigInt(0),
182176
nft: {
183177
capability: 'none',
@@ -189,7 +183,7 @@ export const createClaimDomainTransaction = async ({
189183
to: domainContract.tokenAddress,
190184
amount: BigInt(1000),
191185
token: {
192-
category: domainMintingUTXO.token.category,
186+
category: domainMintingUTXO.token!.category,
193187
amount: BigInt(0),
194188
nft: {
195189
capability: 'none',
@@ -201,7 +195,7 @@ export const createClaimDomainTransaction = async ({
201195
to: convertCashAddressToTokenAddress(bidderAddress),
202196
amount: BigInt(1000),
203197
token: {
204-
category: domainMintingUTXO.token.category,
198+
category: domainMintingUTXO.token!.category,
205199
amount: BigInt(0),
206200
nft: {
207201
capability: 'none',

lib/functions/create-records.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@ import {
88
findInternalAuthNFTUTXO,
99
findOwnershipNFTUTXO,
1010
} from '../util/index.js';
11-
import { CreateRecordsParams, FetchRecordsUtxosParams, FetchRecordsUtxosReturnType } from '../interfaces/index.js';
11+
import { CreateRecordsCoreParams, FetchRecordsUtxosParams, FetchRecordsUtxosResponse } from '../interfaces/index.js';
1212

13-
14-
export const fetchRecordsUtxos = async ({ name,
13+
/**
14+
* Fetches the UTXOs required for creating records.
15+
*
16+
* @param {FetchRecordsUtxosParams} params - The parameters for fetching UTXOs.
17+
* @returns {Promise<FetchRecordsUtxosResponse>} A promise that resolves to the fetched UTXOs.
18+
* @throws {InternalAuthNFTUTXONotFoundError} If the internal authorization NFT UTXO is not found.
19+
* @throws {UserOwnershipNFTUTXONotFoundError} If the user ownership NFT UTXO is not found.
20+
* @throws {UserFundingUTXONotFoundError} If the user funding UTXO is not found.
21+
*/
22+
export const fetchRecordsUtxos = async ({
23+
name,
1524
category,
1625
domainContract,
1726
address,
18-
networkProvider }: FetchRecordsUtxosParams): Promise<FetchRecordsUtxosReturnType> =>
27+
networkProvider,
28+
}: FetchRecordsUtxosParams): Promise<FetchRecordsUtxosResponse> =>
1929
{
2030
const [ domainUTXOs, userUtxos ] = await Promise.all([
2131
networkProvider.getUtxos(domainContract.address),
@@ -50,7 +60,7 @@ export const fetchRecordsUtxos = async ({ name,
5060
/**
5161
* Creates a transaction for adding a record to a domain.
5262
*
53-
* @param {CreateRecordsParams} params - The parameters for creating the record transaction.
63+
* @param {CreateRecordsCoreParams} params - The parameters for creating the record transaction.
5464
* @returns {Promise<TransactionBuilder>} A promise that resolves to the transaction builder.
5565
*/
5666
export const createRecordsTransaction = async ({
@@ -59,7 +69,7 @@ export const createRecordsTransaction = async ({
5969
networkProvider,
6070
records,
6171
utxos,
62-
}: CreateRecordsParams): Promise<TransactionBuilder> =>
72+
}: CreateRecordsCoreParams): Promise<TransactionBuilder> =>
6373
{
6474
const { internalAuthNFTUTXO, ownershipNFTUTXO, fundingUTXO } = utxos;
6575

lib/functions/fetch-records.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@ import { constructDomainContract, extractRecordsFromTransaction, getValidCandida
33
import type { FetchRecordsParams } from '../interfaces/index.js';
44

55
/**
6-
* Retrieves the records for a given domain.
6+
* Fetches domain records based on the provided parameters.
77
*
8-
* @param {string} name - The domain name to retrieve records for.
9-
* @returns {Promise<string[]>} A promise that resolves to the domain records.
8+
* @param {FetchRecordsParams} params - The parameters for fetching domain records.
9+
* @param {string} params.name - The domain name to retrieve records for.
10+
* @param {boolean} [params.keepDuplicates=true] - Whether to keep duplicate records.
11+
* @param {string} params.category - The category of the domain.
12+
* @param {number} params.inactivityExpiryTime - The expiry time for domain inactivity.
13+
* @param {object} params.options - Additional options for domain contract construction.
14+
* @param {object} params.electrumClient - The Electrum client for blockchain interactions.
15+
* @returns {Promise<string[]>} A promise that resolves to an array of domain records.
1016
*/
11-
export const fetchRecords = async (
12-
{ name,
13-
keepDuplicates = true,
14-
category,
15-
inactivityExpiryTime,
16-
options,
17-
electrumClient }: FetchRecordsParams): Promise<string[]> =>
17+
export const fetchRecords = async ({
18+
name,
19+
keepDuplicates = true,
20+
category,
21+
inactivityExpiryTime,
22+
options,
23+
electrumClient,
24+
}: FetchRecordsParams): Promise<string[]> =>
1825
{
1926
const domainContract = constructDomainContract({
2027
name,

lib/functions/get-domain.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
import { constructDomainContract, getDomainPartialBytecode } from '../util/contract.js';
22
import { hexToBin, binToHex } from '@bitauth/libauth';
3-
import { DomainInfo } from '../interfaces/index.js';
3+
import { DomainInfo, GetDomainParams } from '../interfaces/index.js';
44
import { buildLockScriptP2SH32, lockScriptToAddress, pushDataHex, validateName } from '../util/index.js';
55

66

7-
export interface GetDomainParams
8-
{
9-
name: string;
10-
category: string;
11-
inactivityExpiryTime: number;
12-
options: any;
13-
}
14-
157
/**
16-
* Retrieves the domain information for a given full domain name.
17-
*
18-
* @param {string} name - The domain name to retrieve information for.
19-
* @returns {Promise<DomainInfo>} A promise that resolves to an object containing the domain address, contract, and UTXOs.
20-
*/
8+
* Retrieves the domain information for a specified domain name.
9+
*
10+
* @param {GetDomainParams} params - The parameters required to get domain details.
11+
* @param {string} params.name - The domain name to retrieve information for.
12+
* @param {string} params.category - The category of the domain.
13+
* @param {number} params.inactivityExpiryTime - The inactivity expiry time for the domain.
14+
* @param {object} params.options - Additional options for the domain contract.
15+
* @param {AddressType} params.options.addressType - The type of address used.
16+
* @param {NetworkProvider} params.options.provider - The network provider for blockchain interactions.
17+
* @returns {Promise<DomainInfo>} A promise that resolves to an object containing the domain address and contract.
18+
*/
2119
export const getDomain = async ({ name, category, inactivityExpiryTime, options }: GetDomainParams): Promise<DomainInfo> =>
2220
{
23-
// Extract the domain name from the full domain name.
21+
// Validate the domain name.
2422
validateName(name);
2523

2624
// Reverse the category bytes for use in contract parameters.

lib/functions/get-past-auctions.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { binToHex, hexToBin, decodeTransaction } from '@bitauth/libauth';
22
import { fetchHistory, fetchTransaction } from '@electrum-cash/protocol';
3-
import type { GetPastAuctionsParams, PastAuctionResult } from '../interfaces/index.js';
3+
import type { GetPastAuctionsParams, PastAuctionResponse } from '../interfaces/index.js';
44

55
/**
6-
* Retrieves the transaction history of auctions.
7-
*
8-
* @returns {Promise<PastAuctionResult[]>} A promise that resolves to an array of transaction history objects,
9-
* each containing a transaction hex and an auction name.
10-
*/
6+
* Retrieves the transaction history of auctions.
7+
*
8+
* @returns {Promise<PastAuctionResponse[]>} A promise that resolves to an array of transaction history objects,
9+
* each containing a transaction hex and an auction name.
10+
*/
1111
export const getPastAuctions = async ({
1212
category,
1313
electrumClient,
1414
domainContract,
15-
}: GetPastAuctionsParams): Promise<PastAuctionResult[]> =>
15+
}: GetPastAuctionsParams): Promise<PastAuctionResponse[]> =>
1616
{
1717
// @ts-ignore
1818
const history = await fetchHistory(electrumClient, domainContract.address);
@@ -75,5 +75,5 @@ export const getPastAuctions = async ({
7575
};
7676
}));
7777

78-
return validTransactions.filter(tx => tx !== null) as PastAuctionResult[];
78+
return validTransactions.filter(tx => tx !== null) as PastAuctionResponse[];
7979
};

lib/functions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { fetchClaimDomainUtxos, createClaimDomainTransaction } from './claim-domain.js';
1+
export { fetchClaimDomainUtxos, createClaimDomainTransactionCore } from './claim-domain.js';
22
export { fetchAuctionUtxos, createAuctionTransactionCore } from './create-auction.js';
33
export { fetchBidUtxos, createBidTransactionCore } from './create-bid.js';
44
export { fetchDuplicateAuctionGuardUtxos, penalizeDuplicateAuction } from './penalise-duplicate-auction.js';

0 commit comments

Comments
 (0)