Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
- Balance as an ES6 class.
- Added `doTransferToken` to `api/nep5`
- Unit tests for `utils`
- Typescript typings fixed
fix
  • Loading branch information
snowypowers committed Nov 27, 2017
1 parent 4b2708c commit 6f59100
Show file tree
Hide file tree
Showing 32 changed files with 2,077 additions and 1,297 deletions.
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"name": "@cityofzion/neon-js",
"description": "Javascript libraries for neo wallet using https://github.com/neochainio/neowallet/blob/master/js/wallet.js as the original source.",
"version": "2.0.0",
"version": "2.1.0",
"main": "lib/index.js",
"browser": "lib/browser.js",
"types": "src/index.d.ts",
Expand Down
23 changes: 23 additions & 0 deletions source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ Changelog

This details the changes made from the previous recorded version.

2.1.0
=====

- Balance as an ES6 class.

- ``verifyAssets`` to validate unspent coins against a given NEO node. Used to check if balance is fully synced and usable.
- ``applyTx`` to apply a spending of a Transaction to the Balance. Allows a Balance to be used to build another Transaction without waiting for sync.
- Data structure reworked. AssetBalances are now tucked under ``assets``. Use ``assetSymbols`` to discover the keys for lookup.

::

// This array contains all the symbols of the assets available in this Balance
balance.assetSymbols = ['NEO', 'GAS']
// Lookup assets using their symbols
balance.assets = {
NEO: {balance: 1, unspent: [ Object ], spent: [], unconfirmed: []}
GAS: {balance: 25.1, unspent: [ Object ], spent: [], unconfirmed: []}
}

- Added ``doTransferToken`` to ``api/nep5``
- Unit tests for ``utils``
- Typescript typings fixed

2.0.0
======

Expand Down
4 changes: 2 additions & 2 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
# built documents.
#
# The short X.Y version.
version = u'2.0.0'
version = u'2.1.0'
# The full version, including alpha/beta/rc tags.
release = u'2.0.0'
release = u'2.1.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
16 changes: 9 additions & 7 deletions source/interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ A balance describes the assets that an address owns, as well as list the unspent

{// Balance
address: string, // The address
NEO: {
balance: number,
unspent: Coin[]
assets: {
NEO: {
balance: number,
unspent: Coin[]
},
GAS: {
balance: number,
unspent: Coin[]
GAS: {
balance: number,
unspent: Coin[]
}
}
}

The address property acts as an ID for this object and is used to derive the scriptHash when calculating the change to give back to the account.

All the other properties are named using asset symbols. Currently, there are only 2 assets available (NEO/GAS) and they both have similar names to symbols. Symbols should be in capital letters and be of 3-4 letters long.
The assets are stored in an object and retrieved using their symbols. Currently, there are only 2 assets available (NEO/GAS) and they both have similar names to symbols. Symbols should be in capital letters and be of 3-4 letters long.

Each symbol will be contain the ``balance`` and ``unspent`` property. ``balance`` tells us the total amount of this asset available and serves as a simple check if there is enough assets available to fulfil the sending intents. ``unspent`` contains a list of ``Coin`` that are used as Transaction Inputs.

Expand Down
3 changes: 3 additions & 0 deletions source/reference/wallet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Module ``wallet``
.. autoclass:: Account
:members:

.. autoclass:: Balance
:members:

.. autofunction:: encrypt

.. autofunction:: decrypt
Expand Down
25 changes: 25 additions & 0 deletions source/wallet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ You cannot derive a private key from a Account created using a Public Key. (Acco
const account2 = Neon.create.account(publicKey)
account.privateKey // Throws error

Balance
=======

The Balance class stores the balance of the account. It is usually retrieved using a 3rd party API as NEO nodes do not have a RPC call to easily retrieve this information with a single call.

::

import Neon from 'neon-js'
Neon.create.balance({net: 'TestNet', address: 'ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW'})

import {wallet, api} from 'neon-js'
// This form is useless as it is an empty balance.
const balance = new wallet.Balance({net: 'TestNet', address: 'ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW'})
// We get a useful balance that can be used to fill a transaction through api
const filledBalance = api.getBalanceFrom('ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW', api.neonDB)
// This contains all symbols of assets available in this balance
const symbols = filledBalance.assetSymbols
// We retrieve the unspent coins from the assets object using the symbol
const neoCoins = filledBalance.assets['NEO'].unspent
// We can verify the information retrieved using verifyAssets
filledBalance.verifyAssets('https://seed1.neo.org:20332')

The Balance class is used to track the unspent coins available to construct transactions with. ``verifyAssets`` is a handy method to make sure the unspent coins provided by the 3rd party API is really unspent by verifying them against a NEO node. However, this is an expensive operation so use sparingly.


Core
====

Expand Down
Loading

0 comments on commit 6f59100

Please sign in to comment.