Skip to content

Commit

Permalink
add protocol 21 support
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed May 13, 2024
1 parent 7092abc commit 8c8238e
Show file tree
Hide file tree
Showing 12 changed files with 583 additions and 103 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.8.0] - 13.May.2024.
- add protocol 21 support

## [1.7.8] - 29.Apr.2024.
- update Soroban RPC args for sendTransaction and getTransaction
- add optional httpClient Parameter for StellarSDK
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The Soneso open source Stellar SDK for Flutter is build with Dart and provides A
1. Add the dependency to your pubspec.yaml file:
```
dependencies:
stellar_flutter_sdk: ^1.7.8
stellar_flutter_sdk: ^1.8.0
```
2. Install it (command line or IDE):
```
Expand Down
37 changes: 19 additions & 18 deletions lib/src/sep/0008/regulated_assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,29 @@ class RegulatedAssetsService {
if (network == null &&
tomlData.generalInformation.networkPassphrase != null) {
this.network = Network(tomlData.generalInformation.networkPassphrase!);
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) {
this.sdk = StellarSDK.PUBLIC;
} else if (this.network.networkPassphrase ==
Network.TESTNET.networkPassphrase) {
this.sdk = StellarSDK.TESTNET;
} else if (this.network.networkPassphrase ==
Network.FUTURENET.networkPassphrase) {
this.sdk = StellarSDK.FUTURENET;
} else {
throw IncompleteInitData("could not find a horizon url");
}
}
} else {
throw IncompleteInitData('could not find a network passphrase');
}

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) {
this.sdk = StellarSDK.PUBLIC;
} else if (this.network.networkPassphrase ==
Network.TESTNET.networkPassphrase) {
this.sdk = StellarSDK.TESTNET;
} else if (this.network.networkPassphrase ==
Network.FUTURENET.networkPassphrase) {
this.sdk = StellarSDK.FUTURENET;
} else {
throw IncompleteInitData("could not find a horizon url");
}
}

this.regulatedAssets = List<RegulatedAsset>.empty(growable: true);
this.tomlData.currencies?.forEach((element) {
if (element.code != null &&
Expand Down
41 changes: 40 additions & 1 deletion lib/src/soroban/soroban_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,21 @@ abstract class SorobanRpcResponse {
class GetHealthResponse extends SorobanRpcResponse {
/// Health status e.g. "healthy"
String? status;
int? ledgerRetentionWindow;
static const String HEALTHY = "healthy";

GetHealthResponse(Map<String, dynamic> jsonResponse) : super(jsonResponse);

factory GetHealthResponse.fromJson(Map<String, dynamic> json) {
GetHealthResponse response = GetHealthResponse(json);
if (json['result'] != null) {
response.status = json['result']['status'];
if (json['result']['status'] != null) {
response.status = json['result']['status'];
}
if (json['result']['ledgerRetentionWindow'] != null) {
response.ledgerRetentionWindow =
json['result']['ledgerRetentionWindow'];
}
} else if (json['error'] != null) {
response.error = SorobanRpcErrorResponse.fromJson(json);
}
Expand Down Expand Up @@ -439,6 +446,29 @@ class SimulateTransactionRequest {
}
}

class LedgerEntryChange {
String type;
XdrLedgerKey key;
XdrLedgerEntry? before;
XdrLedgerEntry? after;

LedgerEntryChange(this.type, this.key, {this.before, this.after});

factory LedgerEntryChange.fromJson(Map<String, dynamic> json) {
XdrLedgerKey key = XdrLedgerKey.fromBase64EncodedXdrString(json['key']);
XdrLedgerEntry? before;
if (json['before'] != null) {
before = XdrLedgerEntry.fromBase64EncodedXdrString(json['before']);
}
XdrLedgerEntry? after;
if (json['after'] != null) {
after = XdrLedgerEntry.fromBase64EncodedXdrString(json['after']);
}

return LedgerEntryChange(json['type'], key, before: before, after: after);
}
}

/// Response that will be received when submitting a trial contract invocation.
/// See: https://soroban.stellar.org/api/methods/simulateTransaction
class SimulateTransactionResponse extends SorobanRpcResponse {
Expand Down Expand Up @@ -467,6 +497,9 @@ class SimulateTransactionResponse extends SorobanRpcResponse {
/// be used to construct the transaction containing the RestoreFootprint
RestorePreamble? restorePreamble;

/// If present, it indicates how the state (ledger entries) will change as a result of the transaction execution.
List<LedgerEntryChange>? statusChanges;

SimulateTransactionResponse(Map<String, dynamic> jsonResponse)
: super(jsonResponse);

Expand Down Expand Up @@ -508,6 +541,12 @@ class SimulateTransactionResponse extends SorobanRpcResponse {
RestorePreamble.fromJson(json['result']['restorePreamble']);
}

if (json['result']['stateChanges'] != null) {
response.statusChanges = List<LedgerEntryChange>.from(json['result']
['stateChanges']
.map((e) => LedgerEntryChange.fromJson(e)));
}

response.minResourceFee = convertInt(json['result']['minResourceFee']);
} else if (json['error'] != null) {
response.error = SorobanRpcErrorResponse.fromJson(json);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/stellar_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import 'requests/liquidity_pools_request_builder.dart';

/// Main class of the flutter stellar sdk.
class StellarSDK {
static const versionNumber = "1.7.8";
static const versionNumber = "1.8.0";

static final StellarSDK PUBLIC = StellarSDK("https://horizon.stellar.org");
static final StellarSDK TESTNET = StellarSDK("https://horizon-testnet.stellar.org");
Expand Down
6 changes: 5 additions & 1 deletion lib/src/xdr/xdr_contract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,11 @@ class XdrSCAddress {
static XdrSCAddress forContractId(String contractId) {
XdrSCAddress result =
XdrSCAddress(XdrSCAddressType.SC_ADDRESS_TYPE_CONTRACT);
result.contractId = XdrHash(Util.hexToBytes(contractId));
var contractIdHex = contractId;
if (contractId.startsWith('C')) {
contractIdHex = StrKey.decodeContractIdHex(contractIdHex);
}
result.contractId = XdrHash(Util.hexToBytes(contractIdHex));
return result;
}
}
Expand Down
Loading

0 comments on commit 8c8238e

Please sign in to comment.