示例#1
0
 void OnClickWatch()
 {
     lastWatcherId = nanoManager.Watch(NanoUtils.PrivateKeyToAddress(watcherPrivateKey), (watcherInfo) =>
     {
         WatchedUI.text = watcherInfo.hash;
     });
 }
示例#2
0
    void PrivateKeyChanged()
    {
        // Update the public key text element
        address          = NanoUtils.PrivateKeyToAddress(privateKey);
        PublicKeyUI.text = address;

        // Update QRcode for topping up funds
        var qrCodeAsTexture2D = NanoUtils.GenerateQRCodeTextureOnlyAccount(10, address, 10);

        QRCodeTopUpUI.sprite = Sprite.Create(qrCodeAsTexture2D, new Rect(0.0f, 0.0f, qrCodeAsTexture2D.width, qrCodeAsTexture2D.height), new Vector2(0.5f, 0.5f));
    }
示例#3
0
 private IEnumerator SendHandler()
 {
     yield return(nanoManager.Send(NanoUtils.PrivateKeyToAddress(watcherPrivateKey), new NanoAmount("1000000000000000000000000"), privateKey, (error, hash) =>
     {
         if (!error)
         {
             Debug.Log("Send confirmed!!");
         }
         else
         {
             Debug.Log("Error with Send");
         }
     }));
 }
示例#4
0
    IEnumerator PaidArcadeHandler()
    {
        // Recieve this block

        List <PendingBlock> pendingBlocks = null;
        var arcadeAddress = NanoUtils.PrivateKeyToAddress(arcadePrivateKey);

        yield return(nanoManager.PendingBlocks(arcadeAddress, (responsePendingBlocks) =>
        {
            pendingBlocks = responsePendingBlocks;
        }));

        // Just get the first one as it will have the highest amount
        if (pendingBlocks != null && pendingBlocks.Count > 0)
        {
            // Returns the one with the highest amount
            var pendingBlock = pendingBlocks[0];
            yield return(nanoManager.ReceiveWaitConf(arcadeAddress, pendingBlock, arcadePrivateKey, (error, hash) =>
            {
                if (!error)
                {
                    var qrCodePayoutAsTexture2D = NanoUtils.GenerateQRCodeTextureWithPrivateKey(10, arcadePrivateKey, 10);
                    QRCodePayoutArcadeUI.sprite = Sprite.Create(qrCodePayoutAsTexture2D, new Rect(0.0f, 0.0f, qrCodePayoutAsTexture2D.width, qrCodePayoutAsTexture2D.height), new Vector2(0.5f, 0.5f));
                    QRCodePayArcadeUI.sprite = null;

                    // Start the payout listener
                    var expirySecs = 30;
                    nanoManager.ListenForPayoutWaitConfirmation(arcadeAddress, expirySecs, (errorPayout) =>
                    {
                        if (!errorPayout)
                        {
                            PayoutArcadeUI.text = "Extracted privateKey";
                        }
                        else
                        {
                            PayoutArcadeUI.text = "PrivateKey expired";
                            Debug.Log("Did not retrieve the payout fast enough");
                        }
                        QRCodePayoutArcadeUI.sprite = null;
                    });
                }
                else
                {
                    Debug.Log("Error with ReceiveWaitConf");
                }
            }));
        }
    }
示例#5
0
    IEnumerator SendWaitConfHandler()
    {
        var amount = new NanoAmount(NanoUtils.NanoToRaw("0.000001"));

        yield return(nanoManager.SendWaitConf(NanoUtils.PrivateKeyToAddress(watcherPrivateKey), amount, privateKey, (error, hash) =>
        {
            if (!error)
            {
                Debug.Log("Send wait confirmed!!");
            }
            else
            {
                Debug.Log("Error with SendWaitConf");
            }
        }));
    }
示例#6
0
    void Start()
    {
        // Initialize RPC & Websocket
        nanoManager            = gameObject.AddComponent <NanoManager>();
        nanoManager.rpcURL     = "http://95.216.164.23:28103"; // Update this url to point to your JSON-RPC server
        nanoManager.defaultRep = defaultRep;

        nanoWebsocket         = gameObject.AddComponent <NanoWebSocket>();
        nanoWebsocket.url     = "ws://95.216.164.23:28104"; // Update this url to point to your websocket server
        nanoManager.Websocket = nanoWebsocket;

        Debug.Log("Private key files located at: " + Path.Combine(Application.persistentDataPath, "Nano"));

        // Update QR codes for arcade
        arcadePrivateKey = NanoUtils.ByteArrayToHexString(NanoUtils.GeneratePrivateKey());

        nanoManager.AddOnWebsocketConnectListener((bool isError, bool isReconnect) =>
        {
            // Called when the connection is successfully opened (or failed), it will automatically keep trying to connect if there is a failure
            if (!isError)
            {
                nanoManager.ListenForPaymentWaitConfirmation(NanoUtils.PrivateKeyToAddress(arcadePrivateKey), new NanoAmount("1000000000000000000000000"), true, (error) =>
                {
                    if (!error)
                    {
                        PayArcadeUI.text = "Paid!";
                        // Wait until the account has a balance
                        StartCoroutine(PaidArcadeHandler());
                    }
                    else
                    {
                        Debug.Log("Error with payment");
                    }
                });

                Debug.Log("Successfully connected to websocket!!");
            }
            else
            {
                Debug.Log("Failed to connect to websocket!!");
            }
        });

        nanoManager.AddConfirmationListener((websocketConfirmationResponse) =>
        {
            Debug.Log("Confirmation received");
            string output = "";
            var block     = websocketConfirmationResponse.message.block;
            output       += "type: " + block.type + "\n";
            output       += "account: " + block.account + "\n";
            output       += "previous: " + block.previous + "\n";
            output       += "representative: " + block.representative + "\n";
            output       += "balance: " + block.balance + "\n";
            output       += "link: " + block.link + "\n";
            output       += "link_as_account: " + block.link_as_account + "\n";
            output       += "signature: " + block.signature + "\n";
            output       += "work: " + block.work + "\n";
            output       += "subtype: " + block.subtype;
            WebsockConfirmationResponseUI.text = output;
        });

        nanoManager.AddFilteredConfirmationListener((websocketConfirmationResponse) =>
        {
            Debug.Log("Confirmation received");
        });

        // Add event listeners for all the buttons
        CreatePrivateKeyUI.onClick.AddListener(OnClickCreatePrivateKey);
        NextPrivateKeyUI.onClick.AddListener(OnClickNextPrivateKey);
        GenerateWorkUI.onClick.AddListener(OnClickGenerateWork);
        SendNeedsWorkUI.onClick.AddListener(OnClickSendNeedsWork);
        ReceiveNeedsWorkUI.onClick.AddListener(OnClickReceiveNeedsWork);
        SendUI.onClick.AddListener(OnClickSend);
        ReceiveUI.onClick.AddListener(OnClickReceive);
        SendWaitConfUI.onClick.AddListener(OnClickSendWaitConf);
        ReceiveWaitConfUI.onClick.AddListener(OnClickReceiveWaitConf);
        AutomatePocketingUI.onClick.AddListener(OnClickAutomatePocketing);
        UnautomatePocketingUI.onClick.AddListener(OnClickUnautomatePocketing);
        ListenAllConfirmationsUI.onClick.AddListener(OnClickListenAllConfirmations);
        UnlistenAllConfirmationsUI.onClick.AddListener(OnClickUnlistenAllConfirmations);
        WatchUI.onClick.AddListener(OnClickWatch);
        UnwatchUI.onClick.AddListener(OnClickUnwatch);

        var numRawPayToPlay      = "1000000000000000000000000";
        var qrCodePayAsTexture2D = NanoUtils.GenerateQRCodeTextureWithAmount(10, NanoUtils.PrivateKeyToAddress(arcadePrivateKey), numRawPayToPlay, 10);

        QRCodePayArcadeUI.sprite = Sprite.Create(qrCodePayAsTexture2D, new Rect(0.0f, 0.0f, qrCodePayAsTexture2D.width, qrCodePayAsTexture2D.height), new Vector2(0.5f, 0.5f));

        watcherPrivateKey = NanoUtils.ByteArrayToHexString(NanoUtils.GeneratePrivateKey());

        OnClickNextPrivateKey();
    }
示例#7
0
 void OnClickUnwatch()
 {
     nanoManager.Unwatch(NanoUtils.PrivateKeyToAddress(watcherPrivateKey), lastWatcherId);
 }