subscribeToOracleUpdates method

Future<ArchethicOracle> subscribeToOracleUpdates(
  1. dynamic onUpdate(
    1. OracleUcoPrice?
    )
)

Subscribe to be notified when a new oracle data is stored

Implementation

Future<ArchethicOracle> subscribeToOracleUpdates(
  Function(OracleUcoPrice?) onUpdate,
) async {
  String websocketEndpoint;
  switch (endpoint) {
    case 'https://mainnet.archethic.net':
    case 'https://testnet.archethic.net':
      websocketEndpoint =
          "${endpoint!.replaceAll('https:', 'wss:').replaceAll('http:', 'wss:')}/socket/websocket";
      break;
    default:
      websocketEndpoint =
          "${endpoint!.replaceAll('https:', 'wss:').replaceAll('http:', 'ws:')}/socket/websocket";
      break;
  }

  final oracleRepository = ArchethicOracle(
    phoenixHttpEndpoint: '$endpoint/socket/websocket',
    websocketEndpoint: websocketEndpoint,
  );

  await oracleRepository.subscribeToOracleUpdates(
    onUpdate: onUpdate,
  );

  return oracleRepository;
}