Skip to content
Snippets Groups Projects
atomic_swap.dart 4.75 KiB
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i5;
import 'dart:typed_data' as _i6;

import 'package:polkadart/polkadart.dart' as _i1;
import 'package:polkadart/scale_codec.dart' as _i4;

import '../types/gdev_runtime/runtime_call.dart' as _i7;
import '../types/pallet_atomic_swap/balance_swap_action.dart' as _i8;
import '../types/pallet_atomic_swap/pallet/call.dart' as _i9;
import '../types/pallet_atomic_swap/pending_swap.dart' as _i3;
import '../types/sp_core/crypto/account_id32.dart' as _i2;

class Queries {
  const Queries(this.__api);

  final _i1.StateApi __api;

  final _i1.StorageDoubleMap<_i2.AccountId32, List<int>, _i3.PendingSwap>
      _pendingSwaps =
      const _i1.StorageDoubleMap<_i2.AccountId32, List<int>, _i3.PendingSwap>(
    prefix: 'AtomicSwap',
    storage: 'PendingSwaps',
    valueCodec: _i3.PendingSwap.codec,
    hasher1: _i1.StorageHasher.twoxx64Concat(_i2.AccountId32Codec()),
    hasher2: _i1.StorageHasher.blake2b128Concat(_i4.U8ArrayCodec(32)),
  );

  _i5.Future<_i3.PendingSwap?> pendingSwaps(
    _i2.AccountId32 key1,
    List<int> key2, {
    _i1.BlockHash? at,
  }) async {
    final hashedKey = _pendingSwaps.hashedKeyFor(
      key1,
      key2,
    );
    final bytes = await __api.getStorage(
      hashedKey,
      at: at,
    );
    if (bytes != null) {
      return _pendingSwaps.decodeValue(bytes);
    }
    return null; /* Nullable */
  }

  /// Returns the storage key for `pendingSwaps`.
  _i6.Uint8List pendingSwapsKey(
    _i2.AccountId32 key1,
    List<int> key2,
  ) {
    final hashedKey = _pendingSwaps.hashedKeyFor(
      key1,
      key2,
    );
    return hashedKey;
  }

  /// Returns the storage map key prefix for `pendingSwaps`.
  _i6.Uint8List pendingSwapsMapPrefix(_i2.AccountId32 key1) {
    final hashedKey = _pendingSwaps.mapPrefix(key1);
    return hashedKey;
  }
}

class Txs {
  const Txs();

  /// Register a new atomic swap, declaring an intention to send funds from origin to target