Skip to content

Commit c7ad7fb

Browse files
Merge pull request #1 from 0xFirekeeper/main
Passing the ABI to underlying libraries to apply to respective routes.
2 parents 703eeeb + dc082aa commit c7ad7fb

File tree

4 files changed

+84
-55
lines changed

4 files changed

+84
-55
lines changed

Assets/Thirdweb/Scripts/Contract.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ public class Contract
2727
/// </summary>
2828
public Marketplace marketplace;
2929

30-
public Contract(string chain, string address, string abi = null) {
30+
public Contract(string chain, string address, string abi = "")
31+
{
3132
this.chain = chain;
3233
this.address = address;
3334
this.abi = abi;
34-
this.ERC20 = new ERC20(chain, address);
35-
this.ERC721 = new ERC721(chain, address);
36-
this.ERC1155 = new ERC1155(chain, address);
35+
this.ERC20 = new ERC20(chain, address, abi);
36+
this.ERC721 = new ERC721(chain, address, abi);
37+
this.ERC1155 = new ERC1155(chain, address, abi);
3738
this.marketplace = new Marketplace(chain, address);
3839
}
3940

@@ -45,7 +46,7 @@ public Contract(string chain, string address, string abi = null) {
4546
/// <returns>The data deserialized to the given typed</returns>
4647
public async Task<T> Read<T>(string functionName, params object[] args)
4748
{
48-
string [] argsEncoded = new string[args.Length + 1];
49+
string[] argsEncoded = new string[args.Length + 1];
4950
argsEncoded[0] = functionName;
5051
Utils.ToJsonStringArray(args).CopyTo(argsEncoded, 1);
5152
return await Bridge.InvokeRoute<T>(getRoute("call"), argsEncoded);
@@ -59,18 +60,15 @@ public async Task<T> Read<T>(string functionName, params object[] args)
5960
/// <returns>The transaction receipt</returns>
6061
public async Task<TransactionResult> Write(string functionName, params object[] args)
6162
{
62-
string [] argsEncoded = new string[args.Length + 1];
63+
string[] argsEncoded = new string[args.Length + 1];
6364
argsEncoded[0] = functionName;
6465
Utils.ToJsonStringArray(args).CopyTo(argsEncoded, 1);
6566
return await Bridge.InvokeRoute<TransactionResult>(getRoute("call"), argsEncoded);
6667
}
6768

68-
private string getRoute(string functionPath) {
69-
if (abi != null) {
70-
return this.address + "#" + abi + "." + functionPath;
71-
} else {
72-
return this.address + "." + functionPath;
73-
}
69+
private string getRoute(string functionPath)
70+
{
71+
return abi != "" ? this.address + "#" + abi + "." + functionPath : this.address + "." + functionPath;
7472
}
7573
}
7674
}

Assets/Thirdweb/Scripts/ERC1155.cs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,26 @@ public class ERC1155
1111
{
1212
public string chain;
1313
public string address;
14+
public string abi;
1415
/// <summary>
1516
/// Handle signature minting functionality
1617
/// </summary>
1718
public ERC1155Signature signature;
18-
/// <summary>
19+
/// <summary>
1920
/// Query claim conditions
2021
/// </summary>
2122
public ERC1155ClaimConditions claimConditions;
2223

2324
/// <summary>
2425
/// Interact with any ERC1155 compatible contract.
2526
/// </summary>
26-
public ERC1155(string chain, string address)
27+
public ERC1155(string chain, string address, string abi = "")
2728
{
2829
this.chain = chain;
2930
this.address = address;
30-
this.signature = new ERC1155Signature(chain, address);
31-
this.claimConditions = new ERC1155ClaimConditions(chain, address);
31+
this.abi = abi;
32+
this.signature = new ERC1155Signature(chain, address, abi);
33+
this.claimConditions = new ERC1155ClaimConditions(chain, address, abi);
3234
}
3335

3436
// READ FUNCTIONS
@@ -69,7 +71,7 @@ public async Task<string> Balance(string tokenId)
6971
/// <summary>
7072
/// Get the balance of the given NFT for the given wallet address
7173
/// </summary>
72-
public async Task<string> BalanceOf(string address, string tokenId)
74+
public async Task<string> BalanceOf(string address, string tokenId)
7375
{
7476
return await Bridge.InvokeRoute<string>(getRoute("balanceOf"), Utils.ToJsonStringArray(address, tokenId));
7577
}
@@ -173,23 +175,26 @@ public async Task<TransactionResult> MintAdditionalSupplyTo(string address, stri
173175

174176
// PRIVATE
175177

176-
private string getRoute(string functionPath) {
177-
return this.address + ".erc1155." + functionPath;
178+
private string getRoute(string functionPath)
179+
{
180+
return abi != "" ? this.address + "#" + abi + ".erc1155." + functionPath : this.address + ".erc1155." + functionPath;
178181
}
179182
}
180183

181-
/// <summary>
184+
/// <summary>
182185
/// Fetch claim conditions for a given ERC1155 drop contract
183186
/// </summary>
184187
public class ERC1155ClaimConditions
185188
{
186189
public string chain;
187190
public string address;
191+
public string abi;
188192

189-
public ERC1155ClaimConditions(string chain, string address)
193+
public ERC1155ClaimConditions(string chain, string address, string abi = "")
190194
{
191195
this.chain = chain;
192196
this.address = address;
197+
this.abi = abi;
193198
}
194199

195200
/// <summary>
@@ -224,14 +229,15 @@ public async Task<bool> GetClaimerProofs(string tokenId, string claimerAddress)
224229
return await Bridge.InvokeRoute<bool>(getRoute("getClaimerProofs"), Utils.ToJsonStringArray(claimerAddress));
225230
}
226231

227-
private string getRoute(string functionPath) {
228-
return this.address + ".erc1155.claimConditions." + functionPath;
232+
private string getRoute(string functionPath)
233+
{
234+
return abi != "" ? this.address + "#" + abi + ".erc1155.claimConditions." + functionPath : this.address + ".erc1155.claimConditions." + functionPath;
229235
}
230236
}
231237

232238
// TODO switch to another JSON serializer that supports polymorphism
233239
[System.Serializable]
234-
#nullable enable
240+
#nullable enable
235241
public class ERC1155MintPayload
236242
{
237243
public string to;
@@ -247,7 +253,8 @@ public class ERC1155MintPayload
247253
// public long mintStartTime;
248254
// public long mintEndTime;
249255

250-
public ERC1155MintPayload(string receiverAddress, NFTMetadata metadata) {
256+
public ERC1155MintPayload(string receiverAddress, NFTMetadata metadata)
257+
{
251258
this.metadata = metadata;
252259
this.to = receiverAddress;
253260
this.price = "0";
@@ -279,7 +286,8 @@ public class ERC1155MintAdditionalPayload
279286
// public long mintStartTime;
280287
// public long mintEndTime;
281288

282-
public ERC1155MintAdditionalPayload(string receiverAddress, string tokenId) {
289+
public ERC1155MintAdditionalPayload(string receiverAddress, string tokenId)
290+
{
283291
this.tokenId = tokenId;
284292
this.to = receiverAddress;
285293
this.price = "0";
@@ -323,11 +331,13 @@ public class ERC1155Signature
323331
{
324332
public string chain;
325333
public string address;
334+
public string abi;
326335

327-
public ERC1155Signature(string chain, string address)
336+
public ERC1155Signature(string chain, string address, string abi = "")
328337
{
329338
this.chain = chain;
330339
this.address = address;
340+
this.abi = abi;
331341
}
332342

333343
public async Task<ERC1155SignedPayload> Generate(ERC1155MintPayload payloadToSign)
@@ -350,8 +360,9 @@ public async Task<TransactionResult> Mint(ERC1155SignedPayload signedPayload)
350360
return await Bridge.InvokeRoute<TransactionResult>(getRoute("mint"), Utils.ToJsonStringArray(signedPayload));
351361
}
352362

353-
private string getRoute(string functionPath) {
354-
return this.address + ".erc1155.signature." + functionPath;
363+
private string getRoute(string functionPath)
364+
{
365+
return abi != "" ? this.address + "#" + abi + ".erc1155.signature." + functionPath : this.address + ".erc1155.signature." + functionPath;
355366
}
356367
}
357368
}

Assets/Thirdweb/Scripts/ERC20.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class ERC20
1010
{
1111
public string chain;
1212
public string address;
13+
public string abi;
1314
/// <summary>
1415
/// Handle signature minting functionality
1516
/// </summary>
@@ -22,12 +23,13 @@ public class ERC20
2223
/// <summary>
2324
/// Interact with any ERC20 compatible contract.
2425
/// </summary>
25-
public ERC20(string chain, string address)
26+
public ERC20(string chain, string address, string abi = "")
2627
{
2728
this.chain = chain;
2829
this.address = address;
29-
this.signature = new ERC20Signature(chain, address);
30-
this.claimConditions = new ERC20ClaimConditions(chain, address);
30+
this.abi = abi;
31+
this.signature = new ERC20Signature(chain, address, abi);
32+
this.claimConditions = new ERC20ClaimConditions(chain, address, abi);
3133
}
3234

3335
// READ FUNCTIONS
@@ -140,13 +142,14 @@ public async Task<TransactionResult> MintTo(string address, string amount)
140142

141143
// PRIVATE
142144

143-
private string getRoute(string functionPath) {
144-
return this.address + ".erc20." + functionPath;
145+
private string getRoute(string functionPath)
146+
{
147+
return abi != "" ? this.address + "#" + abi + ".erc20." + functionPath : this.address + ".erc20." + functionPath;
145148
}
146149
}
147150

148151
[System.Serializable]
149-
#nullable enable
152+
#nullable enable
150153
public class ERC20MintPayload
151154
{
152155
public string to;
@@ -159,7 +162,8 @@ public class ERC20MintPayload
159162
// public long mintStartTime;
160163
// public long mintEndTime;
161164

162-
public ERC20MintPayload(string receiverAddress, string quantity) {
165+
public ERC20MintPayload(string receiverAddress, string quantity)
166+
{
163167
this.to = receiverAddress;
164168
this.quantity = quantity;
165169
this.price = "0";
@@ -199,11 +203,13 @@ public class ERC20ClaimConditions
199203
{
200204
public string chain;
201205
public string address;
206+
public string abi;
202207

203-
public ERC20ClaimConditions(string chain, string address)
208+
public ERC20ClaimConditions(string chain, string address, string abi = "")
204209
{
205210
this.chain = chain;
206211
this.address = address;
212+
this.abi = abi;
207213
}
208214

209215

@@ -239,8 +245,9 @@ public async Task<bool> GetClaimerProofs(string claimerAddress)
239245
return await Bridge.InvokeRoute<bool>(getRoute("getClaimerProofs"), Utils.ToJsonStringArray(claimerAddress));
240246
}
241247

242-
private string getRoute(string functionPath) {
243-
return this.address + ".erc20.claimConditions." + functionPath;
248+
private string getRoute(string functionPath)
249+
{
250+
return abi != "" ? this.address + "#" + abi + ".erc20.claimConditions." + functionPath : this.address + ".erc20.claimConditions." + functionPath;
244251
}
245252
}
246253

@@ -252,14 +259,16 @@ public class ERC20Signature
252259
{
253260
public string chain;
254261
public string address;
262+
public string abi;
255263

256264
/// <summary>
257265
/// Generate, verify and mint signed mintable payloads
258266
/// </summary>
259-
public ERC20Signature(string chain, string address)
267+
public ERC20Signature(string chain, string address, string abi = "")
260268
{
261269
this.chain = chain;
262270
this.address = address;
271+
this.abi = abi;
263272
}
264273

265274
/// <summary>
@@ -286,8 +295,9 @@ public async Task<TransactionResult> Mint(ERC20SignedPayload signedPayload)
286295
return await Bridge.InvokeRoute<TransactionResult>(getRoute("mint"), Utils.ToJsonStringArray(signedPayload));
287296
}
288297

289-
private string getRoute(string functionPath) {
290-
return this.address + ".erc20.signature." + functionPath;
298+
private string getRoute(string functionPath)
299+
{
300+
return abi != "" ? this.address + "#" + abi + ".erc20.signature." + functionPath : this.address + ".erc20.signature." + functionPath;
291301
}
292302
}
293303
}

0 commit comments

Comments
 (0)