BTSDEX v0.6.0

in #utopian-io2 years ago

BTSDEX.png

Here comes the new version of the btsdex package. At first I planned to release the package by increasing the last number (patch), but due to the loss of compatibility, I had to increase the minor number. I hope you will like the changes.

Loss of compatibility

In all previous versions, before using the BitShares class, it was necessary to initialize it:

BitShares.init(<node>, <autoconnect>, <autoreconnect>)

Now this method is not. But the connect method has been enriched with parameters:

BitShares.connect(<node>, <autoreconnect>)

If you use an event system to connection, and you want to specify connection parameters, use BitShares.node andBitShares.autoreconnect to do this.

const BitShares = require("btsdex");

BitShares.node = "wss://api.bts.blckchnd.com";
BitShares.autoreconnect = false;// default true

BitShares.subscribe("connected", start);

async function start() {
  // code here
}

This is the only incompatibility with other versions.

Transaction builder

Each transaction is considered accepted after inclusion in the block. Blocks are created every 3 seconds. If you need to perform several operations, their sequential execution can take considerable time. Fortunately, several operations can be included in a single transaction. To do this, use the transaction builder.

To create a new transaction:

let tx = BitShares.newTx([<activePrivateKey>, ...])

or if you already have an instance of the BitShares class:

let acc = await BitShares.login(<accountName>, <password>);
let tx = acc.newTx()

Each operation available out of the box has a method (<name>Operation) that forms the operation object, but does not send it to the blockchain.

To obtain the objects of operations:

let operation1 = await acc.transferOperation("scientistnik", "BTS", 10)
let operation2 = await acc.assetIssueOperation("scientistnik", "ABC", 10)
...

Adding operations to a transaction:

tx.add(operation1)
tx.add(operation2)
...

You can get the cost of the transaction:

let cost = await tx.cost()
console.log(cost) // {BTS: 1.234}

After that, the transaction can be sent:

await tx.broadcast()

or

await acc.broadcast(tx)

The operations available to the account in the BitShares network are much more than the available object of the class BitShares. If you know which fields are necessary for an operation, you can use the transaction builder to submit this operation.

Example of creating a new account:

let BitShares = require("btsdex")

BitShares.subscribe("connected", start)

async function start () {
  let acc = await BitShares.login(<accountName>, <password>)

  let params = {
    fee: {amount: 0, asset_id: "1.3.0"},
    name: "trade-bot3",
    registrar: "1.2.21058",
    referrer: "1.2.21058",
    referrer_percent: 5000,
    owner: {
      weight_threshold: 1,
      account_auths: [],
      key_auths: [[<ownerPublicKey>, 1]],
      address_auths: []
    },
    active: {
      weight_threshold: 1,
      account_auths: [],
      key_auths: [[<activePublicKey>, 1]],
      address_auths: []
    },
    options: {
      memo_key: <memoPublicKey>,
      voting_account: "1.2.5",
      num_witness: 0,
      num_committee: 0,
      votes: []
    },
    extensions: []
  };

  let tx = acc.newTx()
  tx.account_create(params) // 'account_create' is the name of the operation
  await tx.broadcast()
}

One-time request in REPL mode

If you only need to make one request, you can use --account,--asset, --block,--object, --history,--node or --transfer command line keys:

$ btsdex --account <'name' or 'id' or 'last number in id'>
{
  "id": "1.2.5992",
  "membership_expiration_date": "1970-01-01T00: 00: 00",
  "registrar": "1.2.37",
  "referrer": "1.2.21",
  ...
}
$ btsdex --asset <'symbol' or 'id' or 'last number in id'>
{
  "id": "1.3.0",
  "symbol": "BTS",
  "precision": 5,
  ...
}
$ btsdex --block [<number>]
block_num: 4636380
{
  "previous": "0046bedba1317d146dd6afbccff94412d76bf094",
  "timestamp": "2018-10-01T13: 09: 40",
  "witness": "1.6.41",
  ...
}
$ btsdex --object 1.2.3
{
  "id": "1.2.3",
  "membership_expiration_date": "1969-12-31T23: 59: 59",
  "registrar": "1.2.3",
  "referrer": "1.2.3",
  ...
}
$ btsdex --history <account> [<limit>] [<start>] [<stop>]
[
  {
    "id": "1.11.98179",
    "op": [
      0,
  ...
}]
$ btsdex --node wss: //api.bts.blckchnd.com
Connected to API node: wss: //api.bts.blckchnd.com
$ btsdex --transfer <from> <to> <amount> <asset> [--key]
Transfered <amount> <asset> from '<from>' to '<to>' with memo '<memo>'

Documentation Update

Updated documentation, added its Russian version.


If you have any wishes for further development of the package, or perhaps there is no very useful function, write on GitHub, or if you want to talk in person, use Telegram-channel btsdex.

I have it all. Great weekend to everyone!

Sort:  

Congratulations @scientistnik! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 250 upvotes. Your next target is to reach 500 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Trick or Treat - Publish your scariest halloween story and win a new badge
SteemitBoard notifications improved

Support SteemitBoard's project! Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.22
TRX 0.02
BTC 11545.73
ETH 394.92
SBD 1.05