Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Expload Game Integration Sample
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ExploadCards;
using Flurl;
using Flurl.Http;
using Flurl.Http.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
public class ExploadApp
{
private static readonly string dappUrl = "http://127.0.0.1:8087/api";
private static NewtonsoftJsonSerializer camelCaseSerializer = new NewtonsoftJsonSerializer(
new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy()
},
Formatting = Formatting.None
}
);
public static async Task<string> GetAddress()
{
try
{
var addressResp = await dappUrl
.AppendPathSegment("address")
.WithTimeout(10)
.ConfigureRequest(c => c.JsonSerializer = camelCaseSerializer)
.GetJsonAsync<PravdaResponce<string>>();
return addressResp.Data;
}
catch (Exception ex)
{
throw new NetworkingException(NetworkingExceptionReason.ExploadApp, ex);
}
}
public static async Task<string> GetNickname(string address)
{
try
{
var nicknameResp = await dappUrl
.AppendPathSegment("username")
.WithTimeout(10)
.SetQueryParam("address", address)
.ConfigureRequest(c => c.JsonSerializer = camelCaseSerializer)
.GetJsonAsync<PravdaResponce<string>>();
return nicknameResp.Data;
}
catch (Exception ex)
{
throw new NetworkingException(NetworkingExceptionReason.ExploadApp, ex);
}
}
public static async Task<string> Authenticate()
{
try
{
var message = Encoding.UTF8.GetBytes("DEPS").ToHex();
var signed = await dappUrl
.AppendPathSegment("auth")
.WithTimeout(10)
.ConfigureRequest(c => c.JsonSerializer = camelCaseSerializer)
.PostJsonAsync(new { App = "DEPS", Bytes = message })
.ReceiveJson<PravdaResponce<SignResponce>>();
return signed.Data.SignedData;
}
catch (Exception ex)
{
throw new NetworkingException(NetworkingExceptionReason.ExploadApp, ex);
}
}
public static async Task<PravdaResponce<PravdaTransactionResult>> CallMethod(string address, string method, params object[] args)
{
var call = new PravdaMethodCall()
{
Address = address,
Method = method,
Args = new List<object>(args)
};
try
{
var result = await dappUrl
.AppendPathSegment("program")
.AppendPathSegment("method")
.WithTimeout(60)
.ConfigureRequest(c => c.JsonSerializer = camelCaseSerializer)
.PostJsonAsync(call)
.ReceiveJson<PravdaResponce<PravdaTransactionResult>>();
return result;
}
catch (Exception ex)
{
throw new NetworkingException(NetworkingExceptionReason.ExploadApp, ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.