Skip to content

Commit 078fae5

Browse files
authored
Merge pull request #15 from codescalers/main_stellar_wallet
add stellar client
2 parents 06058c3 + 2c3f378 commit 078fae5

File tree

15 files changed

+1224
-12
lines changed

15 files changed

+1224
-12
lines changed

.github/workflows/analyze.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ jobs:
1919
- name: Setup Dart SDK
2020
uses: dart-lang/setup-dart@v1.6.0
2121
with:
22-
sdk: "stable"
22+
sdk: "3.2.3"
23+
- name: Setup Flutter
24+
uses: subosito/flutter-action@v2
25+
with:
26+
flutter-version: "3.16.4"
2327
- name: Install Melos
2428
run: dart pub global activate melos
2529

.github/workflows/coverage.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ jobs:
1515
steps:
1616
- name: Set up Repository
1717
uses: actions/checkout@v2
18-
1918
- name: List Files
2019
run: ls -R
2120

@@ -37,13 +36,12 @@ jobs:
3736
- name: Start TFChain Docker Container
3837
run: |
3938
sudo docker run -d --network host ghcr.io/threefoldtech/tfchain --dev --rpc-cors all --rpc-external --rpc-methods=safe
40-
4139
- name: Wait for TFChain to be ready
4240
run: |
4341
while ! nc -z localhost 9944; do
4442
echo "Waiting for TFChain to be ready..."
4543
sleep 5
46-
done
44+
done
4745
4846
- name: Run unit tests and generate coverage
4947
run: |

packages/stellar_client/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
- Initial version.

packages/stellar_client/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Stellar Client
2+
3+
This Dart client allows you to communicate with the Stellar network, enabling the creation or loading of existing Stellar accounts. It supports interactions with both the testnet and public network, and the assets currently supported are TFT (Threefold Token) and XLM (Stellar Lumens).
4+
5+
## Installation
6+
7+
To install the necessary dependencies, run:
8+
9+
```bash
10+
dart pub get
11+
```
12+
13+
## Usage
14+
15+
This client enables you to create new Stellar accounts or load existing ones on the testnet or public network. Once an account is created or loaded, you can manage assets such as TFT and XLM.
16+
17+
### TESTNET
18+
19+
Create new testnet account:
20+
21+
- Use `Client.create(NetworkType.TESTNET)` to create a new client.
22+
- Use `Client.createFromMnemonic(NetworkType.TESTNET, "mnemonic")` to create a client from an existing mnemonic.
23+
- Account can be activated through friendbot (only for testnet).
24+
- After activation, trustlines can be added to the account.
25+
26+
```dart
27+
import 'package:stellar_client/stellar_client.dart';
28+
29+
final stellarClient = Client.create(NetworkType.TESTNET);
30+
// final stellarClient = await Client.createFromMnemonic(NetworkType.TESTNET, "mnemonic");
31+
32+
await stellarClient.activateThroughFriendBot(accountId: stellarClient.accountId);
33+
await stellarClient.addTrustLine();
34+
35+
final balance = await stellarClient.getBalance();
36+
print(balance);
37+
```
38+
39+
Load previously created account:
40+
41+
- Accounts can be loaded from secret seed.
42+
43+
```dart
44+
import 'package:stellar_client/stellar_client.dart';
45+
46+
final stellarClient = Client(NetworkType.TESTNET, secretSeed);
47+
final transactions = await stellarClient.getTransactions();
48+
print(transactions);
49+
```
50+
51+
### PUBLIC
52+
53+
- Activation through Threefold service will add assets automatically.
54+
55+
```dart
56+
import 'package:stellar_client/stellar_client.dart';
57+
58+
final stellarClient = Client.create(NetworkType.PUBLIC);
59+
await stellarClient.activateThroughThreefoldService();
60+
61+
await stellarClient.transfer(
62+
destinationAddress: "destination-public-key",
63+
amount: "20",
64+
currency: "TFT",
65+
memoText: "Memo Text");
66+
67+
await stellarClient.getTransactions();
68+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:stellar_client/stellar_client.dart';
2+
3+
void main() async {
4+
final stellarClient = Client.create(NetworkType.PUBLIC);
5+
await stellarClient.activateThroughThreefoldService();
6+
7+
await stellarClient.transfer(
8+
destinationAddress: "destination-public-key",
9+
amount: "20",
10+
currency: "TFT",
11+
memoText: "Memo Text");
12+
13+
await stellarClient.getTransactions();
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
abstract class BalanceInfo {
2+
String get assetCode;
3+
String get balance;
4+
}
5+
6+
class BalanceData implements BalanceInfo {
7+
@override
8+
final String assetCode;
9+
@override
10+
final String balance;
11+
12+
BalanceData({required this.assetCode, required this.balance});
13+
14+
@override
15+
String toString() {
16+
return 'BalanceData(assetCode: $assetCode, balance: $balance)';
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Currency {
2+
final String assetCode;
3+
final String issuer;
4+
5+
Currency({required this.assetCode, required this.issuer});
6+
7+
Map<String, dynamic> toJson() {
8+
return {
9+
'asset_code': assetCode,
10+
'issuer': issuer,
11+
};
12+
}
13+
}
14+
15+
class Currencies {
16+
late final Map<String, Currency> currencies;
17+
18+
Currencies(this.currencies);
19+
20+
Map<String, dynamic> toJson() {
21+
Map<String, dynamic> jsonMap = {};
22+
currencies.forEach((key, value) {
23+
jsonMap[key] = value.toJson();
24+
});
25+
return jsonMap;
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class TransactionData {
2+
final String asset;
3+
final String feeAccountId;
4+
final String feeFixed;
5+
6+
TransactionData({
7+
required this.asset,
8+
required this.feeAccountId,
9+
required this.feeFixed,
10+
});
11+
12+
factory TransactionData.fromJson(Map<String, dynamic> json) {
13+
return TransactionData(
14+
asset: json['asset'],
15+
feeAccountId: json['fee_account_id'],
16+
feeFixed: json['fee_fixed'],
17+
);
18+
}
19+
20+
@override
21+
String toString() {
22+
return 'TransactionData{asset: $asset, feeAccountId: $feeAccountId, feeFixed: $feeFixed}';
23+
}
24+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class PaymentOperationDetails {
2+
final String from;
3+
final String to;
4+
final double amount;
5+
final String assetCode;
6+
final bool isSuccessful;
7+
8+
PaymentOperationDetails({
9+
required this.from,
10+
required this.to,
11+
required this.amount,
12+
required this.assetCode,
13+
required this.isSuccessful,
14+
});
15+
16+
@override
17+
String toString() {
18+
return 'PaymentOperationDetails(from: $from, to: $to, amount: $amount, assetCode: $assetCode, isSuccessful: $isSuccessful)';
19+
}
20+
}
21+
22+
class CreateAccountOperationDetails {
23+
final String account;
24+
final double startingBalance;
25+
26+
CreateAccountOperationDetails({
27+
required this.account,
28+
required this.startingBalance,
29+
});
30+
31+
@override
32+
String toString() {
33+
return 'CreateAccountOperationDetails(account: $account, startingBalance: $startingBalance)';
34+
}
35+
}
36+
37+
class PathPaymentStrictReceiveOperationDetails {
38+
final String from;
39+
final String to;
40+
final double sourceAmount;
41+
final String sourceAssetCode;
42+
final double destinationAmount;
43+
final String destinationAssetCode;
44+
45+
PathPaymentStrictReceiveOperationDetails({
46+
required this.from,
47+
required this.to,
48+
required this.sourceAmount,
49+
required this.sourceAssetCode,
50+
required this.destinationAmount,
51+
required this.destinationAssetCode,
52+
});
53+
54+
@override
55+
String toString() {
56+
return 'PathPaymentStrictReceiveOperationDetails(from: $from, to: $to, sourceAmount: $sourceAmount, sourceAssetCode: $sourceAssetCode, destinationAmount: $destinationAmount, destinationAssetCode: $destinationAssetCode)';
57+
}
58+
}

0 commit comments

Comments
 (0)