transferPreCombine method

Future<ConstructionPayloadsResponse> transferPreCombine(
  1. Uint8List srcPub,
  2. Uint8List destAddr,
  3. BigInt count,
  4. BigInt? maxFee,
  5. Map<String, dynamic>? opt,
)

Implementation

Future<rosetta.ConstructionPayloadsResponse> transferPreCombine(
  Uint8List srcPub,
  Uint8List destAddr,
  BigInt count,
  BigInt? maxFee,
  Map<String, dynamic>? opt,
) async {
  assert(networkIdentifier != null, 'Cannot get networkIdentifier.');

  final netId = networkIdentifier;
  final oper1 = rosetta.Operation.fromJson(
    {
      'operation_identifier': const {'index': 0},
      'type': 'TRANSACTION',
      'account': {
        'address': getAccountIdFromEd25519PublicKey(srcPub).toHex(),
      },
      'amount': {
        'value': '-${count.toRadixString(10)}',
        'currency': currency?.toJson(),
      },
    },
  ).toJson();
  final oper2 = rosetta.Operation.fromJson(
    {
      'operation_identifier': const {'index': 1},
      'type': 'TRANSACTION',
      'account': {'address': crc32Add(destAddr).toHex()},
      'amount': {
        'value': count.toRadixString(10),
        'currency': currency?.toJson(),
      },
    },
  ).toJson();
  final oper3 = rosetta.Operation.fromJson(
    {
      'operation_identifier': const {'index': 2},
      'type': 'FEE',
      'account': {
        'address': getAccountIdFromEd25519PublicKey(srcPub).toHex(),
      },
      'amount': {
        'value':
            '-${maxFee?.toRadixString(10) ?? suggestedFee?.toRadixString(10)}',
        'currency': currency?.toJson(),
      },
    },
  ).toJson();
  final metaResult = await metadata(
    rosetta.ConstructionMetadataRequest.fromJson(
      {'network_identifier': netId?.toJson()},
    ),
  );
  final meta = {...metaResult.metadata, ...?opt};

  final request = rosetta.ConstructionPayloadsRequest.fromJson({
    'network_identifier': netId?.toJson(),
    'operations': [oper1, oper2, oper3],
    'metadata': meta,
    'public_keys': [
      {'hex_bytes': srcPub.toHex(), 'curve_type': 'edwards25519'},
    ],
  });
  return payloads(request);
}