flutter_libra_core 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

Build Status

Libra Core #

Libra Core is a Dart library client that can be used to interact with Libra nodes.

Thanks to JavaScript Libra Core from Perfect Makanju.

There is an example Flutter application built for Android, [iOS] coming soon.

Table of Content #

Usage #

There are two main interface classes:

  • LibraWallet
  • LibraClient

Creating an Account #

Instantiate LibraWallet to create a libra account:

LibraWallet wallet = new LibraWallet();

Mnemonic is optional, a random mnemonic is generated and used without specifying one

const String mnemonic = 'danger gravity ... flip';
LibraWallet wallet = new LibraWallet(mnemonic: mnemonic);

A LibraWallet holds more than one LibraAccount objects, each account being a child of the wallet (start with index 0).

LibraAccount alice = wallet.newAccount();
LibraAccount bob = wallet.newAccount();

Generate addres from account:

String aliceAddress = alice.getAddress();

Minting Amount #

Instantiate LibraClient and uses faucet service to mint, default config as Testnet:

LibraClient client = new LibraClient();
int amount = 1000000;
await client.mintWithFaucetService(aliceAddress, BigInt.from(amount), needWait: false);

Checking an address balance #

Get state from alice which contains balance and other information such as sequenceNumber

LibraAccountState aliceState = await client.getAccountState(aliceAddress);
print('alice state: ${aliceState.balance}, ${aliceState.sequenceNumber}');

Transferring Libra Coins #

Transfer from alice to bob, implemented with Libra Canonical Serialization:

LibraAccount bob = wallet.newAccount();
String bobAddress = bob.getAddress();
int amount = 1000000;
await client.transferCoins(alice, bobAddress, amount);

// Get bob state
LibraAccountState bobState = await client.getAccountState(bobAddress);
print('bob state: ${bobState.balance}, ${bobState.sequenceNumber}');

Query Transaction with Sequence Number #

Query detail of the transaction sending from alice to bob, implemented with Libra Canonical Deserialization:

LibraSignedTransactionWithProof lastTransaction = await client.getAccountTransaction(aliceAddress, aliceState.sequenceNumber);
print('publicKey from alice: ${LibraHelpers.byteToHex(lastTransaction.signedTransaction.publicKey)}');

License #

MIT

0.1.0 #

  • Initial version, created by mmsqe

example/main.dart

import 'package:flutter_libra_core/flutter_libra_core.dart';

void main() async {
    // Creating an Account
    LibraWallet wallet = new LibraWallet();
    LibraAccount alice = wallet.newAccount();
    String aliceAddress = alice.getAddress();
    // Minting Amount
    LibraClient client = new LibraClient();
    int amount = 1000000;
    await client.mintWithFaucetService(aliceAddress, BigInt.from(amount), needWait: false);   
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_libra_core: ^0.1.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:flutter_libra_core/flutter_libra_core.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
34
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/src/client/Decoder.dart. (-1 points)

Analysis of lib/src/client/Decoder.dart reported 2 hints:

line 17 col 17: The value of the local variable 'key' isn't used.

line 18 col 11: The value of the local variable 'valLen' isn't used.

Fix lib/src/wallet/Mnemonic.dart. (-0.50 points)

Analysis of lib/src/wallet/Mnemonic.dart reported 1 hint:

line 2 col 8: Don't import implementation files from another package.

Format lib/__generated__/proto/access_path.pb.dart.

Run flutter format to format lib/__generated__/proto/access_path.pb.dart.

Fix additional 57 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/__generated__/proto/access_path.pbenum.dart (Run flutter format to format lib/__generated__/proto/access_path.pbenum.dart.)
  • lib/__generated__/proto/access_path.pbjson.dart (Run flutter format to format lib/__generated__/proto/access_path.pbjson.dart.)
  • lib/__generated__/proto/account_state_blob.pb.dart (Run flutter format to format lib/__generated__/proto/account_state_blob.pb.dart.)
  • lib/__generated__/proto/account_state_blob.pbenum.dart (Run flutter format to format lib/__generated__/proto/account_state_blob.pbenum.dart.)
  • lib/__generated__/proto/account_state_blob.pbjson.dart (Run flutter format to format lib/__generated__/proto/account_state_blob.pbjson.dart.)
  • lib/__generated__/proto/admission_control.pb.dart (Run flutter format to format lib/__generated__/proto/admission_control.pb.dart.)
  • lib/__generated__/proto/admission_control.pbenum.dart (Run flutter format to format lib/__generated__/proto/admission_control.pbenum.dart.)
  • lib/__generated__/proto/admission_control.pbjson.dart (Run flutter format to format lib/__generated__/proto/admission_control.pbjson.dart.)
  • lib/__generated__/proto/events.pb.dart (Run flutter format to format lib/__generated__/proto/events.pb.dart.)
  • lib/__generated__/proto/events.pbenum.dart (Run flutter format to format lib/__generated__/proto/events.pbenum.dart.)
  • lib/__generated__/proto/events.pbjson.dart (Run flutter format to format lib/__generated__/proto/events.pbjson.dart.)
  • lib/__generated__/proto/get_with_proof.pb.dart (Run flutter format to format lib/__generated__/proto/get_with_proof.pb.dart.)
  • lib/__generated__/proto/get_with_proof.pbenum.dart (Run flutter format to format lib/__generated__/proto/get_with_proof.pbenum.dart.)
  • lib/__generated__/proto/get_with_proof.pbjson.dart (Run flutter format to format lib/__generated__/proto/get_with_proof.pbjson.dart.)
  • lib/__generated__/proto/language_storage.pb.dart (Run flutter format to format lib/__generated__/proto/language_storage.pb.dart.)
  • lib/__generated__/proto/language_storage.pbenum.dart (Run flutter format to format lib/__generated__/proto/language_storage.pbenum.dart.)
  • lib/__generated__/proto/language_storage.pbjson.dart (Run flutter format to format lib/__generated__/proto/language_storage.pbjson.dart.)
  • lib/__generated__/proto/ledger_info.pb.dart (Run flutter format to format lib/__generated__/proto/ledger_info.pb.dart.)
  • lib/__generated__/proto/ledger_info.pbenum.dart (Run flutter format to format lib/__generated__/proto/ledger_info.pbenum.dart.)
  • lib/__generated__/proto/ledger_info.pbjson.dart (Run flutter format to format lib/__generated__/proto/ledger_info.pbjson.dart.)
  • lib/__generated__/proto/mempool.pb.dart (Run flutter format to format lib/__generated__/proto/mempool.pb.dart.)
  • lib/__generated__/proto/mempool.pbenum.dart (Run flutter format to format lib/__generated__/proto/mempool.pbenum.dart.)
  • lib/__generated__/proto/mempool.pbjson.dart (Run flutter format to format lib/__generated__/proto/mempool.pbjson.dart.)
  • lib/__generated__/proto/mempool_status.pb.dart (Run flutter format to format lib/__generated__/proto/mempool_status.pb.dart.)
  • lib/__generated__/proto/mempool_status.pbenum.dart (Run flutter format to format lib/__generated__/proto/mempool_status.pbenum.dart.)
  • lib/__generated__/proto/mempool_status.pbjson.dart (Run flutter format to format lib/__generated__/proto/mempool_status.pbjson.dart.)
  • lib/__generated__/proto/proof.pb.dart (Run flutter format to format lib/__generated__/proto/proof.pb.dart.)
  • lib/__generated__/proto/proof.pbenum.dart (Run flutter format to format lib/__generated__/proto/proof.pbenum.dart.)
  • lib/__generated__/proto/proof.pbjson.dart (Run flutter format to format lib/__generated__/proto/proof.pbjson.dart.)
  • lib/__generated__/proto/transaction.pb.dart (Run flutter format to format lib/__generated__/proto/transaction.pb.dart.)
  • lib/__generated__/proto/transaction.pbenum.dart (Run flutter format to format lib/__generated__/proto/transaction.pbenum.dart.)
  • lib/__generated__/proto/transaction.pbjson.dart (Run flutter format to format lib/__generated__/proto/transaction.pbjson.dart.)
  • lib/__generated__/proto/transaction_info.pb.dart (Run flutter format to format lib/__generated__/proto/transaction_info.pb.dart.)
  • lib/__generated__/proto/transaction_info.pbenum.dart (Run flutter format to format lib/__generated__/proto/transaction_info.pbenum.dart.)
  • lib/__generated__/proto/transaction_info.pbjson.dart (Run flutter format to format lib/__generated__/proto/transaction_info.pbjson.dart.)
  • lib/__generated__/proto/validator_change.pb.dart (Run flutter format to format lib/__generated__/proto/validator_change.pb.dart.)
  • lib/__generated__/proto/validator_change.pbenum.dart (Run flutter format to format lib/__generated__/proto/validator_change.pbenum.dart.)
  • lib/__generated__/proto/validator_change.pbjson.dart (Run flutter format to format lib/__generated__/proto/validator_change.pbjson.dart.)
  • lib/__generated__/proto/validator_public_keys.pb.dart (Run flutter format to format lib/__generated__/proto/validator_public_keys.pb.dart.)
  • lib/__generated__/proto/validator_public_keys.pbenum.dart (Run flutter format to format lib/__generated__/proto/validator_public_keys.pbenum.dart.)
  • lib/__generated__/proto/validator_public_keys.pbjson.dart (Run flutter format to format lib/__generated__/proto/validator_public_keys.pbjson.dart.)
  • lib/__generated__/proto/validator_set.pb.dart (Run flutter format to format lib/__generated__/proto/validator_set.pb.dart.)
  • lib/__generated__/proto/validator_set.pbenum.dart (Run flutter format to format lib/__generated__/proto/validator_set.pbenum.dart.)
  • lib/__generated__/proto/validator_set.pbjson.dart (Run flutter format to format lib/__generated__/proto/validator_set.pbjson.dart.)
  • lib/__generated__/proto/vm_errors.pb.dart (Run flutter format to format lib/__generated__/proto/vm_errors.pb.dart.)
  • lib/__generated__/proto/vm_errors.pbenum.dart (Run flutter format to format lib/__generated__/proto/vm_errors.pbenum.dart.)
  • lib/__generated__/proto/vm_errors.pbjson.dart (Run flutter format to format lib/__generated__/proto/vm_errors.pbjson.dart.)
  • lib/__generated__/proto/wrappers.pb.dart (Run flutter format to format lib/__generated__/proto/wrappers.pb.dart.)
  • lib/__generated__/proto/wrappers.pbenum.dart (Run flutter format to format lib/__generated__/proto/wrappers.pbenum.dart.)
  • lib/__generated__/proto/wrappers.pbjson.dart (Run flutter format to format lib/__generated__/proto/wrappers.pbjson.dart.)
  • lib/flutter_libra_core.dart (Run flutter format to format lib/flutter_libra_core.dart.)
  • lib/src/client/Encoder.dart (Run flutter format to format lib/src/client/Encoder.dart.)
  • lib/src/client/index.dart (Run flutter format to format lib/src/client/index.dart.)
  • lib/src/common/simple_deserializer.dart (Run flutter format to format lib/src/common/simple_deserializer.dart.)
  • lib/src/common/simple_serializer.dart (Run flutter format to format lib/src/common/simple_serializer.dart.)
  • lib/src/transaction/index.dart (Run flutter format to format lib/src/transaction/index.dart.)
  • lib/src/wallet/Accounts.dart (Run flutter format to format lib/src/wallet/Accounts.dart.)

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 (protoc_plugin).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
bip39 ^1.0.3 1.0.3
convert ^2.1.1 2.1.1
ed25519_dart_base ^0.0.1 0.0.1
fixnum ^0.10.9 0.10.9
flutter 0.0.0
grpc ^2.0.0+1 2.1.2
hex ^0.1.2 0.1.2
pointycastle_base ^0.0.2 0.0.2
protoc_plugin ^17.0.5 17.0.5 19.0.1
Transitive dependencies
analyzer 0.38.5 0.39.0
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
crypto 2.1.3
csslib 0.16.1
dart_style 1.3.2
front_end 0.1.27 0.1.28
glob 1.2.0
googleapis_auth 0.2.10
html 0.14.0+3
http 0.12.0+2
http2 1.0.0
http_parser 3.1.3
js 0.6.1+1
kernel 0.3.27 0.3.28
meta 1.1.7
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pointycastle 1.0.1
protobuf 0.13.16+1 1.0.0
pub_semver 1.4.2
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
flutter_test