stellar 0.3.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 41

Stellar client library for Dart developers.

Usage #

A simple usage example:

import 'package:stellar/stellar.dart';
import 'package:http/http.dart' as http;

void createKey() {
  KeyPair pair = KeyPair.random();
  print("Account Id  : " + pair.accountId);
  print("Secret Seed : " + pair.secretSeed);
}

void createTestAccount(String accountId) {
  var url = "https://friendbot.stellar.org/?addr=${accountId}";
  http.get(url).then((response) {
    switch (response.statusCode) {
      case 200:
        {
          print("SUCCESS! You have a new account : \n${response.body}");
          print("Response body: ${response.body}");
          break;
        }
      default:
        {
          print("ERROR! : \n${response.body}");
        }
    }
  });
}

void getAccountDetails(String accountId) {
  KeyPair pair = KeyPair.fromAccountId(accountId);

  Network.useTestNetwork();
  Server server = Server("https://horizon-testnet.stellar.org");
  server.accounts.account(pair).then((account) {
    print("Balances for account: ${pair.accountId}");

    for (Balance balance in account.balances) {
      print(
          "Type: ${balance.assetType}, Code: ${balance.assetCode}, Balance: ${balance.balance}");

      switch (balance.assetType) {
        case "native":
          {
            print("balance: ${balance.balance} XLM");
            break;
          }
        default:
          {
            print(
                "balance: ${balance.balance} ${balance.assetCode} issuer: ${balance.assetIssuer}");
          }
      }

      print("sequence number: ${account.sequenceNumber}");

      for (Signer signer in account.signers) {
        print("signer public key: ${signer.accountId}");
      }

      print("auth required: ${account.flags.authRequired}");
      print("auth revocable: ${account.flags.authRevocable}");

      for (String key in account.data.keys) {
        print("data key: ${key} value: ${account.data[key]}");
      }
    }
  });
}

void getAccountTransactions(String accountId) {
  KeyPair pair = KeyPair.fromAccountId(accountId);

  Network.useTestNetwork();
  Server server = Server("https://horizon-testnet.stellar.org");
  server.transactions
      .forAccount(pair)
      .order(RequestBuilderOrder.DESC)
      .limit(200)
      .execute()
      .then((page) {
    for (TransactionResponse transactionResponse in page.records) {
      print(transactionResponse);
    }
  });
}

void sendPayment() {
  Network.useTestNetwork();
  Server server = new Server("https://horizon-testnet.stellar.org");

  KeyPair source = KeyPair.fromSecretSeed(
      "SB7IAVKZJCK2T5TAN4F25TC7XGFB4BVLRPFJUT662Y2RK4MK7NAT4FO2");
  KeyPair destination = KeyPair.fromAccountId(
      "GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");

  server.accounts.account(source).then((sourceAccount) {
    Transaction transaction = new TransactionBuilder(sourceAccount)
        .addOperation(new PaymentOperationBuilder(
                destination, new AssetTypeNative(), "10")
            .build())
        .addMemo(Memo.text("Test Transaction"))
        .build();
    transaction.sign(source);

    server.submitTransaction(transaction).then((response) {
      print("Success!");
      print(response);
    }).catchError((error) {
      print("Something went wrong!");
    });
  });
}

void paymentStream() {
  Network.useTestNetwork();
  Server server = new Server("https://horizon-testnet.stellar.org");

  KeyPair destination = KeyPair.fromAccountId(
      "GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");

  server.payments.forAccount(destination).stream().listen((response) {
    if (response is PaymentOperationResponse) {
      switch (response.assetType) {
        case "native":
          print(
              "Payment of ${response.amount} XLM from ${response.sourceAccount.accountId} received");
          break;
        default:
          print(
              "Payment of ${response.amount} ${response.assetCode} from ${response.sourceAccount.accountId}");
      }
    }
  });
}

/*
Account Id  : GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC
Secret Seed : SB7IAVKZJCK2T5TAN4F25TC7XGFB4BVLRPFJUT662Y2RK4MK7NAT4FO2

Account Id  : GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3
Secret Seed : SAACNKL2BBFVU7BVAVI2EIYSZQPQANZNYBVYUR7RFWTTRTOB6FPDR4NY
 */

void main() {
  createKey();
  createTestAccount("GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC");
  getAccountDetails("GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC");
  getAccountTransactions("GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");
  sendPayment();
  paymentStream();
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.3.2 #

  • Remove "dart:mirrors" for Flutter

0.3.0 #

  • Initial version, created by Jeff Lee

example/example.dart

import 'package:stellar/stellar.dart';
import 'package:http/http.dart' as http;

void createKey() {
  KeyPair pair = KeyPair.random();
  print("Account Id  : " + pair.accountId);
  print("Secret Seed : " + pair.secretSeed);
}

void createTestAccount(String accountId) {
  var url = "https://friendbot.stellar.org/?addr=${accountId}";
  http.get(url).then((response) {
    switch (response.statusCode) {
      case 200:
        {
          print("SUCCESS! You have a new account : \n${response.body}");
          print("Response body: ${response.body}");
          break;
        }
      default:
        {
          print("ERROR! : \n${response.body}");
        }
    }
  });
}

void getAccountDetails(String accountId) {
  KeyPair pair = KeyPair.fromAccountId(accountId);

  Network.useTestNetwork();
  Server server = Server("https://horizon-testnet.stellar.org");
  server.accounts.account(pair).then((account) {
    print("Balances for account: ${pair.accountId}");

    for (Balance balance in account.balances) {
      print(
          "Type: ${balance.assetType}, Code: ${balance.assetCode}, Balance: ${balance.balance}");

      switch (balance.assetType) {
        case "native":
          {
            print("balance: ${balance.balance} XLM");
            break;
          }
        default:
          {
            print(
                "balance: ${balance.balance} ${balance.assetCode} issuer: ${balance.assetIssuer}");
          }
      }

      print("sequence number: ${account.sequenceNumber}");

      for (Signer signer in account.signers) {
        print("signer public key: ${signer.accountId}");
      }

      print("auth required: ${account.flags.authRequired}");
      print("auth revocable: ${account.flags.authRevocable}");

      for (String key in account.data.keys) {
        print("data key: ${key} value: ${account.data[key]}");
      }
    }
  });
}

void getAccountTransactions(String accountId) {
  KeyPair pair = KeyPair.fromAccountId(accountId);

  Network.useTestNetwork();
  Server server = Server("https://horizon-testnet.stellar.org");
  server.transactions
      .forAccount(pair)
      .order(RequestBuilderOrder.DESC)
      .limit(200)
      .execute()
      .then((page) {
    for (TransactionResponse transactionResponse in page.records) {
      print(transactionResponse);
    }
  });
}

void sendPayment() {
  Network.useTestNetwork();
  Server server = new Server("https://horizon-testnet.stellar.org");

  KeyPair source = KeyPair.fromSecretSeed(
      "SB7IAVKZJCK2T5TAN4F25TC7XGFB4BVLRPFJUT662Y2RK4MK7NAT4FO2");
  KeyPair destination = KeyPair.fromAccountId(
      "GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");

  server.accounts.account(source).then((sourceAccount) {
    Transaction transaction = new TransactionBuilder(sourceAccount)
        .addOperation(new PaymentOperationBuilder(
                destination, new AssetTypeNative(), "10")
            .build())
        .addMemo(Memo.text("Test Transaction"))
        .build();
    transaction.sign(source);

    server.submitTransaction(transaction).then((response) {
      print("Success!");
      print(response);
    }).catchError((error) {
      print("Something went wrong!");
    });
  });
}

void paymentStream() {
  Network.useTestNetwork();
  Server server = new Server("https://horizon-testnet.stellar.org");

  KeyPair destination = KeyPair.fromAccountId(
      "GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");

  server.payments.forAccount(destination).stream().listen((response) {
    if (response is PaymentOperationResponse) {
      switch (response.assetType) {
        case "native":
          print(
              "Payment of ${response.amount} XLM from ${response.sourceAccount.accountId} received");
          break;
        default:
          print(
              "Payment of ${response.amount} ${response.assetCode} from ${response.sourceAccount.accountId}");
      }
    }
  });
}

/*
Account Id  : GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC
Secret Seed : SB7IAVKZJCK2T5TAN4F25TC7XGFB4BVLRPFJUT662Y2RK4MK7NAT4FO2

Account Id  : GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3
Secret Seed : SAACNKL2BBFVU7BVAVI2EIYSZQPQANZNYBVYUR7RFWTTRTOB6FPDR4NY
 */

void main() {
  createKey();
  createTestAccount("GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC");
  getAccountDetails("GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC");
  getAccountTransactions(
      "GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");
  sendPayment();
  paymentStream();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  stellar: ^0.3.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:stellar/stellar.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
50
Health:
Code health derived from static analysis. [more]
3
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
75
Overall:
Weighted score of the above. [more]
41
Learn more about scoring.

We analyzed this package on Nov 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:stellar/stellar.dart.

Health suggestions

Fix lib/src/xdr/xdr_enum.dart. (-59.23 points)

Analysis of lib/src/xdr/xdr_enum.dart reported 179 hints, including:

line 10 col 37: Avoid const keyword.

line 11 col 38: Avoid const keyword.

line 12 col 38: Avoid const keyword.

line 41 col 7: Avoid const keyword.

line 43 col 7: Avoid const keyword.

Fix lib/src/response.dart. (-34.03 points)

Analysis of lib/src/response.dart reported 83 hints, including:

line 38 col 12: Unnecessary new keyword.

line 77 col 12: Unnecessary new keyword.

line 80 col 15: Unnecessary new keyword.

line 83 col 15: Unnecessary new keyword.

line 86 col 15: Unnecessary new keyword.

Fix lib/src/operation.dart. (-25.97 points)

Analysis of lib/src/operation.dart reported 60 hints, including:

line 16 col 15: Use ; instead of {} for empty constructor bodies.

line 33 col 11: DO use curly braces for all flow control structures.

line 35 col 11: DO use curly braces for all flow control structures.

line 40 col 9: DO use curly braces for all flow control structures.

line 41 col 42: DO use curly braces for all flow control structures.

Fix additional 23 files with analysis or formatting issues. (-164.68 points)

Additional issues in the following files:

  • lib/src/response_effects.dart (59 hints)
  • lib/src/request.dart (47 hints)
  • lib/src/response_operations.dart (41 hints)
  • lib/src/xdr/xdr_operation.dart (32 hints)
  • lib/src/xdr/xdr_entry.dart (26 hints)
  • lib/src/key_pair.dart (25 hints)
  • lib/src/network.dart (21 hints)
  • lib/src/xdr/xdr_type.dart (21 hints)
  • lib/src/xdr/xdr_other.dart (13 hints)
  • lib/src/xdr/xdr_transaction.dart (13 hints)
  • lib/src/assets.dart (11 hints)
  • lib/src/xdr/xdr_scp.dart (10 hints)
  • lib/src/xdr/xdr_ledger.dart (9 hints)
  • lib/src/xdr/data_input.dart (6 hints)
  • lib/src/base32.dart (4 hints)
  • lib/src/xdr/xdr_auth.dart (4 hints)
  • lib/src/xdr/xdr_asset.dart (3 hints)
  • lib/src/memo.dart (2 hints)
  • lib/src/transaction.dart (2 hints)
  • lib/src/util.dart (2 hints)
  • lib/src/xdr/xdr_network.dart (2 hints)
  • lib/src/xdr/data_output.dart (1 hint)
  • lib/src/xdr/xdr_data.dart (1 hint)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (http).

The package description is too short. (-15 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
convert ^2.0.2 2.1.1
crypto ^2.0.6 2.1.3
eventsource ^0.2.1 0.2.2
fixnum ^0.10.9 0.10.11
http ^0.11.3+17 0.11.3+17 0.12.0+2
tweetnacl ^0.3.1 0.3.2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
logging 0.11.3+2
meta 1.1.8
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
sync 0.2.0
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
mockito ^3.0.0
test ^1.0.0