cardano-community / cardanosharp-koios

6 stars 6 forks source link

updated package to include support for netstandard2.0 #23

Closed nothingalike closed 1 year ago

nothingalike commented 1 year ago

Description

We only support newer versions of .NET. This update will allow us to support other versions of .NET.

Motivation and context

User tried to use package but was met with an error of incapability.

Which issue it fixes?

.net version mismatch

LowKeyNerd commented 1 year ago

thanks :)

LowKeyNerd commented 1 year ago

also, did you mean to add a 2.0 instead of two 2.1s?

nothingalike commented 1 year ago

also, did you mean to add a 2.0 instead of two 2.1s?

yeah, corrected. what version of c# can you support up to? at least 8.0?

LowKeyNerd commented 1 year ago

The Unity game engine supports up to C#8. I have an awful, hacky workaround to get it accepted into my project --- download the v9 nuget package, rename it to a .zip, edit the nuspec file to point to 2.0, save, rename it back to a .nupkg. Package is brought into the game successfully, albeit, I'm pretty sure it's broken because of the class errors (it doesn't recognize IAddressClient or RestService). I am a noob when it comes to networking, so forgive my obvious ignorance.

LowKeyNerd commented 1 year ago

A workaround I use on the Ergo eUTXO blockchain is to query a dynamically generated URL, e.g.: https://ergo-explorer.anetabtc.io/api/v1/addresses/9i4eGCsGoP6VkCSArndqGXzDZCWHUX5NDPXxdymxE1F7eTMxLeh/balance/confirmed --- is there a way to conduct a "Get Address Assets" query via something like the URL above?

LowKeyNerd commented 1 year ago

I've been working from this: https://api.koios.rest/#post-/address_info, attempting to call the API via a Http query. I've tried several iterations with no luck because I don't entirely know what I'm doing :). If you have any advice or could send me an example in C# of a query via Http, I'd appreciate it!

    using (var client = new HttpClient())
    {
        var contentType = new MediaTypeWithQualityHeaderValue("application/json");
        var baseAddress = "https://api.koios.rest/api/v0/";
        var api = "/address_info";
        client.BaseAddress = new Uri(baseAddress);
        client.DefaultRequestHeaders.Accept.Add(contentType);

        var data = new Dictionary<string, string>
    {
        {"{_addresses}","addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g"},
    };

        var jsonData = JsonConvert.SerializeObject(data);
        var contentData = new StringContent(jsonData, Encoding.UTF8, "application/json");

        var response = await client.PostAsync(api, contentData);

        if (response.IsSuccessStatusCode)
        {
            var stringData = await response.Content.ReadAsStringAsync();
            var result = JsonConvert.DeserializeObject<object>(stringData);
            Debug.Log(result);
        }

        Debug.Log(response);
    }
safestak-keith commented 1 year ago

I've been working from this: https://api.koios.rest/#post-/address_info, attempting to call the API via a Http query. I've tried several iterations with no luck because I don't entirely know what I'm doing :). If you have any advice or could send me an example in C# of a query via Http, I'd appreciate it!

At first glance it looks like the request body is not in the right format - i.e. object with field _addresses and array of strings as its value. Does your jsonData look like the example below?

{
  "_addresses": [
    "addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g",
    "addr1qyfldpcvte8nkfpyv0jdc8e026cz5qedx7tajvupdu2724tlj8sypsq6p90hl40ya97xamkm9fwsppus2ru8zf6j8g9sm578cu"
  ]
}
LowKeyNerd commented 1 year ago

I've been working from this: https://api.koios.rest/#post-/address_info, attempting to call the API via a Http query. I've tried several iterations with no luck because I don't entirely know what I'm doing :). If you have any advice or could send me an example in C# of a query via Http, I'd appreciate it!

At first glance it looks like the request body is not in the right format - i.e. object with field _addresses and array of strings as its value. Does your jsonData look like the example below?

{
  "_addresses": [
    "addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g",
    "addr1qyfldpcvte8nkfpyv0jdc8e026cz5qedx7tajvupdu2724tlj8sypsq6p90hl40ya97xamkm9fwsppus2ru8zf6j8g9sm578cu"
  ]
}

I'll check it out later today and see! That said, if 2.0 is supported, then I'll probably be fine either way. When do yall plan to roll out an updated nuget package?

LowKeyNerd commented 1 year ago

I've been working from this: https://api.koios.rest/#post-/address_info, attempting to call the API via a Http query. I've tried several iterations with no luck because I don't entirely know what I'm doing :). If you have any advice or could send me an example in C# of a query via Http, I'd appreciate it!

At first glance it looks like the request body is not in the right format - i.e. object with field _addresses and array of strings as its value. Does your jsonData look like the example below?

{
  "_addresses": [
    "addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g",
    "addr1qyfldpcvte8nkfpyv0jdc8e026cz5qedx7tajvupdu2724tlj8sypsq6p90hl40ya97xamkm9fwsppus2ru8zf6j8g9sm578cu"
  ]
}

I got it working!!!

    var client = new HttpClient();

    var payload = new Address
    {
        _addresses = new string[] { "addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g" }
    };

    var jsonData = JsonConvert.SerializeObject(payload);
    var contentData = new StringContent(jsonData, Encoding.UTF8, "application/json");

    //var content = new FormUrlEncodedContent(values);

    var response = await client.PostAsync("https://api.koios.rest/api/v0/address_info", contentData);
    //var response = await client.GetAsync("https://api.koios.rest/api/v0/blocks");

    var responseString = await response.Content.ReadAsStringAsync();

    Debug.Log(responseString);
nothingalike commented 1 year ago

closing this PR. if we need this support in the future we can revisit.