Commit c36eb4ae authored by Cédric Moreau's avatar Cédric Moreau

Transaction: now implemented network wallet verification

parent 48193298
......@@ -140,10 +140,12 @@ module.exports.database = {
});
},
disconnect: function() {
disconnect: function(done) {
mongoose.disconnect(function (err) {
if(err)
logger.error(err);
if (typeof done == 'function')
done(err);
});
}
};
......
......@@ -107,6 +107,9 @@ TransactionSchema.methods = {
},
toString: function () {
return this.issuer + '-' + this.amNumber + '-' + this.coinNumber;
},
getID: function () {
return this.issuer + '-' + this.amNumber + '-' + this.coinNumber;
}
});
}
......@@ -114,6 +117,13 @@ TransactionSchema.methods = {
return coins;
},
getHash: function() {
if (!this.hash) {
this.hash = sha1(rawTX).toUpperCase();
}
return this.hash;
},
getRaw: function() {
var raw = "";
raw += "Version: " + this.version + "\n";
......
......@@ -29,7 +29,7 @@ WalletSchema.methods = {
copyValues: function(to) {
var obj = this;
["version", "currency", "fingerprint", "hosters", "trusts", "hash", "signature", "sigDate", "date"].forEach(function (key) {
["version", "currency", "fingerprint", "hosters", "trusts", "hash", "signature", "sigDate", "date", "requiredTrusts"].forEach(function (key) {
to[key] = obj[key];
});
},
......
......@@ -505,9 +505,9 @@ function PeeringService(pgp, currency, conf) {
that.emit('forward', forward, [peer], done);
};
this.coinIsOwned = function (owner, coin, thtentry, done) {
this.coinIsOwned = function (owner, coin, tx, wallet, done) {
var nbConfirmations = 0;
async.forEach(thtentry.trusts, function(trust, callback){
async.forEach(wallet.trusts, function(trust, callback){
async.waterfall([
function (next){
Peer.getTheOne(trust, next);
......@@ -516,19 +516,35 @@ function PeeringService(pgp, currency, conf) {
peer.connect(next);
},
function (node, next){
next('Err: vucoin need an upgrade!');
},
function (owning) {
if (owning.owner == owner) {
nbConfirmations++;
}
next();
async.waterfall([
function (next){
node.hdc.coins.owner(coin.issuer, coin.amNumber, coin.coinNumber, next);
},
function (owning, next) {
if (owning.owner != owner) {
next('Pretended owner is not');
return;
}
if (!owning.transaction) {
next('Coin matches owner, but has no owning transaction while it should');
} else if (owning.transaction != [tx.sender, tx.number].join('-')) {
next('Coin matches owner, but has not good owning transaction');
} else {
nbConfirmations++;
next();
}
},
], next);
}
], function (err) {
if (err)
logger.warn(err);
callback();
});
}, function(err){
done(null, nbConfirmations >= thtentry.trustThreshold);
if (err)
logger.error(err);
done(null, nbConfirmations >= wallet.requiredTrusts);
});
}
......
......@@ -201,11 +201,11 @@ module.exports.get = function (pgp, currency, conf) {
function (next){
Wallet.getTheOne(tx.recipient, next);
},
function (thtentry, next){
PeeringService.coinIsOwned(tx.sender, coin, thtentry, next);
function (wallet, next){
PeeringService.coinIsOwned(tx.recipient, coin, tx, wallet, next);
},
function (owned, next){
var err = !owned ? 'Coin ' + coin.toString() + ' does not appear to be owned be sender, according to network' : null;
var err = !owned ? 'Coin ' + coin.toString() + ' does not appear to be owned by sender, according to network' : null;
next(err);
},
], callback);
......
......@@ -114,10 +114,7 @@ function handleKey (conf, key, isManaged, message) {
key = key || "";
key = key.toUpperCase();
async.waterfall([
function (next) {
connect(next);
},
function (host, port, conf, next){
function (next){
service.Key.handleKey(key, isManaged, next);
}
], function (err, result) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment