Skip to content

Commit 9ee7181

Browse files
committed
save
1 parent 2a8163e commit 9ee7181

File tree

9 files changed

+898
-9
lines changed

9 files changed

+898
-9
lines changed

Web3/Assets/EasyWeb3/Scripts/Contracts/ERC721.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
using System.Numerics;
33
using System.Threading.Tasks;
44
using System.Collections.Generic;
5+
using Newtonsoft.Json;
56

67
namespace EasyWeb3 {
8+
public class NFTData {
9+
public string image;
10+
}
711
public class NFT {
8-
public string Url {get; private set;}
9-
public NFT(string _url) {
10-
Url = _url;
12+
public string Uri {get; private set;}
13+
public NFTData Data {get; private set;}
14+
public NFT(string _uri, NFTData _data) {
15+
Uri = _uri;
16+
Data = _data;
1117
}
1218
}
1319
public class ERC721 : Contract {
@@ -60,20 +66,27 @@ public async Task<BigInteger> GetTokenOfOwnerByIndex(string _owner, int _index)
6066

6167
public async Task<string> GetToken(int _tokenId) {
6268
var _out = await CallFunction("tokenURI(uint256)", new string[]{"string"}, new string[]{_tokenId.ToString()});
63-
UnityEngine.Debug.Log(_out.Count);
6469
return (string)_out[0];
6570
}
6671

6772
public async Task<List<NFT>> GetOwnerNFTs(string _owner) {
6873
List<NFT> _nfts = new List<NFT>();
6974
BigInteger _bal = await GetBalanceOf(_owner);
70-
UnityEngine.Debug.Log("Owner Balance: "+_bal);
7175
for (int i = 0; i < _bal; i++) {
7276
BigInteger _token = await GetTokenOfOwnerByIndex(_owner, i);
73-
UnityEngine.Debug.Log("Found token: "+_token);
74-
string _nftStr = await GetToken((int)_token);
75-
UnityEngine.Debug.Log("NFT JSON: "+_nftStr);
76-
_nfts.Add(new NFT(_nftStr));
77+
string _uri = await GetToken((int)_token);
78+
UnityEngine.Debug.Log("NFT uri: "+_uri);
79+
string _requrl = _uri.Contains("ipfs://") ? _uri.Replace("ipfs://","https://ipfs.io/ipfs/") : _uri;
80+
UnityEngine.Debug.Log("NFT request url: "+_requrl);
81+
string _json = await RestService.GetService().Get(_requrl);
82+
if (_json.Contains("Error")) {
83+
UnityEngine.Debug.Log(_json);
84+
continue;
85+
}
86+
UnityEngine.Debug.Log("NFT json: "+_json);
87+
NFTData _data = JsonConvert.DeserializeObject<NFTData>(_json);
88+
UnityEngine.Debug.Log("NFT image: "+_data.image);
89+
_nfts.Add(new NFT(_uri, _data));
7790
}
7891
return _nfts;
7992
}

Web3/Assets/EasyWeb3/Scripts/Rest.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Net;
3+
using System.Net.Http;
4+
using System.Net.Security;
5+
using System.Security.Cryptography.X509Certificates;
6+
using System.Threading.Tasks;
7+
8+
namespace EasyWeb3 {
9+
public class RestService
10+
{
11+
private static RestService m_Service;
12+
private static HttpClient m_Http;
13+
14+
public static RestService GetService() {
15+
if (m_Service == null) {
16+
m_Service = new RestService();
17+
m_Http = new HttpClient();
18+
ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
19+
}
20+
21+
return m_Service;
22+
}
23+
24+
public async Task<string> Post(string _url, string _body) {
25+
try {
26+
var _content = new StringContent(_body, System.Text.Encoding.UTF8, "application/json");
27+
HttpResponseMessage _response = await m_Http.PostAsync(_url, _content);
28+
_response.EnsureSuccessStatusCode();
29+
string _responseBody = await _response.Content.ReadAsStringAsync();
30+
return _responseBody;
31+
} catch (HttpRequestException _err) {
32+
return "Error: "+_err;
33+
}
34+
}
35+
36+
public async Task<string> Get(string _url) {
37+
try {
38+
HttpResponseMessage _response = await m_Http.GetAsync(_url);
39+
_response.EnsureSuccessStatusCode();
40+
string _responseBody = await _response.Content.ReadAsStringAsync();
41+
return _responseBody;
42+
} catch (HttpRequestException _err) {
43+
return "Error: "+_err;
44+
}
45+
}
46+
47+
private static bool MyRemoteCertificateValidationCallback(System.Object sender,
48+
X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
49+
{
50+
bool isOk = true;
51+
// If there are errors in the certificate chain,
52+
// look at each error to determine the cause.
53+
if (sslPolicyErrors != SslPolicyErrors.None) {
54+
for (int i=0; i<chain.ChainStatus.Length; i++) {
55+
if (chain.ChainStatus[i].Status == X509ChainStatusFlags.RevocationStatusUnknown) {
56+
continue;
57+
}
58+
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
59+
chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
60+
chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan (0, 1, 0);
61+
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
62+
bool chainIsValid = chain.Build ((X509Certificate2)certificate);
63+
if (!chainIsValid) {
64+
isOk = false;
65+
break;
66+
}
67+
}
68+
}
69+
return isOk;
70+
}
71+
}
72+
}

Web3/Assets/EasyWeb3/Scripts/Rest/RestService.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Web3/Logs/AssetImportWorker0.log

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
Using pre-set license
2+
Built from '2021.3/staging' branch; Version is '2021.3.0f1 (6eacc8284459) revision 7253192'; Using compiler version '192829333'; Build Type 'Release'
3+
OS: 'Windows 10 (10.0.19044) 64bit Core' Language: 'en' Physical Memory: 15734 MB
4+
BatchMode: 1, IsHumanControllingUs: 0, StartBugReporterOnCrash: 0, Is64bit: 1, IsPro: 1
5+
6+
COMMAND LINE ARGUMENTS:
7+
C:\Program Files\Unity\Hub\Editor\2021.3.0f1\Editor\Unity.exe
8+
-adb2
9+
-batchMode
10+
-noUpm
11+
-name
12+
AssetImportWorker0
13+
-projectPath
14+
C:/Users/donea/Documents/github/easyweb3-unity/Web3
15+
-logFile
16+
Logs/AssetImportWorker0.log
17+
-srvPort
18+
55484
19+
Successfully changed project path to: C:/Users/donea/Documents/github/easyweb3-unity/Web3
20+
C:/Users/donea/Documents/github/easyweb3-unity/Web3
21+
[UnityMemory] Configuration Parameters - Can be set up in boot.config
22+
"memorysetup-bucket-allocator-granularity=16"
23+
"memorysetup-bucket-allocator-bucket-count=8"
24+
"memorysetup-bucket-allocator-block-size=33554432"
25+
"memorysetup-bucket-allocator-block-count=8"
26+
"memorysetup-main-allocator-block-size=16777216"
27+
"memorysetup-thread-allocator-block-size=16777216"
28+
"memorysetup-gfx-main-allocator-block-size=16777216"
29+
"memorysetup-gfx-thread-allocator-block-size=16777216"
30+
"memorysetup-cache-allocator-block-size=4194304"
31+
"memorysetup-typetree-allocator-block-size=2097152"
32+
"memorysetup-profiler-bucket-allocator-granularity=16"
33+
"memorysetup-profiler-bucket-allocator-bucket-count=8"
34+
"memorysetup-profiler-bucket-allocator-block-size=33554432"
35+
"memorysetup-profiler-bucket-allocator-block-count=8"
36+
"memorysetup-profiler-allocator-block-size=16777216"
37+
"memorysetup-profiler-editor-allocator-block-size=1048576"
38+
"memorysetup-temp-allocator-size-main=16777216"
39+
"memorysetup-job-temp-allocator-block-size=2097152"
40+
"memorysetup-job-temp-allocator-block-size-background=1048576"
41+
"memorysetup-job-temp-allocator-reduction-small-platforms=262144"
42+
"memorysetup-temp-allocator-size-background-worker=32768"
43+
"memorysetup-temp-allocator-size-job-worker=262144"
44+
"memorysetup-temp-allocator-size-preload-manager=33554432"
45+
"memorysetup-temp-allocator-size-nav-mesh-worker=65536"
46+
"memorysetup-temp-allocator-size-audio-worker=65536"
47+
"memorysetup-temp-allocator-size-cloud-worker=32768"
48+
"memorysetup-temp-allocator-size-gi-baking-worker=262144"
49+
"memorysetup-temp-allocator-size-gfx=262144"
50+
Refreshing native plugins compatible for Editor in 133.23 ms, found 3 plugins.
51+
Preloading 0 native plugins for Editor in 0.00 ms.
52+
Initialize engine version: 2021.3.0f1 (6eacc8284459)
53+
[Subsystems] Discovering subsystems at path C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/Resources/UnitySubsystems
54+
[Subsystems] Discovering subsystems at path C:/Users/donea/Documents/github/easyweb3-unity/Web3/Assets
55+
GfxDevice: creating device client; threaded=0; jobified=0
56+
Direct3D:
57+
Version: Direct3D 11.0 [level 11.1]
58+
Renderer: NVIDIA GeForce RTX 3050 Ti Laptop GPU (ID=0x2563)
59+
Vendor: NVIDIA
60+
VRAM: 3990 MB
61+
Driver: 30.0.15.1179
62+
Initialize mono
63+
Mono path[0] = 'C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/Managed'
64+
Mono path[1] = 'C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit-win32'
65+
Mono config path = 'C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/MonoBleedingEdge/etc'
66+
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,server=y,suspend=n,address=127.0.0.1:56472
67+
Begin MonoManager ReloadAssembly
68+
Registering precompiled unity dll's ...
69+
Register platform support module: C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/PlaybackEngines/WebGLSupport/UnityEditor.WebGL.Extensions.dll
70+
Register platform support module: C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/PlaybackEngines/WindowsStandaloneSupport/UnityEditor.WindowsStandalone.Extensions.dll
71+
Registered in 0.007228 seconds.
72+
Native extension for WindowsStandalone target not found
73+
Native extension for WebGL target not found
74+
Refreshing native plugins compatible for Editor in 115.18 ms, found 3 plugins.
75+
Preloading 0 native plugins for Editor in 0.00 ms.
76+
Mono: successfully reloaded assembly
77+
- Completed reload, in 0.930 seconds
78+
Domain Reload Profiling:
79+
ReloadAssembly (931ms)
80+
BeginReloadAssembly (120ms)
81+
ExecutionOrderSort (0ms)
82+
DisableScriptedObjects (0ms)
83+
BackupInstance (0ms)
84+
ReleaseScriptingObjects (0ms)
85+
CreateAndSetChildDomain (1ms)
86+
EndReloadAssembly (594ms)
87+
LoadAssemblies (117ms)
88+
RebuildTransferFunctionScriptingTraits (0ms)
89+
SetupTypeCache (240ms)
90+
ReleaseScriptCaches (0ms)
91+
RebuildScriptCaches (20ms)
92+
SetupLoadedEditorAssemblies (288ms)
93+
LogAssemblyErrors (0ms)
94+
InitializePlatformSupportModulesInManaged (8ms)
95+
SetLoadedEditorAssemblies (0ms)
96+
RefreshPlugins (115ms)
97+
BeforeProcessingInitializeOnLoad (1ms)
98+
ProcessInitializeOnLoadAttributes (114ms)
99+
ProcessInitializeOnLoadMethodAttributes (49ms)
100+
AfterProcessingInitializeOnLoad (0ms)
101+
EditorAssembliesLoaded (0ms)
102+
ExecutionOrderSort2 (0ms)
103+
AwakeInstancesAfterBackupRestoration (0ms)
104+
Platform modules already initialized, skipping
105+
Registering precompiled user dll's ...
106+
Registered in 0.021771 seconds.

Web3/Logs/AssetImportWorker1.log

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
Using pre-set license
2+
Built from '2021.3/staging' branch; Version is '2021.3.0f1 (6eacc8284459) revision 7253192'; Using compiler version '192829333'; Build Type 'Release'
3+
OS: 'Windows 10 (10.0.19044) 64bit Core' Language: 'en' Physical Memory: 15734 MB
4+
BatchMode: 1, IsHumanControllingUs: 0, StartBugReporterOnCrash: 0, Is64bit: 1, IsPro: 1
5+
6+
COMMAND LINE ARGUMENTS:
7+
C:\Program Files\Unity\Hub\Editor\2021.3.0f1\Editor\Unity.exe
8+
-adb2
9+
-batchMode
10+
-noUpm
11+
-name
12+
AssetImportWorker1
13+
-projectPath
14+
C:/Users/donea/Documents/github/easyweb3-unity/Web3
15+
-logFile
16+
Logs/AssetImportWorker1.log
17+
-srvPort
18+
55484
19+
Successfully changed project path to: C:/Users/donea/Documents/github/easyweb3-unity/Web3
20+
C:/Users/donea/Documents/github/easyweb3-unity/Web3
21+
[UnityMemory] Configuration Parameters - Can be set up in boot.config
22+
"memorysetup-bucket-allocator-granularity=16"
23+
"memorysetup-bucket-allocator-bucket-count=8"
24+
"memorysetup-bucket-allocator-block-size=33554432"
25+
"memorysetup-bucket-allocator-block-count=8"
26+
"memorysetup-main-allocator-block-size=16777216"
27+
"memorysetup-thread-allocator-block-size=16777216"
28+
"memorysetup-gfx-main-allocator-block-size=16777216"
29+
"memorysetup-gfx-thread-allocator-block-size=16777216"
30+
"memorysetup-cache-allocator-block-size=4194304"
31+
"memorysetup-typetree-allocator-block-size=2097152"
32+
"memorysetup-profiler-bucket-allocator-granularity=16"
33+
"memorysetup-profiler-bucket-allocator-bucket-count=8"
34+
"memorysetup-profiler-bucket-allocator-block-size=33554432"
35+
"memorysetup-profiler-bucket-allocator-block-count=8"
36+
"memorysetup-profiler-allocator-block-size=16777216"
37+
"memorysetup-profiler-editor-allocator-block-size=1048576"
38+
"memorysetup-temp-allocator-size-main=16777216"
39+
"memorysetup-job-temp-allocator-block-size=2097152"
40+
"memorysetup-job-temp-allocator-block-size-background=1048576"
41+
"memorysetup-job-temp-allocator-reduction-small-platforms=262144"
42+
"memorysetup-temp-allocator-size-background-worker=32768"
43+
"memorysetup-temp-allocator-size-job-worker=262144"
44+
"memorysetup-temp-allocator-size-preload-manager=33554432"
45+
"memorysetup-temp-allocator-size-nav-mesh-worker=65536"
46+
"memorysetup-temp-allocator-size-audio-worker=65536"
47+
"memorysetup-temp-allocator-size-cloud-worker=32768"
48+
"memorysetup-temp-allocator-size-gi-baking-worker=262144"
49+
"memorysetup-temp-allocator-size-gfx=262144"
50+
Refreshing native plugins compatible for Editor in 133.24 ms, found 3 plugins.
51+
Preloading 0 native plugins for Editor in 0.00 ms.
52+
Initialize engine version: 2021.3.0f1 (6eacc8284459)
53+
[Subsystems] Discovering subsystems at path C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/Resources/UnitySubsystems
54+
[Subsystems] Discovering subsystems at path C:/Users/donea/Documents/github/easyweb3-unity/Web3/Assets
55+
GfxDevice: creating device client; threaded=0; jobified=0
56+
Direct3D:
57+
Version: Direct3D 11.0 [level 11.1]
58+
Renderer: NVIDIA GeForce RTX 3050 Ti Laptop GPU (ID=0x2563)
59+
Vendor: NVIDIA
60+
VRAM: 3990 MB
61+
Driver: 30.0.15.1179
62+
Initialize mono
63+
Mono path[0] = 'C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/Managed'
64+
Mono path[1] = 'C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit-win32'
65+
Mono config path = 'C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/MonoBleedingEdge/etc'
66+
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,server=y,suspend=n,address=127.0.0.1:56964
67+
Begin MonoManager ReloadAssembly
68+
Registering precompiled unity dll's ...
69+
Register platform support module: C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/PlaybackEngines/WebGLSupport/UnityEditor.WebGL.Extensions.dll
70+
Register platform support module: C:/Program Files/Unity/Hub/Editor/2021.3.0f1/Editor/Data/PlaybackEngines/WindowsStandaloneSupport/UnityEditor.WindowsStandalone.Extensions.dll
71+
Registered in 0.006972 seconds.
72+
Native extension for WindowsStandalone target not found
73+
Native extension for WebGL target not found
74+
Refreshing native plugins compatible for Editor in 115.23 ms, found 3 plugins.
75+
Preloading 0 native plugins for Editor in 0.00 ms.
76+
Mono: successfully reloaded assembly
77+
- Completed reload, in 0.930 seconds
78+
Domain Reload Profiling:
79+
ReloadAssembly (931ms)
80+
BeginReloadAssembly (119ms)
81+
ExecutionOrderSort (0ms)
82+
DisableScriptedObjects (0ms)
83+
BackupInstance (0ms)
84+
ReleaseScriptingObjects (0ms)
85+
CreateAndSetChildDomain (1ms)
86+
EndReloadAssembly (594ms)
87+
LoadAssemblies (117ms)
88+
RebuildTransferFunctionScriptingTraits (0ms)
89+
SetupTypeCache (240ms)
90+
ReleaseScriptCaches (0ms)
91+
RebuildScriptCaches (21ms)
92+
SetupLoadedEditorAssemblies (288ms)
93+
LogAssemblyErrors (0ms)
94+
InitializePlatformSupportModulesInManaged (8ms)
95+
SetLoadedEditorAssemblies (0ms)
96+
RefreshPlugins (115ms)
97+
BeforeProcessingInitializeOnLoad (1ms)
98+
ProcessInitializeOnLoadAttributes (114ms)
99+
ProcessInitializeOnLoadMethodAttributes (49ms)
100+
AfterProcessingInitializeOnLoad (0ms)
101+
EditorAssembliesLoaded (0ms)
102+
ExecutionOrderSort2 (0ms)
103+
AwakeInstancesAfterBackupRestoration (0ms)
104+
Platform modules already initialized, skipping
105+
Registering precompiled user dll's ...
106+
Registered in 0.021595 seconds.

0 commit comments

Comments
 (0)