Пример #1
0
        public async Task <Result <decimal> > GetFa12AllowanceAsync(
            string holderAddress,
            string spenderAddress,
            string callingAddress,
            SecureBytes securePublicKey,
            CancellationToken cancellationToken = default)
        {
            var tokenConfig = _currency as Fa12Config;

            try
            {
                var rpc = new Rpc(_rpcNodeUri);

                var tx = new TezosTransaction
                {
                    Currency     = tokenConfig.Name,
                    From         = callingAddress,
                    To           = tokenConfig.TokenContractAddress,
                    Fee          = 0,      //token.GetAllowanceFee,
                    GasLimit     = tokenConfig.GetAllowanceGasLimit,
                    StorageLimit = 0,      //token.GetAllowanceStorageLimit,
                    Params       = CreateGetAllowanceParams(holderAddress, spenderAddress, tokenConfig.ViewContractAddress),

                    UseRun            = false,
                    UseOfflineCounter = false
                };

                _ = await tx
                    .FillOperationsAsync(
                    securePublicKey : securePublicKey,
                    tezosConfig : tokenConfig,
                    cancellationToken : cancellationToken)
                    .ConfigureAwait(false);

                var runResults = await rpc
                                 .RunOperations(tx.Head, tx.Operations)
                                 .ConfigureAwait(false);

                return(runResults
                    ?["contents"]
                       ?.LastOrDefault()
                    ?["metadata"]
                    ?["internal_operation_results"]
                    ?[0]
                    ?["result"]
                    ?["errors"]
                    ?[1]
                    ?["with"]
                    ?["args"]
                    ?[0]
                    ?["args"]
                    ?[0]
                    ?["int"]
                       ?.Value <decimal>() ?? 0);
            }
            catch (Exception e)
            {
                return(new Error(Errors.RequestError, e.Message));
            }
        }
Пример #2
0
        public async Task <Result <decimal> > GetTokenAllowanceAsync(
            string holderAddress,
            string spenderAddress,
            string callingAddress,
            SecureBytes securePublicKey,
            CancellationToken cancellationToken = default)
        {
            var token = _currency as TezosTokens.FA12;

            try
            {
                var rpc = new Rpc(_rpcNodeUri);

                var head = await rpc
                           .GetHeader()
                           .ConfigureAwait(false);

                var tx = new TezosTransaction
                {
                    Currency     = token,
                    From         = callingAddress,
                    To           = token.TokenContractAddress,
                    Fee          = 0, //token.GetAllowanceFee,
                    GasLimit     = token.GetAllowanceGasLimit,
                    StorageLimit = 0, //token.GetAllowanceStorageLimit,
                    Params       = GetAllowanceParams(holderAddress, spenderAddress, token.ViewContractAddress),
                };

                await tx.FillOperationsAsync(
                    head : head,
                    securePublicKey : securePublicKey,
                    incrementCounter : false,
                    cancellationToken : cancellationToken)
                .ConfigureAwait(false);

                var runResults = await rpc
                                 .RunOperations(head, tx.Operations)
                                 .ConfigureAwait(false);

                Log.Debug("getTokenAllowance result {@result}", runResults);

                return(runResults?["contents"]?.LastOrDefault()?["metadata"]?["internal_operation_results"]?[0]?["result"]?["errors"]?[1]?["with"]?["args"]?[0]?["args"]?[0]?["int"]?.Value <decimal>());
            }
            catch (Exception e)
            {
                return(new Error(Errors.RequestError, e.Message));
            }
        }