private async Task <SmartContractRegistration> GetSmartContractRegistrationFromZeroAsync(
            IExecutive executiveZero, IChainContext chainContext, Address address)
        {
            var transaction = new Transaction()
            {
                From       = _defaultContractZeroCodeProvider.ContractZeroAddress,
                To         = _defaultContractZeroCodeProvider.ContractZeroAddress,
                MethodName = "GetSmartContractRegistrationByAddress",
                Params     = address.ToByteString()
            };


            var txContext = _transactionContextFactory.Create(transaction, chainContext);

            await executiveZero.ApplyAsync(txContext);

            var returnBytes = txContext.Trace?.ReturnValue;

            if (returnBytes != null && returnBytes != ByteString.Empty)
            {
                return(SmartContractRegistration.Parser.ParseFrom(returnBytes));
            }

            throw new SmartContractFindRegistrationException(
                      $"failed to find registration from zero contract {txContext.Trace.Error}");
        }
Exemplo n.º 2
0
        public async Task <TransactionTrace> ExecuteAsync(IChainContext chainContext, Transaction transaction,
                                                          Timestamp currentBlockTime)
        {
            var transactionContext = _transactionContextFactory.Create(transaction, chainContext, currentBlockTime);
            var executive          = await _smartContractExecutiveService.GetExecutiveAsync(
                chainContext, transaction.To);

            try
            {
                await executive.ApplyAsync(transactionContext);
            }
            finally
            {
                await _smartContractExecutiveService.PutExecutiveAsync(chainContext, transaction.To, executive);
            }

            return(transactionContext.Trace);
        }
Exemplo n.º 3
0
        protected ITransactionContext CreateTransactionContext(SingleTransactionExecutingDto singleTxExecutingDto)
        {
            if (singleTxExecutingDto.Transaction.To == null || singleTxExecutingDto.Transaction.From == null)
            {
                throw new Exception($"error tx: {singleTxExecutingDto.Transaction}");
            }


            var origin = singleTxExecutingDto.Origin != null
                ? singleTxExecutingDto.Origin
                : singleTxExecutingDto.Transaction.From;

            var txContext = _transactionContextFactory.Create(singleTxExecutingDto.Transaction,
                                                              singleTxExecutingDto.ChainContext, singleTxExecutingDto.OriginTransactionId, origin,
                                                              singleTxExecutingDto.Depth, singleTxExecutingDto.CurrentBlockTime);

            return(txContext);
        }