Exemplo n.º 1
0
        public static IExtrinsicCall ContractCall(this BackgroundService service, IApplication application,
                                                  Func <IContractCallParameter> contractParameter)
        {
            var parameter = contractParameter();
            var call      = CallCall.Create(0, 200000000000, parameter, application.Serializer);

            return(call);
        }
        private Func <MarketplaceDbContext, ValueTask>?HandleContractCall(CallCall callCall, PublicKey sender)
        {
            if (!callCall.Dest.Bytes.SequenceEqual(_configuration.MatcherContractPublicKey.Bytes))
            {
                return(null);
            }

            return(callCall.Parameters switch
            {
                AskParameter a => HandleAsk(a, sender),
                BuyParameter b => HandleBuy(b, sender),
                CancelParameter c => HandleCancel(c, sender),
                WithdrawParameter w => HandleWithdraw(w, sender),
                _ => null
            });
        protected override IEnumerable <ExtrinsicHandler> ProcessExtrinsics(IEnumerable <DeserializedExtrinsic> extrinsics, ulong blockNumber, CancellationToken stoppingToken)
        {
            foreach (var extrinsic in extrinsics)
            {
                Func <MarketplaceDbContext, ValueTask>?handler = extrinsic.Extrinsic.Call.Call switch
                {
                    CallCall c => HandleContractCall(c, extrinsic.Extrinsic.Prefix.Value.AsT1.Address.PublicKey),
                    TransferCall t => HandleTransfer(t, extrinsic.Extrinsic.Prefix.Value.AsT1.Address.PublicKey, blockNumber),
                    _ => null
                };

                if (handler != null)
                {
                    yield return(new ExtrinsicHandler()
                    {
                        OnSaveToDb = handler,
                        OnAfterSaveToDb = () => _eventBusService.PublishRegisterNft(stoppingToken),
                    });
                }
            }
        }