fix addresses in helper / utxos

This commit is contained in:
Matias Alejo Garcia 2015-02-04 21:38:23 -03:00
parent 06ae34a71f
commit 9a88a6f8f6
3 changed files with 27 additions and 19 deletions

View File

@ -2,6 +2,7 @@
var _ = require('lodash');
var Guid = require('guid');
var Bitcore = require('bitcore');
var TxProposalAction = require('./txproposalaction');
@ -38,7 +39,6 @@ TxProposal.fromObj = function (obj) {
x.message = obj.message;
x.changeAddress = obj.changeAddress;
x.inputs = obj.inputs;
x.rawTx = obj.rawTx;
x.requiredSignatures = obj.requiredSignatures;
x.maxRejections = obj.maxRejections;
x.status = obj.status;
@ -51,6 +51,7 @@ TxProposal.fromObj = function (obj) {
return x;
};
TxProposal.prototype._updateStatus = function () {
if (this.status != 'pending') return;
@ -61,6 +62,16 @@ TxProposal.prototype._updateStatus = function () {
}
};
TxProposal.prototype._getBitcoreTx = function () {
return new Bitcore.Transaction()
.from(this.inputs)
.to(this.toAddress, this.amount)
.change(this.changeAddress);
};
TxProposal.prototype.addAction = function (copayerId, type, signature) {
var action = new TxProposalAction({
copayerId: copayerId,
@ -71,7 +82,15 @@ TxProposal.prototype.addAction = function (copayerId, type, signature) {
this._updateStatus();
};
TxProposal.prototype.sign = function (copayerId, signature) {
TxProposal.prototype._checkSignature = function (signatures) {
var t = this._getBitcoreTx();
t.applyS
};
TxProposal.prototype.sign = function (copayerId, signatures) {
this._checkSignature(signature);
this.addAction(copayerId, 'accept', signature);
};

View File

@ -347,19 +347,6 @@ CopayServer.prototype.getBalance = function(opts, cb) {
};
CopayServer.prototype._createRawTx = function(txp) {
console.log('[server.js.320:txp:]', txp.inputs, txp.toAddress, txp.amount, txp.changeAddress); //TODO
var rawTx = new Bitcore.Transaction()
.from(txp.inputs)
.to(txp.toAddress, txp.amount)
.change(txp.changeAddress);
console.log('[server.js.324:rawTx:]', rawTx); //TODO
return rawTx;
};
CopayServer.prototype._inputSatoshis = function(i) {
return i.amount ? Utils.strip(i.amount * 1e8) : i.satoshis;

View File

@ -134,7 +134,7 @@ helpers.createUtxos = function(server, wallet, amounts, cb) {
vout: Math.floor((Math.random() * 10) + 1),
satoshis: amount,
scriptPubKey: addresses[i].getScriptPubKey(wallet.m).toBuffer().toString('hex'),
address: addresses[i].address,
address: addresses[i++].address,
};
});
@ -154,9 +154,9 @@ helpers.clientSign = function(tx, xpriv, n) {
_.each(tx.inputs, function(i) {
if (!derived[i.path]) {
privs.push(xpriv.derive(i.path).privateKey);
derived[i.path] = true;
}
derived[i.path] = xpriv.derive(i.path).privateKey;
}
privs.push(derived[i.path]);
});
var t = new Bitcore.Transaction();
@ -986,9 +986,11 @@ describe('Copay server', function() {
}, function(err, txs) {
var tx = txs[0];
tx.id.should.equal(txid);
console.log('[integration.js.988:tx:]',tx); //TODO
//
var signatures = helpers.clientSign(tx, someXPrivKey[0], wallet.n);
console.log('[integration.js.992:signatures:]',signatures); //TODO
server.signTx({
walletId: '123',
copayerId: '1',