diff --git a/lib/src/sep/0001/stellar_toml.dart b/lib/src/sep/0001/stellar_toml.dart
index 6f389e2..057cc45 100644
--- a/lib/src/sep/0001/stellar_toml.dart
+++ b/lib/src/sep/0001/stellar_toml.dart
@@ -8,8 +8,6 @@ import 'dart:developer';
import 'package:http/http.dart' as http;
import 'package:toml/toml.dart';
-import '../../requests/request_builder.dart';
-
/// Parses the stellar toml data from a given string or from a given domain.
/// See Stellar Toml
/// Supported Version: 2.5.0
@@ -176,12 +174,10 @@ class StellarToml {
}
static Future fromDomain(String domain,
- {http.Client? httpClient}) async {
+ {http.Client? httpClient, Map? httpRequestHeaders}) async {
Uri uri = Uri.parse("https://" + domain + "/.well-known/stellar.toml");
http.Client client = httpClient == null ? http.Client() : httpClient;
- return await client
- .get(uri, headers: RequestBuilder.headers)
- .then((response) {
+ return await client.get(uri, headers: httpRequestHeaders).then((response) {
if (response.statusCode != 200) {
throw Exception(
"Stellar toml not found, response status code ${response.statusCode}");
@@ -192,12 +188,13 @@ class StellarToml {
/// Alternately to specifying a currency in its content, stellar.toml can link out to a separate TOML file for the currency by specifying toml="https://DOMAIN/.well-known/CURRENCY.toml" as the currency's only field.
/// In this case you can use this method to load the currency data from the received link (Currency.toml).
- static Future currencyFromUrl(String toml) async {
+ static Future currencyFromUrl(String toml,
+ {http.Client? httpClient, Map? httpRequestHeaders}) async {
Uri uri = Uri.parse(toml);
- return await http.Client()
- .get(uri, headers: RequestBuilder.headers)
- .then((response) {
+ http.Client client = httpClient == null ? http.Client() : httpClient;
+
+ return await client.get(uri, headers: httpRequestHeaders).then((response) {
if (response.statusCode != 200) {
throw Exception(
"Currency toml not found, response status code ${response.statusCode}");
diff --git a/lib/src/sep/0002/federation.dart b/lib/src/sep/0002/federation.dart
index f219506..786430c 100644
--- a/lib/src/sep/0002/federation.dart
+++ b/lib/src/sep/0002/federation.dart
@@ -13,25 +13,31 @@ import '../../requests/request_builder.dart';
class Federation {
/// Resolves a stellar address such as bob*soneso.com.
/// Returns a [FederationResponse] object.
- static Future resolveStellarAddress(String address) async {
- String addr = address;
- if (!addr.contains("*")) {
- throw Exception("invalid federation address: $addr");
+ static Future resolveStellarAddress(String address,
+ {http.Client? httpClient,
+ Map? httpRequestHeaders}) async {
+ if (!address.contains("*")) {
+ throw Exception("invalid federation address: $address");
}
- String domain = addr.split("*").last;
- StellarToml toml = await StellarToml.fromDomain(domain);
+ String domain = address.split("*").last;
+ StellarToml toml = await StellarToml.fromDomain(domain,
+ httpClient: httpClient, httpRequestHeaders: httpRequestHeaders);
String? federationServer = toml.generalInformation.federationServer;
if (federationServer == null) {
throw Exception("no federation server found for domain $domain");
}
Uri serverURI = Uri.parse(federationServer);
- http.Client httpClient = http.Client();
-
- _FederationRequestBuilder requestBuilder = _FederationRequestBuilder(httpClient, serverURI);
- FederationResponse response =
- await requestBuilder.forStringToLookUp(addr).forType("name").execute();
+ http.Client client = httpClient == null ? http.Client() : httpClient;
+
+ _FederationRequestBuilder requestBuilder = _FederationRequestBuilder(
+ client, serverURI,
+ httpRequestHeaders: httpRequestHeaders);
+ FederationResponse response = await requestBuilder
+ .forStringToLookUp(address)
+ .forType("name")
+ .execute();
return response;
}
@@ -39,14 +45,19 @@ class Federation {
/// The url of the federation server has to be provided.
/// Returns a [FederationResponse] object.
static Future resolveStellarAccountId(
- String accountId, String federationServerUrl) async {
-
+ String accountId, String federationServerUrl,
+ {http.Client? httpClient,
+ Map? httpRequestHeaders}) async {
Uri serverURI = Uri.parse(federationServerUrl);
- http.Client httpClient = http.Client();
-
- _FederationRequestBuilder requestBuilder = _FederationRequestBuilder(httpClient, serverURI);
- FederationResponse response =
- await requestBuilder.forStringToLookUp(accountId).forType("id").execute();
+ http.Client client = httpClient == null ? http.Client() : httpClient;
+
+ _FederationRequestBuilder requestBuilder = _FederationRequestBuilder(
+ client, serverURI,
+ httpRequestHeaders: httpRequestHeaders);
+ FederationResponse response = await requestBuilder
+ .forStringToLookUp(accountId)
+ .forType("id")
+ .execute();
return response;
}
@@ -54,12 +65,15 @@ class Federation {
/// The url of the federation server has to be provided.
/// Returns a [FederationResponse] object.
static Future resolveStellarTransactionId(
- String txId, String federationServerUrl) async {
-
+ String txId, String federationServerUrl,
+ {http.Client? httpClient,
+ Map? httpRequestHeaders}) async {
Uri serverURI = Uri.parse(federationServerUrl);
- http.Client httpClient = http.Client();
+ http.Client client = httpClient == null ? http.Client() : httpClient;
- _FederationRequestBuilder requestBuilder = _FederationRequestBuilder(httpClient, serverURI);
+ _FederationRequestBuilder requestBuilder = _FederationRequestBuilder(
+ client, serverURI,
+ httpRequestHeaders: httpRequestHeaders);
FederationResponse response =
await requestBuilder.forStringToLookUp(txId).forType("txid").execute();
return response;
@@ -69,14 +83,19 @@ class Federation {
/// The url of the federation server and the forward query parameters have to be provided.
/// Returns a [FederationResponse] object.
static Future resolveForward(
- Map forwardQueryParameters, String federationServerUrl) async {
-
+ Map forwardQueryParameters, String federationServerUrl,
+ {http.Client? httpClient,
+ Map? httpRequestHeaders}) async {
Uri serverURI = Uri.parse(federationServerUrl);
- http.Client httpClient = http.Client();
-
- _FederationRequestBuilder requestBuilder = _FederationRequestBuilder(httpClient, serverURI);
- FederationResponse response =
- await requestBuilder.forType("forward").forQueryParameters(forwardQueryParameters).execute();
+ http.Client client = httpClient == null ? http.Client() : httpClient;
+
+ _FederationRequestBuilder requestBuilder = _FederationRequestBuilder(
+ client, serverURI,
+ httpRequestHeaders: httpRequestHeaders);
+ FederationResponse response = await requestBuilder
+ .forType("forward")
+ .forQueryParameters(forwardQueryParameters)
+ .execute();
return response;
}
}
@@ -89,25 +108,33 @@ class FederationResponse extends Response {
String? memoType;
String? memo;
- FederationResponse(this.stellarAddress, this.accountId, this.memoType, this.memo);
+ FederationResponse(
+ this.stellarAddress, this.accountId, this.memoType, this.memo);
- factory FederationResponse.fromJson(Map json) => FederationResponse(
- json['stellar_address'],
- json['account_id'],
- json['memo_type'] == null ? null : json['memo_type'],
- json['memo'] == null ? null : json['memo']);
+ factory FederationResponse.fromJson(Map json) =>
+ FederationResponse(
+ json['stellar_address'],
+ json['account_id'],
+ json['memo_type'] == null ? null : json['memo_type'],
+ json['memo'] == null ? null : json['memo']);
}
// Requests the federation data.
class _FederationRequestBuilder extends RequestBuilder {
- _FederationRequestBuilder(http.Client httpClient, Uri serverURI)
+ Map? httpRequestHeaders;
+
+ _FederationRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
Future federationURI(Uri uri) async {
TypeToken type = TypeToken();
- ResponseHandler responseHandler = ResponseHandler(type);
+ ResponseHandler responseHandler =
+ ResponseHandler(type);
- return await httpClient.get(uri, headers: RequestBuilder.headers).then((response) {
+ return await httpClient
+ .get(uri, headers: httpRequestHeaders)
+ .then((response) {
return responseHandler.handleResponse(response);
});
}
@@ -122,21 +149,31 @@ class _FederationRequestBuilder extends RequestBuilder {
return this;
}
- _FederationRequestBuilder forQueryParameters(Map queryParams) {
+ _FederationRequestBuilder forQueryParameters(
+ Map queryParams) {
queryParameters.addAll(queryParams);
return this;
}
- static Future requestExecute(http.Client httpClient, Uri uri) async {
+ static Future requestExecute(
+ http.Client httpClient, Uri uri,
+ {Map? httpRequestHeaders}) async {
TypeToken type = TypeToken();
- ResponseHandler responseHandler = ResponseHandler(type);
-
- return await httpClient.get(uri, headers: RequestBuilder.headers).then((response) {
+ ResponseHandler responseHandler =
+ ResponseHandler(type);
+
+ return await httpClient
+ .get(
+ uri,
+ headers: httpRequestHeaders,
+ )
+ .then((response) {
return responseHandler.handleResponse(response);
});
}
Future execute() {
- return _FederationRequestBuilder.requestExecute(this.httpClient, this.buildUri());
+ return _FederationRequestBuilder.requestExecute(
+ this.httpClient, this.buildUri());
}
}
diff --git a/lib/src/sep/0006/transfer_server_service.dart b/lib/src/sep/0006/transfer_server_service.dart
index ee9e4e3..37540db 100644
--- a/lib/src/sep/0006/transfer_server_service.dart
+++ b/lib/src/sep/0006/transfer_server_service.dart
@@ -11,25 +11,24 @@ import '../../util.dart';
/// See Deposit and Withdrawal API
class TransferServerService {
late String _transferServiceAddress;
- http.Client httpClient = http.Client();
+ late http.Client httpClient;
+ Map? httpRequestHeaders;
TransferServerService(this._transferServiceAddress,
- {http.Client? httpClient}) {
- if (httpClient != null) {
- this.httpClient = httpClient;
- } else {
- this.httpClient = http.Client();
- }
+ {http.Client? httpClient, this.httpRequestHeaders}) {
+ this.httpClient = httpClient == null ? http.Client() : httpClient;
}
static Future fromDomain(String domain,
- {http.Client? httpClient}) async {
- StellarToml toml =
- await StellarToml.fromDomain(domain, httpClient: httpClient);
+ {http.Client? httpClient,
+ Map? httpRequestHeaders}) async {
+ StellarToml toml = await StellarToml.fromDomain(domain,
+ httpClient: httpClient, httpRequestHeaders: httpRequestHeaders);
String? transferServer = toml.generalInformation.transferServer;
checkNotNull(transferServer,
"transfer server not found in stellar toml of domain " + domain);
- return TransferServerService(transferServer!, httpClient: httpClient);
+ return TransferServerService(transferServer!,
+ httpClient: httpClient, httpRequestHeaders: httpRequestHeaders);
}
/// Get basic info from the anchor about what their TRANSFER_SERVER supports.
@@ -42,8 +41,9 @@ class TransferServerService {
Future info({String? language, String? jwt}) async {
Uri serverURI = Util.appendEndpointToUrl(_transferServiceAddress, 'info');
- _InfoRequestBuilder requestBuilder =
- _InfoRequestBuilder(httpClient, serverURI);
+ _InfoRequestBuilder requestBuilder = _InfoRequestBuilder(
+ httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
final Map queryParams = {};
@@ -76,8 +76,11 @@ class TransferServerService {
Uri serverURI =
Util.appendEndpointToUrl(_transferServiceAddress, 'deposit');
- _DepositRequestBuilder requestBuilder =
- _DepositRequestBuilder(httpClient, serverURI);
+ _DepositRequestBuilder requestBuilder = _DepositRequestBuilder(
+ httpClient,
+ serverURI,
+ httpRequestHeaders: this.httpRequestHeaders,
+ );
final Map queryParams = {
"asset_code": request.assetCode,
@@ -152,8 +155,11 @@ class TransferServerService {
Uri serverURI =
Util.appendEndpointToUrl(_transferServiceAddress, 'deposit-exchange');
- _DepositRequestBuilder requestBuilder =
- _DepositRequestBuilder(httpClient, serverURI);
+ _DepositRequestBuilder requestBuilder = _DepositRequestBuilder(
+ httpClient,
+ serverURI,
+ httpRequestHeaders: this.httpRequestHeaders,
+ );
final Map queryParams = {
"destination_asset": request.destinationAsset,
@@ -233,8 +239,11 @@ class TransferServerService {
Uri serverURI =
Util.appendEndpointToUrl(_transferServiceAddress, 'withdraw');
- _WithdrawRequestBuilder requestBuilder =
- _WithdrawRequestBuilder(httpClient, serverURI);
+ _WithdrawRequestBuilder requestBuilder = _WithdrawRequestBuilder(
+ httpClient,
+ serverURI,
+ httpRequestHeaders: this.httpRequestHeaders,
+ );
final Map queryParams = {
"asset_code": request.assetCode,
@@ -315,8 +324,11 @@ class TransferServerService {
Uri serverURI =
Util.appendEndpointToUrl(_transferServiceAddress, 'withdraw-exchange');
- _WithdrawRequestBuilder requestBuilder =
- _WithdrawRequestBuilder(httpClient, serverURI);
+ _WithdrawRequestBuilder requestBuilder = _WithdrawRequestBuilder(
+ httpClient,
+ serverURI,
+ httpRequestHeaders: this.httpRequestHeaders,
+ );
final Map queryParams = {
"source_asset": request.sourceAsset,
@@ -402,8 +414,9 @@ class TransferServerService {
Future fee(FeeRequest request) async {
Uri serverURI = Util.appendEndpointToUrl(_transferServiceAddress, 'fee');
- _FeeRequestBuilder requestBuilder =
- _FeeRequestBuilder(httpClient, serverURI);
+ _FeeRequestBuilder requestBuilder = _FeeRequestBuilder(
+ httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
final Map queryParams = {
"operation": request.operation,
@@ -434,7 +447,11 @@ class TransferServerService {
Util.appendEndpointToUrl(_transferServiceAddress, 'transactions');
_AnchorTransactionsRequestBuilder requestBuilder =
- _AnchorTransactionsRequestBuilder(httpClient, serverURI);
+ _AnchorTransactionsRequestBuilder(
+ httpClient,
+ serverURI,
+ httpRequestHeaders: this.httpRequestHeaders,
+ );
final Map queryParams = {
"asset_code": request.assetCode,
@@ -476,7 +493,8 @@ class TransferServerService {
Util.appendEndpointToUrl(_transferServiceAddress, 'transaction');
_AnchorTransactionRequestBuilder requestBuilder =
- _AnchorTransactionRequestBuilder(httpClient, serverURI);
+ _AnchorTransactionRequestBuilder(httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
final Map queryParams = {};
@@ -501,13 +519,13 @@ class TransferServerService {
Future patchTransaction(
PatchTransactionRequest request) async {
-
checkNotNull(request.fields, "request.fields cannot be null");
Uri serverURI = Util.appendEndpointToUrl(
_transferServiceAddress, 'transactions/${request.id}');
_PatchTransactionRequestBuilder requestBuilder =
- _PatchTransactionRequestBuilder(httpClient, serverURI);
+ _PatchTransactionRequestBuilder(httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
http.Response response =
await requestBuilder.forFields(request.fields!).execute(request.jwt);
@@ -707,7 +725,10 @@ class ExtraInfo extends Response {
// Requests the deposit data.
class _DepositRequestBuilder extends RequestBuilder {
- _DepositRequestBuilder(http.Client httpClient, Uri serverURI)
+ Map? httpRequestHeaders;
+
+ _DepositRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_DepositRequestBuilder forQueryParameters(Map queryParams) {
@@ -716,13 +737,14 @@ class _DepositRequestBuilder extends RequestBuilder {
}
static Future requestExecute(
- http.Client httpClient, Uri uri, String? jwt) async {
+ http.Client httpClient, Uri uri, String? jwt,
+ {Map? httpRequestHeaders}) async {
TypeToken type = TypeToken();
ResponseHandler responseHandler =
ResponseHandler(type);
final Map depositHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
@@ -733,7 +755,8 @@ class _DepositRequestBuilder extends RequestBuilder {
Future execute(String? jwt) {
return _DepositRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), jwt);
+ this.httpClient, this.buildUri(), jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
@@ -1262,7 +1285,10 @@ class WithdrawResponse extends Response {
// Requests the withdraw data.
class _WithdrawRequestBuilder extends RequestBuilder {
- _WithdrawRequestBuilder(http.Client httpClient, Uri serverURI)
+ Map? httpRequestHeaders;
+
+ _WithdrawRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_WithdrawRequestBuilder forQueryParameters(Map queryParams) {
@@ -1271,13 +1297,14 @@ class _WithdrawRequestBuilder extends RequestBuilder {
}
static Future requestExecute(
- http.Client httpClient, Uri uri, String? jwt) async {
+ http.Client httpClient, Uri uri, String? jwt,
+ {Map? httpRequestHeaders}) async {
TypeToken type = TypeToken();
ResponseHandler responseHandler =
ResponseHandler(type);
final Map withdrawHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
return await httpClient.get(uri, headers: withdrawHeaders).then((response) {
@@ -1287,7 +1314,8 @@ class _WithdrawRequestBuilder extends RequestBuilder {
Future execute(String? jwt) {
return _WithdrawRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), jwt);
+ this.httpClient, this.buildUri(), jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
@@ -1691,7 +1719,10 @@ class InfoResponse extends Response {
// Requests the info data.
class _InfoRequestBuilder extends RequestBuilder {
- _InfoRequestBuilder(http.Client httpClient, Uri serverURI)
+ Map? httpRequestHeaders;
+
+ _InfoRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_InfoRequestBuilder forQueryParameters(Map queryParams) {
@@ -1700,13 +1731,14 @@ class _InfoRequestBuilder extends RequestBuilder {
}
static Future requestExecute(
- http.Client httpClient, Uri uri, String? jwt) async {
+ http.Client httpClient, Uri uri, String? jwt,
+ {Map? httpRequestHeaders}) async {
TypeToken type = TypeToken();
ResponseHandler responseHandler =
ResponseHandler(type);
final Map infoHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
return await httpClient.get(uri, headers: infoHeaders).then((response) {
@@ -1716,7 +1748,8 @@ class _InfoRequestBuilder extends RequestBuilder {
Future execute(String? jwt) {
return _InfoRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), jwt);
+ this.httpClient, this.buildUri(), jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
@@ -1759,7 +1792,10 @@ class FeeResponse extends Response {
// Requests the fee data.
class _FeeRequestBuilder extends RequestBuilder {
- _FeeRequestBuilder(http.Client httpClient, Uri serverURI)
+ Map? httpRequestHeaders;
+
+ _FeeRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_FeeRequestBuilder forQueryParameters(Map queryParams) {
@@ -1768,13 +1804,14 @@ class _FeeRequestBuilder extends RequestBuilder {
}
static Future requestExecute(
- http.Client httpClient, Uri uri, String? jwt) async {
+ http.Client httpClient, Uri uri, String? jwt,
+ {Map? httpRequestHeaders}) async {
TypeToken type = TypeToken();
ResponseHandler responseHandler =
ResponseHandler(type);
final Map feeHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
return await httpClient.get(uri, headers: feeHeaders).then((response) {
@@ -1784,7 +1821,8 @@ class _FeeRequestBuilder extends RequestBuilder {
Future execute(String? jwt) {
return _FeeRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), jwt);
+ this.httpClient, this.buildUri(), jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
@@ -2192,7 +2230,10 @@ class AnchorTransactionsResponse extends Response {
// Requests the transaction history data.
class _AnchorTransactionsRequestBuilder extends RequestBuilder {
- _AnchorTransactionsRequestBuilder(http.Client httpClient, Uri serverURI)
+ Map? httpRequestHeaders;
+
+ _AnchorTransactionsRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_AnchorTransactionsRequestBuilder forQueryParameters(
@@ -2202,14 +2243,15 @@ class _AnchorTransactionsRequestBuilder extends RequestBuilder {
}
static Future requestExecute(
- http.Client httpClient, Uri uri, String? jwt) async {
+ http.Client httpClient, Uri uri, String? jwt,
+ {Map? httpRequestHeaders}) async {
TypeToken type =
TypeToken();
ResponseHandler responseHandler =
ResponseHandler(type);
final Map atHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
return await httpClient.get(uri, headers: atHeaders).then((response) {
@@ -2219,7 +2261,8 @@ class _AnchorTransactionsRequestBuilder extends RequestBuilder {
Future execute(String? jwt) {
return _AnchorTransactionsRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), jwt);
+ this.httpClient, this.buildUri(), jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
@@ -2262,7 +2305,10 @@ class AnchorTransactionResponse extends Response {
// Requests the transaction data for a specific transaction.
class _AnchorTransactionRequestBuilder extends RequestBuilder {
- _AnchorTransactionRequestBuilder(http.Client httpClient, Uri serverURI)
+ Map? httpRequestHeaders;
+
+ _AnchorTransactionRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_AnchorTransactionRequestBuilder forQueryParameters(
@@ -2272,14 +2318,15 @@ class _AnchorTransactionRequestBuilder extends RequestBuilder {
}
static Future requestExecute(
- http.Client httpClient, Uri uri, String? jwt) async {
+ http.Client httpClient, Uri uri, String? jwt,
+ {Map? httpRequestHeaders}) async {
TypeToken type =
TypeToken();
ResponseHandler responseHandler =
ResponseHandler(type);
final Map atHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
return await httpClient.get(uri, headers: atHeaders).then((response) {
@@ -2289,7 +2336,8 @@ class _AnchorTransactionRequestBuilder extends RequestBuilder {
Future execute(String? jwt) {
return _AnchorTransactionRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), jwt);
+ this.httpClient, this.buildUri(), jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
@@ -2309,9 +2357,11 @@ class PatchTransactionRequest {
// Pending Transaction Info Update.
class _PatchTransactionRequestBuilder extends RequestBuilder {
+ Map? httpRequestHeaders;
late Map _fields;
- _PatchTransactionRequestBuilder(http.Client httpClient, Uri serverURI)
+ _PatchTransactionRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_PatchTransactionRequestBuilder forFields(Map fields) {
@@ -2319,10 +2369,11 @@ class _PatchTransactionRequestBuilder extends RequestBuilder {
return this;
}
- static Future requestExecute(http.Client httpClient, Uri uri,
- Map fields, String? jwt) async {
+ static Future requestExecute(
+ http.Client httpClient, Uri uri, Map fields, String? jwt,
+ {Map? httpRequestHeaders}) async {
final Map atHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
return await httpClient.patch(uri,
@@ -2331,6 +2382,7 @@ class _PatchTransactionRequestBuilder extends RequestBuilder {
Future execute(String? jwt) {
return _PatchTransactionRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), _fields, jwt);
+ this.httpClient, this.buildUri(), _fields, jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
diff --git a/lib/src/sep/0007/URIScheme.dart b/lib/src/sep/0007/URIScheme.dart
index a317f79..3640960 100644
--- a/lib/src/sep/0007/URIScheme.dart
+++ b/lib/src/sep/0007/URIScheme.dart
@@ -2,7 +2,6 @@ import 'dart:typed_data';
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../../sep/0001/stellar_toml.dart';
-import '../../requests/request_builder.dart';
import '../../responses/submit_transaction_response.dart';
import '../../stellar_sdk.dart';
import '../../transaction.dart';
@@ -35,7 +34,12 @@ class URIScheme {
static int messageMaxLength = 300;
- http.Client httpClient = new http.Client();
+ late http.Client httpClient;
+ Map? httpRequestHeaders;
+
+ URIScheme({http.Client? httpClient, this.httpRequestHeaders}) {
+ this.httpClient = httpClient ?? http.Client();
+ }
/// This function is used to generate a URIScheme compliant URL to serve
/// as a request to sign a transaction.
@@ -191,7 +195,7 @@ class URIScheme {
final String? callback = getParameterValue(callbackParameterName, url);
if (callback != null && callback.startsWith("url:")) {
final Uri serverURI = Uri.parse(callback.substring(4));
- Map headers = {...RequestBuilder.headers};
+ Map headers = {...(this.httpRequestHeaders ?? {})};
headers.putIfAbsent(
"Content-Type", () => "application/x-www-form-urlencoded");
String bodyStr = xdrParameterName +
@@ -260,7 +264,8 @@ class URIScheme {
StellarToml? toml;
try {
- toml = await StellarToml.fromDomain(originDomain, httpClient: httpClient);
+ toml = await StellarToml.fromDomain(originDomain, httpClient: httpClient,
+ httpRequestHeaders: this.httpRequestHeaders);
} on Exception catch (_) {
throw URISchemeError(URISchemeError.tomlNotFoundOrInvalid);
}
diff --git a/lib/src/sep/0008/regulated_assets.dart b/lib/src/sep/0008/regulated_assets.dart
index 091cf43..e15c0d2 100644
--- a/lib/src/sep/0008/regulated_assets.dart
+++ b/lib/src/sep/0008/regulated_assets.dart
@@ -9,14 +9,14 @@ class RegulatedAssetsService {
late Network network;
late StellarSDK sdk;
late List regulatedAssets;
+ Map? httpRequestHeaders;
RegulatedAssetsService(this.tomlData,
- {http.Client? httpClient, String? horizonUrl, Network? network}) {
- if (httpClient != null) {
- this.httpClient = httpClient;
- } else {
- this.httpClient = http.Client();
- }
+ {http.Client? httpClient,
+ this.httpRequestHeaders,
+ String? horizonUrl,
+ Network? network}) {
+ this.httpClient = httpClient ?? http.Client();
if (horizonUrl != null) {
this.sdk = StellarSDK(horizonUrl);
@@ -33,13 +33,11 @@ class RegulatedAssetsService {
throw IncompleteInitData('could not find a network passphrase');
}
- if (horizonUrl == null &&
- tomlData.generalInformation.horizonUrl != null) {
+ if (horizonUrl == null && tomlData.generalInformation.horizonUrl != null) {
this.sdk = StellarSDK(tomlData.generalInformation.horizonUrl!);
} else if (horizonUrl == null) {
// try to init from known horizon urls
- if (this.network.networkPassphrase ==
- Network.PUBLIC.networkPassphrase) {
+ if (this.network.networkPassphrase == Network.PUBLIC.networkPassphrase) {
this.sdk = StellarSDK.PUBLIC;
} else if (this.network.networkPassphrase ==
Network.TESTNET.networkPassphrase) {
@@ -69,10 +67,14 @@ class RegulatedAssetsService {
/// Creates an instance of this class by loading the toml data from the given [domain] stellar toml file.
static Future fromDomain(String domain,
- {http.Client? httpClient, String? horizonUrl, Network? network}) async {
- StellarToml toml =
- await StellarToml.fromDomain(domain, httpClient: httpClient);
- return RegulatedAssetsService(toml, httpClient: httpClient);
+ {http.Client? httpClient,
+ Map? httpRequestHeaders,
+ String? horizonUrl,
+ Network? network}) async {
+ StellarToml toml = await StellarToml.fromDomain(domain,
+ httpClient: httpClient, httpRequestHeaders: httpRequestHeaders);
+ return RegulatedAssetsService(toml,
+ httpClient: httpClient, httpRequestHeaders: httpRequestHeaders);
}
/// Checks if authorization is required for the given asset.
@@ -94,7 +96,7 @@ class RegulatedAssetsService {
Future postTransaction(
String tx, String approvalServer) async {
Uri requestURI = Uri.parse(approvalServer);
- Map headers = {...RequestBuilder.headers};
+ Map headers = {...(this.httpRequestHeaders ?? {})};
headers.putIfAbsent("Content-Type", () => "application/json");
PostTransactionResponse result = await httpClient
@@ -126,7 +128,7 @@ class RegulatedAssetsService {
String url, Map actionFields) async {
Uri requestURI = Uri.parse(url);
- Map headers = {...RequestBuilder.headers};
+ Map headers = {...(this.httpRequestHeaders ?? {})};
headers.putIfAbsent("Content-Type", () => "application/json");
PostActionResponse result = await httpClient
diff --git a/lib/src/sep/0010/webauth.dart b/lib/src/sep/0010/webauth.dart
index d465007..1bad980 100644
--- a/lib/src/sep/0010/webauth.dart
+++ b/lib/src/sep/0010/webauth.dart
@@ -27,6 +27,7 @@ class WebAuth {
String _serverHomeDomain;
late http.Client httpClient;
int gracePeriod = 60 * 5;
+ Map? httpRequestHeaders;
/// Constructor
/// - Parameter authEndpoint: Endpoint to be used for the authentication procedure. Usually taken from stellar.toml.
@@ -34,12 +35,9 @@ class WebAuth {
/// - Parameter serverSigningKey: The server public key, taken from stellar.toml.
/// - Parameter serverHomeDomain: The server home domain of the server where the stellar.toml was loaded from
WebAuth(this._authEndpoint, this._network, this._serverSigningKey,
- this._serverHomeDomain, {http.Client? httpClient}) {
- if (httpClient != null) {
- this.httpClient = httpClient;
- } else {
- this.httpClient = http.Client();
- }
+ this._serverHomeDomain,
+ {http.Client? httpClient, this.httpRequestHeaders}) {
+ this.httpClient = httpClient ?? http.Client();
}
/// Creates a WebAuth instance by loading the needed data from the stellar.toml file hosted on the given domain.
@@ -50,10 +48,12 @@ class WebAuth {
String domain,
Network network, {
http.Client? httpClient,
+ Map? httpRequestHeaders,
}) async {
final StellarToml toml = await StellarToml.fromDomain(
domain,
httpClient: httpClient,
+ httpRequestHeaders: httpRequestHeaders,
);
if (toml.generalInformation.webAuthEndpoint == null) {
@@ -64,7 +64,8 @@ class WebAuth {
}
return new WebAuth(toml.generalInformation.webAuthEndpoint!, network,
- toml.generalInformation.signingKey!, domain, httpClient: httpClient);
+ toml.generalInformation.signingKey!, domain,
+ httpClient: httpClient);
}
/// Get JWT token for wallet.
@@ -93,8 +94,11 @@ class WebAuth {
if (clientDomain == null) {
throw MissingClientDomainException();
}
- final StellarToml clientToml =
- await StellarToml.fromDomain(clientDomain, httpClient: httpClient);
+ final StellarToml clientToml = await StellarToml.fromDomain(
+ clientDomain,
+ httpClient: this.httpClient,
+ httpRequestHeaders: this.httpRequestHeaders,
+ );
if (clientToml.generalInformation.signingKey == null) {
throw NoClientDomainSigningKeyFoundException(clientDomain);
}
@@ -283,7 +287,7 @@ class WebAuth {
String base64EnvelopeXDR) async {
Uri serverURI = Uri.parse(_authEndpoint);
- Map headers = {...RequestBuilder.headers};
+ Map headers = {...(this.httpRequestHeaders ?? {})};
headers.putIfAbsent("Content-Type", () => "application/json");
SubmitCompletedChallengeResponse result = await httpClient
@@ -324,8 +328,9 @@ class WebAuth {
Uri serverURI = Uri.parse(_authEndpoint);
try {
- _ChallengeRequestBuilder requestBuilder =
- new _ChallengeRequestBuilder(httpClient, serverURI);
+ _ChallengeRequestBuilder requestBuilder = new _ChallengeRequestBuilder(
+ httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
ChallengeResponse response = await requestBuilder
.forAccountId(accountId)
.forHomeDomain(homeDomain)
@@ -345,7 +350,9 @@ class WebAuth {
// Requests the challenge data.
class _ChallengeRequestBuilder extends RequestBuilder {
- _ChallengeRequestBuilder(http.Client httpClient, Uri serverURI)
+ Map? httpRequestHeaders;
+ _ChallengeRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
Future challengeURI(Uri uri) async {
@@ -354,7 +361,7 @@ class _ChallengeRequestBuilder extends RequestBuilder {
ResponseHandler(type);
return await httpClient
- .get(uri, headers: RequestBuilder.headers)
+ .get(uri, headers: httpRequestHeaders ?? {})
.then((response) {
return responseHandler.handleResponse(response);
});
@@ -392,13 +399,14 @@ class _ChallengeRequestBuilder extends RequestBuilder {
}
static Future requestExecute(
- http.Client httpClient, Uri uri) async {
+ http.Client httpClient, Uri uri,
+ {Map? httpRequestHeaders}) async {
TypeToken type = new TypeToken();
ResponseHandler responseHandler =
new ResponseHandler(type);
return await httpClient
- .get(uri, headers: RequestBuilder.headers)
+ .get(uri, headers: httpRequestHeaders ?? {})
.then((response) {
return responseHandler.handleResponse(response);
});
@@ -406,7 +414,8 @@ class _ChallengeRequestBuilder extends RequestBuilder {
Future execute() {
return _ChallengeRequestBuilder.requestExecute(
- this.httpClient, this.buildUri());
+ this.httpClient, this.buildUri(),
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
@@ -557,4 +566,4 @@ class NoMemoForMuxedAccountsException implements Exception {
String toString() {
return "Memo cannot be used if account is a muxed account";
}
-}
\ No newline at end of file
+}
diff --git a/lib/src/sep/0012/kyc_service.dart b/lib/src/sep/0012/kyc_service.dart
index 3b25eab..9cf6bc1 100644
--- a/lib/src/sep/0012/kyc_service.dart
+++ b/lib/src/sep/0012/kyc_service.dart
@@ -12,26 +12,28 @@ import '../0009/standard_kyc_fields.dart';
class KYCService {
String _serviceAddress;
late http.Client httpClient;
+ Map? httpRequestHeaders;
- KYCService(this._serviceAddress, {http.Client? httpClient}) {
- if (httpClient != null) {
- this.httpClient = httpClient;
- } else {
- this.httpClient = http.Client();
- }
+ KYCService(this._serviceAddress,
+ {http.Client? httpClient, this.httpRequestHeaders}) {
+ this.httpClient = httpClient ?? http.Client();
}
- static Future fromDomain(String domain, {
+ static Future fromDomain(
+ String domain, {
http.Client? httpClient,
+ Map? httpRequestHeaders,
}) async {
+ StellarToml toml = await StellarToml.fromDomain(domain,
+ httpClient: httpClient, httpRequestHeaders: httpRequestHeaders);
- StellarToml toml = await StellarToml.fromDomain(domain, httpClient: httpClient);
- String? addr = toml.generalInformation.kYCServer;
- if (addr == null) {
- addr = toml.generalInformation.transferServer;
- }
- checkNotNull(addr, "kyc or transfer server not available for domain " + domain);
- return KYCService(addr!, httpClient: httpClient);
+ String? address = toml.generalInformation.kYCServer ??
+ toml.generalInformation.transferServer;
+
+ checkNotNull(
+ address, "kyc or transfer server not available for domain " + domain);
+ return KYCService(address!,
+ httpClient: httpClient, httpRequestHeaders: httpRequestHeaders);
}
/// Check the status of a customers info (customer GET)
@@ -40,11 +42,13 @@ class KYCService {
// If the server does not have a customer registered for the parameters sent in the request, it will return the fields required in the response. The same response will be returned when no parameters are sent.
// 2. Check the status of a customer that may already be registered
// This allows clients to check whether the customers information was accepted, rejected, or still needs more info. If the server still needs more info, or the server needs updated information, it will return the fields required.
- Future getCustomerInfo(GetCustomerInfoRequest request) async {
+ Future getCustomerInfo(
+ GetCustomerInfoRequest request) async {
Uri serverURI = Uri.parse(_serviceAddress + "/customer");
_GetCustomerInfoRequestBuilder requestBuilder =
- _GetCustomerInfoRequestBuilder(httpClient, serverURI);
+ _GetCustomerInfoRequestBuilder(httpClient, serverURI,
+ httpRequestHeaders: httpRequestHeaders);
final Map queryParams = {};
@@ -67,19 +71,21 @@ class KYCService {
queryParams["lang"] = request.lang!;
}
- GetCustomerInfoResponse response =
- await requestBuilder.forQueryParameters(queryParams).execute(request.jwt!);
+ GetCustomerInfoResponse response = await requestBuilder
+ .forQueryParameters(queryParams)
+ .execute(request.jwt!);
return response;
}
/// Upload customer information to an anchor in an authenticated and idempotent fashion.
- Future putCustomerInfo(PutCustomerInfoRequest request) async {
-
+ Future putCustomerInfo(
+ PutCustomerInfoRequest request) async {
Uri serverURI = Uri.parse(_serviceAddress + "/customer");
_PutCustomerInfoRequestBuilder requestBuilder =
- _PutCustomerInfoRequestBuilder(httpClient, serverURI);
+ _PutCustomerInfoRequestBuilder(httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
final Map fields = {};
final Map files = {};
@@ -99,10 +105,12 @@ class KYCService {
if (request.type != null) {
fields["type"] = request.type!;
}
- if (request.kycFields != null && request.kycFields?.naturalPersonKYCFields != null) {
+ if (request.kycFields != null &&
+ request.kycFields?.naturalPersonKYCFields != null) {
fields.addAll(request.kycFields!.naturalPersonKYCFields!.fields());
}
- if (request.kycFields != null && request.kycFields?.organizationKYCFields != null) {
+ if (request.kycFields != null &&
+ request.kycFields?.organizationKYCFields != null) {
fields.addAll(request.kycFields!.organizationKYCFields!.fields());
}
if (request.customFields != null) {
@@ -110,18 +118,22 @@ class KYCService {
}
// files always at the end.
- if (request.kycFields != null && request.kycFields?.naturalPersonKYCFields != null) {
+ if (request.kycFields != null &&
+ request.kycFields?.naturalPersonKYCFields != null) {
files.addAll(request.kycFields!.naturalPersonKYCFields!.files());
}
- if (request.kycFields != null && request.kycFields?.organizationKYCFields != null) {
+ if (request.kycFields != null &&
+ request.kycFields?.organizationKYCFields != null) {
files.addAll(request.kycFields!.organizationKYCFields!.files());
}
if (request.customFiles != null) {
files.addAll(request.customFiles!);
}
- PutCustomerInfoResponse response =
- await requestBuilder.forFields(fields).forFiles(files).execute(request.jwt!);
+ PutCustomerInfoResponse response = await requestBuilder
+ .forFields(fields)
+ .forFiles(files)
+ .execute(request.jwt!);
return response;
}
@@ -131,11 +143,11 @@ class KYCService {
/// See: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#customer-put-verification
Future putCustomerVerification(
PutCustomerVerificationRequest request) async {
-
Uri serverURI = Uri.parse(_serviceAddress + "/customer/verification");
_PutCustomerVerificationRequestBuilder requestBuilder =
- _PutCustomerVerificationRequestBuilder(httpClient, serverURI);
+ _PutCustomerVerificationRequestBuilder(httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
final Map fields = {};
@@ -147,7 +159,8 @@ class KYCService {
fields.addAll(request.verificationFields!);
}
- GetCustomerInfoResponse response = await requestBuilder.forFields(fields).execute(request.jwt!);
+ GetCustomerInfoResponse response =
+ await requestBuilder.forFields(fields).execute(request.jwt!);
return response;
}
@@ -158,11 +171,14 @@ class KYCService {
/// This request must be authenticated (via SEP-10) as coming from the owner of the account that will be deleted - [jwt].
Future deleteCustomer(
String account, String? memo, String? memoType, String jwt) async {
-
Uri serverURI = Uri.parse(_serviceAddress + "/customer/" + account);
_DeleteCustomerRequestBuilder requestBuilder =
- _DeleteCustomerRequestBuilder(httpClient, serverURI);
+ _DeleteCustomerRequestBuilder(
+ httpClient,
+ serverURI,
+ httpRequestHeaders: this.httpRequestHeaders,
+ );
final Map fields = {};
@@ -173,20 +189,22 @@ class KYCService {
fields["memo_type"] = memo!;
}
- http.Response response = await requestBuilder.forFields(fields).execute(jwt);
+ http.Response response =
+ await requestBuilder.forFields(fields).execute(jwt);
return response;
}
/// Allow the wallet to provide a callback URL to the anchor. The provided callback URL will replace (and supercede) any previously-set callback URL for this account.
/// See: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#customer-callback-put
- Future putCustomerCallback(PutCustomerCallbackRequest request) async {
-
+ Future putCustomerCallback(
+ PutCustomerCallbackRequest request) async {
checkNotNull(request.url, "request.url cannot be null");
Uri serverURI = Uri.parse(_serviceAddress + "/customer/callback");
_PutCustomerCallbackRequestBuilder requestBuilder =
- _PutCustomerCallbackRequestBuilder(httpClient, serverURI);
+ _PutCustomerCallbackRequestBuilder(httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
final Map fields = {};
@@ -208,7 +226,8 @@ class KYCService {
fields["memo_type"] = request.memoType!;
}
- http.Response response = await requestBuilder.forFields(fields).execute(request.jwt!);
+ http.Response response =
+ await requestBuilder.forFields(fields).execute(request.jwt!);
return response;
}
@@ -254,13 +273,15 @@ class GetCustomerInfoField extends Response {
/// (optional) A boolean whether this field is required to proceed or not. Defaults to false.
bool? optional;
- GetCustomerInfoField(this.type, this.description, this.choices, this.optional);
+ GetCustomerInfoField(
+ this.type, this.description, this.choices, this.optional);
- factory GetCustomerInfoField.fromJson(Map json) => GetCustomerInfoField(
- json['type'],
- json['description'],
- json['choices'] == null ? null : List.from(json['choices']),
- json['optional']);
+ factory GetCustomerInfoField.fromJson(Map json) =>
+ GetCustomerInfoField(
+ json['type'],
+ json['description'],
+ json['choices'] == null ? null : List.from(json['choices']),
+ json['optional']);
}
/// The provided CustomerInfoProvidedField object defines the pieces of information the anchor has received for
@@ -286,8 +307,8 @@ class GetCustomerInfoProvidedField extends Response {
/// (optional) The human readable description of why the field is REJECTED.
String? error;
- GetCustomerInfoProvidedField(
- this.type, this.description, this.choices, this.optional, this.status, this.error);
+ GetCustomerInfoProvidedField(this.type, this.description, this.choices,
+ this.optional, this.status, this.error);
factory GetCustomerInfoProvidedField.fromJson(Map json) =>
GetCustomerInfoProvidedField(
@@ -317,7 +338,8 @@ class GetCustomerInfoResponse extends Response {
/// (optional) Human readable message describing the current state of customer's KYC process.
String? message;
- GetCustomerInfoResponse(this.id, this.status, this.fields, this.providedFields, this.message);
+ GetCustomerInfoResponse(
+ this.id, this.status, this.fields, this.providedFields, this.message);
factory GetCustomerInfoResponse.fromJson(Map json) {
Map? fieldsDynamic =
@@ -325,17 +347,20 @@ class GetCustomerInfoResponse extends Response {
Map? fields = {};
if (fieldsDynamic != null) {
fieldsDynamic.forEach((key, value) {
- fields![key] = GetCustomerInfoField.fromJson(value as Map);
+ fields![key] =
+ GetCustomerInfoField.fromJson(value as Map);
});
} else {
fields = null;
}
- fieldsDynamic =
- json['provided_fields'] == null ? null : json['provided_fields'] as Map;
+ fieldsDynamic = json['provided_fields'] == null
+ ? null
+ : json['provided_fields'] as Map;
Map? providedFields = {};
if (fieldsDynamic != null) {
fieldsDynamic.forEach((key, value) {
- providedFields![key] = GetCustomerInfoProvidedField.fromJson(value as Map);
+ providedFields![key] = GetCustomerInfoProvidedField.fromJson(
+ value as Map);
});
} else {
providedFields = null;
@@ -348,21 +373,27 @@ class GetCustomerInfoResponse extends Response {
// Requests the customer info data.
class _GetCustomerInfoRequestBuilder extends RequestBuilder {
- _GetCustomerInfoRequestBuilder(http.Client httpClient, Uri serverURI)
+ Map? httpRequestHeaders;
+
+ _GetCustomerInfoRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
- _GetCustomerInfoRequestBuilder forQueryParameters(Map queryParams) {
+ _GetCustomerInfoRequestBuilder forQueryParameters(
+ Map queryParams) {
queryParameters.addAll(queryParams);
return this;
}
static Future requestExecute(
- http.Client httpClient, Uri uri, String? jwt) async {
- TypeToken type = TypeToken();
+ http.Client httpClient, Uri uri, String? jwt,
+ {Map? httpRequestHeaders}) async {
+ TypeToken type =
+ TypeToken();
ResponseHandler responseHandler =
ResponseHandler(type);
- final Map feeHeaders = {...RequestBuilder.headers};
+ final Map feeHeaders = {...(httpRequestHeaders ?? {})};
if (jwt != null) {
feeHeaders["Authorization"] = "Bearer $jwt";
}
@@ -372,7 +403,8 @@ class _GetCustomerInfoRequestBuilder extends RequestBuilder {
}
Future execute(String jwt) {
- return _GetCustomerInfoRequestBuilder.requestExecute(this.httpClient, this.buildUri(), jwt);
+ return _GetCustomerInfoRequestBuilder.requestExecute(
+ this.httpClient, this.buildUri(), jwt);
}
}
@@ -420,8 +452,10 @@ class PutCustomerInfoResponse extends Response {
class _PutCustomerInfoRequestBuilder extends RequestBuilder {
Map? _fields;
Map? _files;
+ Map? httpRequestHeaders;
- _PutCustomerInfoRequestBuilder(http.Client httpClient, Uri serverURI)
+ _PutCustomerInfoRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_PutCustomerInfoRequestBuilder forFields(Map fields) {
@@ -434,14 +468,20 @@ class _PutCustomerInfoRequestBuilder extends RequestBuilder {
return this;
}
- static Future requestExecute(http.Client httpClient, Uri uri,
- Map? fields, Map? files, String? jwt) async {
- TypeToken type = TypeToken();
+ static Future requestExecute(
+ http.Client httpClient,
+ Uri uri,
+ Map? fields,
+ Map? files,
+ String? jwt,
+ {Map? httpRequestHeaders}) async {
+ TypeToken type =
+ TypeToken();
ResponseHandler responseHandler =
ResponseHandler(type);
final Map hHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
var request = http.MultipartRequest('PUT', uri);
@@ -461,7 +501,8 @@ class _PutCustomerInfoRequestBuilder extends RequestBuilder {
Future execute(String jwt) {
return _PutCustomerInfoRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), _fields, _files, jwt);
+ this.httpClient, this.buildUri(), _fields, _files, jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
@@ -480,8 +521,10 @@ class PutCustomerVerificationRequest {
// Puts the customer verification data.
class _PutCustomerVerificationRequestBuilder extends RequestBuilder {
Map? _fields;
+ Map? httpRequestHeaders;
- _PutCustomerVerificationRequestBuilder(http.Client httpClient, Uri serverURI)
+ _PutCustomerVerificationRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_PutCustomerVerificationRequestBuilder forFields(Map fields) {
@@ -490,13 +533,15 @@ class _PutCustomerVerificationRequestBuilder extends RequestBuilder {
}
static Future requestExecute(
- http.Client httpClient, Uri uri, Map? fields, String? jwt) async {
- TypeToken type = TypeToken();
+ http.Client httpClient, Uri uri, Map? fields, String? jwt,
+ {Map? httpRequestHeaders}) async {
+ TypeToken type =
+ TypeToken();
ResponseHandler responseHandler =
ResponseHandler(type);
final Map hHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
var request = http.MultipartRequest('PUT', uri);
@@ -513,15 +558,18 @@ class _PutCustomerVerificationRequestBuilder extends RequestBuilder {
Future execute(String jwt) {
return _PutCustomerVerificationRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), _fields, jwt);
+ this.httpClient, this.buildUri(), _fields, jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
// Delete customer
class _DeleteCustomerRequestBuilder extends RequestBuilder {
Map? _fields;
+ Map? httpRequestHeaders;
- _DeleteCustomerRequestBuilder(http.Client httpClient, Uri serverURI)
+ _DeleteCustomerRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_DeleteCustomerRequestBuilder forFields(Map fields) {
@@ -530,9 +578,10 @@ class _DeleteCustomerRequestBuilder extends RequestBuilder {
}
static Future requestExecute(
- http.Client httpClient, Uri uri, Map? fields, String? jwt) async {
+ http.Client httpClient, Uri uri, Map? fields, String? jwt,
+ {Map? httpRequestHeaders}) async {
final Map hHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
var request = http.MultipartRequest('DELETE', uri);
@@ -549,7 +598,8 @@ class _DeleteCustomerRequestBuilder extends RequestBuilder {
Future execute(String jwt) {
return _DeleteCustomerRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), _fields, jwt);
+ this.httpClient, this.buildUri(), _fields, jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
@@ -578,8 +628,10 @@ class PutCustomerCallbackRequest {
// Put customer callback
class _PutCustomerCallbackRequestBuilder extends RequestBuilder {
Map? _fields;
+ Map? httpRequestHeaders;
- _PutCustomerCallbackRequestBuilder(http.Client httpClient, Uri serverURI)
+ _PutCustomerCallbackRequestBuilder(http.Client httpClient, Uri serverURI,
+ {this.httpRequestHeaders})
: super(httpClient, serverURI, null);
_PutCustomerCallbackRequestBuilder forFields(Map fields) {
@@ -588,9 +640,10 @@ class _PutCustomerCallbackRequestBuilder extends RequestBuilder {
}
static Future requestExecute(
- http.Client httpClient, Uri uri, Map? fields, String? jwt) async {
+ http.Client httpClient, Uri uri, Map? fields, String? jwt,
+ {Map? httpRequestHeaders}) async {
final Map hHeaders = {
- ...RequestBuilder.headers,
+ ...(httpRequestHeaders ?? {}),
if (jwt != null) "Authorization": "Bearer $jwt",
};
var request = http.MultipartRequest('PUT', uri);
@@ -607,6 +660,7 @@ class _PutCustomerCallbackRequestBuilder extends RequestBuilder {
Future execute(String jwt) {
return _PutCustomerCallbackRequestBuilder.requestExecute(
- this.httpClient, this.buildUri(), _fields, jwt);
+ this.httpClient, this.buildUri(), _fields, jwt,
+ httpRequestHeaders: this.httpRequestHeaders);
}
}
diff --git a/lib/src/sep/0024/sep24_service.dart b/lib/src/sep/0024/sep24_service.dart
index 862227e..2cc410d 100644
--- a/lib/src/sep/0024/sep24_service.dart
+++ b/lib/src/sep/0024/sep24_service.dart
@@ -13,22 +13,24 @@ import 'dart:convert';
class TransferServerSEP24Service {
String _transferServiceAddress;
late http.Client httpClient;
+ Map? httpRequestHeaders;
- TransferServerSEP24Service(this._transferServiceAddress, {http.Client? httpClient}) {
- if (httpClient != null) {
- this.httpClient = httpClient;
- } else {
- this.httpClient = http.Client();
- }
+ TransferServerSEP24Service(this._transferServiceAddress,
+ {http.Client? httpClient, this.httpRequestHeaders}) {
+ this.httpClient = httpClient ?? http.Client();
}
/// Creates an instance of this class by loading the transfer server sep 24 url from the given [domain] stellar toml file.
- static Future fromDomain(String domain, {http.Client? httpClient}) async {
- StellarToml toml = await StellarToml.fromDomain(domain, httpClient: httpClient);
+ static Future fromDomain(String domain,
+ {http.Client? httpClient,
+ Map? httpRequestHeaders}) async {
+ StellarToml toml = await StellarToml.fromDomain(domain,
+ httpClient: httpClient, httpRequestHeaders: httpRequestHeaders);
String? addr = toml.generalInformation.transferServerSep24;
checkNotNull(
addr, "Transfer server SEP 24 not available for domain " + domain);
- return TransferServerSEP24Service(addr!, httpClient: httpClient);
+ return TransferServerSEP24Service(addr!,
+ httpClient: httpClient, httpRequestHeaders: httpRequestHeaders);
}
/// Get the anchors basic info about what their TRANSFER_SERVER_SEP0024 support to wallets and clients.
@@ -36,8 +38,9 @@ class TransferServerSEP24Service {
Future info([String? lang]) async {
Uri serverURI = Util.appendEndpointToUrl(_transferServiceAddress, 'info');
- _InfoRequestBuilder requestBuilder =
- _InfoRequestBuilder(httpClient, serverURI);
+ _InfoRequestBuilder requestBuilder = _InfoRequestBuilder(
+ httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
final Map queryParams = {};
@@ -61,8 +64,9 @@ class TransferServerSEP24Service {
Future fee(SEP24FeeRequest request) async {
Uri serverURI = Util.appendEndpointToUrl(_transferServiceAddress, 'fee');
- _FeeRequestBuilder requestBuilder =
- _FeeRequestBuilder(httpClient, serverURI);
+ _FeeRequestBuilder requestBuilder = _FeeRequestBuilder(
+ httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
final Map queryParams = {
"operation": request.operation,
@@ -82,8 +86,7 @@ class TransferServerSEP24Service {
} on ErrorResponse catch (e) {
if (e.code == 403) {
_handleForbiddenResponse(e);
- }
- else if (e.code != 200) {
+ } else if (e.code != 200) {
_handleErrorResponse(e);
}
throw e;
@@ -122,8 +125,9 @@ class TransferServerSEP24Service {
Uri serverURI = Util.appendEndpointToUrl(
_transferServiceAddress, 'transactions/deposit/interactive');
- _PostRequestBuilder requestBuilder =
- _PostRequestBuilder(httpClient, serverURI);
+ _PostRequestBuilder requestBuilder = _PostRequestBuilder(
+ httpClient, serverURI,
+ httpRequestHeaders: this.httpRequestHeaders);
final Map