Unity与Cryptocurrency IOTA API的集成

时间:2018-11-25 19:52:02

标签: c# android visual-studio api unity3d

我正在致力于将IOTA集成到Unity游戏引擎中,任何具有c#编程经验以及三元逻辑和IOTA经验的人都可以帮助我了解通过Unity发送交易所需的操作,我正在开发Android该应用程序可以从钱包中向用户提供IOTA付款(我通过游戏中的广告获得付款),我从felandil的c#库中配置了一些代码,但我不断收到类似以下错误:IotaApiException:Command getTransactionsToApprove失败了!

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Threading;
using RestSharp;
using Tangle.Net.Entity;
using Tangle.Net.ProofOfWork;
using Tangle.Net.Repository;
using Tangle.Net.Repository.Client;
using Tangle.Net.Repository.Factory;
using Tangle.Net.Utils;
using Tangle.Net.Cryptography;

public class ConnectIOTA : MonoBehaviour {

    string accountSeed = "*********Imagine*this*is*my*seed************";
    string nodeUri = "https://potato.iotasalad.org:14265";   
    string sendAddress = "JPKYBFBTSNZNYEJMFIKBKGCAWM9KSOOEDB9PQ9TOESEKNZHPWPGJJZEEBFDWTHMHZXNEPAODZRWQ9KNDCQFMMHMTH9";
    string message = "Sent via unity";
    int sendAmount = 100;
    public Button submit;

    void Start () {
        Button btn = submit.GetComponent<Button>();
        btn.onClick.AddListener(TaskOnClick);
    }


    void Update () {

    }

    public void TaskOnClick()
    {

        //if (int.Parse(sendAmount.text) > 0)
        //{
        //    SendMessageWITOA(accountSeed, nodeUri, sendAddress, sendAmount, message);

        //}
        //else
        //{

            SendMessage(nodeUri, sendAddress, message);
        //}


    }

    void SendMessage(string nodeUri, string sendAddress, string message)
    {

        RestIotaClient iotaClient = new RestIotaClient(new RestClient(nodeUri));
        PoWService powService = new PoWService(new CpuPearlDiver()); // the examples will use the CPU to do PoW for a transaction.
        RestIotaRepository repository = new RestIotaRepository(iotaClient, powService);

        Bundle bundle = new Bundle();
        bundle.AddTransfer(new Transfer
        {
            Address = new Address(sendAddress),
            Message = TryteString.FromUtf8String(message),
            Tag = Tag.Empty,
            Timestamp = Timestamp.UnixSecondsTimestamp
        });

        bundle.Finalize();
        bundle.Sign();

        repository.SendTrytes(bundle.Transactions, 27, 14);

    }

0 个答案:

没有答案