Example #1
0
        protected override Memory <byte> ParseSigned(ushort version, Memory <byte> spanBody, out SignedPacketBase signedPacketBase)
        {
            byte[]        prevHash     = spanBody.Slice(0, Globals.DEFAULT_HASH_SIZE).ToArray();
            Memory <byte> spanPostBody = ParseLinked(version, spanBody.Slice(Globals.DEFAULT_HASH_SIZE), out LinkedPacketBase linkedPacketBase);

            linkedPacketBase.HashPrev = prevHash;
            signedPacketBase          = linkedPacketBase;

            return(spanPostBody);
        }
Example #2
0
        protected override Memory <byte> ParseSigned(ushort version, Memory <byte> spanBody, out SignedPacketBase syncedBlockBase)
        {
            if (version == 1)
            {
                int readBytes = 0;

                PacketType referencedPacketType = (PacketType)BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span);
                readBytes += sizeof(ushort);

                ushort referencedBlockType = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span.Slice(readBytes));
                readBytes += sizeof(ushort);

                byte[] referencedBlockHash = spanBody.Slice(readBytes, Globals.DEFAULT_HASH_SIZE).ToArray();
                readBytes += Globals.DEFAULT_HASH_SIZE;

                byte[] referencedTarget = spanBody.Slice(readBytes, Globals.DEFAULT_HASH_SIZE).ToArray();
                readBytes += Globals.DEFAULT_HASH_SIZE;

                byte[] transactionKey = null;

                if ((referencedBlockType & BlockTypes.TransitionalFlag) == BlockTypes.TransitionalFlag)
                {
                    transactionKey = spanBody.Slice(readBytes, Globals.DEFAULT_HASH_SIZE).ToArray();
                    readBytes     += Globals.DEFAULT_HASH_SIZE;
                }

                RegistryRegisterBlock transactionRegisterBlock = new RegistryRegisterBlock
                {
                    ReferencedPacketType     = referencedPacketType,
                    ReferencedBlockType      = referencedBlockType,
                    ReferencedBodyHash       = referencedBlockHash,
                    ReferencedTarget         = referencedTarget,
                    ReferencedTransactionKey = transactionKey
                };

                syncedBlockBase = transactionRegisterBlock;

                return(spanBody.Slice(readBytes));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }
Example #3
0
 protected abstract Memory <byte> ParseSigned(ushort version, Memory <byte> spanBody, out SignedPacketBase signedBlockBase);
Example #4
0
        protected override Memory <byte> ParseSigned(ushort version, Memory <byte> spanBody, out SignedPacketBase syncedBlockBase)
        {
            int   readBytes = 0;
            ulong funds     = BinaryPrimitives.ReadUInt64LittleEndian(spanBody.Span.Slice(readBytes));

            readBytes += sizeof(ulong);

            Memory <byte> spanPostBody = ParseTransactional(version, spanBody.Slice(readBytes), out TransactionalPacketBase transactionalBlockBase);

            transactionalBlockBase.UptodateFunds = funds;
            syncedBlockBase = transactionalBlockBase;

            return(spanPostBody);
        }
Example #5
0
        protected override Memory <byte> ParseSigned(ushort version, Memory <byte> spanBody, out SignedPacketBase syncedBlockBase)
        {
            if (version == 1)
            {
                int readBytes = 0;
                RegistryShortBlock transactionsShortBlock = new RegistryShortBlock();

                ushort witnessStateKeysCount = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span.Slice(readBytes));
                readBytes += sizeof(ushort);

                ushort witnessUtxoKeysCount = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span.Slice(readBytes));
                readBytes += sizeof(ushort);

                transactionsShortBlock.WitnessStateKeys = new WitnessStateKey[witnessStateKeysCount];
                transactionsShortBlock.WitnessUtxoKeys  = new WitnessUtxoKey[witnessUtxoKeysCount];

                for (int i = 0; i < witnessStateKeysCount; i++)
                {
                    byte[] witnessPublicKey = spanBody.Slice(readBytes, Globals.NODE_PUBLIC_KEY_SIZE).ToArray();
                    readBytes += Globals.NODE_PUBLIC_KEY_SIZE;

                    ulong witnessHeight = BinaryPrimitives.ReadUInt64LittleEndian(spanBody.Slice(readBytes).Span);
                    readBytes += sizeof(ulong);

                    IKey key = _keyProvider.GetKey(witnessPublicKey);

                    transactionsShortBlock.WitnessStateKeys[i] = new WitnessStateKey {
                        PublicKey = key, Height = witnessHeight
                    };
                }

                for (int i = 0; i < witnessUtxoKeysCount; i++)
                {
                    byte[] witnessKeyImage = spanBody.Slice(readBytes, Globals.NODE_PUBLIC_KEY_SIZE).ToArray();
                    readBytes += Globals.NODE_PUBLIC_KEY_SIZE;

                    IKey key = _keyProvider.GetKey(witnessKeyImage);

                    transactionsShortBlock.WitnessUtxoKeys[i] = new WitnessUtxoKey {
                        KeyImage = key
                    };
                }

                syncedBlockBase = transactionsShortBlock;

                return(spanBody.Slice(readBytes));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }
Example #6
0
        protected override Memory <byte> ParseSigned(ushort version, Memory <byte> spanBody, out SignedPacketBase syncedBlockBase)
        {
            if (version == 1)
            {
                RegistryConfidenceBlock registryConfidenceBlock = new RegistryConfidenceBlock();
                ushort bitMaskLength = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span);
                registryConfidenceBlock.BitMask             = spanBody.Slice(2, bitMaskLength).ToArray();
                registryConfidenceBlock.ConfidenceProof     = spanBody.Slice(2 + bitMaskLength, Globals.TRANSACTION_KEY_HASH_SIZE).ToArray();
                registryConfidenceBlock.ReferencedBlockHash = spanBody.Slice(2 + bitMaskLength + Globals.TRANSACTION_KEY_HASH_SIZE, Globals.DEFAULT_HASH_SIZE).ToArray();

                syncedBlockBase = registryConfidenceBlock;

                return(spanBody.Slice(2 + bitMaskLength + Globals.TRANSACTION_KEY_HASH_SIZE + Globals.DEFAULT_HASH_SIZE));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }
Example #7
0
        protected override Memory <byte> ParseSigned(ushort version, Memory <byte> spanBody, out SignedPacketBase syncedBlockBase)
        {
            if (version == 1)
            {
                RegistryConfirmationBlock block = new RegistryConfirmationBlock
                {
                    ReferencedBlockHash = spanBody.Slice(0, Globals.DEFAULT_HASH_SIZE).ToArray()
                };

                syncedBlockBase = block;

                return(spanBody.Slice(Globals.DEFAULT_HASH_SIZE));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }
Example #8
0
        protected override Memory <byte> ParseSigned(ushort version, Memory <byte> spanBody, out SignedPacketBase syncedBlockBase)
        {
            if (version == 1)
            {
                int readBytes = 0;

                RegistryFullBlock transactionsFullBlock = new RegistryFullBlock();
                ushort            stateWitnessesCount   = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span.Slice(readBytes));
                readBytes += sizeof(ushort);

                ushort utxoWitnessesCount = BinaryPrimitives.ReadUInt16LittleEndian(spanBody.Span.Slice(readBytes));
                readBytes += sizeof(ushort);

                transactionsFullBlock.StateWitnesses = new RegistryRegisterBlock[stateWitnessesCount];
                transactionsFullBlock.UtxoWitnesses  = new RegistryRegisterUtxoConfidential[utxoWitnessesCount];

                for (int i = 0; i < stateWitnessesCount; i++)
                {
                    RegistryRegisterBlock block = (RegistryRegisterBlock)_registryRegisterBlockParser.Parse(spanBody.Slice(readBytes));

                    readBytes += block?.RawData.Length ?? 0;

                    transactionsFullBlock.StateWitnesses[i] = block;
                }

                for (int i = 0; i < utxoWitnessesCount; i++)
                {
                    RegistryRegisterUtxoConfidential block = (RegistryRegisterUtxoConfidential)_registryRegisterUtxoConfidentialBlockParser.Parse(spanBody.Slice(readBytes));

                    readBytes += block?.RawData.Length ?? 0;

                    transactionsFullBlock.UtxoWitnesses[i] = block;
                }

                transactionsFullBlock.ShortBlockHash = spanBody.Slice(readBytes, Globals.DEFAULT_HASH_SIZE).ToArray();
                readBytes += Globals.DEFAULT_HASH_SIZE;

                syncedBlockBase = transactionsFullBlock;

                return(spanBody.Slice(readBytes));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }