add docs to Address class

This commit is contained in:
Matias Alejo Garcia 2014-05-03 16:52:39 -03:00
parent f0155a5297
commit 536db27da3
1 changed files with 35 additions and 3 deletions

View File

@ -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;
};