laksadart 0.1.19

  • Readme
  • Changelog
  • Example
  • Installing
  • 35

Laksa, Dart Version #

Waiting for Usage example and docs

Porting from Laksa and ZilliqaJS #

  • Account

    • [x] create
    • [x] toFile
    • [x] fromFile
    • [x] signTransaction
  • Wallet

    • [x] add
    • [x] remove
    • [x] getAccount
    • [x] encryptAccount
    • [x] decryptAccount
    • [x] setDefaultAccount
    • [x] getDefaultAccount
  • crypto

    • [x] getDerivedKey ((keystore))
    • [x] encrypt(keystore)
    • [x] decrypt(keystore)
    • [x] sign(Schnorr function)
    • [x] verify(Schnorr function)
    • [x] SchnorrSign(Schnorr function with protobuf encodation)
    • [x] generatePrivateKey
    • [x] getPublicKeyFromPrivateKey
    • [x] getPublicKeyFromPrivateKey
    • [x] getAddressFromPublicKey
    • [x] getAddressFromPrivateKey
    • [x] hmac-drbg(HMAC update digest)
    • [x] getDRBG(inner function)
    • [x] generateNewPrivateKey(inner function)
    • [x] privateKeyToPublic(inner function)
    • [x] getPublic(inner function)
  • Messenger

    • [x] send
    • [x] sendServer(Scilla runner)
    • [x] setNodeProvider
    • [x] setScillaProvider
    • [x] setMiddleware
    • [x] useMiddleware
  • Blockchain(RPC methods)

    • [x] getBalance
    • [x] getBlockchainInfo
    • [x] getDSBlock
    • [x] getTxBlock
    • [x] getLatestDSBlock
    • [x] getNumDSBlocks
    • [x] getDSBlockRate
    • [x] getDSBlockListing
    • [x] getLatestTxBlock
    • [x] getNumTxBlocks
    • [x] getTxBlockRate
    • [x] getTxBlockListing
    • [x] getNumTransactions
    • [x] getTransactionRate
    • [x] getCurrentMiniEpoch
    • [x] getCurrentDSEpoch
    • [x] getPrevDifficulty
    • [x] getPrevDSDifficulty
    • [x] getRecentTransactions
    • [x] getNumTxnsTxEpoch
    • [x] getNumTxnsDSEpoch
    • [x] getMinimumGasPrice
    • [x] createTransaction
    • [x] checkCode(Scilla runner)
    • [x] testCall(Scilla runner)
  • Provider

    • BaseProvider
    • HttpProvider
      • [x] buildPayload
      • [x] buildEndpointPayload
      • [x] performRPC
      • [x] send
      • [x] sendServer(Scilla runner)
    • RPCMiddleware
      • [x] RPCResponseBody
      • [x] SuccessMiddleware
      • [x] ErrorMiddleware
    • RPCMehod
    • Endpoint
  • Transaction

    • [x] Factory
    • [x] sendTransaction
    • [x] trackTx
    • [x] confirm
    • [x] getVersion(calculate version number)
  • Contract

    • [x] Factory
    • [x] deploy
    • [x] call
    • [x] confirmTx
    • [x] sendContract
    • [x] signTxn
    • [x] getState
    • [x] setInitParamsValues
    • [x] setDeployPayload
    • [x] setCallPayload
  • utils

    • [x] numbers.strip0x
    • [x] numbers.toHex
    • [x] numbers.bytesToHex
    • [x] numbers.numberToBytes
    • [x] numbers.hexToBytes
    • [x] numbers.intToBytes
    • [x] numbers.hexToInt
    • [x] validators.isUrl
    • [x] validators.isByteString
    • [x] validators.isAddres
    • [x] validators.isPublicKey
    • [x] validators.isPrivateKey
    • [x] validators.isSignature
    • [x] unit.fromQa
    • [x] unit.toQa
    • [x] encodeTransactionProto

Thanks to #

  • Zilliqa, who make the js lib originally.
  • PointyCastle, who make the dart crypto packages.
  • Web3Dart, who make the web3 dart version.

Change Log #

[v0.1.19] AUG-21-2019

Feb-20-2019 #

  • added isolates to account.encryptAccount/decryptAccount
  • replace angel_validate to validators

Jan-19-2019 #

  • dartfmt the proto package
  • edit testScilla.dart, eliminate the == type warning
  • update description
  • move example.dart to example folder

Jan-18-2019 #

initial added to pub

example/example.dart

import 'dart:convert';
import 'dart:io';
import 'package:laksadart/src/utils/unit.dart' as unit;
import 'package:laksadart/laksadart.dart';

main() async {
  var laksa = new Laksa(
      nodeUrl: 'https://dev-api.zilliqa.com', // 'https://api.zilliqa.com',
      scillaUrl: 'https://scilla-runner.zilliqa.com',
      networkID: 'DevNet');

  var acc = laksa.wallet
      .add('e19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930');

  void autoTransaction() async {
    await acc.encryptAccount('111');
    await acc.updateBalance();
    var nonce = acc.nonce;
    var txn = laksa.transactions.newTx({
      'toAddr': '2e3c9b415b19ae4035503a06192a0fad76e04243',
      'amount': unit.Unit.Li(nonce + 1).qa,
      'gasPrice': unit.Unit.Li(1000).qa,
      'gasLimit': 1,
      'version':
          laksa.messenger.setTransactionVersion(1, laksa.messenger.Network_ID)
    });

    var signed = await acc.signTransaction(txn, passphrase: '111');
    print(json.encode(signed.toPayload));
    var sent = await signed.sendTransaction();
    print(sent.transaction.TranID);
    var sendTime = DateTime.now();
    var result = await sent.transaction.confirm(
        txHash: sent.transaction.TranID, maxAttempts: 33, interval: 1000);
    print(result.receipt['success']);
    if (result != null) {
      var during = DateTime.now().difference(sendTime);
      print('confirmed during:$during');
    }
  }

  void deploy() async {
    // File contract = new File('../test/contracts/helloworldversion.txt');
    File contract = new File('../test/contracts/fungible-token.scilla');

    await contract.readAsString().then((contractString) async {
      Laksa laksa = new Laksa(
          nodeUrl:
              'https://dev-api.zilliqa.com', //'https://staging-api.aws.z7a.xyz'
          scillaUrl: 'https://scilla-runner.zilliqa.com',
          networkID: 'DevNet');
      // var init = [
      //   {
      //     'vname': '_scilla_version',
      //     'type': 'Uint32',
      //     'value': '0',
      //   },
      //   {
      //     'value': '0x9bfec715a6bd658fcb62b0f8cc9bfa2ade71434a',
      //     'vname': 'owner',
      //     'type': 'ByStr20'
      //   }
      // ];

      var init = [
        {"vname": "_scilla_version", "type": "Uint32", "value": "0"},
        {
          "vname": "owner",
          "type": "ByStr20",
          "value": "0x9bfec715a6bd658fcb62b0f8cc9bfa2ade71434a"
        },
        {"vname": "total_tokens", "type": "Uint128", "value": "1000000000"},
        {"vname": "decimals", "type": "Uint32", "value": "0"},
        {"vname": "name", "type": "String", "value": "BobCoin"},
        {"vname": "symbol", "type": "String", "value": "\$\BOB"}
      ];

      laksa.wallet.add(
          'e19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930');

      var newContract = laksa.contracts
          .newContract(code: contractString, init: init, version: 0);
      newContract.setDeployPayload(
          gasLimit: 10000, gasPrice: BigInt.from(1000000000), toDS: true);
      var sent = await newContract.sendContract();
      print(sent.transaction.toPayload);
      var sendTime = DateTime.now();
      print('sent contract at:$sendTime');
      print(sent.transaction.TranID);
      var deployed = await sent.confirmTx(maxAttempts: 33, interval: 1000);
      print(deployed.ContractAddress);
      if (deployed != null) {
        var during = DateTime.now().difference(sendTime);
        print('deployed confirmed during:$during');
      }

      // test call contract

      // deployed.setCallPayload(
      //     transition: 'setHello',
      //     params: [
      //       {'vname': "msg", 'type': "String", 'value': "Test World"}
      //     ],
      //     gasLimit: 8000,
      //     gasPrice: unit.Unit.Li(1000).qa,
      //     amount: unit.Unit.Qa(0).qa,
      //     toDS: true);
      // var sentCall = await deployed.sendContract();
      // print(sentCall.transaction.toPayload);
      // var calledTime = DateTime.now();
      // print('sent called time:$calledTime');
      // print(sentCall.transaction.TranID);

      // await sentCall.confirmTx(maxAttempts: 33, interval: 1000);
      // print(sentCall.ContractAddress);
      // if (sentCall != null) {
      //   var during2 = DateTime.now().difference(calledTime);
      //   print('called confirmed during:$during2');
      // }
      // var state = await sentCall.getState();
      // print("The state of the contract is:$state");
    });
  }

  void wallet() async {
    Laksa laksa = new Laksa(
        nodeUrl:
            'https://dev-api.zilliqa.com', //'https://staging-api.aws.z7a.xyz'
        scillaUrl: 'https://scilla-runner.zilliqa.com',
        networkID: 'DevNet');
    var newAcc = laksa.wallet.create();
    await newAcc.encryptAccount('passphrase');

    print(getAddressFromPublicKey(
        '02526CC9198736761D9FFDAE0CA5E848667D31BFDB7754D8F7B2291D17A60CF63C'));

    // print(newAcc.address);
    // await newAcc.updateBalance();
    // print(newAcc.balance);
  }

  // await wallet();
  // for (int i = 0; i < 10; i++) {
  //   await autoTransaction();
  // }

  await deploy();
}

Use this package as a library

1. Depend on it

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


dependencies:
  laksadart: ^0.1.19

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:laksadart/laksadart.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
75
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
35
Learn more about scoring.

We analyzed this package on Jan 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Fix lib/src/proto/message.pbjson.dart. (-12.66 points)

Analysis of lib/src/proto/message.pbjson.dart reported 27 hints, including:

line 7 col 24: Avoid const keyword.

line 9 col 8: Avoid const keyword.

line 10 col 5: Avoid const keyword.

line 14 col 39: Avoid const keyword.

line 16 col 8: Avoid const keyword.

Fix lib/src/account/account.dart. (-11.78 points)

Analysis of lib/src/account/account.dart reported 25 hints, including:

line 24 col 7: Unnecessary new keyword.

line 63 col 22: Unnecessary new keyword.

line 74 col 14: Unnecessary new keyword.

line 94 col 14: Unnecessary new keyword.

line 103 col 14: Unnecessary new keyword.

Fix lib/src/crypto/isolates.dart. (-11.33 points)

Analysis of lib/src/crypto/isolates.dart reported 24 hints, including:

line 8 col 20: Unnecessary new keyword.

line 17 col 23: Unnecessary new keyword.

line 36 col 16: Unnecessary new keyword.

line 60 col 20: Unnecessary new keyword.

line 70 col 23: Unnecessary new keyword.

Fix additional 30 files with analysis or formatting issues. (-79.69 points)

Additional issues in the following files:

  • lib/src/proto/message.pb.dart (23 hints)
  • lib/src/crypto/schnorr.dart (17 hints)
  • lib/src/account/address.dart (15 hints)
  • lib/src/Laksa.dart (13 hints)
  • lib/src/account/wallet.dart (10 hints)
  • lib/src/crypto/hmac-drbg.dart (7 hints)
  • lib/src/crypto/keystore/util.dart (7 hints)
  • lib/src/crypto/keystore/keyDerivator.dart (6 hints)
  • lib/src/contract/testScilla.dart (5 hints)
  • lib/src/transaction/transaction.dart (5 hints)
  • lib/src/utils/common.dart (5 hints)
  • lib/src/utils/numbers.dart (5 hints)
  • lib/src/utils/unit.dart (5 hints)
  • lib/src/contract/abi.dart (4 hints)
  • lib/src/contract/contract.dart (4 hints)
  • lib/src/contract/factory.dart (4 hints)
  • lib/src/crypto/keystore/function.dart (4 hints)
  • lib/src/messenger/Messenger.dart (3 hints)
  • lib/src/provider/Base.dart (3 hints)
  • lib/src/provider/Middleware.dart (3 hints)
  • lib/src/crypto/bech32.dart (2 hints)
  • lib/src/crypto/dartRandom.dart (2 hints)
  • lib/src/messenger/Blockchain.dart (2 hints)
  • lib/src/provider/Http.dart (2 hints)
  • lib/src/transaction/util.dart (2 hints)
  • lib/src/crypto/keystore/keyStore.dart (1 hint)
  • lib/src/crypto/sha256digest.dart (1 hint)
  • lib/src/transaction/factory.dart (1 hint)
  • lib/src/utils/transaction.dart (1 hint)
  • lib/src/utils/validators.dart (1 hint)

Maintenance issues and suggestions

Support latest dependencies. (-40 points)

The version constraint in pubspec.yaml does not support the latest published versions for 4 dependencies (json_serializable, protobuf, uuid, validators).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
bip32 ^1.0.5 1.0.5
bip39 ^1.0.3 1.0.3
collection ^1.14.11 1.14.12
convert ^2.1.1 2.1.1
crypto ^2.0.6 2.1.4
fixnum ^0.10.9 0.10.11
http ^0.12.0 0.12.0+4
json_serializable ^2.0.1 2.3.0 3.2.5
meta ^1.1.6 1.1.8
pointycastle ^1.0.0-rc4 1.0.2
protobuf ^0.10.5 0.10.8 1.0.1
tuple ^1.0.2 1.0.3
uuid ^1.0.3 1.0.3 2.0.4
validators ^1.0.0+1 1.0.0+1 2.0.0+1
Transitive dependencies
analyzer 0.36.4 0.39.4
args 1.5.2
async 2.4.0
boolean_selector 1.0.5 2.0.0
bs58check 1.0.1
build 1.2.2
build_config 0.4.1+1
charcode 1.1.2
checked_yaml 1.0.2
coverage 0.13.4
csslib 0.16.1
dart_style 1.2.9 1.3.3
front_end 0.1.19 0.1.29
glob 1.2.0
hex 0.1.2
html 0.14.0+3
http_multi_server 2.1.0
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_annotation 2.3.0 3.0.1
kernel 0.3.19 0.3.29
logging 0.11.4
matcher 0.12.6
mime 0.9.6+3
multi_server_socket 1.0.2
node_interop 1.0.3
node_io 1.0.1+2
node_preamble 1.4.8
package_config 1.1.0 2.0.0
package_resolver 1.0.10
path 1.6.4
pedantic 1.9.0
pool 1.4.0
pub_semver 1.4.2
pubspec_parse 0.1.5
quiver 2.1.2+1
shelf 0.7.5
shelf_packages_handler 1.0.4
shelf_static 0.2.8
shelf_web_socket 0.2.3
source_gen 0.9.4+4 0.9.4+7
source_map_stack_trace 1.1.5
source_maps 0.10.8
source_span 1.6.0
stack_trace 1.9.3
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
test_api 0.2.13
test_core 0.2.18
typed_data 1.1.6
vm_service 2.3.1
watcher 0.9.7+13
web_socket_channel 1.1.0
yaml 2.2.0
Dev dependencies
test ^1.3.2 1.11.1