From 9d0b5e04fe4099ce5ee3f74a2861daac7c6354f9 Mon Sep 17 00:00:00 2001 From: Esteban Ordano Date: Tue, 16 Dec 2014 03:02:05 -0300 Subject: [PATCH] Update Signature, URI, Unit --- docs/Signature.md | 1 - docs/URI.md | 18 +++++------------- docs/Unit.md | 17 +++++------------ lib/unit.js | 5 +++-- 4 files changed, 13 insertions(+), 28 deletions(-) delete mode 100644 docs/Signature.md diff --git a/docs/Signature.md b/docs/Signature.md deleted file mode 100644 index e400025..0000000 --- a/docs/Signature.md +++ /dev/null @@ -1 +0,0 @@ -# Signature diff --git a/docs/URI.md b/docs/URI.md index 17578eb..5bcc7f7 100644 --- a/docs/URI.md +++ b/docs/URI.md @@ -1,7 +1,6 @@ # URI -Represents a bitcoin payment uri. Bitcoin URI strings became the most popular -way to share payment request, sometimes as a bitcoin link and others using a QR code. +Represents a bitcoin payment uri. Bitcoin URI strings became the most popular way to share payment request, sometimes as a bitcoin link and others using a QR code. URI Examples: ``` @@ -10,9 +9,7 @@ bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2 bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2&message=Payment&label=Satoshi&extra=other-param ``` -The main use that we expect you'll have for the `URI` class in bitcore is -validating and parsing bitcoin URIs. A `URI` instance exposes the address as a -bitcore `Address` object and the amount in Satoshis, if present. +The main use that we expect you'll have for the `URI` class in bitcore is validating and parsing bitcoin URIs. A `URI` instance exposes the address as a bitcore `Address` object and the amount in Satoshis, if present. The code for validating uris looks like this: ```javascript @@ -22,16 +19,11 @@ var uri = new URI(uriString); console.log(uri.address.network, uri.amount); // 'livenet', 120000000 ``` -All standard parameters can be found as members of the `URI` instance. However -a bitcoin uri may contain other non-standard parameters, all those can be found -under the `extra` namespace. +All standard parameters can be found as members of the `URI` instance. However a bitcoin uri may contain other non-standard parameters, all those can be found under the `extra` namespace. -See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki) -for more information. +See [the official BIP21 spec](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki) for more information. -Other usecase important usecase for the `URI` class is creating a bitcoin URI for -sharing a payment request. That can be acomplished by using an Object to create -an instance of URI. +Other usecase important usecase for the `URI` class is creating a bitcoin URI for sharing a payment request. That can be acomplished by using an Object to create an instance of URI. The code for creating an URI from an Object looks like this: ```javascript diff --git a/docs/Unit.md b/docs/Unit.md index a6fec8f..2639148 100644 --- a/docs/Unit.md +++ b/docs/Unit.md @@ -1,22 +1,18 @@ # Unit -Unit it's a utility for handling and converting bitcoins units. We strongly -recommend you to always use satoshis to represent amount inside your application -and only convert them to other units in the front-end. +Unit is an utility for handling and converting bitcoins units. We strongly recommend you to always use satoshis to represent amount inside your application and only convert them to other units in the front-end. -The supported units are BTC, mBTC, bits and satoshis. The codes for each unit -can be found as members of the Unit class. +The supported units are BTC, mBTC, bits and satoshis. The codes for each unit can be found as members of the Unit class. ```javascript var btcCode = Unit.BTC; var mbtcCode = Unit.mBTC; +var ubtcCode = Unit.uBTC; var bitsCode = Unit.bits; var satsCode = Unit.satoshis; ``` -There are two ways for creating a unit instance. You can instanciate the class -using a value and a unit code; alternatively if the unit it's fixed you could -you some of the static methods. Check some examples below: +There are two ways for creating a unit instance. You can instanciate the class using a value and a unit code; alternatively if the unit it's fixed you could you some of the static methods. Check some examples below: ```javascript var unit; @@ -33,10 +29,7 @@ unit = Unit.fromBits(amount); unit = Unit.fromSatoshis(amount); ``` -Once you have a unit instance, you can check it's representantion in all the -available units. For your convinience the classes expose three ways to acomplish -this. Using the `.to(unitCode)` method, using a fixed unit like `.toSatoshis()` -or by using the accessors. +Once you have a unit instance, you can check it's representantion in all the available units. For your convinience the classes expose three ways to acomplish this. Using the `.to(unitCode)` method, using a fixed unit like `.toSatoshis()` or by using the accessors. ```javascript var unit; diff --git a/lib/unit.js b/lib/unit.js index 45a2dfd..d334397 100644 --- a/lib/unit.js +++ b/lib/unit.js @@ -48,6 +48,7 @@ function Unit(amount, code) { var UNITS = { 'BTC' : [1e8, 8], 'mBTC' : [1e5, 5], + 'uBTC' : [1e2, 2], 'bits' : [1e2, 2], 'satoshis' : [1, 0] }; @@ -95,7 +96,7 @@ Unit.fromMilis = function(amount) { * @param {Number} amount - The amount in bits * @returns {Unit} A Unit instance */ -Unit.fromBits = function(amount) { +Unit.fromMicros = Unit.fromBits = function(amount) { return new Unit(amount, Unit.bits); }; @@ -152,7 +153,7 @@ Unit.prototype.toMilis = function(code) { * * @returns {Number} The value converted to bits */ -Unit.prototype.toBits = function(code) { +Unit.prototype.toMicros = Unit.prototype.toBits = function(code) { return this.to(Unit.bits); };