Beispiel #1
0
 public override bool addTransaction(Transaction tx, bool force_broadcast)
 {
     // TODO Send to peer if directly connectable
     CoreProtocolMessage.broadcastProtocolMessage(new char[] { 'M', 'H' }, ProtocolMessageCode.transactionData, tx.getBytes(), null);
     PendingTransactions.addPendingLocalTransaction(tx);
     return(true);
 }
Beispiel #2
0
        // Broadcasts the solution to the network
        public void sendSolution(byte[] nonce)
        {
            byte[] pubkey = Node.walletStorage.getPrimaryPublicKey();
            // Check if this wallet's public key is already in the WalletState
            Wallet mywallet = Node.walletState.getWallet(Node.walletStorage.getPrimaryAddress());

            if (mywallet.publicKey != null && mywallet.publicKey.SequenceEqual(pubkey))
            {
                // Walletstate public key matches, we don't need to send the public key in the transaction
                pubkey = null;
            }

            byte[] data = null;

            using (MemoryStream mw = new MemoryStream())
            {
                using (BinaryWriter writerw = new BinaryWriter(mw))
                {
                    writerw.Write(activeBlock.blockNum);
                    writerw.Write(Crypto.hashToString(nonce));
                    data = mw.ToArray();
                }
            }

            Transaction tx = new Transaction((int)Transaction.Type.PoWSolution, new IxiNumber(0), new IxiNumber(0), ConsensusConfig.ixianInfiniMineAddress, Node.walletStorage.getPrimaryAddress(), data, pubkey, Node.blockChain.getLastBlockNum());

            if (TransactionPool.addTransaction(tx))
            {
                PendingTransactions.addPendingLocalTransaction(tx);
            }
            else
            {
                Logging.error("An unknown error occured while sending PoW solution.");
            }
        }
        public static void onBotAction(byte[] action_data, RemoteEndpoint endpoint, int channel = 0)
        {
            SpixiBotAction sba = new SpixiBotAction(action_data);

            switch (sba.action)
            {
            case SpixiBotActionCode.getChannels:
                sendChannels(endpoint);
                break;

            case SpixiBotActionCode.getInfo:
                Node.users.setPubKey(endpoint.presence.wallet, endpoint.serverPubKey, false);
                sendInfo(endpoint.presence.wallet);
                break;

            case SpixiBotActionCode.getUsers:
                sendUsers(endpoint);
                break;

            case SpixiBotActionCode.getUser:
                sendUser(endpoint.presence.wallet, Node.users.getUser(sba.data));
                break;

            case SpixiBotActionCode.payment:
                StreamTransaction stream_tx = new StreamTransaction(sba.data);

                if (!stream_tx.transaction.toList.Keys.First().SequenceEqual(IxianHandler.getWalletStorage().getPrimaryAddress()))
                {
                    Logging.warn("Received transaction txid " + stream_tx.transaction.id + " from " + Base58Check.Base58CheckEncoding.EncodePlain(endpoint.presence.wallet) + " that's not for this node.");
                    return;
                }

                StreamMessage sm = pendingMessages.Find(x => x.id.SequenceEqual(stream_tx.messageID));
                if (sm == null)
                {
                    // TODO TODO TODO send get message request to the client
                    Logging.warn("Received transaction txid " + stream_tx.transaction.id + " from " + Base58Check.Base58CheckEncoding.EncodePlain(endpoint.presence.wallet) + " but have no message for this transaction.");
                    return;
                }

                IxiNumber price = getMessagePrice(sm.sender, sm.data.Length);
                if (stream_tx.transaction.amount < price)
                {
                    Logging.warn("Received transaction txid " + stream_tx.transaction.id + " from " + Base58Check.Base58CheckEncoding.EncodePlain(endpoint.presence.wallet) + " that has lower than expected amount.");
                    return;
                }

                CoreProtocolMessage.broadcastProtocolMessage(new char[] { 'M', 'H' }, ProtocolMessageCode.transactionData, stream_tx.transaction.getBytes(), null);
                CoreProtocolMessage.broadcastGetTransaction(stream_tx.transaction.id, 0, null, false);
                PendingTransactions.addPendingLocalTransaction(stream_tx.transaction, stream_tx.messageID);
                break;

            case SpixiBotActionCode.enableNotifications:
                bool send_notifications = false;
                if (sba.data[0] == 1)
                {
                    send_notifications = true;
                }
                Node.users.getUser(endpoint.presence.wallet).sendNotification = send_notifications;
                Node.users.writeContactsToFile();
                break;
            }
        }
Beispiel #4
0
 public override bool addTransaction(Transaction tx)
 {
     PendingTransactions.addPendingLocalTransaction(tx);
     return(true);
 }