Skip to content
Snippets Groups Projects
Select Git revision
  • 3dbc519def3eb77dd7e1843e98ec43c19e1f839b
  • master default protected
  • tuxmain/fix-change-owner-key
  • fix_picked_up_file_in_runtime_release
  • network/gtest-1000 protected
  • upgradable-multisig
  • runtime/gtest-1000
  • network/gdev-800 protected
  • cgeek/issue-297-cpu
  • gdev-800-tests
  • update-docker-compose-rpc-squid-names
  • fix-252
  • 1000i100-test
  • hugo/tmp-0.9.1
  • network/gdev-803 protected
  • hugo/endpoint-gossip
  • network/gdev-802 protected
  • hugo/distance-precompute
  • network/gdev-900 protected
  • tuxmain/anonymous-tx
  • debug/podman
  • gtest-1000-0.11.1 protected
  • gtest-1000-0.11.0 protected
  • gtest-1000 protected
  • gdev-900-0.10.1 protected
  • gdev-900-0.10.0 protected
  • gdev-900-0.9.2 protected
  • gdev-800-0.8.0 protected
  • gdev-900-0.9.1 protected
  • gdev-900-0.9.0 protected
  • gdev-803 protected
  • gdev-802 protected
  • runtime-801 protected
  • gdev-800 protected
  • runtime-800-bis protected
  • runtime-800 protected
  • runtime-800-backup protected
  • runtime-701 protected
  • runtime-700 protected
  • runtime-600 protected
  • runtime-500 protected
41 results

apis.rs

Blame
    • Benjamin Gallois's avatar
      211ba93c
      Upgrade Polkadot-v1.6.0 (nodes/rust/duniter-v2s!236) · 211ba93c
      Benjamin Gallois authored and Hugo Trentesaux's avatar Hugo Trentesaux committed
      * version 1.0
      
      * add Cargo.lock tweak explanation
      
      * remove artefact file
      
      * format tomls
      
      * fix benchmarks in ci
      
      * harmonize quotes
      
      * fix features propagation
      
      * tweak Cargo.lock
      
      * fix version field missing for srtool
      
      * fix rebase errors
      
      * refactor workspace
      
      * upgrade genesis builder
      
      * upgrade cucumber
      
      * update to benchmarking v2
      211ba93c
      History
      Upgrade Polkadot-v1.6.0 (nodes/rust/duniter-v2s!236)
      Benjamin Gallois authored and Hugo Trentesaux's avatar Hugo Trentesaux committed
      * version 1.0
      
      * add Cargo.lock tweak explanation
      
      * remove artefact file
      
      * format tomls
      
      * fix benchmarks in ci
      
      * harmonize quotes
      
      * fix features propagation
      
      * tweak Cargo.lock
      
      * fix version field missing for srtool
      
      * fix rebase errors
      
      * refactor workspace
      
      * upgrade genesis builder
      
      * upgrade cucumber
      
      * update to benchmarking v2
    gva.dart 4.26 KiB
    import 'package:bip32_ed25519/api.dart';
    import 'package:durt/src/gva/queries.dart';
    import 'package:durt/src/gva/transaction.dart';
    import 'package:graphql/client.dart';
    
    class Gva {
      final GraphQLClient _client;
      Gva._(this._client);
    
      /// Main constructor for GVA query object
      factory Gva({required String node}) {
        final _httpLink = HttpLink(node);
    
        final GraphQLClient client = GraphQLClient(
          cache: GraphQLCache(),
          link: _httpLink,
        );
    
        return Gva._(client);
      }
    
      /// Return the balance from a given pubkey, or 0 if null.
      Future<double> balance(String pubkey, {bool ud = false}) async {
        double balance = 0;
    
        final QueryOptions options = QueryOptions(
          document: gql(getBalanceQuery),
          variables: <String, dynamic>{
            'pubkey': pubkey,
          },
        );
        final QueryResult result = await _client.query(options);
    
        if (result.hasException) {
          print(result.exception.toString());
          throw Exception('Unexpected error happened in graphql request');
        } else if (result.data?['balance'] != null) {
          balance = result.data!['balance']['amount'] / 100;
          if (ud) {
            double currentUd = result.data!['currentUd']['amount'] / 100;
            balance = balance / currentUd;
          }
        }
    
        return balance.toPrecision(2);
      }
    
      /// Return the username from a given pubkey.
      Future<String> getUsername(String pubkey) async {
        String username = '';
    
        final QueryOptions options = QueryOptions(
          document: gql(getIdQuery),
          variables: <String, dynamic>{
            'pubkey': pubkey,
          },
        );
        final QueryResult result = await _client.query(options);
    
        if (result.hasException) {
          print(result.exception.toString());
          throw Exception('Unexpected error happened in graphql request');
        } else if (result.data?['idty']?['username'] != null) {
          username = result.data!['idty']['username'];
        }
    
        return username;
      }
    
      /// Return the username from a given pubkey.