这是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 @@ -6,6 +6,7 @@
using ChainSafe.Gaming.UnityPackage;
using ChainSafe.Gaming.UnityPackage.Model;
using ChainSafe.Gaming.Web3;
using JetBrains.Annotations;
using Nethereum.Hex.HexTypes;
using Newtonsoft.Json;
using Scripts.EVM.Remote;
Expand Down Expand Up @@ -167,16 +168,19 @@ public static async Task<TransactionReceipt> Create721Collection(string _bearerT
var formData = new List<IMultipartFormSection>
{
new MultipartFormDataSection("name", _name),
new MultipartFormDataSection("description", _description),
new MultipartFormDataSection("owner", Web3Accessor.Web3.Signer.PublicAddress),
new MultipartFormDataSection("chain_id", Web3Accessor.Web3.ChainConfig.ChainId),
new MultipartFormDataSection("projectID", Web3Accessor.Web3.ProjectConfig.ProjectId),
new MultipartFormFileSection("logo", logoImageData, "logo.png", "image/png"),
new MultipartFormFileSection("banner", bannerImageData, "banner.png", "image/png"),
new MultipartFormDataSection("isImported", "true"),
new MultipartFormDataSection("contractAddress", ChainSafeContracts.MarketplaceContracts[Web3Accessor.Web3.ChainConfig.ChainId]),
new MultipartFormDataSection("type", "erc721")
new MultipartFormDataSection("type", "ERC721")
};
if (!string.IsNullOrEmpty(_description))
{
formData.Insert(1, new MultipartFormDataSection("description", _description));
}
var path = "/collections";
var collectionResponse = await CSServer.CreateData(_bearerToken, path, formData);
var collectionData = JsonConvert.DeserializeObject<CollectionResponses.Collections>(collectionResponse);
Expand Down Expand Up @@ -213,16 +217,19 @@ public static async Task<TransactionReceipt> Create1155Collection(string _bearer
var formData = new List<IMultipartFormSection>
{
new MultipartFormDataSection("name", _name),
new MultipartFormDataSection("description", _description),
new MultipartFormDataSection("owner", Web3Accessor.Web3.Signer.PublicAddress),
new MultipartFormDataSection("chain_id", Web3Accessor.Web3.ChainConfig.ChainId),
new MultipartFormDataSection("projectID", Web3Accessor.Web3.ProjectConfig.ProjectId),
new MultipartFormFileSection("logo", logoImageData, "logo.png", "image/png"),
new MultipartFormFileSection("banner", bannerImageData, "banner.png", "image/png"),
new MultipartFormDataSection("isImported", "true"),
new MultipartFormDataSection("contractAddress", ChainSafeContracts.MarketplaceContracts[Web3Accessor.Web3.ChainConfig.ChainId]),
new MultipartFormDataSection("type", "erc1155")
new MultipartFormDataSection("type", "ERC1155")
};
if (!string.IsNullOrEmpty(_description))
{
formData.Insert(1, new MultipartFormDataSection("description", _description));
}
var path = "/collections";
var collectionResponse = await CSServer.CreateData(_bearerToken, path, formData);
var collectionData = JsonConvert.DeserializeObject<CollectionResponses.Collections>(collectionResponse);
Expand Down Expand Up @@ -251,15 +258,32 @@ public static async Task<TransactionReceipt> Create1155Collection(string _bearer
/// <param name="_collectionContract">721 collection contract to mint from/to</param>
/// <param name="_uri">URI in full format i.e https://ipfs.chainsafe.io/ipfs/bafyjvzacdj4apx52hvbyjkwyf7i6a7t3pcqd4kw4xxfc67hgvn3a</param>
/// <returns>Contract send data object</returns>
public static async Task<TransactionReceipt> Mint721CollectionNft(string _collectionContract, string _uri)
public static async Task<TransactionReceipt> Mint721CollectionNft(string _bearerToken, string _collectionContract, string _name, [CanBeNull] string _description)
{
try
{
var imageData = await UploadPlatforms.GetImageData();
var formData = new List<IMultipartFormSection>
{
new MultipartFormDataSection("name", _name),
new MultipartFormFileSection("image", imageData, "nftImage.png", "image/png"),
new MultipartFormDataSection("tokenType", "ERC721")
// TODO add attributes to form later
// attributes[0].trait_type: prop1
// attributes[0].value: 100
};
if (!string.IsNullOrEmpty(_description))
{
formData.Insert(2, 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";
object[] args =
{
Web3Accessor.Web3.Signer.PublicAddress,
_uri
collectionData.cid
};
var contract = Web3Accessor.Web3.ContractBuilder.Build(ABI.GeneralErc721, _collectionContract);
var data = await contract.SendWithReceipt(method, args);
Expand All @@ -279,16 +303,33 @@ public static async Task<TransactionReceipt> Mint721CollectionNft(string _collec
/// <param name="_uri">URI in full format i.e https://ipfs.chainsafe.io/ipfs/bafyjvzacdj4apx52hvbyjkwyf7i6a7t3pcqd4kw4xxfc67hgvn3a</param>
/// <param name="_amount">Amount of Nfts to mint</param>
/// <returns>Contract send data object</returns>
public static async Task<TransactionReceipt> Mint1155CollectionNft(string _collectionContract, string _uri, string _amount)
public static async Task<TransactionReceipt> Mint1155CollectionNft(string _bearerToken, string _collectionContract, string _amount, string _name, [CanBeNull] string _description)
{
try
{
var imageData = await UploadPlatforms.GetImageData();
var formData = new List<IMultipartFormSection>
{
new MultipartFormDataSection("name", _name),
new MultipartFormFileSection("image", imageData, "nftImage.png", "image/png"),
new MultipartFormDataSection("tokenType", "ERC1155")
// TODO add attributes to form later
// attributes[0].trait_type: prop1
// attributes[0].value: 100
};
if (!string.IsNullOrEmpty(_description))
{
formData.Insert(2, 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);
object[] args =
{
Web3Accessor.Web3.Signer.PublicAddress,
_uri,
collectionData.cid,
amount
};

Expand Down Expand Up @@ -334,10 +375,13 @@ public static async Task<TransactionReceipt> CreateMarketplace(string _bearerTok
var formData = new List<IMultipartFormSection>
{
new MultipartFormDataSection("name", _name),
new MultipartFormDataSection("description", _description),
new MultipartFormDataSection("chain_id", Web3Accessor.Web3.ChainConfig.ChainId),
new MultipartFormFileSection("banner", bannerImageData, "banner.png", "image/png")
};
if (!string.IsNullOrEmpty(_description))
{
formData.Insert(1, new MultipartFormDataSection("description", _description));
}
var path = "/marketplaces";
var marketplaceResponse = await CSServer.CreateData(_bearerToken, path, formData);
Debug.Log(marketplaceResponse);
Expand Down Expand Up @@ -484,6 +528,14 @@ public static void PrintObject(object obj)
Debug.Log($"{property.Name}: {value}");
}
}

/// <summary>
/// Handles CID response from API for metadata uploads.
/// </summary>
public class ApiResponse
{
public string cid { get; set; }
}

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ public static async Task<string> DeleteData(string _bearerToken, string _path)
public static async Task<string> CreateData(string _bearerToken, string _path,
List<IMultipartFormSection> _formData)
{
using (UnityWebRequest request = UnityWebRequest.Post($"{host}{Web3Accessor.Web3.ProjectConfig.ProjectId}{_path}", _formData))
var url = $"{host}{Web3Accessor.Web3.ProjectConfig.ProjectId}{_path}";
if (_path == "/nft?hash=blake2b-208")
{
url = "https://api.chainsafe.io/v1/nft?hash=blake2b-208";
}
using (UnityWebRequest request = UnityWebRequest.Post($"{url}", _formData))
{
request.SetRequestHeader("Authorization", $"Bearer {_bearerToken}");
await request.SendWebRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15504,7 +15504,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3594bd0b36708be40bfaecfe61e16ab7, type: 3}
m_Name:
m_EditorClassIdentifier:
fillDuration: 2
radialImage: {fileID: 5961661105869613969}
--- !u!1 &7516127192911281330
GameObject:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ChainSafe.Gaming.Ipfs;
using ChainSafe.Gaming.Marketplace;
using ChainSafe.Gaming.Web3;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using EvmMarketplace = Scripts.EVM.Marketplace.Marketplace;
using ChainSafe.Gaming.Marketplace.Models;
using ChainSafe.Gaming.UnityPackage.Model;

namespace ChainSafe.Gaming.Collection
{
Expand Down Expand Up @@ -96,7 +92,14 @@ private void PopulateCollections(UnityPackage.Model.NftTokenModel.ProjectCollect
private async void PopulateCollectionItems(int index, string collectionType)
{
var projectResponse = await EvmMarketplace.GetProjectTokens();
if (index >= projectResponse.tokens.Count)
{
EventManagerMarketplace.RaiseToggleProcessingMenu();
return;
}
var collectionContract = projectResponse.tokens[index].collection_id;
var mintCollectionNftConfigArgs = new EventManagerMarketplace.MintCollectionNftConfigEventArgs(null, collectionContract);
EventManagerMarketplace.RaiseMintCollectionNftManager(mintCollectionNftConfigArgs);
if (!Enum.TryParse(collectionType, true, out CollectionType collectionTypeEnum))
{
collectionTypeEnum = CollectionType.Unknown;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using ChainSafe.Gaming.Ipfs;
using ChainSafe.Gaming.Web3;
using TMPro;
using UnityEngine;
Expand All @@ -12,8 +10,6 @@
using EvmMarketplace = Scripts.EVM.Marketplace.Marketplace;
using ChainSafe.Gaming.Marketplace.Models;
using ChainSafe.Gaming.UnityPackage;
using ChainSafe.Gaming.UnityPackage.Model;
using Newtonsoft.Json;

namespace ChainSafe.Gaming.Marketplace
{
Expand Down Expand Up @@ -89,6 +85,11 @@ private void PopulateMarketplaces(UnityPackage.Model.MarketplaceModel.ProjectMar
private async void PopulateMarketplaceItems(string marketplaceContract, int index)
{
var projectResponse = await EvmMarketplace.GetProjectItems();
if (index >= projectResponse.items.Count)
{
EventManagerMarketplace.RaiseToggleProcessingMenu();
return;
}
var response = await EvmMarketplace.GetMarketplaceItems(projectResponse.items[index].marketplace_id);
foreach (var item in response.items)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ private void UploadCollectionImage()
{
if (processing) return;
processing = true;
// form won't post with null values here, hacky and could be better.
nameInput.text ??= " ";
descriptionInput.text ??= " ";
switch (typeDropDown.options[typeDropDown.value].text)
{
case "721":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using ChainSafe.Gaming.Web3;
using TMPro;
using UnityEngine;
Expand Down Expand Up @@ -35,9 +34,6 @@ private void UploadMarketplaceImage()
{
if (processing) return;
processing = true;
// form won't post with null values here, hacky and could be better.
nameInput.text ??= " ";
descriptionInput.text ??= " ";
CreateMarketplace(nameInput.text, descriptionInput.text, whiteListing);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class EventManagerMarketplace
public static event EventHandler<CollectionBrowserConfigEventArgs> ConfigureCollectionBrowserManager;
public static event EventHandler<MarketplaceCreateConfigEventArgs> ConfigureMarketplaceCreateManager;
public static event EventHandler<CollectionCreateConfigEventArgs> ConfigureCollectionCreateManager;
public static event EventHandler<MintCollectionNftConfigEventArgs> ConfigureMintCollectionNftManager;
public static event EventHandler<ListNftToMarketplaceConfigEventArgs> ConfigureListNftToMarketplaceManager;
public static event EventHandler<ListNftToMarketplaceTxEventArgs> ConfigureListNftToMarketplaceTxManager;
public static event Action ToggleProcessingMenu;
Expand All @@ -37,6 +38,7 @@ public static class EventManagerMarketplace
public static event Action CloseSelectedCollection;
public static event Action UploadMarketplaceImage;
public static event Action ListNftToMarketplace;
public static event Action MintNftToCollection;
public static event Action CreateMarketplace;
public static event Action LogoutMarketplace;

Expand Down Expand Up @@ -85,9 +87,9 @@ public static void RaiseToggleCreateCollectionMenu()
}

/// <summary>
/// Invokes ToggleMintNftToSelectionMenu.
/// Invokes ToggleMintNftToCollectionMenu.
/// </summary>
public static void RaiseToggleMintNftToSelectionMenu()
public static void RaiseToggleMintNftToCollectionMenu()
{
ToggleMintNftToCollectionMenu?.Invoke();
}
Expand Down Expand Up @@ -164,6 +166,11 @@ public static void RaiseCloseSelectedMarketplace()
CloseSelectedMarketplace?.Invoke();
}

public static void RaiseMintNftToCollection()
{
MintNftToCollection?.Invoke();
}

/// <summary>
/// Invokes ListNftToMarketplace.
/// </summary>
Expand Down Expand Up @@ -269,6 +276,15 @@ public static void RaiseConfigureCollectionCreateManager(CollectionCreateConfigE
ConfigureCollectionCreateManager?.Invoke(null, args);
}

/// <summary>
/// Configure marketplace create manager.
/// </summary>
/// <param name="args">Input args.</param>
public static void RaiseMintCollectionNftManager(MintCollectionNftConfigEventArgs args)
{
ConfigureMintCollectionNftManager?.Invoke(null, args);
}

#endregion

/// <summary>
Expand All @@ -293,6 +309,9 @@ private static void ResetBearerTokens()

var listNftToMarketplaceCreateEventArgs = new ListNftToMarketplaceConfigEventArgs(string.Empty);
RaiseConfigureListNftToMarketplaceManager(listNftToMarketplaceCreateEventArgs);

var mintCollectionNftConfigEventArgs = new MintCollectionNftConfigEventArgs(string.Empty, string.Empty);
RaiseMintCollectionNftManager(mintCollectionNftConfigEventArgs);
}

#region Configuration Classes
Expand Down Expand Up @@ -525,6 +544,26 @@ public CollectionCreateConfigEventArgs(string bearerToken)
#endregion
}

public class MintCollectionNftConfigEventArgs : EventArgs
{
#region Properties

public string BearerToken { get; private set; }
public string CollectionContractToListFrom { get; private set; }

#endregion

#region Methods

public MintCollectionNftConfigEventArgs(string bearerToken, string collectionToListFrom)
{
BearerToken = bearerToken;
CollectionContractToListFrom = collectionToListFrom;
}

#endregion
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ private async void TryLogin(string authResponseToken)
EventManagerMarketplace.RaiseConfigureCollectionCreateManager(collectionCreateConfigArgs);
var listNftToMarketplaceCreateConfigArgs = new EventManagerMarketplace.ListNftToMarketplaceConfigEventArgs(loginResponse.access_token.token);
EventManagerMarketplace.RaiseConfigureListNftToMarketplaceManager(listNftToMarketplaceCreateConfigArgs);
var mintCollectionNftConfigArgs = new EventManagerMarketplace.MintCollectionNftConfigEventArgs(loginResponse.access_token.token, null);
EventManagerMarketplace.RaiseMintCollectionNftManager(mintCollectionNftConfigArgs);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void Awake()
createMarketplaceUploadImageButton.onClick.AddListener(UploadMarketplaceImage);
createCollectionUploadImageButton.onClick.AddListener(UploadCollectionImage);
mintNftToCollectionMenuButton.onClick.AddListener(ToggleMintNftToCollectionMenu);
mintNftToCollectionButton.onClick.AddListener(UploadNftImageToCollection);
mintNftToCollectionButton.onClick.AddListener(MintNftToCollection);
backButtonMintNftToCollection.onClick.AddListener(ToggleMintNftToCollectionMenu);
listNftToMarketplaceButton.onClick.AddListener(ListNftToMarketplace);
backButtonListNftToMarketplace.onClick.AddListener(ToggleListNftToMarketplaceMenu);
Expand Down Expand Up @@ -215,9 +215,9 @@ private void UploadMarketplaceImage()
/// <summary>
/// Uploads marketplace image.
/// </summary>
private void UploadNftImageToCollection()
private void MintNftToCollection()
{
EventManagerMarketplace.RaiseUploadNftImageToCollection();
EventManagerMarketplace.RaiseMintNftToCollection();
}

/// <summary>
Expand All @@ -226,7 +226,7 @@ private void UploadNftImageToCollection()
private void ToggleMintNftToCollectionMenu()
{
mintNftToCollectionMenu.SetActive(!mintNftToCollectionMenu.activeSelf);
EventManagerMarketplace.RaiseToggleMintNftToSelectionMenu();
EventManagerMarketplace.RaiseToggleMintNftToCollectionMenu();
}

/// <summary>
Expand Down
Loading