HashToString() public static method

public static HashToString ( byte hash ) : string
hash byte
return string
Exemplo n.º 1
0
        public void LoadTransaction(byte[] data)
        {
            byte[] hash    = Program.GenerateHash(data);
            string hashStr = Program.HashToString(hash);

            if (mTransactions.ContainsKey(hashStr))
            {
                Transaction t = mTransactions[hashStr];
                t.Load(data);
            }
            else
            {
                Console.WriteLine("Unknown transaction");
            }
        }
Exemplo n.º 2
0
        public void HandleInvPacket(NodeConnection node, byte[] payload)
        {
            MemoryStream stream = new MemoryStream(payload);
            BinaryReader br     = new BinaryReader(stream);

            List <Transaction> transLoadList = new List <Transaction>();
            List <Block>       blockLoadList = new List <Block>();

            ulong count = Program.ReadVarInt(br);

            for (ulong i = 0; i < count; i++)
            {
                uint   type = br.ReadUInt32();
                byte[] hash = br.ReadBytes(32);
                if (type != 0)
                {
                    string str = Program.HashToString(hash);
                    if (type == 1)
                    {
                        if (mTransactions.ContainsKey(str))
                        {
                            // We already know about this transaction
                            Transaction t = mTransactions[str];
                            if (t.Status == Transaction.DataStatus.NoData)
                            {
                                // No details about this transaction loaded yet, request it
                                t.Status = Transaction.DataStatus.Requested;
                                transLoadList.Add(t);
                            }
                        }
                        else
                        {
                            // Transaction we dont know about yet
                            Transaction t = new Transaction(hash, Transaction.DataStatus.Requested);

                            // Add it to the transaction dictionary
                            mTransactions[str] = t;

                            // Add it to the list of transactions to requrest data about
                            transLoadList.Add(t);
                        }
                    }
                    else
                    {
                        if (mBlocks.ContainsKey(str))
                        {
                            // We already know about this block
                            Block b = mBlocks[str];
                            if (b.Status == NetworkDataObject.DataStatus.NoData)
                            {
                                // No details about this block loaded yet, request it
                                b.Status = NetworkDataObject.DataStatus.Requested;
                                blockLoadList.Add(b);
                            }
                        }
                        else
                        {
                            // Block we dont know about yet
                            Block b = new Block(hash, NetworkDataObject.DataStatus.Requested);

                            // Add it to the block dictionary
                            mBlocks[str] = b;

                            // Add it to the list of blocks to requrest data about
                            blockLoadList.Add(b);
                        }
                    }
                }
            }

            // Load the transactions and blocks we dont have loaded
            node.RequestData(transLoadList, blockLoadList);

            br.Close();
        }