src/path_call_builder.js

  1. import {CallBuilder} from './call_builder';
  2. /**
  3. * The DigitalBits Network allows payments to be made across assets through path payments. A path payment specifies a
  4. * series of assets to route a payment through, from source asset (the asset debited from the payer) to destination
  5. * asset (the asset credited to the payee).
  6. *
  7. * A path search is specified using:
  8. *
  9. * * The destination address
  10. * * The source address
  11. * * The asset and amount that the destination account should receive
  12. *
  13. * As part of the search, frontier will load a list of assets available to the source address and will find any
  14. * payment paths from those source assets to the desired destination asset. The search's amount parameter will be
  15. * used to determine if there a given path can satisfy a payment of the desired amount.
  16. *
  17. * Do not create this object directly, use {@link Server#paths}.
  18. * @see [Find Payment Paths](https://developer.digitalbits.io/frontier/reference/path-finding.html)
  19. * @param {string} serverUrl Frontier server URL.
  20. * @param {string} source The sender's account ID. Any returned path must use a source that the sender can hold.
  21. * @param {string} destination The destination account ID that any returned path should use.
  22. * @param {Asset} destinationAsset The destination asset.
  23. * @param {string} destinationAmount The amount, denominated in the destination asset, that any returned path should be able to satisfy.
  24. */
  25. export class PathCallBuilder extends CallBuilder {
  26. constructor(serverUrl, source, destination, destinationAsset, destinationAmount) {
  27. super(serverUrl);
  28. this.url.segment('paths');
  29. this.url.addQuery('destination_account', destination);
  30. this.url.addQuery('source_account', source);
  31. this.url.addQuery('destination_amount', destinationAmount);
  32. if (!destinationAsset.isNative()) {
  33. this.url.addQuery('destination_asset_type', destinationAsset.getAssetType());
  34. this.url.addQuery('destination_asset_code', destinationAsset.getCode());
  35. this.url.addQuery('destination_asset_issuer', destinationAsset.getIssuer());
  36. } else {
  37. this.url.addQuery('destination_asset_type', 'native');
  38. }
  39. }
  40. }