private void ApproveTx(BlockHeader parent, Transaction tx)
 {
     tx.Nonce = _stateReader.GetNonce(parent.StateRoot, tx.SenderAddress);
     _wallet.Sign(tx, _chainId);
     tx.Hash      = tx.CalculateHash();
     tx.Timestamp = _timestamper.EpochSeconds;
 }
Beispiel #2
0
 public void Sign(Transaction tx, int chainId)
 {
     if (_logger.IsDebug)
     {
         _logger.Debug($"Signing transaction: {tx.Value} to {tx.To}");
     }
     IBasicWallet.Sign(this, tx, chainId);
 }
Beispiel #3
0
        private Block Seal(Block block)
        {
            // Bail out if we're unauthorized to sign a block
            if (!CanSeal(block.Number, block.ParentHash))
            {
                if (_logger.IsInfo)
                {
                    _logger.Info($"Not authorized to seal the block {block.ToString(Block.Format.Short)}");
                }
                return(null);
            }

            BlockHeader header = block.Header;

            // Sealing the genesis block is not supported
            UInt256 number = header.Number;

            if (number == 0)
            {
                throw new InvalidOperationException("Can't sign genesis block");
            }

            // For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing)
            if (_config.BlockPeriod == 0 && block.Transactions.Length == 0)
            {
                if (_logger.IsError)
                {
                    _logger.Error($"Not sealing empty block on 0-period chain {block.Number}");
                }
                throw new InvalidOperationException("An attempt has been made to seal an empty block on a 0-period clique chain");
            }

            // Sign all the things!
            Keccak    headerHash = _snapshotManager.CalculateCliqueHeaderHash(header);
            Signature signature  = _wallet.Sign(headerHash, _sealerAddress);
            // Copy signature bytes (R and S)
            var signatureBytes = signature.Bytes;

            Array.Copy(signatureBytes, 0, header.ExtraData, header.ExtraData.Length - Clique.ExtraSealLength, signatureBytes.Length);
            // Copy signature's recovery id (V)
            byte recoveryId = signature.RecoveryId;

            header.ExtraData[header.ExtraData.Length - 1] = recoveryId;

            return(block);
        }
Beispiel #4
0
        private Block Seal(Block block)
        {
            // Bail out if we're unauthorized to sign a block
            if (!CanSeal(block.Number, block.ParentHash))
            {
                if (_logger.IsInfo)
                {
                    _logger.Info($"Not authorized to seal the block {block.ToString(Block.Format.Short)}");
                }
                return(null);
            }

            var headerHash = BlockHeader.CalculateHash(block.Header, RlpBehaviors.ForSealing);
            var signature  = _wallet.Sign(headerHash, _nodeAddress);

            block.Header.AuRaSignature = signature.BytesWithRecovery;

            return(block);
        }