示例#1
0
        public IEnumerator Receive(string address, PendingBlock pendingBlock, string privateKey, string work, Action <bool, string> callback)
        {
            // First we get the frontier
            NanoAmount currentBalance = null;
            string     previous       = null;
            var        rep            = defaultRep;

            yield return(AccountInfo(address, (accountInfo) =>
            {
                currentBalance = new NanoAmount(accountInfo.balance);
                previous = accountInfo.frontier;
                if (previous != null)
                {
                    rep = accountInfo.representative;
                }
            }));

            if (String.IsNullOrEmpty(work))
            {
                // Generate the work
                yield return(WorkGenerate(address, previous, (workResponse) =>
                {
                    work = workResponse;
                }));
            }

            if (!String.IsNullOrEmpty(work))
            {
                // Create the block to receive
                var newBalance = currentBalance + pendingBlock.amount;
                var block      = CreateBlock(address, NanoUtils.HexStringToByteArray(privateKey), newBalance, pendingBlock.source, previous, rep, work);
                yield return(Process(block, previous == null ? BlockType.open : BlockType.receive, (hash) =>
                {
                    if (hash != null)
                    {
                        callback(false, hash);
                    }
                    else
                    {
                        callback(true, "");
                    }
                    Debug.Log(hash);
                }));
            }
            else
            {
                callback(true, "");
            }
        }
示例#2
0
 public IEnumerator ReceiveWaitConf(string address, PendingBlock pendingBlock, string privateKey, Action <bool, string> callback)
 {
     yield return(Receive(address, pendingBlock, privateKey, (error, hash) =>
     {
         if (error)
         {
             callback(error, hash);
         }
         else
         {
             // Register and save callback
             blockListener[hash] = callback;
         }
     }));
 }
示例#3
0
        public IEnumerator PendingBlocks(string address, Action <List <PendingBlock> > callback)
        {
            List <PendingBlock> pendingBlocks = new List <PendingBlock>();

            yield return(rpc.PendingBlocks(address, (responsePending) =>
            {
                if (responsePending != null)
                {
                    var json = JSON.Parse(responsePending);
                    foreach (System.Collections.Generic.KeyValuePair <string, JSONNode> kvp in json["blocks"])
                    {
                        PendingBlock pendingBlock = new PendingBlock();
                        pendingBlock.source = kvp.Key;
                        pendingBlock.amount = new NanoAmount((string)kvp.Value);
                        pendingBlocks.Add(pendingBlock);
                    }
                }
            }));

            callback(pendingBlocks);
        }
示例#4
0
 public IEnumerator Receive(string address, PendingBlock pendingBlock, string privateKey, Action <bool, string> callback)
 {
     yield return(Receive(address, pendingBlock, privateKey, String.Empty, callback));
 }