11using System . Threading . Tasks ;
2- using UnityEngine ;
32
43namespace Thirdweb
54{
6-
75 /// <summary>
86 /// Convenient wrapper to interact with any EVM contract
97 /// </summary>
@@ -22,37 +20,21 @@ public async Task<T> Read<T>(string functionName, params object[] args)
2220 {
2321 string [ ] argsEncoded = new string [ args . Length + 1 ] ;
2422 argsEncoded [ 0 ] = functionName ;
25- toJsonStringArray ( args ) . CopyTo ( argsEncoded , 1 ) ;
23+ Utils . ToJsonStringArray ( args ) . CopyTo ( argsEncoded , 1 ) ;
2624 return await Bridge . InvokeRoute < T > ( getRoute ( "call" ) , argsEncoded ) ;
2725 }
2826
2927 public async Task < TransactionResult > Write ( string functionName , params object [ ] args )
3028 {
3129 string [ ] argsEncoded = new string [ args . Length + 1 ] ;
3230 argsEncoded [ 0 ] = functionName ;
33- toJsonStringArray ( args ) . CopyTo ( argsEncoded , 1 ) ;
31+ Utils . ToJsonStringArray ( args ) . CopyTo ( argsEncoded , 1 ) ;
3432 return await Bridge . InvokeRoute < TransactionResult > ( getRoute ( "call" ) , argsEncoded ) ;
3533 }
3634
3735 private string getRoute ( string functionPath ) {
3836 return this . address + "." + functionPath ;
3937 }
4038
41- private string [ ] toJsonStringArray ( params object [ ] args ) {
42- string [ ] stringArgs = new string [ args . Length ] ;
43- for ( int i = 0 ; i < args . Length ; i ++ )
44- {
45- // if value type, convert to string otherwise serialize to json
46- if ( args [ i ] . GetType ( ) . IsPrimitive || args [ i ] is string )
47- {
48- stringArgs [ i ] = args [ i ] . ToString ( ) ;
49- }
50- else
51- {
52- stringArgs [ i ] = JsonUtility . ToJson ( args [ i ] ) ;
53- }
54- }
55- return stringArgs ;
56- }
5739 }
5840}
0 commit comments