Skip to content

Commit ae271b5

Browse files
Use safer separators to handle ABIs with dots
1 parent bf942b8 commit ae271b5

File tree

9 files changed

+39
-32
lines changed

9 files changed

+39
-32
lines changed

Assets/Thirdweb/Scripts/Common.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
namespace Thirdweb {
22
public abstract class Routable {
3+
public static string separator = "/";
4+
public static string subSeparator = "#";
5+
6+
public static string append(string route, string subRoute) {
7+
return $"{route}{separator}{subRoute}";
8+
}
9+
310
protected string baseRoute;
411

512
public Routable(string baseRoute) {
613
this.baseRoute = baseRoute;
714
}
815

916
protected string getRoute(string functionName) {
10-
return $"{baseRoute}.{functionName}";
17+
return $"{baseRoute}{separator}{functionName}";
1118
}
1219
}
1320
}

Assets/Thirdweb/Scripts/Contract.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Contract : Routable
2727
/// </summary>
2828
public Marketplace marketplace;
2929

30-
public Contract(string chain, string address, string abi = null) : base(abi != null ? $"{address}#{abi}" : address)
30+
public Contract(string chain, string address, string abi = null) : base(abi != null ? $"{address}{Routable.subSeparator}{abi}" : address)
3131
{
3232
this.chain = chain;
3333
this.address = address;

Assets/Thirdweb/Scripts/Deployer.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ namespace Thirdweb
55
/// <summary>
66
/// Deploy contracts to the blockchain.
77
/// </summary>
8-
public class Deployer
8+
public class Deployer : Routable
99
{
10+
11+
public Deployer() : base($"sdk{subSeparator}deployer")
12+
{
13+
}
14+
1015
public async Task<string> DeployNFTCollection(NFTContractDeployMetadata metadata)
1116
{
1217
return await Bridge.InvokeRoute<string>(getRoute("deployNFTCollection"), Utils.ToJsonStringArray(metadata));
@@ -64,12 +69,6 @@ public async Task<string> DeployReleasedContract(string releaserAddress, string
6469
public async Task<string> DeployFromContractUri(string uri, object[] constructorParams) {
6570
return await Bridge.InvokeRoute<string>(getRoute("deployContractFromUri"), Utils.ToJsonStringArray(uri, constructorParams));
6671
}
67-
68-
/// PRIVATE
69-
70-
private string getRoute(string functionPath) {
71-
return "sdk#deployer." + functionPath;
72-
}
7372
}
7473

7574
[System.Serializable]

Assets/Thirdweb/Scripts/ERC1155.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ERC1155 : Routable
2121
/// <summary>
2222
/// Interact with any ERC1155 compatible contract.
2323
/// </summary>
24-
public ERC1155(string parentRoute) : base($"{parentRoute}.erc1155")
24+
public ERC1155(string parentRoute) : base(Routable.append(parentRoute, "erc1155"))
2525
{
2626
this.signature = new ERC1155Signature(baseRoute);
2727
this.claimConditions = new ERC1155ClaimConditions(baseRoute);
@@ -173,7 +173,7 @@ public async Task<TransactionResult> MintAdditionalSupplyTo(string address, stri
173173
/// </summary>
174174
public class ERC1155ClaimConditions : Routable
175175
{
176-
public ERC1155ClaimConditions(string parentRoute) : base($"{parentRoute}.claimConditions")
176+
public ERC1155ClaimConditions(string parentRoute) : base(Routable.append(parentRoute, "claimConditions"))
177177
{
178178
}
179179

@@ -310,7 +310,7 @@ public class ERC1155Signature : Routable
310310
/// <summary>
311311
/// Generate, verify and mint signed mintable payloads
312312
/// </summary>
313-
public ERC1155Signature(string parentRoute) : base($"{parentRoute}.signature")
313+
public ERC1155Signature(string parentRoute) : base(Routable.append(parentRoute, "signature"))
314314
{
315315
}
316316

Assets/Thirdweb/Scripts/ERC20.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ERC20 : Routable
2020
/// <summary>
2121
/// Interact with any ERC20 compatible contract.
2222
/// </summary>
23-
public ERC20(string parentRoute) : base($"{parentRoute}.erc20")
23+
public ERC20(string parentRoute) : base(Routable.append(parentRoute, "erc20"))
2424
{
2525
this.signature = new ERC20Signature(baseRoute);
2626
this.claimConditions = new ERC20ClaimConditions(baseRoute);
@@ -188,7 +188,7 @@ public struct ERC20SignedPayload
188188
#nullable enable
189189
public class ERC20ClaimConditions : Routable
190190
{
191-
public ERC20ClaimConditions(string parentRoute) : base($"{parentRoute}.claimConditions")
191+
public ERC20ClaimConditions(string parentRoute) : base(Routable.append(parentRoute, "claimConditions"))
192192
{
193193
}
194194

@@ -234,7 +234,7 @@ public class ERC20Signature : Routable
234234
/// <summary>
235235
/// Generate, verify and mint signed mintable payloads
236236
/// </summary>
237-
public ERC20Signature(string parentRoute) : base($"{parentRoute}.signature")
237+
public ERC20Signature(string parentRoute) : base(Routable.append(parentRoute, "signature"))
238238
{
239239
}
240240

Assets/Thirdweb/Scripts/ERC721.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ERC721 : Routable
2121
/// <summary>
2222
/// Interact with any ERC721 compatible contract.
2323
/// </summary>
24-
public ERC721(string parentRoute) : base($"{parentRoute}.erc721")
24+
public ERC721(string parentRoute) : base(Routable.append(parentRoute, "erc721"))
2525
{
2626
this.signature = new ERC721Signature(baseRoute);
2727
this.claimConditions = new ERC721ClaimConditions(baseRoute);
@@ -176,7 +176,7 @@ public async Task<TransactionResult> MintTo(string address, NFTMetadata nft)
176176
/// </summary>
177177
public class ERC721ClaimConditions : Routable
178178
{
179-
public ERC721ClaimConditions(string parentRoute) : base($"{parentRoute}.claimConditions")
179+
public ERC721ClaimConditions(string parentRoute) : base(Routable.append(parentRoute, "claimConditions"))
180180
{
181181
}
182182

@@ -214,7 +214,7 @@ public async Task<bool> GetClaimerProofs(string claimerAddress)
214214
}
215215

216216
[System.Serializable]
217-
#nullable enable
217+
#nullable enable
218218
public class ERC721MintPayload
219219
{
220220
public string to;
@@ -278,7 +278,7 @@ public class ERC721Signature : Routable
278278
/// <summary>
279279
/// Generate, verify and mint signed mintable payloads
280280
/// </summary>
281-
public ERC721Signature(string parentRoute) : base($"{parentRoute}.signature")
281+
public ERC721Signature(string parentRoute) : base(Routable.append(parentRoute, "signature"))
282282
{
283283
}
284284

Assets/Thirdweb/Scripts/Marketplace.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Marketplace : Routable
2222
/// <summary>
2323
/// Interact with a Marketplace contract.
2424
/// </summary>
25-
public Marketplace(string chain, string address) : base($"{address}#marketplace")
25+
public Marketplace(string chain, string address) : base($"{address}{subSeparator}marketplace")
2626
{
2727
this.chain = chain;
2828
this.address = address;
@@ -87,7 +87,7 @@ public async Task<TransactionResult> MakeOffer(string listingId, string pricePer
8787

8888
public class MarketplaceDirect : Routable
8989
{
90-
public MarketplaceDirect(string parentRoute) : base($"{parentRoute}.direct")
90+
public MarketplaceDirect(string parentRoute) : base(Routable.append(parentRoute, "direct"))
9191
{
9292
}
9393

@@ -120,7 +120,7 @@ public async Task<TransactionResult> CancelListing(string listingId)
120120
// AUCTION
121121

122122
public class MarketplaceAuction : Routable {
123-
public MarketplaceAuction(string parentRoute) : base($"{parentRoute}.auction")
123+
public MarketplaceAuction(string parentRoute) : base(Routable.append(parentRoute, "auction"))
124124
{
125125
}
126126

Assets/Thirdweb/Scripts/Wallet.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ namespace Thirdweb
55
/// <summary>
66
/// Connect and Interact with a Wallet.
77
/// </summary>
8-
public class Wallet
8+
public class Wallet : Routable
99
{
10+
public Wallet() : base($"sdk{subSeparator}wallet")
11+
{
12+
}
13+
1014
/// <summary>
1115
/// Connect a user's wallet via browser extension
1216
/// </summary>
@@ -21,7 +25,7 @@ public Task<string> Connect()
2125
/// <param name="domain">The domain to authenticate to</param>
2226
public async Task<LoginPayload> Authenticate(string domain)
2327
{
24-
return await Bridge.InvokeRoute<LoginPayload>("sdk#auth.login", Utils.ToJsonStringArray(domain));
28+
return await Bridge.InvokeRoute<LoginPayload>($"sdk{subSeparator}auth{separator}login", Utils.ToJsonStringArray(domain));
2529
}
2630

2731
/// <summary>
@@ -96,11 +100,5 @@ public async Task<TransactionResult> SendRawTransaction(TransactionRequest trans
96100
{
97101
return await Bridge.InvokeRoute<TransactionResult>(getRoute("sendRawTransaction"), Utils.ToJsonStringArray(transactionRequest));
98102
}
99-
100-
/// PRIVATE
101-
102-
private string getRoute(string functionPath) {
103-
return "sdk#wallet." + functionPath;
104-
}
105103
}
106104
}

Assets/WebGLTemplates/Thirdweb/lib/thirdweb.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import { ethers } from "./ethers.js";
33
import { ThirdwebSDK } from "https://esm.sh/@thirdweb-dev/sdk?bundle";
44

5+
const separator = "/";
6+
const subSeparator = "#";
7+
58
// big number transform
69
const bigNumberReplacer = (key, value) => {
710
// if we find a BigNumber then make it into a string (since that is safe)
@@ -67,8 +70,8 @@ w.bridge.switchNetwork = async (chainId) => {
6770
};
6871

6972
w.bridge.invoke = async (route, payload) => {
70-
const routeArgs = route.split(".");
71-
const firstArg = routeArgs[0].split("#");
73+
const routeArgs = route.split(separator);
74+
const firstArg = routeArgs[0].split(subSeparator);
7275
const addrOrSDK = firstArg[0];
7376

7477
const fnArgs = JSON.parse(payload).arguments;

0 commit comments

Comments
 (0)