From 536db27da3b7be7ef06f066060ffd7f231f8334e Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 3 May 2014 16:52:39 -0300 Subject: [PATCH] add docs to Address class --- lib/Address.js | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/Address.js b/lib/Address.js index 9ca055b..6f592ab 100644 --- a/lib/Address.js +++ b/lib/Address.js @@ -1,3 +1,34 @@ +// Address +// ======= +// +// Handles a bitcoin address +// +// +// Synopsis +// -------- +// ``` +// var address = new Address('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'); +// if (address.isValid()) { +// //... +// } +// +// // Also an address can be created from +// // public keys +// var address = Address.fromPubKey(myPubkey); +// +// // Or from a ScriptPubKey (from a transaction output) +// var address = Address.fromScriptPubKey(scriptPubKey); +// +// // Multisig address p2sh handling +// var myPukeys = [pubkey0, pubkey1, pubkey2]; +// var p2shAddress = Address.fromPubKeys(2, myPubkeys); +// if (p2shAddress.isScript()) { //true +// } +// +// +// ``` + + 'use strict'; var imports = require('soop').imports(); var coinUtil = imports.coinUtil || require('../util'); @@ -31,7 +62,7 @@ Address.fromKey = function(key, network) { return Address.fromPubKey(key.public, network); }; -//create a p2sh m-of-n multisig address +// create a p2sh m-of-n multisig address Address.fromPubKeys = function(mReq, pubKeys, network, opts) { if (!network) network = 'livenet'; @@ -43,7 +74,6 @@ Address.fromPubKeys = function(mReq, pubKeys, network, opts) { } var script = Script.createMultisig(mReq, pubKeys, opts); - return Address.fromScript(script, network); }; @@ -101,7 +131,7 @@ Address.fromScriptPubKey = function(scriptPubKey, network) { return ret; }; - +// validates the address Address.prototype.validate = function() { this.doAsBinary(function() { Address.super(this, 'validate', arguments); @@ -115,6 +145,7 @@ Address.prototype.isValid = function() { return answer; }; +// returns the network information (livenet or testnet, as described on networks.js) of the address Address.prototype.network = function() { var version = this.version(); @@ -130,6 +161,7 @@ Address.prototype.network = function() { return answer; }; +// returns true is the address is a pay-to-script (P2SH) address type. Address.prototype.isScript = function() { return this.isValid() && this.version() === this.network().P2SHVersion; };