bitcore-wallet-service/lib/model/address.js

49 lines
1.0 KiB
JavaScript
Raw Normal View History

2015-01-27 05:18:45 -08:00
'use strict';
2015-03-12 07:34:41 -07:00
var Bitcore = require('bitcore-wallet-utils').Bitcore;
2015-02-03 11:46:28 -08:00
2015-02-17 16:20:08 -08:00
function Address() {
this.version = '1.0.0';
};
Address.create = function(opts) {
2015-02-02 12:07:18 -08:00
opts = opts || {};
2015-01-27 05:18:45 -08:00
2015-02-17 16:20:08 -08:00
var x = new Address();
x.createdOn = Math.floor(Date.now() / 1000);
x.address = opts.address;
2015-04-20 13:46:40 -07:00
x.walletId = opts.walletId;
2015-02-21 14:13:15 -08:00
x.isChange = opts.isChange;
2015-02-17 16:20:08 -08:00
x.path = opts.path;
x.publicKeys = opts.publicKeys;
2015-04-23 08:25:36 -07:00
x.network = Bitcore.Address(x.address).toObject().network;
2015-02-17 16:20:08 -08:00
return x;
2015-01-27 05:18:45 -08:00
};
2015-02-17 16:20:08 -08:00
Address.fromObj = function(obj) {
2015-02-02 12:07:18 -08:00
var x = new Address();
2015-01-27 05:18:45 -08:00
2015-02-02 12:07:18 -08:00
x.createdOn = obj.createdOn;
x.address = obj.address;
2015-04-20 13:46:40 -07:00
x.walletId = obj.walletId;
2015-04-23 08:25:36 -07:00
x.network = obj.network;
2015-02-21 14:13:15 -08:00
x.isChange = obj.isChange;
2015-02-02 12:07:18 -08:00
x.path = obj.path;
2015-02-03 11:46:28 -08:00
x.publicKeys = obj.publicKeys;
2015-02-02 12:07:18 -08:00
return x;
2015-01-27 05:18:45 -08:00
};
2015-02-03 11:46:28 -08:00
/**
* getScriptPubKey
*
* @param {number} threshold - amount of required signatures to spend the output
* @return {Script}
*/
2015-02-17 16:20:08 -08:00
Address.prototype.getScriptPubKey = function(threshold) {
2015-02-03 18:17:06 -08:00
return Bitcore.Script.buildMultisigOut(this.publicKeys, threshold).toScriptHashOut();
2015-02-03 11:46:28 -08:00
};
2015-01-27 05:18:45 -08:00
module.exports = Address;