这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,31 @@ public static async Task<TransactionReceipt> Mint721CollectionNft(string _bearer
var path = "/nft?hash=blake2b-208";
var collectionResponse = await CSServer.CreateData(_bearerToken, path, formData);
var collectionData = JsonConvert.DeserializeObject<ApiResponse>(collectionResponse);
Debug.Log($"CID: {collectionData.cid}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this debug

var method = "mint";
object[] args =
{
Web3Accessor.Web3.Signer.PublicAddress,
collectionData.cid
};
var contract = Web3Accessor.Web3.ContractBuilder.Build(ABI.GeneralErc721, _collectionContract);
var data = await contract.SendWithReceipt(method, args);
var txArgs = new TransactionRequest
{
GasLimit = new HexBigInteger(90000)
};
var data = await contract.SendWithReceipt(method, args, txArgs);
return data.receipt;
}
catch (Web3Exception e)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can replace this with

catch (Exception e)
{
if (!(e is Web3Exception))
{
Debug.LogError("Error: " + e.Message);
}
throw e;
}

{
Console.WriteLine(e);
throw;
}
catch (Exception e)
{
Debug.LogError("Error: " + e.Message);
throw;
}
}

/// <summary>
Expand All @@ -319,13 +329,14 @@ public static async Task<TransactionReceipt> Mint1155CollectionNft(string _beare
};
if (!string.IsNullOrEmpty(_description))
{
formData.Insert(2, new MultipartFormDataSection("description", _description));
formData.Insert(1, new MultipartFormDataSection("description", _description));
}
var path = "/nft?hash=blake2b-208";
var collectionResponse = await CSServer.CreateData(_bearerToken, path, formData);
var collectionData = JsonConvert.DeserializeObject<ApiResponse>(collectionResponse);
var method = "mint";
var amount = BigInteger.Parse(_amount);
Debug.Log($"Amount3: {amount}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this debug can be removed

object[] args =
{
Web3Accessor.Web3.Signer.PublicAddress,
Expand All @@ -334,14 +345,23 @@ public static async Task<TransactionReceipt> Mint1155CollectionNft(string _beare
};

var contract = Web3Accessor.Web3.ContractBuilder.Build(ABI.GeneralErc1155, _collectionContract);
var data = await contract.SendWithReceipt(method, args);
var txArgs = new TransactionRequest
{
GasLimit = new HexBigInteger(90000)
};
var data = await contract.SendWithReceipt(method, args, txArgs);
return data.receipt;
}
catch (Web3Exception e)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can also be replaced with my suggestion above

{
Console.WriteLine(e);
throw;
}
catch (Exception e)
{
Debug.LogError("Error: " + e.Message);
throw;
}
}

/// <summary>
Expand Down Expand Up @@ -435,7 +455,7 @@ public static async Task<TransactionReceipt> SetApprovalMarketplace(string _nftC
_marketplaceContract,
_permission
};
var abi = _type == "721" ? Token.ABI.GeneralErc721 : Token.ABI.GeneralErc1155;
var abi = _type == "ERC721" ? Token.ABI.GeneralErc721 : Token.ABI.GeneralErc1155;
var contract = Web3Accessor.Web3.ContractBuilder.Build(abi, _nftContract);
var data = await contract.SendWithReceipt(method, args);
return data.receipt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ChainSafe.Gaming.UnityPackage;
using ChainSafe.Gaming.Web3;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Networking;
Expand Down Expand Up @@ -75,7 +77,7 @@ public static async Task<string> DeleteData(string _bearerToken, string _path)
if (request.result != UnityWebRequest.Result.Success)
{
Debug.LogError($"Error deleting: {request.error}");
return request.error;
throw new Exception($"Error: {request.error}");
}
return "Deleted successfully";
}
Expand All @@ -93,16 +95,17 @@ public static async Task<string> CreateData(string _bearerToken, string _path,
var url = $"{host}{Web3Accessor.Web3.ProjectConfig.ProjectId}{_path}";
if (_path == "/nft?hash=blake2b-208")
{
url = "https://api.chainsafe.io/v1/nft?hash=blake2b-208";
url = "https://api.chainsafe.io/api/v1/nft?hash=blake2b-208";
}
using (UnityWebRequest request = UnityWebRequest.Post($"{url}", _formData))
{
request.SetRequestHeader("Authorization", $"Bearer {_bearerToken}");
request.SetRequestHeader("Accept", "application/json");
await request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
Debug.LogError("Creation failed: " + request.downloadHandler.text);
return request.error;
throw new Exception($"Error: {request.error}");
}
return request.downloadHandler.text;
}
Expand Down
Loading