示例#1
0
        public static TItem Get <TItem>(this IDb db, Keccak key, IRlpDecoder <TItem> decoder, ICache <Keccak, TItem> cache = null, bool shouldCache = true) where TItem : class
        {
            TItem item = cache?.Get(key);

            if (item == null)
            {
                if (db is IDbWithSpan spanDb && decoder is IRlpValueDecoder <TItem> valueDecoder)
                {
                    Span <byte> data = spanDb.GetSpan(key);
                    if (data.IsNullOrEmpty())
                    {
                        return(null);
                    }

                    try
                    {
                        var rlpValueContext = data.AsRlpValueContext();
                        item = valueDecoder.Decode(ref rlpValueContext, RlpBehaviors.AllowExtraData);
                    }
                    finally
                    {
                        spanDb.DangerousReleaseMemory(data);
                    }
                }
                else
                {
                    byte[] data = db.Get(key);
                    if (data == null)
                    {
                        return(null);
                    }

                    item = decoder.Decode(data.AsRlpStream(), RlpBehaviors.AllowExtraData);
                }
            }
示例#2
0
        public static T[] DecodeArray <T>(this IRlpDecoder <T> decoder, RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            int checkPosition = rlpStream.ReadSequenceLength() + rlpStream.Position;

            T[] result = new T[rlpStream.ReadNumberOfItemsRemaining(checkPosition)];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = decoder.Decode(rlpStream, rlpBehaviors);
            }

            return(result);
        }
示例#3
0
 public CreatedServices(Address consumerAddress,
                        IAbiEncoder abiEncoder, IRlpDecoder <DataHeader> dataHeaderRlpDecoder, IDepositService depositService,
                        INdmDataPublisher ndmDataPublisher, IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel,
                        INdmConsumerChannelManager ndmConsumerChannelManager, IBlockchainBridge blockchainBridge)
 {
     ConsumerAddress           = consumerAddress;
     AbiEncoder                = abiEncoder;
     DataHeaderRlpDecoder      = dataHeaderRlpDecoder;
     DepositService            = depositService;
     NdmDataPublisher          = ndmDataPublisher;
     JsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel;
     NdmConsumerChannelManager = ndmConsumerChannelManager;
     BlockchainBridge          = blockchainBridge;
 }
示例#4
0
        public static Rlp Encode <T>(this IRlpDecoder <T> decoder, T[] items, RlpBehaviors behaviors = RlpBehaviors.None)
        {
            if (items == null)
            {
                return(Rlp.OfEmptySequence);
            }

            Rlp[] rlpSequence = new Rlp[items.Length];
            for (int i = 0; i < items.Length; i++)
            {
                rlpSequence[i] = items[i] == null ? Rlp.OfEmptySequence : decoder.Encode(items[i], behaviors);
            }

            return(Rlp.Encode(rlpSequence));
        }
示例#5
0
        public static Rlp Encode <T>(T[] items, RlpBehaviors behaviors = RlpBehaviors.None)
        {
            if (Decoders.ContainsKey(typeof(T)))
            {
                IRlpDecoder <T> decoder     = (IRlpDecoder <T>)Decoders[typeof(T)];
                Rlp[]           rlpSequence = new Rlp[items.Length];
                for (int i = 0; i < items.Length; i++)
                {
                    rlpSequence[i] = items[i] == null ? OfEmptySequence : decoder.Encode(items[i], behaviors);
                }

                return(Encode(rlpSequence));
            }

            throw new RlpException($"{nameof(Rlp)} does not support decoding {typeof(T).Name}");
        }
示例#6
0
 public NdmCreatedServices(Address consumerAddress,
                           IAbiEncoder abiEncoder, IRlpDecoder <DataAsset> dataAssetRlpDecoder, IDepositService depositService,
                           INdmDataPublisher ndmDataPublisher, IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel,
                           INdmConsumerChannelManager ndmConsumerChannelManager, INdmBlockchainBridge blockchainBridge,
                           IEthJsonRpcClientProxy ethJsonRpcClientProxy)
 {
     ConsumerAddress           = consumerAddress;
     AbiEncoder                = abiEncoder;
     DataAssetRlpDecoder       = dataAssetRlpDecoder;
     DepositService            = depositService;
     NdmDataPublisher          = ndmDataPublisher;
     JsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel;
     NdmConsumerChannelManager = ndmConsumerChannelManager;
     BlockchainBridge          = blockchainBridge;
     EthJsonRpcClientProxy     = ethJsonRpcClientProxy;
 }
示例#7
0
 public NdmCreatedServices(Address consumerAddress,
                           IAbiEncoder abiEncoder, IRlpDecoder <DataAsset> dataAssetRlpDecoder, IDepositService depositService,
                           GasPriceService gasPriceService, TransactionService transactionService,
                           INdmDataPublisher ndmDataPublisher, IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel,
                           INdmConsumerChannelManager ndmConsumerChannelManager, INdmBlockchainBridge blockchainBridge)
 {
     ConsumerAddress           = consumerAddress;
     AbiEncoder                = abiEncoder;
     DataAssetRlpDecoder       = dataAssetRlpDecoder;
     DepositService            = depositService;
     GasPriceService           = gasPriceService;
     TransactionService        = transactionService;
     NdmDataPublisher          = ndmDataPublisher;
     JsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel;
     NdmConsumerChannelManager = ndmConsumerChannelManager;
     BlockchainBridge          = blockchainBridge;
 }
示例#8
0
        public static T[] DecodeArray <T>(DecoderContext context, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            if (Decoders.ContainsKey(typeof(T)))
            {
                IRlpDecoder <T> decoder       = (IRlpDecoder <T>)Decoders[typeof(T)];
                int             checkPosition = context.ReadSequenceLength() + context.Position;
                T[]             result        = new T[context.ReadNumberOfItemsRemaining(checkPosition)];
                for (int i = 0; i < result.Length; i++)
                {
                    result[i] = decoder.Decode(context, rlpBehaviors);
                }

                return(result);
            }

            throw new RlpException($"{nameof(Rlp)} does not support decoding {typeof(T).Name}");
        }
示例#9
0
 public NdmCreatedServices(
     Address consumerAddress,
     IAbiEncoder abiEncoder,
     IRlpDecoder <DataAsset> dataAssetRlpDecoder,
     IDepositService depositService,
     GasPriceService gasPriceService,
     TransactionService transactionService,
     INdmDataPublisher ndmDataPublisher,
     IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel,
     INdmConsumerChannelManager ndmConsumerChannelManager,
     INdmBlockchainBridge blockchainBridge)
 {
     ConsumerAddress           = consumerAddress ?? throw new ArgumentNullException(nameof(consumerAddress));
     AbiEncoder                = abiEncoder ?? throw new ArgumentNullException(nameof(abiEncoder));
     DataAssetRlpDecoder       = dataAssetRlpDecoder ?? throw new ArgumentNullException(nameof(dataAssetRlpDecoder));
     DepositService            = depositService ?? throw new ArgumentNullException(nameof(depositService));
     GasPriceService           = gasPriceService ?? throw new ArgumentNullException(nameof(gasPriceService));
     TransactionService        = transactionService ?? throw new ArgumentNullException(nameof(transactionService));
     NdmDataPublisher          = ndmDataPublisher ?? throw new ArgumentNullException(nameof(ndmDataPublisher));
     JsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel ?? throw new ArgumentNullException(nameof(jsonRpcNdmConsumerChannel));
     NdmConsumerChannelManager = ndmConsumerChannelManager ?? throw new ArgumentNullException(nameof(ndmConsumerChannelManager));
     BlockchainBridge          = blockchainBridge ?? throw new ArgumentNullException(nameof(blockchainBridge));
 }
 public ConsumerDepositApprovalRocksRepository(IDb database, IRlpDecoder <DepositApproval> rlpDecoder)
 {
     _database   = database;
     _rlpDecoder = rlpDecoder;
 }
示例#11
0
 public PaymentClaimRocksRepository(IDb database, IRlpNdmDecoder <PaymentClaim> rlpDecoder)
 {
     _database   = database;
     _rlpDecoder = rlpDecoder ?? throw new ArgumentNullException(nameof(rlpDecoder));
 }
 public ProviderRocksRepository(IDb database, IRlpDecoder <DepositDetails> rlpDecoder)
 {
     _database   = database;
     _rlpDecoder = rlpDecoder;
 }
 public ConsumerSessionRocksRepository(IDb database, IRlpDecoder <ConsumerSession> rlpDecoder)
 {
     _database   = database;
     _rlpDecoder = rlpDecoder;
 }
示例#14
0
 public ReceiptRocksRepository(IDb database, IRlpDecoder <DataDeliveryReceiptDetails> rlpDecoder)
 {
     _database   = database;
     _rlpDecoder = rlpDecoder;
 }
示例#15
0
 public ConfigRocksRepository(IDb database, IRlpDecoder <NdmConfig> rlpDecoder)
 {
     _database   = database;
     _rlpDecoder = rlpDecoder;
 }
示例#16
0
 public EthRequestRocksRepository(IDb database, IRlpDecoder <EthRequest> rlpDecoder)
 {
     _database   = database;
     _rlpDecoder = rlpDecoder;
 }
 public ProviderDepositApprovalRocksRepository(IDb database, IRlpNdmDecoder <DepositApproval> rlpDecoder)
 {
     _database   = database;
     _rlpDecoder = rlpDecoder ?? throw new ArgumentNullException(nameof(rlpDecoder));
 }
 public ConsumerRocksRepository(IDb database, IRlpNdmDecoder <Consumer> rlpDecoder)
 {
     _database   = database;
     _rlpDecoder = rlpDecoder ?? throw new ArgumentNullException(nameof(rlpDecoder));
 }