Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit ba3c3c3

Browse files
Remove un-used byoc registry and factory (#440)
* remove byoc registry and factory * fix tests * remove await adn log Co-authored-by: Jonas Daniels <[email protected]>
1 parent 43182eb commit ba3c3c3

14 files changed

+41
-154
lines changed

docs/sdk.ipfsstorage.uploadmetadatabatch.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,20 @@ Uploads JSON metadata to IPFS
1111
```typescript
1212
uploadMetadataBatch(metadatas: JsonObject[], fileStartNumber?: number, contractAddress?: string, signerAddress?: string, options?: {
1313
onProgress: (event: UploadProgressEvent) => void;
14-
}): Promise<{
15-
baseUri: string;
16-
uris: string[];
17-
}>;
14+
}): Promise<UploadResult>;
1815
```
1916

2017
## Parameters
2118

2219
| Parameter | Type | Description |
2320
| --- | --- | --- |
24-
| metadatas | [JsonObject](./sdk.jsonobject.md)<!-- -->\[\] | |
21+
| metadatas | [JsonObject](./sdk.jsonobject.md)<!-- -->\[\] | The metadata to be uploaded. |
2522
| fileStartNumber | number | <i>(Optional)</i> Optional. The first file file name begins with. |
2623
| contractAddress | string | <i>(Optional)</i> Optional. The contract address the data belongs to. |
2724
| signerAddress | string | <i>(Optional)</i> Optional. The address of the signer. |
28-
| options | { onProgress: (event: [UploadProgressEvent](./sdk.uploadprogressevent.md)<!-- -->) =&gt; void; } | <i>(Optional)</i> |
25+
| options | { onProgress: (event: [UploadProgressEvent](./sdk.uploadprogressevent.md)<!-- -->) =&gt; void; } | <i>(Optional)</i> Optional. Upload progress callback. |
2926

3027
<b>Returns:</b>
3128

32-
Promise&lt;{ baseUri: string; uris: string\[\]; }&gt;
29+
Promise&lt;[UploadResult](./sdk.uploadresult.md)<!-- -->&gt;
3330

docs/sdk.istorage.uploadmetadatabatch.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ uploadMetadataBatch(metadatas: JsonObject[], fileStartNumber?: number, contractA
1818

1919
| Parameter | Type | Description |
2020
| --- | --- | --- |
21-
| metadatas | [JsonObject](./sdk.jsonobject.md)<!-- -->\[\] | |
21+
| metadatas | [JsonObject](./sdk.jsonobject.md)<!-- -->\[\] | The metadata to be uploaded. |
2222
| fileStartNumber | number | <i>(Optional)</i> Optional. The first file file name begins with. |
2323
| contractAddress | string | <i>(Optional)</i> Optional. The contract address the data belongs to. |
2424
| signerAddress | string | <i>(Optional)</i> Optional. The address of the signer. |
25-
| options | { onProgress: (event: [UploadProgressEvent](./sdk.uploadprogressevent.md)<!-- -->) =&gt; void; } | <i>(Optional)</i> |
25+
| options | { onProgress: (event: [UploadProgressEvent](./sdk.uploadprogressevent.md)<!-- -->) =&gt; void; } | <i>(Optional)</i> Optional. Upload progress callback. |
2626

2727
<b>Returns:</b>
2828

etc/sdk.api.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,10 +2040,7 @@ export class IpfsStorage implements IStorage {
20402040
}): Promise<string>;
20412041
uploadMetadataBatch(metadatas: JsonObject[], fileStartNumber?: number, contractAddress?: string, signerAddress?: string, options?: {
20422042
onProgress: (event: UploadProgressEvent) => void;
2043-
}): Promise<{
2044-
baseUri: string;
2045-
uris: string[];
2046-
}>;
2043+
}): Promise<UploadResult>;
20472044
// @internal
20482045
uploadSingle(data: string | Record<string, any>, contractAddress?: string, signerAddress?: string): Promise<string>;
20492046
}
@@ -4921,7 +4918,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
49214918
// Warning: (ae-forgotten-export) The symbol "ContractPublisher" needs to be exported by the entry point index.d.ts
49224919
//
49234920
// @internal (undocumented)
4924-
getPublisher(): Promise<ContractPublisher>;
4921+
getPublisher(): ContractPublisher;
49254922
// @internal
49264923
getSignatureDrop(contractAddress: string): SignatureDrop;
49274924
getSplit(address: string): Split;

src/constants/addresses.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ export function getContractAddressByChainId(
122122
return process.env.factoryAddress as string;
123123
} else if (contractName === "twRegistry") {
124124
return process.env.registryAddress as string;
125-
} else if (contractName === "twBYOCRegistry") {
126-
return process.env.byocRegistryAddress as string;
127-
} else if (contractName === "contractDeployer") {
128-
return process.env.contractDeployerAddress as string;
129125
} else if (contractName === "contractMetadataRegistry") {
130126
return process.env.contractMetadataRegistryAddress as string;
131127
} else if (contractName === "sigMint") {

src/core/classes/contract-deployer.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,8 @@ export class ContractDeployer extends RPCConnectionHandler {
362362
chainId,
363363
"twRegistry",
364364
);
365-
const contractPublisherAddress = getContractAddressByChainId(
366-
chainId,
367-
"twBYOCRegistry",
368-
);
369365
return new ContractRegistry(
370366
registryAddress,
371-
contractPublisherAddress,
372367
this.getSignerOrProvider(),
373368
this.options,
374369
);

src/core/classes/contract-publisher.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ import {
2626
} from "../../schema/contracts/custom";
2727
import { ContractWrapper } from "./contract-wrapper";
2828
import {
29-
ContractDeployer,
3029
ContractPublisher as OnChainContractPublisher,
3130
IContractPublisher,
3231
} from "contracts";
3332
import { getContractPublisherAddress } from "../../constants";
34-
import ContractDeployerAbi from "../../../abis/ContractDeployer.json";
3533
import ContractPublisherAbi from "../../../abis/ContractPublisher.json";
3634
import { ContractPublishedEvent } from "contracts/ContractPublisher";
3735

@@ -42,10 +40,8 @@ import { ContractPublishedEvent } from "contracts/ContractPublisher";
4240
export class ContractPublisher extends RPCConnectionHandler {
4341
private storage: IStorage;
4442
private publisher: ContractWrapper<OnChainContractPublisher>;
45-
private factory: ContractWrapper<ContractDeployer>;
4643

4744
constructor(
48-
contractDeployerAddress: string,
4945
network: NetworkOrSignerOrProvider,
5046
options: SDKOptions,
5147
storage: IStorage,
@@ -58,20 +54,13 @@ export class ContractPublisher extends RPCConnectionHandler {
5854
ContractPublisherAbi,
5955
options,
6056
);
61-
this.factory = new ContractWrapper<ContractDeployer>(
62-
network,
63-
contractDeployerAddress,
64-
ContractDeployerAbi,
65-
options,
66-
);
6757
}
6858

6959
public override updateSignerOrProvider(
7060
network: NetworkOrSignerOrProvider,
7161
): void {
7262
super.updateSignerOrProvider(network);
7363
this.publisher.updateSignerOrProvider(network);
74-
this.factory.updateSignerOrProvider(network);
7564
}
7665

7766
/**

src/core/classes/ipfs-storage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { IpfsUploader } from "../uploaders/ipfs-uploader";
1414
import { UploadProgressEvent } from "../../types/events";
1515
import { File } from "@web-std/file";
1616
import FormData from "form-data";
17+
import { UploadResult } from "../interfaces";
1718

1819
/**
1920
* IPFS Storage implementation, accepts custom IPFS gateways
@@ -149,7 +150,7 @@ export class IpfsStorage implements IStorage {
149150
options?: {
150151
onProgress: (event: UploadProgressEvent) => void;
151152
},
152-
) {
153+
): Promise<UploadResult> {
153154
const metadataToUpload = (
154155
await this.batchUploadProperties(metadatas, options)
155156
).map((m: any) => JSON.stringify(m));

src/core/classes/registry.ts

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,20 @@ import { TransactionResult } from "..";
99
* @internal
1010
*/
1111
export class ContractRegistry extends ContractWrapper<TWRegistry> {
12-
private byocRegistry: ContractWrapper<TWRegistry>;
13-
1412
constructor(
1513
registryAddress: string,
16-
contractPublisherAddress: string,
1714
network: NetworkOrSignerOrProvider,
1815
options?: SDKOptions,
1916
) {
2017
super(network, registryAddress, TWRegistry__factory.abi, options);
21-
this.byocRegistry = new ContractWrapper<TWRegistry>(
22-
network,
23-
contractPublisherAddress,
24-
TWRegistry__factory.abi,
25-
options,
26-
);
2718
}
2819

2920
public async getContractAddresses(walletAddress: string) {
30-
let byocContracts: string[] = [];
31-
try {
32-
byocContracts = await this.byocRegistry.readContract.getAll(
33-
walletAddress,
34-
);
35-
} catch (e) {
36-
// do nothing
37-
}
3821
// TODO @fixme the filter here is necessary because for some reason getAll returns a 0x0 address for the first entry
39-
return (await this.readContract.getAll(walletAddress))
40-
.concat(byocContracts)
41-
.filter(
42-
(adr) =>
43-
utils.isAddress(adr) && adr.toLowerCase() !== constants.AddressZero,
44-
);
22+
return (await this.readContract.getAll(walletAddress)).filter(
23+
(adr) =>
24+
utils.isAddress(adr) && adr.toLowerCase() !== constants.AddressZero,
25+
);
4526
}
4627

4728
public async addContract(
@@ -70,32 +51,6 @@ export class ContractRegistry extends ContractWrapper<TWRegistry> {
7051
};
7152
}
7253

73-
public async addCustomContract(
74-
contractAddress: string,
75-
): Promise<TransactionResult> {
76-
return await this.addCustomContracts([contractAddress]);
77-
}
78-
79-
public async addCustomContracts(
80-
contractAddresses: string[],
81-
): Promise<TransactionResult> {
82-
const deployerAddress = await this.getSignerAddress();
83-
84-
const encoded: string[] = [];
85-
contractAddresses.forEach((address) => {
86-
encoded.push(
87-
this.byocRegistry.readContract.interface.encodeFunctionData("add", [
88-
deployerAddress,
89-
address,
90-
]),
91-
);
92-
});
93-
94-
return {
95-
receipt: await this.byocRegistry.multiCall(encoded),
96-
};
97-
}
98-
9954
public async removeContract(
10055
contractAddress: string,
10156
): Promise<TransactionResult> {
@@ -121,30 +76,4 @@ export class ContractRegistry extends ContractWrapper<TWRegistry> {
12176
receipt: await this.multiCall(encoded),
12277
};
12378
}
124-
125-
public async removeCustomContract(
126-
contractAddress: string,
127-
): Promise<TransactionResult> {
128-
return await this.removeCustomContracts([contractAddress]);
129-
}
130-
131-
public async removeCustomContracts(
132-
contractAddresses: string[],
133-
): Promise<TransactionResult> {
134-
const deployerAddress = await this.getSignerAddress();
135-
136-
const encoded: string[] = [];
137-
contractAddresses.forEach((address) => {
138-
encoded.push(
139-
this.byocRegistry.readContract.interface.encodeFunctionData("remove", [
140-
deployerAddress,
141-
address,
142-
]),
143-
);
144-
});
145-
146-
return {
147-
receipt: await this.byocRegistry.multiCall(encoded),
148-
};
149-
}
15079
}

src/core/interfaces/IStorage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ export interface IStorage {
8484
*
8585
* Uploads JSON metadata to IPFS
8686
*
87-
* @param metadata - The metadata to be uploaded.
87+
* @param metadatas - The metadata to be uploaded.
8888
* @param fileStartNumber - Optional. The first file file name begins with.
8989
* @param contractAddress - Optional. The contract address the data belongs to.
9090
* @param signerAddress - Optional. The address of the signer.
91+
* @param options - Optional. Upload progress callback.
9192
*/
9293
uploadMetadataBatch(
9394
metadatas: JsonObject[],

src/core/sdk.ts

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
Marketplace,
99
NFTCollection,
1010
NFTDrop,
11-
SignatureDrop,
1211
Pack,
1312
REMOTE_CONTRACT_TO_CONTRACT_TYPE,
13+
SignatureDrop,
1414
Split,
1515
Token,
1616
Vote,
@@ -34,7 +34,6 @@ import { ContractPublisher } from "./classes/contract-publisher";
3434
import { ContractMetadata } from "./classes";
3535
import {
3636
ChainOrRpc,
37-
getContractAddressByChainId,
3837
getProviderForNetwork,
3938
getReadOnlyProvider,
4039
} from "../constants";
@@ -121,7 +120,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
121120
* @internal
122121
* should never be accessed directly, use {@link ThirdwebSDK.getPublisher} instead
123122
*/
124-
private _publisher: Promise<ContractPublisher> | undefined;
123+
private _publisher: ContractPublisher;
125124
/**
126125
* Internal handler for uploading and downloading files
127126
*/
@@ -151,6 +150,11 @@ export class ThirdwebSDK extends RPCConnectionHandler {
151150
this.storage = new RemoteStorage(storage);
152151
this.deployer = new ContractDeployer(signerOrProvider, options, storage);
153152
this.wallet = new UserWallet(signerOrProvider, options);
153+
this._publisher = new ContractPublisher(
154+
signerOrProvider,
155+
this.options,
156+
this.storageHandler,
157+
);
154158
}
155159

156160
/**
@@ -405,9 +409,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
405409
private updateContractSignerOrProvider() {
406410
this.wallet.onNetworkUpdated(this.getSignerOrProvider());
407411
this.deployer.updateSignerOrProvider(this.getSignerOrProvider());
408-
this._publisher?.then((publisher) => {
409-
publisher.updateSignerOrProvider(this.getSignerOrProvider());
410-
});
412+
this._publisher.updateSignerOrProvider(this.getSignerOrProvider());
411413
for (const [, contract] of this.contractCache) {
412414
contract.onNetworkUpdated(this.getSignerOrProvider());
413415
}
@@ -424,7 +426,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
424426
return this.contractCache.get(address) as SmartContract;
425427
}
426428
try {
427-
const publisher = await this.getPublisher();
429+
const publisher = this.getPublisher();
428430
const metadata = await publisher.fetchContractMetadataFromAddress(
429431
address,
430432
);
@@ -459,29 +461,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
459461
/**
460462
* @internal
461463
*/
462-
public async getPublisher(): Promise<ContractPublisher> {
463-
// if we already have a registry just return it back
464-
if (this._publisher) {
465-
return this._publisher;
466-
}
467-
468-
// otherwise get the factory address for the active chain and get a new one
469-
470-
// have to do it like this otherwise we run it over and over and over
471-
// "this._publisher" has to be assigned to the promise upfront.
472-
return (this._publisher = this.getProvider()
473-
.getNetwork()
474-
.then(async ({ chainId }) => {
475-
const factoryAddress = getContractAddressByChainId(
476-
chainId,
477-
"contractDeployer",
478-
);
479-
return new ContractPublisher(
480-
factoryAddress,
481-
this.getSignerOrProvider(),
482-
this.options,
483-
this.storageHandler,
484-
);
485-
}));
464+
public getPublisher(): ContractPublisher {
465+
return this._publisher;
486466
}
487467
}

0 commit comments

Comments
 (0)