Example #1
0
        public IEnumerator Send(string toAddress, NanoAmount amount, string privateKey, string work, Action <bool, string> callback)
        {
            // First we get the frontier
            NanoAmount currentBalance = null;
            string     previous       = null;
            string     rep            = defaultRep;
            string     fromAddress    = NanoUtils.PrivateKeyToAddress(privateKey);

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

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

                if (!String.IsNullOrEmpty(work))
                {
                    // Create the block to send
                    var newBalance = currentBalance - amount;
                    var block      = CreateBlock(fromAddress, NanoUtils.HexStringToByteArray(privateKey), newBalance, NanoUtils.AddressToPublicKeyHexString(toAddress), previous, rep, work);
                    yield return(Process(block, BlockType.send, (hash) =>
                    {
                        if (hash != null)
                        {
                            callback(false, hash);
                        }
                        else
                        {
                            callback(true, "");
                        }
                        Debug.Log(hash);
                    }));
                }
                else
                {
                    callback(true, "");
                    Debug.Log("Invalid work");
                }
            }
            else
            {
                callback(true, "");
                Debug.Log("No account exists to send from");
            }
        }
Example #2
0
 public override bool Equals(Object obj)
 {
     if ((obj == null) || !this.GetType().Equals(obj.GetType()))
     {
         return(false);
     }
     else
     {
         NanoAmount p = (NanoAmount)obj;
         return(rawValue.Equals(p.rawValue));
     }
 }
Example #3
0
        public void ListenForPaymentWaitConfirmation(string address, NanoAmount amount, bool exactAmount, Action <bool> callback)
        {
            if (listeningPayment.callback != null)
            {
                Unwatch(listeningPayment.address, listeningPayment.watcherId);
            }

            listeningPayment.address     = address;
            listeningPayment.amount      = amount;
            listeningPayment.callback    = callback;
            listeningPayment.watcherId   = Watch(address, (watcherInfo) => { });
            listeningPayment.exactAmount = exactAmount;
        }
Example #4
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, "");
            }
        }
Example #5
0
        private Dictionary <string, KeyCallback> keyListeners             = new Dictionary <string, KeyCallback>(); // For automatic pocketing

        public IEnumerator SendWaitConf(string toAddress, NanoAmount amount, string privateKey, Action <bool, string> callback)
        {
            yield return(Send(toAddress, amount, privateKey, (error, hash) =>
            {
                if (error)
                {
                    callback(error, hash);
                }
                else
                {
                    // Register and save callback
                    blockListener[hash] = callback;
                }
            }));
        }
Example #6
0
        public Block CreateBlock(string address, byte[] privateKey, NanoAmount balance, string link, string previous, string rep, string work)
        {
            Block block = new Block();

            block.account        = address;
            block.balance        = balance.ToString();
            block.link           = link;
            block.previous       = previous == null ? "0000000000000000000000000000000000000000000000000000000000000000" : previous;
            block.representative = rep;
            // Sign the block
            var hash      = NanoUtils.HashStateBlock(address, block.previous, balance.ToString(), rep, link);
            var signature = NanoUtils.SignHash(hash, privateKey);

            block.signature = signature;
            block.work      = work;
            return(block);
        }
Example #7
0
 public IEnumerator Send(string toAddress, NanoAmount amount, string privateKey, Action <bool, string> callback)
 {
     yield return(Send(toAddress, amount, privateKey, null, callback));
 }
Example #8
0
 public WatcherInfo(NanoAmount amount, ConfType confType, string hash)
 {
     this.amount   = amount;
     this.confType = confType;
     this.hash     = hash;
 }