Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b535637
Revert "automated duplicating imported samples modifications (#595)"
robGG1997 Sep 14, 2023
95fb832
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Sep 14, 2023
e3ab3c2
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Sep 14, 2023
a536df0
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Sep 15, 2023
c12a0de
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Sep 18, 2023
8e1ea0a
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Sep 18, 2023
1318cd7
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Sep 21, 2023
33b8e52
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Sep 22, 2023
0a205bd
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Sep 25, 2023
df4795a
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Sep 29, 2023
abc34f6
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Sep 29, 2023
031e8d3
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Oct 18, 2023
3a4bdd9
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Oct 24, 2023
67d871d
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Oct 25, 2023
3c1d099
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Oct 30, 2023
ed22cb7
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Oct 31, 2023
4c8b282
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Nov 1, 2023
ea609de
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Nov 2, 2023
adcb974
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Nov 2, 2023
77dd93a
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Nov 3, 2023
12af139
Merge branch 'main' of https://github.com/ChainSafe/web3.unity
robGG1997 Nov 7, 2023
7ecba01
checkpoint
robGG1997 Nov 8, 2023
ec8d80c
added overload with different typed tokenId parameter
robGG1997 Nov 8, 2023
5ece09b
reverted type cast for batchOwnerOf
robGG1997 Nov 8, 2023
18d7bc3
small optimization changes
robGG1997 Nov 8, 2023
423d05c
Auto-duplicate Packages Samples
robGG1997 Nov 8, 2023
d370253
Merge branch 'main' into rob/721-1155-integer-check-701
robGG1997 Nov 8, 2023
398a05c
tokenId type now BigInteger
robGG1997 Nov 8, 2023
b520786
added overload implementation for 1155
robGG1997 Nov 8, 2023
4da4916
fix for loading SampleImportNftTexture scene
robGG1997 Nov 8, 2023
2b69919
Auto-duplicate Packages Samples
robGG1997 Nov 8, 2023
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 @@ -20,12 +20,34 @@ public class Erc1155
/// <returns></returns>
public static async Task<BigInteger> BalanceOf(Web3 web3, string contractAddress, string account, string tokenId)
{
var contract = web3.ContractBuilder.Build(Abi, contractAddress);
var contractData = await contract.Call(CommonMethod.BalanceOf, new object[]
return await BalanceOf(web3, contractAddress, account, new object[]
{
account,
tokenId
});
}

/// <summary>
/// Balance of ERC1155 Token
/// </summary>
/// <param name="web3"></param>
/// <param name="contractAddress"></param>
/// <param name="account"></param>
/// <param name="tokenId"></param>
/// <returns></returns>
public static async Task<BigInteger> BalanceOf(Web3 web3, string contractAddress, string account, BigInteger tokenId)
{
return await BalanceOf(web3, contractAddress, account, new object[]
{
account,
tokenId
});
}

private static async Task<BigInteger> BalanceOf(Web3 web3, string contractAddress, string account, object[] parameters)
{
var contract = web3.ContractBuilder.Build(Abi, contractAddress);
var contractData = await contract.Call(CommonMethod.BalanceOf, parameters);
return BigInteger.Parse(contractData[0].ToString());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Numerics;
using System.Threading.Tasks;
using ChainSafe.Gaming.Web3;
using Newtonsoft.Json;
Expand Down Expand Up @@ -36,13 +37,28 @@ public static async Task<int> BalanceOf(Web3 web3, string contractAddress, strin
/// <param name="tokenId"></param>
/// <returns></returns>
public static async Task<string> OwnerOf(Web3 web3, string contractAddress, string tokenId)
{
return await OwnerOf(web3, contractAddress, new object[] { tokenId, });
}

/// <summary>
/// Owner Of ERC721 Token
/// </summary>
/// <param name="web3"></param>
/// <param name="contractAddress"></param>
/// <param name="tokenId"></param>
/// <returns></returns>
public static async Task<string> OwnerOf(Web3 web3, string contractAddress, BigInteger tokenId)
{
return await OwnerOf(web3, contractAddress, new object[] { tokenId, });
}

private static async Task<string> OwnerOf(Web3 web3, string contractAddress, object[] parameters)
{
var method = CommonMethod.OwnerOf;
var contract = web3.ContractBuilder.Build(_abi, contractAddress);
var contractData = await contract.Call(method, new object[]
{
tokenId
});

var contractData = await contract.Call(method, parameters);
return contractData[0].ToString();
}

Expand All @@ -64,10 +80,12 @@ public static async Task<List<string>> OwnerOfBatch(
// build array of args
var obj = new string[tokenIds.Length][];
for (var i = 0; i < tokenIds.Length; i++)
{
obj[i] = new[]
{
tokenIds[i]
};
}
var args = JsonConvert.SerializeObject(obj);
var response = await Remote.CSServer.Multicall(web3, web3.ChainConfig.ChainId, web3.ChainConfig.Network,
contractAddress, _abi, method, args, multicall, web3.ChainConfig.Rpc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public async Task<BigInteger> BalanceOf(string contract, string account, string
{
return await Erc1155.BalanceOf(web3, contract, account, tokenId);
}

public async Task<BigInteger> BalanceOf(string contract, string account, BigInteger tokenId)
{
return await Erc1155.BalanceOf(web3, contract, account, tokenId);
}

public async Task<List<BigInteger>> BalanceOfBatch(string contract, string[] accounts, string[] tokenIds)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Threading.Tasks;
using ChainSafe.Gaming.Web3;
using Scripts.EVM.Remote;
Expand All @@ -25,6 +26,11 @@ public async Task<string> OwnerOf(string contractAddress, string tokenId)
{
return await Erc721.OwnerOf(web3, contractAddress, tokenId);
}

public async Task<string> OwnerOf(string contractAddress, BigInteger tokenId)
{
return await Erc721.OwnerOf(web3, contractAddress, tokenId);
}

public async Task<List<string>> OwnerOfBatch(string contractAddress, string[] tokenIds, string multicall = "")
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Numerics;
using System.Threading.Tasks;
using ChainSafe.Gaming.UnityPackage;
using Web3Unity.Scripts.Prefabs;

Expand All @@ -20,7 +21,8 @@ protected override void Awake()

protected override async Task ExecuteSample()
{
var balance = await logic.BalanceOf(contractAddress, account, tokenId);
var balance = tokenId.StartsWith("0x") ?
await logic.BalanceOf(contractAddress, account, tokenId) : await logic.BalanceOf(contractAddress, account, BigInteger.Parse(tokenId));
SampleOutputUtil.PrintResult(balance.ToString(), nameof(Erc1155Sample), nameof(Erc1155Sample.BalanceOf));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Samples.Behaviours.Erc721
public class Erc721OwnerOfBatchBehaviour : SampleBehaviour
{
public string contractAddress = "0x47381c5c948254e6e0E324F1AA54b7B24104D92D";
public List<string> tokenIds = new() { "33", "29" };
public string[] tokenIds = { "33", "29" };

[Header("Optional")]
// optional: multicall contract https://github.com/makerdao/multicall
Expand All @@ -25,7 +25,7 @@ protected override void Awake()

protected override async Task ExecuteSample()
{
var owners = await logic.OwnerOfBatch(contractAddress, tokenIds.ToArray(), multicall);
var owners = await logic.OwnerOfBatch(contractAddress, tokenIds, multicall);
var ownersString = $"{owners.Count} owner(s):\n" + string.Join(",\n", owners);
SampleOutputUtil.PrintResult(ownersString, nameof(Erc721Sample), nameof(Erc721Sample.OwnerOfBatch));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Numerics;
using System.Threading.Tasks;
using ChainSafe.Gaming.UnityPackage;
using Web3Unity.Scripts.Prefabs;

Expand All @@ -19,7 +20,9 @@ protected override void Awake()

protected override async Task ExecuteSample()
{
var owner = await logic.OwnerOf(contractAddress, tokenId);
// check if tokenId is int or hex string
var owner = tokenId.StartsWith("0x") ?
await logic.OwnerOf(contractAddress, tokenId) : await logic.OwnerOf(contractAddress, BigInteger.Parse(tokenId));
SampleOutputUtil.PrintResult(owner, nameof(Erc721Sample), nameof(Erc721Sample.OwnerOf));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class LoadScene : MonoBehaviour
{
public void Load()
{
SceneManager.LoadScene(Login.LoginSceneIndex);
SceneManager.LoadScene("SampleImportNftTexture");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Numerics;
using System.Threading.Tasks;
using ChainSafe.Gaming.UnityPackage;
using Web3Unity.Scripts.Prefabs;

Expand All @@ -20,7 +21,8 @@ protected override void Awake()

protected override async Task ExecuteSample()
{
var balance = await logic.BalanceOf(contractAddress, account, tokenId);
var balance = tokenId.StartsWith("0x") ?
await logic.BalanceOf(contractAddress, account, tokenId) : await logic.BalanceOf(contractAddress, account, BigInteger.Parse(tokenId));
SampleOutputUtil.PrintResult(balance.ToString(), nameof(Erc1155Sample), nameof(Erc1155Sample.BalanceOf));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Samples.Behaviours.Erc721
public class Erc721OwnerOfBatchBehaviour : SampleBehaviour
{
public string contractAddress = "0x47381c5c948254e6e0E324F1AA54b7B24104D92D";
public List<string> tokenIds = new() { "33", "29" };
public string[] tokenIds = { "33", "29" };

[Header("Optional")]
// optional: multicall contract https://github.com/makerdao/multicall
Expand All @@ -25,7 +25,7 @@ protected override void Awake()

protected override async Task ExecuteSample()
{
var owners = await logic.OwnerOfBatch(contractAddress, tokenIds.ToArray(), multicall);
var owners = await logic.OwnerOfBatch(contractAddress, tokenIds, multicall);
var ownersString = $"{owners.Count} owner(s):\n" + string.Join(",\n", owners);
SampleOutputUtil.PrintResult(ownersString, nameof(Erc721Sample), nameof(Erc721Sample.OwnerOfBatch));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Numerics;
using System.Threading.Tasks;
using ChainSafe.Gaming.UnityPackage;
using Web3Unity.Scripts.Prefabs;

Expand All @@ -19,7 +20,9 @@ protected override void Awake()

protected override async Task ExecuteSample()
{
var owner = await logic.OwnerOf(contractAddress, tokenId);
// check if tokenId is int or hex string
var owner = tokenId.StartsWith("0x") ?
await logic.OwnerOf(contractAddress, tokenId) : await logic.OwnerOf(contractAddress, BigInteger.Parse(tokenId));
SampleOutputUtil.PrintResult(owner, nameof(Erc721Sample), nameof(Erc721Sample.OwnerOf));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class LoadScene : MonoBehaviour
{
public void Load()
{
SceneManager.LoadScene(Login.LoginSceneIndex);
SceneManager.LoadScene("SampleImportNftTexture");
}
}
}