public HelperTrieProofsMessage Deserialize(RlpStream rlpStream) { HelperTrieProofsMessage message = new HelperTrieProofsMessage(); rlpStream.ReadSequenceLength(); message.RequestId = rlpStream.DecodeLong(); message.BufferValue = rlpStream.DecodeInt(); rlpStream.ReadSequenceLength(); message.ProofNodes = rlpStream.DecodeArray(stream => stream.DecodeByteArray()); message.AuxiliaryData = rlpStream.DecodeArray(stream => stream.DecodeByteArray()); return(message); }
private static ParityTraceAction DecodeAction(RlpStream rlpStream) { ParityTraceAction action = new ParityTraceAction(); int sequenceLength = rlpStream.ReadSequenceLength(); if (rlpStream.ReadNumberOfItemsRemaining(rlpStream.Position + sequenceLength) == 3) { action.CallType = "reward"; action.RewardType = rlpStream.DecodeString(); action.Author = rlpStream.DecodeAddress(); action.Value = rlpStream.DecodeUInt256(); action.TraceAddress = Array.Empty <int>(); } else { action.CallType = rlpStream.DecodeString(); action.From = rlpStream.DecodeAddress(); action.To = rlpStream.DecodeAddress(); action.Value = rlpStream.DecodeUInt256(); action.Gas = rlpStream.DecodeLong(); action.Input = rlpStream.DecodeByteArray(); action.Result = new ParityTraceResult(); action.Result.Output = rlpStream.DecodeByteArray(); action.Result.GasUsed = rlpStream.DecodeLong(); action.TraceAddress = rlpStream.DecodeArray(c => c.DecodeInt()); int subtracesCount = rlpStream.DecodeInt(); action.Subtraces = new List <ParityTraceAction>(subtracesCount); for (int i = 0; i < subtracesCount; i++) { action.Subtraces.Add(DecodeAction(rlpStream)); } } return(action); }
public HelloMessage Deserialize(byte[] bytes) { RlpStream rlpStream = bytes.AsRlpStream(); rlpStream.ReadSequenceLength(); HelloMessage helloMessage = new HelloMessage(); helloMessage.P2PVersion = rlpStream.DecodeByte(); helloMessage.ClientId = string.Intern(rlpStream.DecodeString()); helloMessage.Capabilities = rlpStream.DecodeArray(ctx => { ctx.ReadSequenceLength(); string protocolCode = string.Intern(ctx.DecodeString()); int version = ctx.DecodeByte(); return(new Capability(protocolCode, version)); }).ToList(); helloMessage.ListenPort = rlpStream.DecodeInt(); byte[] publicKeyBytes = rlpStream.DecodeByteArray(); if (publicKeyBytes.Length != PublicKey.LengthInBytes && publicKeyBytes.Length != PublicKey.PrefixedLengthInBytes) { throw new NetworkingException($"Client {helloMessage.ClientId} sent an invalid public key format (length was {publicKeyBytes.Length})", NetworkExceptionType.HandshakeOrInit); } else { helloMessage.NodeId = new PublicKey(publicKeyBytes); } return(helloMessage); }
public GetNodeDataMessage Deserialize(byte[] bytes) { RlpStream rlpStream = bytes.AsRlpStream(); var keys = rlpStream.DecodeArray(itemContext => itemContext.DecodeKeccak()); return(new GetNodeDataMessage(keys)); }
public GetReceiptsMessage Deserialize(byte[] bytes) { RlpStream rlpStream = bytes.AsRlpStream(); Keccak[] hashes = rlpStream.DecodeArray(itemContext => itemContext.DecodeKeccak()); return(new GetReceiptsMessage(hashes)); }
private PathGroup DecodeGroup(RlpStream stream) { PathGroup group = new PathGroup(); group.Group = stream.DecodeArray(s => stream.DecodeByteArray()); return(group); }
public ReceiptsMessage Deserialize(RlpStream rlpStream) { TxReceipt[][] data = rlpStream.DecodeArray(itemContext => itemContext.DecodeArray(nestedContext => _decoder.Decode(nestedContext)) ?? new TxReceipt[0], true); ReceiptsMessage message = new ReceiptsMessage(data); return(message); }
public static ContractCodesMessage Deserialize(RlpStream rlpStream) { ContractCodesMessage contractCodesMessage = new ContractCodesMessage(); rlpStream.ReadSequenceLength(); contractCodesMessage.RequestId = rlpStream.DecodeLong(); contractCodesMessage.BufferValue = rlpStream.DecodeInt(); contractCodesMessage.Codes = rlpStream.DecodeArray(stream => stream.DecodeByteArray()); return(contractCodesMessage); }
private static BlockBodiesMessage Deserialize(RlpStream rlpStream) { BlockBodiesMessage message = new BlockBodiesMessage(); message.Bodies = rlpStream.DecodeArray(ctx => { int sequenceLength = rlpStream.ReadSequenceLength(); if (sequenceLength == 0) { return(null); } Transaction[] transactions = rlpStream.DecodeArray(txCtx => Rlp.Decode <Transaction>(ctx)); BlockHeader[] ommers = rlpStream.DecodeArray(txCtx => Rlp.Decode <BlockHeader>(ctx)); return(new BlockBody(transactions, ommers)); }, false); return(message); }
public EnableDataStreamMessage Deserialize(byte[] bytes) { RlpStream context = bytes.AsRlpStream(); context.ReadSequenceLength(); Keccak?depositId = context.DecodeKeccak(); string client = context.DecodeString(); string?[] args = context.DecodeArray(c => c.DecodeString()); return(new EnableDataStreamMessage(depositId, client, args)); }
public static BlockBodiesMessage Deserialize(RlpStream rlpStream) { BlockBodiesMessage message = new(); message.Bodies = rlpStream.DecodeArray(ctx => { int sequenceLength = rlpStream.ReadSequenceLength(); if (sequenceLength == 0) { return(null); } // quite significant allocations (>0.5%) here based on a sample 3M blocks sync // (just on these delegates) Transaction[] transactions = rlpStream.DecodeArray(_ => Rlp.Decode <Transaction>(ctx)); BlockHeader[] ommers = rlpStream.DecodeArray(_ => Rlp.Decode <BlockHeader>(ctx)); return(new BlockBody(transactions, ommers)); }, false); return(message); }
protected override GetByteCodesMessage Deserialize(RlpStream rlpStream) { GetByteCodesMessage message = new (); rlpStream.ReadSequenceLength(); message.RequestId = rlpStream.DecodeLong(); message.Hashes = rlpStream.DecodeArray(_ => rlpStream.DecodeKeccak()); message.Bytes = rlpStream.DecodeLong(); return(message); }
public NodeDataMessage Deserialize(byte[] bytes) { if (bytes.Length == 0 && bytes[0] == Rlp.OfEmptySequence[0]) { return(new NodeDataMessage(null)); } RlpStream rlpStream = bytes.AsRlpStream(); var data = rlpStream.DecodeArray(itemContext => itemContext.DecodeByteArray()); NodeDataMessage message = new NodeDataMessage(data); return(message); }
public ReceiptsMessage Deserialize(byte[] bytes) { if (bytes.Length == 0 && bytes[0] == Rlp.OfEmptySequence[0]) { return(new ReceiptsMessage(null)); } RlpStream rlpStream = bytes.AsRlpStream(); var data = rlpStream.DecodeArray(itemContext => itemContext.DecodeArray(nestedContext => Rlp.Decode <TxReceipt>(nestedContext)) ?? new TxReceipt[0], true); ReceiptsMessage message = new ReceiptsMessage(data); return(message); }
protected override GetStorageRangeMessage Deserialize(RlpStream rlpStream) { GetStorageRangeMessage message = new (); rlpStream.ReadSequenceLength(); message.RequestId = rlpStream.DecodeLong(); message.StoragetRange = new(); message.StoragetRange.RootHash = rlpStream.DecodeKeccak(); message.StoragetRange.Accounts = rlpStream.DecodeArray(DecodePathWithRlpData); message.StoragetRange.StartingHash = rlpStream.DecodeKeccak(); message.StoragetRange.LimitHash = rlpStream.DecodeKeccak(); message.ResponseBytes = rlpStream.DecodeLong(); return(message); }
private BaselineMetadata LoadMetadata() { byte[] serializedMetadata = _baselineDb[_metadataKey]; BaselineMetadata metadata; if (serializedMetadata == null) { metadata = new BaselineMetadata(); } else { RlpStream rlpStream = new RlpStream(serializedMetadata); metadata = new BaselineMetadata(rlpStream.DecodeArray(itemContext => itemContext.DecodeAddress())); } return(metadata); }
public static GetContractCodesMessage Deserialize(RlpStream rlpStream) { GetContractCodesMessage getContractCodesMessage = new GetContractCodesMessage(); rlpStream.ReadSequenceLength(); getContractCodesMessage.RequestId = rlpStream.DecodeLong(); getContractCodesMessage.Requests = rlpStream.DecodeArray(stream => { CodeRequest request = new CodeRequest(); stream.ReadSequenceLength(); request.BlockHash = stream.DecodeKeccak(); request.AccountKey = stream.DecodeKeccak(); return(request); }); return(getContractCodesMessage); }
public static GetHelperTrieProofsMessage Deserialize(RlpStream rlpStream) { GetHelperTrieProofsMessage message = new GetHelperTrieProofsMessage(); rlpStream.ReadSequenceLength(); message.RequestId = rlpStream.DecodeLong(); message.Requests = rlpStream.DecodeArray(stream => { HelperTrieRequest request = new HelperTrieRequest(); stream.ReadSequenceLength(); request.SubType = (HelperTrieType)stream.DecodeInt(); request.SectionIndex = stream.DecodeLong(); request.Key = stream.DecodeByteArray(); request.FromLevel = stream.DecodeLong(); request.AuxiliaryData = stream.DecodeInt(); return(request); }); return(message); }
private Node[] DeserializeNodes(RlpStream rlpStream) { return(rlpStream.DecodeArray(ctx => { int lastPosition = ctx.ReadSequenceLength() + ctx.Position; int count = ctx.ReadNumberOfItemsRemaining(lastPosition); byte[] ip = ctx.DecodeByteArray(); IPEndPoint address = GetAddress(ip, ctx.DecodeInt()); if (count > 3) { ctx.DecodeInt(); } byte[] id = ctx.DecodeByteArray(); return new Node(new PublicKey(id), address); })); }
private BaselineMetadata LoadMetadata() { byte[] serializedMetadata = _baselineDb[_metadataKey]; BaselineMetadata metadata; if (serializedMetadata == null) { metadata = new BaselineMetadata(); } else { RlpStream rlpStream = new RlpStream(serializedMetadata); Address?[] addresses = rlpStream.DecodeArray(itemContext => itemContext.DecodeAddress()); metadata = new BaselineMetadata( addresses.Where(a => a != null).Select(a => a !).ToArray()); } return(metadata); }
public HelloMessage Deserialize(byte[] bytes) { RlpStream rlpStream = bytes.AsRlpStream(); rlpStream.ReadSequenceLength(); HelloMessage helloMessage = new HelloMessage(); helloMessage.P2PVersion = rlpStream.DecodeByte(); helloMessage.ClientId = string.Intern(rlpStream.DecodeString()); helloMessage.Capabilities = rlpStream.DecodeArray(ctx => { ctx.ReadSequenceLength(); string protocolCode = string.Intern(ctx.DecodeString()); int version = ctx.DecodeByte(); return(new Capability(protocolCode, version)); }).ToList(); helloMessage.ListenPort = rlpStream.DecodeInt(); helloMessage.NodeId = new PublicKey(rlpStream.DecodeByteArray()); return(helloMessage); }
private BloomStorageLevel[] CreateStorageLevels(IBloomConfig config) { void ValidateConfigValue() { if (config.IndexLevelBucketSizes.Length == 0) { throw new ArgumentException($"Can not create bloom index when there are no {nameof(config.IndexLevelBucketSizes)} provided.", nameof(config.IndexLevelBucketSizes)); } } List <int> InsertBaseLevelIfNeeded() { List <int> sizes = config.IndexLevelBucketSizes.ToList(); if (sizes.FirstOrDefault() != 1) { sizes.Insert(0, 1); } return(sizes); } void ValidateCurrentDbStructure(IList <int> sizes) { var levelsFromDb = _bloomInfoDb.Get(LevelsKey); if (levelsFromDb == null) { _bloomInfoDb.Set(LevelsKey, Rlp.Encode(sizes.ToArray()).Bytes); } else { var stream = new RlpStream(levelsFromDb); var dbBucketSizes = stream.DecodeArray(x => x.DecodeInt()); if (!dbBucketSizes.SequenceEqual(sizes)) { throw new ArgumentException($"Can not load bloom db. {nameof(config.IndexLevelBucketSizes)} changed without rebuilding bloom db. Db structure is [{string.Join(",", dbBucketSizes)}]. Current config value is [{string.Join(",", sizes)}]. " + $"If you want to rebuild {DbNames.Bloom} db, please delete db folder. If not, please change config value to reflect current db structure", nameof(config.IndexLevelBucketSizes)); } } } ValidateConfigValue(); var configIndexLevelBucketSizes = InsertBaseLevelIfNeeded(); ValidateCurrentDbStructure(configIndexLevelBucketSizes); var lastLevelSize = 1; return(configIndexLevelBucketSizes .Select((size, i) => { byte level = (byte)(configIndexLevelBucketSizes.Count - i - 1); var levelElementSize = lastLevelSize * size; lastLevelSize = levelElementSize; return new BloomStorageLevel(_fileStoreFactory.Create(level.ToString()), level, levelElementSize, size, _config.MigrationStatistics); }) .Reverse() .ToArray()); }
public NdmConfig Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { var sequenceLength = rlpStream.ReadSequenceLength(); if (sequenceLength == 0) { return(null); } var enabled = rlpStream.DecodeBool(); var id = rlpStream.DecodeString(); var initializerName = rlpStream.DecodeString(); var storeConfigInDatabase = rlpStream.DecodeBool(); var verifyP2PSignature = rlpStream.DecodeBool(); var persistence = rlpStream.DecodeString(); var faucetEnabled = rlpStream.DecodeBool(); var faucetAddress = rlpStream.DecodeString(); var faucetHost = rlpStream.DecodeString(); var faucetWeiRequestMaxValue = rlpStream.DecodeUInt256(); var faucetEthDailyRequestsTotalValue = rlpStream.DecodeUInt256(); var consumerAddress = rlpStream.DecodeString(); var contractAddress = rlpStream.DecodeString(); var providerName = rlpStream.DecodeString(); var providerAddress = rlpStream.DecodeString(); var providerColdWalletAddress = rlpStream.DecodeString(); var receiptRequestThreshold = rlpStream.DecodeUInt256(); var receiptsMergeThreshold = rlpStream.DecodeUInt256(); var paymentClaimThreshold = rlpStream.DecodeUInt256(); var blockConfirmations = rlpStream.DecodeUInt(); var filesPath = rlpStream.DecodeString(); var fileMaxSize = rlpStream.DecodeUlong(); var pluginsPath = rlpStream.DecodeString(); var proxyEnabled = rlpStream.DecodeBool(); var jsonRpcUrlProxies = rlpStream.DecodeArray(c => c.DecodeString()); return(new NdmConfig { Enabled = enabled, Id = id, InitializerName = initializerName, StoreConfigInDatabase = storeConfigInDatabase, VerifyP2PSignature = verifyP2PSignature, Persistence = persistence, FaucetEnabled = faucetEnabled, FaucetAddress = faucetAddress, FaucetHost = faucetHost, FaucetWeiRequestMaxValue = faucetWeiRequestMaxValue, FaucetEthDailyRequestsTotalValue = faucetEthDailyRequestsTotalValue, ConsumerAddress = consumerAddress, ContractAddress = contractAddress, ProviderName = providerName, ProviderAddress = providerAddress, ProviderColdWalletAddress = providerColdWalletAddress, ReceiptRequestThreshold = receiptRequestThreshold, ReceiptsMergeThreshold = receiptsMergeThreshold, PaymentClaimThreshold = paymentClaimThreshold, BlockConfirmations = blockConfirmations, FilesPath = filesPath, FileMaxSize = fileMaxSize, PluginsPath = pluginsPath, ProxyEnabled = proxyEnabled, JsonRpcUrlProxies = jsonRpcUrlProxies }); }
public NdmConfig Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { try { rlpStream.ReadSequenceLength(); bool enabled = rlpStream.DecodeBool(); string id = rlpStream.DecodeString(); string initializerName = rlpStream.DecodeString(); bool storeConfigInDatabase = rlpStream.DecodeBool(); bool verifyP2PSignature = rlpStream.DecodeBool(); string persistence = rlpStream.DecodeString(); bool faucetEnabled = rlpStream.DecodeBool(); string faucetAddress = rlpStream.DecodeString(); string faucetHost = rlpStream.DecodeString(); UInt256 faucetWeiRequestMaxValue = rlpStream.DecodeUInt256(); UInt256 faucetEthDailyRequestsTotalValue = rlpStream.DecodeUInt256(); string consumerAddress = rlpStream.DecodeString(); string contractAddress = rlpStream.DecodeString(); string providerName = rlpStream.DecodeString(); string providerAddress = rlpStream.DecodeString(); string providerColdWalletAddress = rlpStream.DecodeString(); UInt256 receiptRequestThreshold = rlpStream.DecodeUInt256(); UInt256 receiptsMergeThreshold = rlpStream.DecodeUInt256(); UInt256 paymentClaimThreshold = rlpStream.DecodeUInt256(); uint blockConfirmations = rlpStream.DecodeUInt(); string filesPath = rlpStream.DecodeString(); ulong fileMaxSize = rlpStream.DecodeUlong(); string pluginsPath = rlpStream.DecodeString(); string databasePath = rlpStream.DecodeString(); bool proxyEnabled = rlpStream.DecodeBool(); var jsonRpcUrlProxies = rlpStream.DecodeArray(c => c.DecodeString()); string gasPriceType = rlpStream.DecodeString(); UInt256 gasPrice = rlpStream.DecodeUInt256(); uint cancelTransactionGasPricePercentageMultiplier = rlpStream.DecodeUInt(); bool jsonRpcDataChannelEnabled = rlpStream.DecodeBool(); UInt256 refundGasPrice = rlpStream.DecodeUInt256(); return(new NdmConfig { Enabled = enabled, Id = id, InitializerName = initializerName, StoreConfigInDatabase = storeConfigInDatabase, VerifyP2PSignature = verifyP2PSignature, Persistence = persistence, FaucetEnabled = faucetEnabled, FaucetAddress = faucetAddress == string.Empty ? null : faucetAddress, FaucetHost = faucetHost == string.Empty ? null : faucetHost, FaucetWeiRequestMaxValue = faucetWeiRequestMaxValue, FaucetEthDailyRequestsTotalValue = faucetEthDailyRequestsTotalValue, ConsumerAddress = consumerAddress == string.Empty ? null : consumerAddress, ContractAddress = contractAddress == string.Empty ? null : contractAddress, ProviderName = providerName, ProviderAddress = providerAddress == string.Empty ? null : providerAddress, ProviderColdWalletAddress = providerColdWalletAddress == string.Empty ? null : providerColdWalletAddress, ReceiptRequestThreshold = receiptRequestThreshold, ReceiptsMergeThreshold = receiptsMergeThreshold, PaymentClaimThreshold = paymentClaimThreshold, BlockConfirmations = blockConfirmations, FilesPath = filesPath, FileMaxSize = fileMaxSize, PluginsPath = pluginsPath, DatabasePath = databasePath, ProxyEnabled = proxyEnabled, JsonRpcUrlProxies = jsonRpcUrlProxies !, GasPriceType = gasPriceType, GasPrice = gasPrice, CancelTransactionGasPricePercentageMultiplier = cancelTransactionGasPricePercentageMultiplier, JsonRpcDataChannelEnabled = jsonRpcDataChannelEnabled, RefundGasPrice = refundGasPrice }); }
public static GetBlockBodiesMessage Deserialize(RlpStream rlpStream) { Keccak[] hashes = rlpStream.DecodeArray(ctx => rlpStream.DecodeKeccak(), false); return(new GetBlockBodiesMessage(hashes)); }
protected static Keccak[] DeserializeHashes(RlpStream rlpStream) { Keccak[] hashes = rlpStream.DecodeArray(itemContext => itemContext.DecodeKeccak()); return(hashes); }