even more async
This commit is contained in:
parent
b4815b2b06
commit
db9b98b2a9
@ -333,7 +333,7 @@ export class Wallet {
|
|||||||
* Get exchanges and associated coins that are still spendable,
|
* Get exchanges and associated coins that are still spendable,
|
||||||
* but only if the sum the coins' remaining value exceeds the payment amount.
|
* but only if the sum the coins' remaining value exceeds the payment amount.
|
||||||
*/
|
*/
|
||||||
private getPossibleExchangeCoins(paymentAmount: AmountJson,
|
private async getPossibleExchangeCoins(paymentAmount: AmountJson,
|
||||||
depositFeeLimit: AmountJson,
|
depositFeeLimit: AmountJson,
|
||||||
allowedExchanges: ExchangeHandle[]): Promise<ExchangeCoins> {
|
allowedExchanges: ExchangeHandle[]): Promise<ExchangeCoins> {
|
||||||
// Mapping from exchange base URL to list of coins together with their
|
// Mapping from exchange base URL to list of coins together with their
|
||||||
@ -389,7 +389,8 @@ export class Wallet {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all(ps).then(() => {
|
await Promise.all(ps);
|
||||||
|
|
||||||
let ret: ExchangeCoins = {};
|
let ret: ExchangeCoins = {};
|
||||||
|
|
||||||
if (Object.keys(m).length == 0) {
|
if (Object.keys(m).length == 0) {
|
||||||
@ -436,7 +437,6 @@ export class Wallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -691,14 +691,12 @@ export class Wallet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
r.confirmed = true;
|
r.confirmed = true;
|
||||||
return Query(this.db)
|
await Query(this.db)
|
||||||
.put("reserves", r)
|
.put("reserves", r)
|
||||||
.put("history", historyEntry)
|
.put("history", historyEntry)
|
||||||
.finish()
|
.finish();
|
||||||
.then(() => {
|
|
||||||
// Do this in the background
|
|
||||||
this.processReserve(r);
|
this.processReserve(r);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -757,17 +755,14 @@ export class Wallet {
|
|||||||
/**
|
/**
|
||||||
* Withdraw one coin of the given denomination from the given reserve.
|
* Withdraw one coin of the given denomination from the given reserve.
|
||||||
*/
|
*/
|
||||||
private withdraw(denom: Denomination, reserve: Reserve): Promise<void> {
|
private async withdraw(denom: Denomination, reserve: Reserve): Promise<void> {
|
||||||
console.log("creating pre coin at", new Date());
|
console.log("creating pre coin at", new Date());
|
||||||
return this.cryptoApi
|
let preCoin = await this.cryptoApi
|
||||||
.createPreCoin(denom, reserve)
|
.createPreCoin(denom, reserve);
|
||||||
.then((preCoin) => {
|
await Query(this.db)
|
||||||
return Query(this.db)
|
|
||||||
.put("precoins", preCoin)
|
.put("precoins", preCoin)
|
||||||
.finish()
|
.finish();
|
||||||
.then(() => this.processPreCoin(preCoin));
|
await this.processPreCoin(preCoin);
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -791,12 +786,11 @@ export class Wallet {
|
|||||||
*/
|
*/
|
||||||
private async updateReserve(reservePub: string,
|
private async updateReserve(reservePub: string,
|
||||||
exchange: IExchangeInfo): Promise<Reserve> {
|
exchange: IExchangeInfo): Promise<Reserve> {
|
||||||
return Query(this.db)
|
let reserve = await Query(this.db)
|
||||||
.get("reserves", reservePub)
|
.get("reserves", reservePub);
|
||||||
.then((reserve) => {
|
|
||||||
let reqUrl = URI("reserve/status").absoluteTo(exchange.baseUrl);
|
let reqUrl = URI("reserve/status").absoluteTo(exchange.baseUrl);
|
||||||
reqUrl.query({'reserve_pub': reservePub});
|
reqUrl.query({'reserve_pub': reservePub});
|
||||||
return this.http.get(reqUrl).then(resp => {
|
let resp = await this.http.get(reqUrl);
|
||||||
if (resp.status != 200) {
|
if (resp.status != 200) {
|
||||||
throw Error();
|
throw Error();
|
||||||
}
|
}
|
||||||
@ -816,12 +810,10 @@ export class Wallet {
|
|||||||
newAmount
|
newAmount
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Query(this.db)
|
await Query(this.db)
|
||||||
.put("reserves", reserve)
|
.put("reserves", reserve)
|
||||||
.finish()
|
.finish();
|
||||||
.then(() => reserve);
|
return reserve;
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -950,16 +942,15 @@ export class Wallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private updateExchangeInfo(exchangeInfo: IExchangeInfo,
|
private async updateExchangeInfo(exchangeInfo: IExchangeInfo,
|
||||||
newKeys: KeysJson): Promise<IExchangeInfo> {
|
newKeys: KeysJson): Promise<IExchangeInfo> {
|
||||||
|
|
||||||
if (exchangeInfo.masterPublicKey != newKeys.master_public_key) {
|
if (exchangeInfo.masterPublicKey != newKeys.master_public_key) {
|
||||||
throw Error("public keys do not match");
|
throw Error("public keys do not match");
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeInfo.active_denoms = [];
|
exchangeInfo.active_denoms = [];
|
||||||
|
|
||||||
let ps = newKeys.denoms.map((newDenom) => {
|
let denomsToCheck = newKeys.denoms.filter((newDenom) => {
|
||||||
// did we find the new denom in the list of all (old) denoms?
|
// did we find the new denom in the list of all (old) denoms?
|
||||||
let found = false;
|
let found = false;
|
||||||
for (let oldDenom of exchangeInfo.all_denoms) {
|
for (let oldDenom of exchangeInfo.all_denoms) {
|
||||||
@ -983,28 +974,29 @@ export class Wallet {
|
|||||||
if (found) {
|
if (found) {
|
||||||
exchangeInfo.active_denoms.push(newDenom);
|
exchangeInfo.active_denoms.push(newDenom);
|
||||||
// No need to check signatures
|
// No need to check signatures
|
||||||
return Promise.resolve();
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
return this.cryptoApi
|
let ps = denomsToCheck.map(async(denom) => {
|
||||||
.isValidDenom(newDenom, exchangeInfo.masterPublicKey)
|
let valid = await this.cryptoApi
|
||||||
.then((valid) => {
|
.isValidDenom(denom,
|
||||||
|
exchangeInfo.masterPublicKey);
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
console.error("invalid denomination",
|
console.error("invalid denomination",
|
||||||
newDenom,
|
denom,
|
||||||
"with key",
|
"with key",
|
||||||
exchangeInfo.masterPublicKey);
|
exchangeInfo.masterPublicKey);
|
||||||
// FIXME: report to auditors
|
// FIXME: report to auditors
|
||||||
}
|
}
|
||||||
return this.cryptoApi.hashRsaPub(newDenom.denom_pub);
|
exchangeInfo.active_denoms.push(denom);
|
||||||
})
|
exchangeInfo.all_denoms.push(denom);
|
||||||
.then((h) => {
|
|
||||||
exchangeInfo.active_denoms.push(newDenom);
|
|
||||||
exchangeInfo.all_denoms.push(newDenom);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all(ps).then(() => exchangeInfo);
|
await Promise.all(ps);
|
||||||
|
|
||||||
|
return exchangeInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user