Example #1
0
        private void onRequest(string recipient, string amount)
        {
            byte[] recipient_bytes = Base58Check.Base58CheckEncoding.DecodePlain(recipient);
            Friend friend          = FriendList.getFriend(recipient_bytes);

            if (friend != null && (new IxiNumber(amount)) > 0)
            {
                FriendMessage friend_message = FriendList.addMessageWithType(null, FriendMessageType.requestFunds, friend.walletAddress, amount, true);

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.requestFunds, Encoding.UTF8.GetBytes(amount));

                StreamMessage message = new StreamMessage();
                message.type        = StreamMessageCode.info;
                message.recipient   = Base58Check.Base58CheckEncoding.DecodePlain(recipient);
                message.sender      = Node.walletStorage.getPrimaryAddress();
                message.transaction = new byte[1];
                message.sigdata     = new byte[1];
                message.data        = spixi_message.getBytes();
                message.id          = friend_message.id;

                StreamProcessor.sendMessage(friend, message);

                Navigation.PopAsync(Config.defaultXamarinAnimations);
            }// else error?
        }
Example #2
0
        private static void handleRequestAdd(byte[] id, byte[] sender_wallet, byte[] pub_key)
        {
            if (!(new Address(pub_key)).address.SequenceEqual(sender_wallet))
            {
                Logging.error("Received invalid pubkey in handleRequestAdd for {0}", Base58Check.Base58CheckEncoding.EncodePlain(sender_wallet));
                return;
            }

            Friend new_friend = FriendList.addFriend(sender_wallet, pub_key, Base58Check.Base58CheckEncoding.EncodePlain(sender_wallet), null, null, 0, false);

            if (new_friend != null)
            {
                new_friend.handshakeStatus = 1;
                FriendList.addMessageWithType(id, FriendMessageType.requestAdd, sender_wallet, "");
                requestNickname(new_friend);
            }
            else
            {
                Friend friend = FriendList.getFriend(sender_wallet);
                friend.handshakeStatus = 1;
                if (friend.approved)
                {
                    sendAcceptAdd(friend);
                }
            }
        }
Example #3
0
 public void endCall(byte[] session_id, bool call_accepted, long call_duration, bool local_sender)
 {
     lock (messages)
     {
         var fm = messages.Find(x => x.id.SequenceEqual(session_id));
         if (call_accepted == true && messages.Last() != fm)
         {
             fm.message = call_duration.ToString();
             FriendList.addMessageWithType(null, FriendMessageType.voiceCallEnd, walletAddress, fm.message, local_sender, null, 0, false);
         }
         else
         {
             fm.type = FriendMessageType.voiceCallEnd;
             if (call_accepted)
             {
                 fm.message = call_duration.ToString();
             }
             Node.localStorage.writeMessages(walletAddress, messages);
             if (chat_page != null)
             {
                 chat_page.insertMessage(fm);
             }
         }
     }
 }
Example #4
0
        private static void handleRequestFunds(byte[] sender_wallet, string amount)
        {
            // Retrieve the corresponding contact
            Friend friend = FriendList.getFriend(sender_wallet);

            if (friend == null)
            {
                return;
            }

            FriendList.addMessageWithType(FriendMessageType.requestFunds, sender_wallet, amount);
        }
Example #5
0
        private static void handleSentFunds(byte[] id, byte[] sender_wallet, string txid)
        {
            // Retrieve the corresponding contact
            Friend friend = FriendList.getFriend(sender_wallet);

            if (friend == null)
            {
                return;
            }

            FriendList.addMessageWithType(id, FriendMessageType.sentFunds, sender_wallet, txid);
        }
Example #6
0
        private void sendPayment(string txfee)
        {
            Logging.info("Preparing to send payment");
            //Navigation.PopAsync(Config.defaultXamarinAnimations);

            // Create an ixian transaction and send it to the dlt network
            IxiNumber fee = ConsensusConfig.transactionPrice;

            byte[] from   = Node.walletStorage.getPrimaryAddress();
            byte[] pubKey = Node.walletStorage.getPrimaryPublicKey();
            Logging.info("Preparing tx");

            Transaction transaction = new Transaction((int)Transaction.Type.Normal, fee, to_list, from, null, pubKey, IxianHandler.getHighestKnownNetworkBlockHeight());

            Logging.info("Broadcasting tx");

            IxianHandler.addTransaction(transaction);
            Logging.info("Adding to cache");

            // Add the unconfirmed transaction to the cache
            TransactionCache.addUnconfirmedTransaction(transaction);
            Logging.info("Showing payment details");

            // Send message to recipients
            foreach (var entry in to_list)
            {
                Friend friend = FriendList.getFriend(entry.Key);

                if (friend != null)
                {
                    FriendMessage friend_message = FriendList.addMessageWithType(null, FriendMessageType.sentFunds, entry.Key, transaction.id, true);

                    SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.sentFunds, Encoding.UTF8.GetBytes(transaction.id));

                    StreamMessage message = new StreamMessage();
                    message.type        = StreamMessageCode.info;
                    message.recipient   = friend.walletAddress;
                    message.sender      = Node.walletStorage.getPrimaryAddress();
                    message.transaction = new byte[1];
                    message.sigdata     = new byte[1];
                    message.data        = spixi_message.getBytes();
                    message.id          = friend_message.id;

                    StreamProcessor.sendMessage(friend, message);
                }
            }

            // Show the payment details
            Navigation.PushAsync(new WalletSentPage(transaction, false), Config.defaultXamarinAnimations);
        }
Example #7
0
        // Called when receiving file headers from the message recipient
        public static void handleFileHeader(byte[] sender, SpixiMessage data)
        {
            Friend friend = FriendList.getFriend(sender);

            if (friend != null)
            {
                Logging.info("Received file header");
                FileTransfer transfer = new FileTransfer(data.data);
                FriendList.addMessageWithType(data.id, FriendMessageType.fileHeader, sender, transfer.name);
            }
            else
            {
                Logging.error("Received File Header for an unknown friend.");
            }
        }
Example #8
0
        // Called when receiving file headers from the message recipient
        public static void handleFileHeader(byte[] sender, SpixiMessage data)
        {
            Friend friend = FriendList.getFriend(sender);

            if (friend != null)
            {
                FileTransfer transfer     = TransferManager.prepareIncomingFileTransfer(data.data, sender);
                string       message_data = string.Format("{0}:{1}", transfer.uid, transfer.fileName);
                FriendList.addMessageWithType(data.id, FriendMessageType.fileHeader, sender, message_data);
            }
            else
            {
                Logging.error("Received File Header from an unknown friend.");
            }
        }
Example #9
0
        public void onApp(string app_id)
        {
            byte[][]      user_addresses  = new byte[][] { friend.walletAddress };
            CustomAppPage custom_app_page = new CustomAppPage(app_id, IxianHandler.getWalletStorage().getPrimaryAddress(), user_addresses, Node.customAppManager.getAppEntryPoint(app_id));

            custom_app_page.accepted = true;
            Node.customAppManager.addAppPage(custom_app_page);

            Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
            {
                Navigation.PushAsync(custom_app_page, Config.defaultXamarinAnimations);
            });

            FriendList.addMessageWithType(custom_app_page.sessionId, FriendMessageType.appSession, friend.walletAddress, app_id, true, null, 0, false);
            StreamProcessor.sendAppRequest(friend, app_id, custom_app_page.sessionId, null);
        }
Example #10
0
        private static void handleRequestAdd(byte[] sender_wallet)
        {
            byte[] pub_k = FriendList.findContactPubkey(sender_wallet);
            if (pub_k == null)
            {
                Console.WriteLine("Contact {0} not found in presence list!", Base58Check.Base58CheckEncoding.EncodePlain(sender_wallet));

                foreach (Presence pr in PresenceList.presences)
                {
                    Console.WriteLine("Presence: {0}", Base58Check.Base58CheckEncoding.EncodePlain(pr.wallet));
                }
                return;
            }

            FriendList.addFriend(sender_wallet, pub_k, "New Contact", false);
            FriendList.addMessageWithType(FriendMessageType.requestAdd, sender_wallet, "");
        }
Example #11
0
        public async System.Threading.Tasks.Task onSendFile()
        {
            try
            {
                FileData fileData = await CrossFilePicker.Current.PickFile();

                if (fileData == null)
                {
                    return; // User canceled file picking
                }
                string fileName = fileData.FileName;
                string filePath = fileData.FilePath;

                FileTransfer transfer = TransferManager.prepareFileTransfer(fileName, fileData.GetStream(), filePath);
                Logging.info("File Transfer uid: " + transfer.uid);

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.fileHeader, transfer.getBytes());

                StreamMessage message = new StreamMessage();
                message.type        = StreamMessageCode.data;
                message.recipient   = friend.walletAddress;
                message.sender      = Node.walletStorage.getPrimaryAddress();
                message.transaction = new byte[1];
                message.sigdata     = new byte[1];
                message.data        = spixi_message.getBytes();

                StreamProcessor.sendMessage(friend, message);


                string message_data = string.Format("{0}:{1}", transfer.uid, transfer.fileName);

                // store the message and display it
                FriendMessage friend_message = FriendList.addMessageWithType(message.id, FriendMessageType.fileHeader, friend.walletAddress, message_data, true);

                friend_message.transferId = transfer.uid;
                friend_message.filePath   = transfer.filePath;

                Node.localStorage.writeMessages(friend.walletAddress, friend.messages);
            }
            catch (Exception ex)
            {
                Logging.error("Exception choosing file: " + ex.ToString());
            }
        }
        private void onSend()
        {
            // Create an ixian transaction and send it to the dlt network
            byte[] to = friend.walletAddress;

            IxiNumber amounti = new IxiNumber(amount);
            IxiNumber fee     = CoreConfig.transactionPrice;

            byte[] from   = Node.walletStorage.getPrimaryAddress();
            byte[] pubKey = Node.walletStorage.getPrimaryPublicKey();

            Transaction transaction = new Transaction((int)Transaction.Type.Normal, amount, fee, to, from, null, pubKey, Node.getLastBlockHeight());

            NetworkClientManager.broadcastData(new char[] { 'M' }, ProtocolMessageCode.newTransaction, transaction.getBytes(), null);

            // Add the unconfirmed transaction the the cache
            TransactionCache.addUnconfirmedTransaction(transaction);
            FriendList.addMessageWithType(FriendMessageType.sentFunds, friend.walletAddress, transaction.id);
            Navigation.PopAsync(Config.defaultXamarinAnimations);
        }
Example #13
0
        private void sendPayment(string txfee)
        {
            Logging.info("Preparing to send payment");
            //Navigation.PopAsync(Config.defaultXamarinAnimations);

            Logging.info("Broadcasting tx");

            IxianHandler.addTransaction(transaction);
            Logging.info("Adding to cache");

            // Add the unconfirmed transaction to the cache
            TransactionCache.addUnconfirmedTransaction(transaction);
            Logging.info("Showing payment details");

            // Send message to recipients
            foreach (var entry in to_list)
            {
                Friend friend = FriendList.getFriend(entry.Key);

                if (friend != null)
                {
                    FriendMessage friend_message = FriendList.addMessageWithType(null, FriendMessageType.sentFunds, entry.Key, transaction.id, true);

                    SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.sentFunds, Encoding.UTF8.GetBytes(transaction.id));

                    StreamMessage message = new StreamMessage();
                    message.type        = StreamMessageCode.info;
                    message.recipient   = friend.walletAddress;
                    message.sender      = Node.walletStorage.getPrimaryAddress();
                    message.transaction = new byte[1];
                    message.sigdata     = new byte[1];
                    message.data        = spixi_message.getBytes();
                    message.id          = friend_message.id;

                    StreamProcessor.sendMessage(friend, message);
                }
            }

            // Show the payment details
            Navigation.PushAsync(new WalletSentPage(transaction, false), Config.defaultXamarinAnimations);
        }
Example #14
0
 public void endCall(byte[] session_id, bool call_accepted, long call_duration, bool local_sender)
 {
     if (session_id == null)
     {
         return;
     }
     lock (messages)
     {
         var tmp_messages = getMessages(0);
         if (tmp_messages == null)
         {
             return;
         }
         var fm = tmp_messages.Find(x => x.id.SequenceEqual(session_id));
         if (fm == null)
         {
             Logging.warn("Cannot end call, no message with session ID exists.");
             return;
         }
         if (call_accepted == true && tmp_messages.Last() != fm)
         {
             fm.message = call_duration.ToString();
             FriendList.addMessageWithType(null, FriendMessageType.voiceCallEnd, walletAddress, 0, fm.message, local_sender, null, 0, false);
         }
         else
         {
             fm.type = FriendMessageType.voiceCallEnd;
             if (call_accepted)
             {
                 fm.message = call_duration.ToString();
             }
             Node.localStorage.requestWriteMessages(walletAddress, 0);
             if (chat_page != null)
             {
                 chat_page.insertMessage(fm, 0);
             }
         }
     }
 }
Example #15
0
        public async void onSend(string str)
        {
            if (str.Length < 1)
            {
                return;
            }

            await Task.Run(async() =>
            {
                // TODOSPIXI

                /*            // Send the message to the S2 nodes
                 *          byte[] recipient_address = friend.wallet_address;
                 *          byte[] encrypted_message = StreamProcessor.prepareSpixiMessage(SpixiMessageCode.chat, str, friend.pubkey);
                 *          // CryptoManager.lib.encryptData(Encoding.UTF8.GetBytes(string_to_send), friend.pubkey);
                 *
                 *          // Check the relay ip
                 *          string relayip = friend.getRelayIP();
                 *          if (relayip == null)
                 *          {
                 *              Logging.warn("No relay node to send message to!");
                 *              return;
                 *          }
                 *          if (relayip.Equals(node_ip, StringComparison.Ordinal) == false)
                 *          {
                 *
                 *              node_ip = relayip;
                 *              // Connect to the contact's S2 relay first
                 *              NetworkClientManager.connectToStreamNode(relayip);
                 *
                 *              // TODO: optimize this
                 *              while (NetworkClientManager.isNodeConnected(relayip) == false)
                 *              {
                 *
                 *              }
                 *          }
                 *
                 *          Message message = new Message();
                 *          message.recipientAddress = recipient_address;
                 *          message.data = encrypted_message;
                 *
                 *          StreamProcessor.sendMessage(message, node_ip);*/

                // store the message and display it
                FriendMessage friend_message = FriendList.addMessageWithType(null, FriendMessageType.standard, friend.walletAddress, str, true);

                // Finally, clear the input field
                Utils.sendUiCommand(webView, "clearInput");

                // Send the message
                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.chat, Encoding.UTF8.GetBytes(str));

                StreamMessage message = new StreamMessage();
                message.type          = StreamMessageCode.data;
                message.recipient     = friend.walletAddress;
                message.sender        = Node.walletStorage.getPrimaryAddress();
                message.transaction   = new byte[1];
                message.sigdata       = new byte[1];
                message.data          = spixi_message.getBytes();
                message.id            = friend_message.id;

                if (friend.bot)
                {
                    message.encryptionType = StreamMessageEncryptionCode.none;
                    message.sign(IxianHandler.getWalletStorage().getPrimaryPrivateKey());
                }

                StreamProcessor.sendMessage(friend, message);
            });
        }
Example #16
0
        public async Task onSendFile()
        {
            // Show file picker and send the file
            try
            {
                Stream stream   = null;
                string fileName = null;
                string filePath = null;

                // Special case for iOS platform
                if (Device.RuntimePlatform == Device.iOS)
                {
                    var picker_service = DependencyService.Get <IPicturePicker>();

                    SpixiImageData spixi_img_data = await picker_service.PickImageAsync();

                    stream = spixi_img_data.stream;

                    if (stream == null)
                    {
                        return;
                    }

                    fileName = spixi_img_data.name;
                    filePath = spixi_img_data.path;
                }
                else
                {
                    FileData fileData = await CrossFilePicker.Current.PickFile();

                    if (fileData == null)
                    {
                        return; // User canceled file picking
                    }
                    stream = fileData.GetStream();

                    fileName = fileData.FileName;
                    filePath = fileData.FilePath;
                }

                FileTransfer transfer = TransferManager.prepareFileTransfer(fileName, stream, filePath);
                Logging.info("File Transfer uid: " + transfer.uid);

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.fileHeader, transfer.getBytes());

                StreamMessage message = new StreamMessage();
                message.type        = StreamMessageCode.data;
                message.recipient   = friend.walletAddress;
                message.sender      = Node.walletStorage.getPrimaryAddress();
                message.transaction = new byte[1];
                message.sigdata     = new byte[1];
                message.data        = spixi_message.getBytes();

                StreamProcessor.sendMessage(friend, message);


                string message_data = string.Format("{0}:{1}", transfer.uid, transfer.fileName);

                // store the message and display it
                FriendMessage friend_message = FriendList.addMessageWithType(message.id, FriendMessageType.fileHeader, friend.walletAddress, message_data, true);

                friend_message.transferId = transfer.uid;
                friend_message.filePath   = transfer.filePath;

                Node.localStorage.writeMessages(friend.walletAddress, friend.messages);
            }
            catch (Exception ex)
            {
                Logging.error("Exception choosing file: " + ex.ToString());
            }
        }