Exemplo n.º 1
0
 public async Task <IBlockchainOperation> CreateVASPContractAsync(
     Address from,
     VASPCode vaspCode,
     Address owner,
     Channels channels,
     TransportKey transportKey,
     MessageKey messageKey,
     SigningKey signingKey,
     ConfirmationLevel minimalConfirmationLevel = default)
 {
     return(await SendTransactionAsync
            (
                from,
                new CreateVASPContractTransaction
     {
         VASPCode = vaspCode,
         Owner = owner,
         Channels = channels,
         TransportKey = transportKey,
         MessageKey = messageKey,
         SigningKey = signingKey
     },
                minimalConfirmationLevel
            ));
 }
        public override async Task <string> GetCredentialsAsync(
            VASPId vaspId,
            VASPCredentialsRef vaspCredentialsRef,
            ConfirmationLevel minimalConfirmationLevel = default)
        {
            var vaspCredentialsRefString = vaspCredentialsRef.ToString();

            if (!_vaspCredentialsRefRegex.IsMatch(vaspCredentialsRefString))
            {
                throw new FormatException("Specified VASP credentials ref is not properly formatted to be used with a VASP directory.");
            }

            var credentialsInsertedEventHandler = Web3.Eth.GetEvent <CredentialsInsertedEvent>(ContractAddress);
            var credentialsInsertedEventFilter  = credentialsInsertedEventHandler.CreateFilterInput
                                                  (
                firstIndexedParameterValue: (byte[])vaspId,
                secondIndexedParameterValue: vaspCredentialsRefString.HexToByteArray(),
                fromBlock: BlockParameter.CreateEarliest(),
                toBlock: await Web3.GetBestTrustedBlockAsync(minimalConfirmationLevel)
                                                  );

            var latestCredentials = (await credentialsInsertedEventHandler.GetAllChanges(credentialsInsertedEventFilter))
                                    .OrderBy(x => x.Log.BlockNumber)
                                    .Select(x => x.Event.Credentials)
                                    .LastOrDefault() ?? string.Empty;

            return(latestCredentials);
        }
Exemplo n.º 3
0
 public async Task <VASPCode> GetVASPCodeAsync(
     ConfirmationLevel minimalConfirmationLevel = default)
 {
     return(await GetVASPCodeAsync
            (
                await Web3.GetBestTrustedBlockAsync(minimalConfirmationLevel)
            ));
 }
Exemplo n.º 4
0
 public async Task <TransportKey> GetTransportKeyAsync(
     ConfirmationLevel minimalConfirmationLevel = default)
 {
     return(await GetTransportKeyAsync
            (
                await Web3.GetBestTrustedBlockAsync(minimalConfirmationLevel)
            ));
 }
Exemplo n.º 5
0
 public async Task <Channels> GetChannelsAsync(
     ConfirmationLevel minimalConfirmationLevel = default)
 {
     return(await GetChannelsAsync
            (
                await Web3.GetBestTrustedBlockAsync(minimalConfirmationLevel)
            ));
 }
        public static async Task <bool> VASPIsRegisteredAsync(
            this IVASPIndexClient vaspIndex,
            VASPCode vaspCode,
            ConfirmationLevel minimalConfirmationLevel = default)
        {
            var vaspContractAddress = await vaspIndex.GetVASPContractAddressAsync(vaspCode, minimalConfirmationLevel);

            return(!Address.IsEmpty(vaspContractAddress));
        }
Exemplo n.º 7
0
 internal BlockchainOperation(
     BlockchainOperationId id,
     IWeb3 web3,
     ConfirmationLevel minimalConfirmationLevel = default)
 {
     _minimalConfirmationLevel = minimalConfirmationLevel;
     _web3 = web3;
     Id    = id;
 }
        public static async Task <bool> VASPIsRegisteredAsync(
            this IVASPDirectoryClient vaspDirectory,
            VASPId vaspId,
            ConfirmationLevel minimalConfirmationLevel = default)
        {
            var refAndHash = await vaspDirectory.GetCredentialsRefAndHashAsync(vaspId, minimalConfirmationLevel);

            return(VASPIsRegistered(refAndHash));
        }
Exemplo n.º 9
0
 protected async Task <TResult> CallWithSimpleResultAsync <TQuery, TResult>(
     CallDefinition <TQuery, TResult> callDefinition,
     ConfirmationLevel minimalConfirmationLevel)
     where TQuery : CallDefinition <TQuery, TResult>, new()
 {
     return(await CallWithSimpleResultAsync
            (
                callDefinition,
                await Web3.GetBestTrustedBlockAsync(minimalConfirmationLevel)
            ));
 }
        public static async Task <(bool VASPIsRegistered, VASPCode VASPCode)> TryGetVASPCodeAsync(
            this IVASPIndexClient vaspIndex,
            Address vaspContractAddress,
            ConfirmationLevel minimalConfirmationLevel = default)
        {
            var vaspCode = await vaspIndex.GetVASPCodeAsync(vaspContractAddress, minimalConfirmationLevel);

            var vaspIsRegistered = !VASPCode.IsEmpty(vaspCode);

            return(vaspIsRegistered, vaspCode);
        }
Exemplo n.º 11
0
        public async Task <VASPCode> GetVASPCodeAsync(
            Address vaspContractAddress,
            ConfirmationLevel minimalConfirmationLevel = default)
        {
            var callResult = await CallWithSimpleResultAsync
                             (
                new GetVASPCodeByAddressCall { VASPAddress = vaspContractAddress },
                minimalConfirmationLevel
                             );

            return(new VASPCode(callResult));
        }
Exemplo n.º 12
0
        public async Task <Address> GetVASPContractAddressAsync(
            VASPCode vaspCode,
            ConfirmationLevel minimalConfirmationLevel = default)
        {
            var callResult = await CallWithSimpleResultAsync
                             (
                new GetVASPAddressByCodeCall { VASPCode = vaspCode },
                minimalConfirmationLevel
                             );

            return(Address.Parse(callResult));
        }
        public static async Task <(bool VASPIsRegistered, string Credentials)> TryGetCredentialsAsync(
            this IVASPDirectoryClient vaspDirectory,
            VASPId vaspId,
            ConfirmationLevel minimalConfirmationLevel = default)
        {
            var(vaspIsRegistered, (@ref, _)) =
                await vaspDirectory.TryGetCredentialsRefAndHashAsync(vaspId, minimalConfirmationLevel);

            var credentials =
                vaspIsRegistered ? await vaspDirectory.GetCredentialsAsync(vaspId, @ref, minimalConfirmationLevel) : string.Empty;

            return(vaspIsRegistered, credentials);
        }
        public override async Task <VASPCredentialsRefAndHash> GetCredentialsRefAndHashAsync(
            VASPId vaspId,
            ConfirmationLevel minimalConfirmationLevel = default)
        {
            var vaspCredentialsRefAndHash = await base.GetCredentialsRefAndHashAsync(vaspId, minimalConfirmationLevel);

            var(@ref, hash) = vaspCredentialsRefAndHash;

            if (VASPCredentialsRef.IsEmpty(@ref) != VASPCredentialsHash.IsEmpty(hash))
            {
                throw new Exception("Smart contract returned an unexpected combination of VASP credentials reference and hash.");
            }

            return(vaspCredentialsRefAndHash);
        }
        public virtual async Task <VASPCredentialsRefAndHash> GetCredentialsRefAndHashAsync(
            VASPId vaspId,
            ConfirmationLevel minimalConfirmationLevel = default)
        {
            var callResult = await CallWithComplexResultAsync
                             (
                new GetCredentialsRefCall { VASPId = vaspId },
                minimalConfirmationLevel
                             );

            return(new VASPCredentialsRefAndHash
                   (
                       new VASPCredentialsHash(callResult.CredentialsHashBytes),
                       new VASPCredentialsRef(callResult.CredentialsRefString)
                   ));
        }
Exemplo n.º 16
0
        protected async Task <BlockchainOperation> SendTransactionAsync <TParameters>(
            Address from,
            TransactionDefinition <TParameters> transactionDefinition,
            ConfirmationLevel minimalConfirmationLevel)
            where TParameters : TransactionDefinition <TParameters>, new()
        {
            var transactionInput = await Web3.Eth
                                   .GetContractTransactionHandler <TParameters>()
                                   .CreateTransactionInputEstimatingGasAsync
                                   (
                ContractAddress,
                (TParameters)transactionDefinition
                                   );

            transactionInput.From     = from;
            transactionInput.GasPrice = new HexBigInteger(await EstimateGasPriceStrategy.ExecuteAsync());

            string transactionHash;

            if (Web3.TransactionManager.Account != null)
            {
                var signedTransaction = await Web3.TransactionManager
                                        .SignTransactionAsync(transactionInput);

                transactionHash = await Web3.Eth.Transactions
                                  .SendRawTransaction
                                  .SendRequestAsync(signedTransaction);
            }
            else
            {
                transactionHash = await Web3.Eth.Transactions
                                  .SendTransaction
                                  .SendRequestAsync(transactionInput);
            }

            var blockchainOperationId = BlockchainOperationId.Parse(transactionHash);

            return(new BlockchainOperation(blockchainOperationId, Web3, minimalConfirmationLevel));
        }
Exemplo n.º 17
0
        public async Task <VASPInfo> GetVASPInfoAsync(
            ConfirmationLevel minimalConfirmationLevel = default)
        {
            var block = await Web3.GetBestTrustedBlockAsync(minimalConfirmationLevel);

            var getChannels     = GetChannelsAsync(block);
            var getVASPCode     = GetVASPCodeAsync(block);
            var getMessageKey   = GetMessageKeyAsync(block);
            var getSigningKey   = GetSigningKeyAsync(block);
            var getTransportKey = GetTransportKeyAsync(block);

            await Task.WhenAll(getChannels, getVASPCode, getMessageKey, getSigningKey, getTransportKey);

            return(new VASPInfo
                   (
                       channels: getChannels.Result,
                       vaspCode: getVASPCode.Result,
                       messageKey: getMessageKey.Result,
                       signingKey: getSigningKey.Result,
                       transportKey: getTransportKey.Result
                   ));
        }
Exemplo n.º 18
0
 public IBlockchainOperation GetOperation(
     BlockchainOperationId operationId,
     ConfirmationLevel minimalConfirmationLevel = default)
 {
     return(new BlockchainOperation(operationId, _web3, minimalConfirmationLevel));
 }
 public abstract Task <string> GetCredentialsAsync(
     VASPId vaspId,
     VASPCredentialsRef vaspCredentialsRef,
     ConfirmationLevel minimalConfirmationLevel = default);