Skip to content

Commit

Permalink
Merge pull request #14 from Origin-Byte/suiplay-integration
Browse files Browse the repository at this point in the history
Suiplay integration
  • Loading branch information
Tamas Szucs authored Jul 21, 2023
2 parents 366727a + ec92e80 commit 8607984
Show file tree
Hide file tree
Showing 73 changed files with 16,465 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MintSuitradersNft : IMoveCallTransactionBuilder

public string Recipient { get; set; }

public MoveCallTransaction BuildMoveCallTransaction(string gas = null, ulong gasBudget = 10000, ExecuteTransactionRequestType RequestType = ExecuteTransactionRequestType.WaitForLocalExecution)
public MoveCallTransaction BuildMoveCallTransaction(string gas = null, ulong gasBudget = 10000000, ExecuteTransactionRequestType RequestType = ExecuteTransactionRequestType.WaitForLocalExecution)
{
return new MoveCallTransaction()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using Suinet.NftProtocol.Domains;
using Suinet.NftProtocol.Examples;
using Suinet.NftProtocol.Examples;
using Suinet.NftProtocol.Nft;
using Suinet.NftProtocol.TransactionBuilders;
using Suinet.Rpc;
using Suinet.Rpc.Client;
using Suinet.Rpc.Types;
using Suinet.Wallet;
using System;
using Suinet.Wallet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;

namespace Suinet.NftProtocol
{
Expand All @@ -35,13 +36,13 @@ public async Task<RpcResult<TransactionBlockResponse>> EnableSalesAsync(EnableSa
}

private async Task<RpcResult<TransactionBlockResponse>> ExecuteTxAsync(IMoveCallTransactionBuilder txBuilder, string gasObjectId = null)
{
{
var moveCallResult = await _jsonRpcApiClient.MoveCallAsync(txBuilder.BuildMoveCallTransaction(gasObjectId));

var txBytes = moveCallResult.Result.TxBytes;
var rawSigner = new RawSigner(_keypair);
var signature = rawSigner.SignData(Intent.GetMessageWithIntent(txBytes));

var signature = rawSigner.SignData(Intent.GetMessageWithIntent(txBytes));

var txResponse = await _jsonRpcApiClient.ExecuteTransactionBlockAsync(txBytes, new[] { signature.Value }, TransactionBlockResponseOptions.ShowAll(), ExecuteTransactionRequestType.WaitForLocalExecution);

return txResponse;
Expand All @@ -61,19 +62,11 @@ public async Task<RpcResult<ArtNft>> GetArtNftAsync(string objectId, params Type

public async Task<RpcResult<IEnumerable<ArtNft>>> GetArtNftsOwnedByAddressAsync(string address, params Type[] withDomains)
{
throw new NotImplementedException();

//var nftsResult = await _jsonRpcApiClient.GetObjectsOwnedByAddressAsync<ArtNft>(address, null, null);

//if (nftsResult == null || !nftsResult.IsSuccess) return nftsResult;

//// TODO test is Task.WhenAll works correctly on webgl
//foreach (var nft in nftsResult.Result)
//{
// await LoadDomainsForArtNftAsync(nft, withDomains);
//}

//return nftsResult;
var filter = ObjectDataFilterFactory.CreateMatchAllFilter(ObjectDataFilterFactory.CreateAddressOwnerFilter(address));
var query = new ObjectResponseQuery() {Filter = filter, Options = ObjectDataOptions.ShowAll()};
return await _jsonRpcApiClient.GetOwnedObjectsAsync<ArtNft>(address, new ArtNftParser(), query
, null, null);
}

private async Task LoadDomainsForArtNftAsync(ArtNft nft, params Type[] withDomains)
Expand All @@ -84,56 +77,56 @@ private async Task LoadDomainsForArtNftAsync(ArtNft nft, params Type[] withDomai

bool filterDomains = withDomains != null && withDomains.Any();

if (!filterDomains || withDomains.Contains(typeof(UrlDomain)))
{
var objectFieldInfo = dynamicFields.Result.Data.FirstOrDefault(d => d.ObjectType.Struct == nameof(UrlDomain));

if (objectFieldInfo != null)
{
var domainResult = await _jsonRpcApiClient.GetDynamicFieldObjectAsync<UrlDomain>(parentObjectId, objectFieldInfo.Name, null);
if (domainResult != null && domainResult.IsSuccess)
{
nft.Url = domainResult.Result.Url;
if (!filterDomains || withDomains.Contains(typeof(UrlDomain)))
{
var objectFieldInfo = dynamicFields.Result.Data.FirstOrDefault(d => d.ObjectType.Struct == nameof(UrlDomain));

if (objectFieldInfo != null)
{
var domainResult = await _jsonRpcApiClient.GetDynamicFieldObjectAsync<UrlDomain>(parentObjectId, objectFieldInfo.Name, null);
if (domainResult != null && domainResult.IsSuccess)
{
nft.Url = domainResult.Result.Url;
}
}
}

if (!filterDomains || withDomains.Contains(typeof(DisplayDomain)))
{
var objectFieldInfo = dynamicFields.Result.Data.FirstOrDefault(d => d.ObjectType.Struct == nameof(DisplayDomain));

if (objectFieldInfo != null)
{
var domainResult = await _jsonRpcApiClient.GetDynamicFieldObjectAsync<DisplayDomain>(parentObjectId, objectFieldInfo.Name, null);
if (domainResult != null && domainResult.IsSuccess)
{
var domain = domainResult.Result;
nft.Name = domain?.Name;
nft.Description = domain?.Description;
}
}
}

if (!filterDomains || withDomains.Contains(typeof(DisplayDomain)))
{
var objectFieldInfo = dynamicFields.Result.Data.FirstOrDefault(d => d.ObjectType.Struct == nameof(DisplayDomain));

if (objectFieldInfo != null)
{
var domainResult = await _jsonRpcApiClient.GetDynamicFieldObjectAsync<DisplayDomain>(parentObjectId, objectFieldInfo.Name, null);
if (domainResult != null && domainResult.IsSuccess)
{
var domain = domainResult.Result;
nft.Name = domain?.Name;
nft.Description = domain?.Description;
}
}
}

if (!filterDomains || withDomains.Contains(typeof(AttributesDomain)))
{
var objectFieldInfo = dynamicFields.Result.Data.FirstOrDefault(d => d.ObjectType.Struct == nameof(AttributesDomain));

if (objectFieldInfo != null)
{
var domainResult = await _jsonRpcApiClient.GetDynamicFieldObjectAsync<AttributesDomain>(parentObjectId, objectFieldInfo.Name, null);

if (domainResult != null && domainResult.IsSuccess)
{
//nft.Attributes = domainResult.Result.Attributes;
}

if (!filterDomains || withDomains.Contains(typeof(AttributesDomain)))
{
var objectFieldInfo = dynamicFields.Result.Data.FirstOrDefault(d => d.ObjectType.Struct == nameof(AttributesDomain));

if (objectFieldInfo != null)
{
var domainResult = await _jsonRpcApiClient.GetDynamicFieldObjectAsync<AttributesDomain>(parentObjectId, objectFieldInfo.Name, null);

if (domainResult != null && domainResult.IsSuccess)
{
//nft.Attributes = domainResult.Result.Attributes;
}
}
}
}

public async Task<RpcResult<IEnumerable<ArtNft>>> GetArtNftsFromKioskAsync(string kioskId)
{
throw new NotImplementedException();
//var kiosk = await
}
}

public async Task<RpcResult<IEnumerable<ArtNft>>> GetArtNftsFromKioskAsync(string kioskId)
{
throw new NotImplementedException();
//var kiosk = await
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using UnityEngine;

namespace Suinet.Rpc.Types.JsonConverters
{
Expand Down Expand Up @@ -29,10 +30,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
throw new JsonSerializationException("Type of TransactionBlockKind not recognized");
}
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public static class SuiConstants

public const string KIOSK_TYPE = "0x2::kiosk::Kiosk";
public const string KIOSK_ITEM_TYPE = "0x2::kiosk::Item";

public const string SUIPLAY_API_URL = "https://suiplay-api.originbyte.io/v1";
}
}
8 changes: 8 additions & 0 deletions Assets/SuiUnitySDK/Plugins/Suinet/Suinet.SuiPlay.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/SuiUnitySDK/Plugins/Suinet/Suinet.SuiPlay/DTO.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Suinet.SuiPlay.DTO
{
public class EmailData
{
public string Email { get; set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Assets/SuiUnitySDK/Plugins/Suinet/Suinet.SuiPlay/DTO/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;

namespace Suinet.SuiPlay.DTO
{
public class Player
{
public string Id { get; set; }
public string DisplayName { get; set; }
public object LastLogin { get; set; }
public string UserId { get; set; }
public Dictionary<string, object> Properties { get; set; }
public Dictionary<string, Wallet> Wallets { get; set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Assets/SuiUnitySDK/Plugins/Suinet/Suinet.SuiPlay/DTO/Wallet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Suinet.SuiPlay.DTO
{
public class Wallet
{
public string Id { get; set; }
public string Address { get; set; }
public string Chain { get; set; }
public string Network { get; set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8607984

Please sign in to comment.