Skip to content

Commit

Permalink
feat: Solana support for NFTs owned by an account component
Browse files Browse the repository at this point in the history
  • Loading branch information
saszer committed Aug 2, 2022
1 parent b8700f2 commit 7f979aa
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Runtime/Internal/FormMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static Params Formeet(string filePath)

List<IMultipartFormSection> form= new List<IMultipartFormSection>
{
new MultipartFormFileSection("file", File.ReadAllBytes(filePath), Path.GetFileName(filePath), filetype)
new MultipartFormFileSection("file", System.IO.File.ReadAllBytes(filePath), Path.GetFileName(filePath), filetype)
};
// generate a boundary then convert the form to byte[]
byte[] boundary = UnityWebRequest.GenerateBoundary();
Expand Down
28 changes: 28 additions & 0 deletions Runtime/Internal/models/NFTs_model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ public class Metadata
public string animation_url;
public string dna;
public string id;
public Properties properties;
public int seller_fee_basis_points;
public string symbol;
public Collection collection;
}

[Serializable]
public class Collection
{
public string family;
public string name;
}

[Serializable]
public class Properties
{
public string category;
public List<Creator> creators;
public List<Files> files;
}

[Serializable]
public class Files
{
public string type;
public string uri;
}

[Serializable]
Expand All @@ -81,6 +107,8 @@ public class Nft
public Metadata metadata = new Metadata();
public string description;
public string creator_address;
public string mint_address;
public string collection_id;
public string file_url;
public string cached_file_url;
public string animation_url;
Expand Down
3 changes: 3 additions & 0 deletions Runtime/Internal/models/Txn_model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class Creator
{
public string account_address ;
public string creator_share ;
public string address;
public object share;
public bool verified;
}

[Serializable]
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Mint_File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void Stop(bool destroy)

void FileLocate(string path)
{
if (!File.Exists(path))
if (!System.IO.File.Exists(path))
{
if (OnErrorAction != null)
OnErrorAction("(~_^) ERROR! Can't locate the file to upload: " + path);
Expand Down
29 changes: 19 additions & 10 deletions Runtime/NFTs_OwnedByAnAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public enum Chains
{
ethereum,
polygon,
rinkeby
rinkeby,
solana
}

public enum Includes
Expand All @@ -46,7 +47,7 @@ public enum Includes
[Header("Optional: Filter by and return NFTs only from the given contract address/collection")]

[SerializeField]
[Tooltip("Leave blank if not using")]
[Tooltip("Filter from a collection, EVM only, Leave blank if not using")]
string contract_address;

[Header("Include optional data in the response.")]
Expand Down Expand Up @@ -204,16 +205,23 @@ public NFTs_model Run()

string BuildUrl()
{
WEB_URL = RequestUriInit + address + "?chain=" + chain.ToString().ToLower();
if (continuation != "")
if (chain == Chains.solana)
{
WEB_URL = WEB_URL + "&continuation=" + continuation;
}
WEB_URL = WEB_URL + "&include=" + include.ToString().ToLower();
WEB_URL = "https://api.nftport.xyz/v0/solana/accounts/" + address + "?include=" + include;
}
else
{
WEB_URL = RequestUriInit + address + "?chain=" + chain.ToString().ToLower();
if (continuation != "")
{
WEB_URL = WEB_URL + "&continuation=" + continuation;
}
WEB_URL = WEB_URL + "&include=" + include.ToString().ToLower();

if (contract_address != "")
WEB_URL = WEB_URL + "&contract_address=" + contract_address;

if (contract_address != "")
WEB_URL = WEB_URL + "&contract_address=" + contract_address;
}

return WEB_URL;
}

Expand All @@ -234,6 +242,7 @@ IEnumerator CallAPIProcess()

if (request.error != null)
{
NFTs = null;
if(OnErrorAction!=null)
OnErrorAction($"Null data. Response code: {request.responseCode}. Result {jsonResult}");
if(debugErrorLog)
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Storage_UploadFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ string BuildUrl()

void FileLocate(string path)
{
if (!File.Exists(path))
if (!System.IO.File.Exists(path))
{
if (OnErrorAction != null)
OnErrorAction("(~_^) ERROR! Can't locate the file to upload: " + path);
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Storage_UploadMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void SaveFile(string saveToPath, string fileName)
#if UNITY_EDITOR
AssetDatabase.Refresh();
#endif
if(File.Exists(saveToPath+fileName)){
if(System.IO.File.Exists(saveToPath+fileName)){
Debug.Log($"File Saved to: " + saveToPath + fileName);
}
else
Expand Down

0 comments on commit 7f979aa

Please sign in to comment.