support exchange API version 7:0:0

This commit is contained in:
Florian Dold 2020-03-09 16:37:46 +05:30
parent bf1b350d44
commit 26d961ad63
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
6 changed files with 21 additions and 10 deletions

View File

@ -77,6 +77,7 @@ async function setExchangeError(
baseUrl: string, baseUrl: string,
err: OperationError, err: OperationError,
): Promise<void> { ): Promise<void> {
console.log(`last error for exchange ${baseUrl}:`, err);
const mut = (exchange: ExchangeRecord) => { const mut = (exchange: ExchangeRecord) => {
exchange.lastError = err; exchange.lastError = err;
return exchange; return exchange;

View File

@ -229,7 +229,10 @@ async function refreshMelt(
return; return;
} }
const reqUrl = new URL("refresh/melt", refreshSession.exchangeBaseUrl); const reqUrl = new URL(
`coins/${coin.coinPub}/melt`,
refreshSession.exchangeBaseUrl,
);
const meltReq = { const meltReq = {
coin_pub: coin.coinPub, coin_pub: coin.coinPub,
confirm_sig: refreshSession.confirmSig, confirm_sig: refreshSession.confirmSig,
@ -244,7 +247,10 @@ async function refreshMelt(
console.log(`got status ${resp.status} for refresh/melt`); console.log(`got status ${resp.status} for refresh/melt`);
try { try {
const respJson = await resp.json(); const respJson = await resp.json();
console.log(`body of refresh/melt error response:`, JSON.stringify(respJson, undefined, 2)); console.log(
`body of refresh/melt error response:`,
JSON.stringify(respJson, undefined, 2),
);
} catch (e) { } catch (e) {
console.log(`body of refresh/melt error response is not JSON`); console.log(`body of refresh/melt error response is not JSON`);
} }
@ -344,7 +350,10 @@ async function refreshReveal(
link_sigs: linkSigs, link_sigs: linkSigs,
}; };
const reqUrl = new URL("refresh/reveal", refreshSession.exchangeBaseUrl); const reqUrl = new URL(
`refreshes/${refreshSession.hash}/reveal`,
refreshSession.exchangeBaseUrl,
);
logger.trace("reveal request:", req); logger.trace("reveal request:", req);
let resp; let resp;
@ -523,7 +532,9 @@ async function processRefreshSession(
refreshGroupId: string, refreshGroupId: string,
coinIndex: number, coinIndex: number,
) { ) {
logger.trace(`processing refresh session for coin ${coinIndex} of group ${refreshGroupId}`); logger.trace(
`processing refresh session for coin ${coinIndex} of group ${refreshGroupId}`,
);
let refreshGroup = await ws.db.get(Stores.refreshGroups, refreshGroupId); let refreshGroup = await ws.db.get(Stores.refreshGroups, refreshGroupId);
if (!refreshGroup) { if (!refreshGroup) {
return; return;

View File

@ -423,7 +423,7 @@ async function processPurchaseApplyRefundImpl(
console.log("sending refund permission", perm); console.log("sending refund permission", perm);
// FIXME: not correct once we support multiple exchanges per payment // FIXME: not correct once we support multiple exchanges per payment
const exchangeUrl = purchase.payReq.coins[0].exchange_url; const exchangeUrl = purchase.payReq.coins[0].exchange_url;
const reqUrl = new URL("refund", exchangeUrl); const reqUrl = new URL(`coins/${perm.coin_pub}/refund`, exchangeUrl);
const resp = await ws.http.postJson(reqUrl.href, req); const resp = await ws.http.postJson(reqUrl.href, req);
console.log("sent refund permission"); console.log("sent refund permission");
switch (resp.status) { switch (resp.status) {

View File

@ -402,12 +402,11 @@ async function updateReserve(
return; return;
} }
const reqUrl = new URL("reserve/status", reserve.exchangeBaseUrl); const reqUrl = new URL(`reserves/${reservePub}`, reserve.exchangeBaseUrl);
reqUrl.searchParams.set("reserve_pub", reservePub);
let resp; let resp;
try { try {
resp = await ws.http.get(reqUrl.href); resp = await ws.http.get(reqUrl.href);
console.log("got reserve/status response", await resp.json()); console.log("got reserves/${RESERVE_PUB} response", await resp.json());
if (resp.status === 404) { if (resp.status === 404) {
const m = "reserve not known to the exchange yet" const m = "reserve not known to the exchange yet"
throw new OperationFailedError(m, { throw new OperationFailedError(m, {

View File

@ -20,7 +20,7 @@
* *
* Uses libtool's current:revision:age versioning. * Uses libtool's current:revision:age versioning.
*/ */
export const WALLET_EXCHANGE_PROTOCOL_VERSION = "6"; export const WALLET_EXCHANGE_PROTOCOL_VERSION = "7:0:0";
/** /**
* Cache breaker that is appended to queries such as /keys and /wire * Cache breaker that is appended to queries such as /keys and /wire

View File

@ -197,7 +197,7 @@ async function processPlanchet(
wd.reserve_pub = planchet.reservePub; wd.reserve_pub = planchet.reservePub;
wd.reserve_sig = planchet.withdrawSig; wd.reserve_sig = planchet.withdrawSig;
wd.coin_ev = planchet.coinEv; wd.coin_ev = planchet.coinEv;
const reqUrl = new URL("reserve/withdraw", exchange.baseUrl).href; const reqUrl = new URL(`reserves/${planchet.reservePub}/withdraw`, exchange.baseUrl).href;
const resp = await ws.http.postJson(reqUrl, wd); const resp = await ws.http.postJson(reqUrl, wd);
if (resp.status !== 200) { if (resp.status !== 200) {
throw Error(`unexpected status ${resp.status} for withdraw`); throw Error(`unexpected status ${resp.status} for withdraw`);