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,
|
||||
* but only if the sum the coins' remaining value exceeds the payment amount.
|
||||
*/
|
||||
private getPossibleExchangeCoins(paymentAmount: AmountJson,
|
||||
private async getPossibleExchangeCoins(paymentAmount: AmountJson,
|
||||
depositFeeLimit: AmountJson,
|
||||
allowedExchanges: ExchangeHandle[]): Promise<ExchangeCoins> {
|
||||
// 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 = {};
|
||||
|
||||
if (Object.keys(m).length == 0) {
|
||||
@ -436,7 +437,6 @@ export class Wallet {
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -691,14 +691,12 @@ export class Wallet {
|
||||
return;
|
||||
}
|
||||
r.confirmed = true;
|
||||
return Query(this.db)
|
||||
await Query(this.db)
|
||||
.put("reserves", r)
|
||||
.put("history", historyEntry)
|
||||
.finish()
|
||||
.then(() => {
|
||||
// Do this in the background
|
||||
.finish();
|
||||
|
||||
this.processReserve(r);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -757,17 +755,14 @@ export class Wallet {
|
||||
/**
|
||||
* 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());
|
||||
return this.cryptoApi
|
||||
.createPreCoin(denom, reserve)
|
||||
.then((preCoin) => {
|
||||
return Query(this.db)
|
||||
let preCoin = await this.cryptoApi
|
||||
.createPreCoin(denom, reserve);
|
||||
await Query(this.db)
|
||||
.put("precoins", preCoin)
|
||||
.finish()
|
||||
.then(() => this.processPreCoin(preCoin));
|
||||
});
|
||||
|
||||
.finish();
|
||||
await this.processPreCoin(preCoin);
|
||||
}
|
||||
|
||||
|
||||
@ -791,12 +786,11 @@ export class Wallet {
|
||||
*/
|
||||
private async updateReserve(reservePub: string,
|
||||
exchange: IExchangeInfo): Promise<Reserve> {
|
||||
return Query(this.db)
|
||||
.get("reserves", reservePub)
|
||||
.then((reserve) => {
|
||||
let reserve = await Query(this.db)
|
||||
.get("reserves", reservePub);
|
||||
let reqUrl = URI("reserve/status").absoluteTo(exchange.baseUrl);
|
||||
reqUrl.query({'reserve_pub': reservePub});
|
||||
return this.http.get(reqUrl).then(resp => {
|
||||
let resp = await this.http.get(reqUrl);
|
||||
if (resp.status != 200) {
|
||||
throw Error();
|
||||
}
|
||||
@ -816,12 +810,10 @@ export class Wallet {
|
||||
newAmount
|
||||
}
|
||||
};
|
||||
return Query(this.db)
|
||||
await Query(this.db)
|
||||
.put("reserves", reserve)
|
||||
.finish()
|
||||
.then(() => reserve);
|
||||
});
|
||||
});
|
||||
.finish();
|
||||
return reserve;
|
||||
}
|
||||
|
||||
|
||||
@ -950,16 +942,15 @@ export class Wallet {
|
||||
}
|
||||
|
||||
|
||||
private updateExchangeInfo(exchangeInfo: IExchangeInfo,
|
||||
private async updateExchangeInfo(exchangeInfo: IExchangeInfo,
|
||||
newKeys: KeysJson): Promise<IExchangeInfo> {
|
||||
|
||||
if (exchangeInfo.masterPublicKey != newKeys.master_public_key) {
|
||||
throw Error("public keys do not match");
|
||||
}
|
||||
|
||||
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?
|
||||
let found = false;
|
||||
for (let oldDenom of exchangeInfo.all_denoms) {
|
||||
@ -983,28 +974,29 @@ export class Wallet {
|
||||
if (found) {
|
||||
exchangeInfo.active_denoms.push(newDenom);
|
||||
// No need to check signatures
|
||||
return Promise.resolve();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return this.cryptoApi
|
||||
.isValidDenom(newDenom, exchangeInfo.masterPublicKey)
|
||||
.then((valid) => {
|
||||
let ps = denomsToCheck.map(async(denom) => {
|
||||
let valid = await this.cryptoApi
|
||||
.isValidDenom(denom,
|
||||
exchangeInfo.masterPublicKey);
|
||||
if (!valid) {
|
||||
console.error("invalid denomination",
|
||||
newDenom,
|
||||
denom,
|
||||
"with key",
|
||||
exchangeInfo.masterPublicKey);
|
||||
// FIXME: report to auditors
|
||||
}
|
||||
return this.cryptoApi.hashRsaPub(newDenom.denom_pub);
|
||||
})
|
||||
.then((h) => {
|
||||
exchangeInfo.active_denoms.push(newDenom);
|
||||
exchangeInfo.all_denoms.push(newDenom);
|
||||
});
|
||||
exchangeInfo.active_denoms.push(denom);
|
||||
exchangeInfo.all_denoms.push(denom);
|
||||
});
|
||||
|
||||
return Promise.all(ps).then(() => exchangeInfo);
|
||||
await Promise.all(ps);
|
||||
|
||||
return exchangeInfo;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user