From 93e3d52735b35a0b5405ed774a5bf0dbc8d8e8f2 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 14 Feb 2017 19:45:22 +0100 Subject: remove repurchase correlation id --- src/content_scripts/notify.ts | 75 +++++++++++++------------------------------ src/types-test.ts | 1 - src/types.ts | 13 -------- src/wallet.ts | 33 ------------------- src/wxBackend.ts | 6 +--- 5 files changed, 23 insertions(+), 105 deletions(-) (limited to 'src') diff --git a/src/content_scripts/notify.ts b/src/content_scripts/notify.ts index 582375e1d..a731e4da1 100644 --- a/src/content_scripts/notify.ts +++ b/src/content_scripts/notify.ts @@ -76,20 +76,6 @@ namespace TalerNotify { }); } - function checkRepurchase(contract: string): Promise { - const walletMsg = { - type: "check-repurchase", - detail: { - contract: contract - }, - }; - return new Promise((resolve, reject) => { - chrome.runtime.sendMessage(walletMsg, (resp: any) => { - resolve(resp); - }); - }); - } - function queryPayment(query: any): Promise { // current URL without fragment const walletMsg = { @@ -239,49 +225,32 @@ namespace TalerNotify { return; } - let resp = await checkRepurchase(proposal.data); - - if (resp.error) { - console.error("wallet backend error", resp); - return; + let merchantName = "(unknown)"; + try { + merchantName = proposal.data.merchant.name; + } catch (e) { + // bad contract / name not included } - if (resp.isRepurchase) { - logVerbose && console.log("doing repurchase"); - console.assert(resp.existingFulfillmentUrl); - console.assert(resp.existingContractHash); - window.location.href = subst(resp.existingFulfillmentUrl, - resp.existingContractHash); - - } else { - - let merchantName = "(unknown)"; - try { - merchantName = proposal.data.merchant.name; - } catch (e) { - // bad contract / name not included + let historyEntry = { + timestamp: (new Date).getTime(), + subjectId: `contract-${contractHash}`, + type: "offer-contract", + detail: { + contractHash, + merchantName, } + }; + await putHistory(historyEntry); + let offerId = await saveOffer(proposal); - let historyEntry = { - timestamp: (new Date).getTime(), - subjectId: `contract-${contractHash}`, - type: "offer-contract", - detail: { - contractHash, - merchantName, - } - }; - await putHistory(historyEntry); - let offerId = await saveOffer(proposal); - - const uri = URI(chrome.extension.getURL( - "/src/pages/confirm-contract.html")); - const params = { - offerId: offerId.toString(), - }; - const target = uri.query(params).href(); - document.location.replace(target); - } + const uri = URI(chrome.extension.getURL( + "/src/pages/confirm-contract.html")); + const params = { + offerId: offerId.toString(), + }; + const target = uri.query(params).href(); + document.location.replace(target); } function registerHandlers() { diff --git a/src/types-test.ts b/src/types-test.ts index f8f25bc00..7298728ff 100644 --- a/src/types-test.ts +++ b/src/types-test.ts @@ -53,7 +53,6 @@ test("contract validation", (t: TestLib) => { timestamp: "Date(12345)", transaction_id: 1234, fulfillment_url: "foo", - repurchase_correlation_id: "blabla", }; types.Contract.checked(c); diff --git a/src/types.ts b/src/types.ts index 30e9b7856..28c989a0f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -486,12 +486,6 @@ export class Contract { @Checkable.String fulfillment_url: string; - @Checkable.Optional(Checkable.String) - repurchase_correlation_id: string; - - @Checkable.Optional(Checkable.String) - instance: string; - @Checkable.Any extra: any; @@ -614,13 +608,6 @@ export namespace Amounts { } -export interface CheckRepurchaseResult { - isRepurchase: boolean; - existingContractHash?: string; - existingFulfillmentUrl?: string; -} - - export interface Notifier { notify(): void; } diff --git a/src/wallet.ts b/src/wallet.ts index 67393edae..01d26c297 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -24,7 +24,6 @@ import { AmountJson, Amounts, - CheckRepurchaseResult, CoinRecord, CoinPaySig, Contract, @@ -349,10 +348,6 @@ export namespace Stores { super("transactions", {keyPath: "contractHash"}); } - repurchaseIndex = new Index<[string,string],TransactionRecord>(this, "repurchase", [ - "contract.merchant_pub", - "contract.repurchase_correlation_id" - ]); fulfillmentUrlIndex = new Index(this, "fulfillment_url", "contract.fulfillment_url"); orderIdIndex = new Index(this, "order_id", "contract.order_id"); } @@ -1691,34 +1686,6 @@ export class Wallet { return this.cryptoApi.hashString(canonicalJson(contract)); } - /** - * Check if there's an equivalent contract we've already purchased. - */ - async checkRepurchase(contract: Contract): Promise { - if (!contract.repurchase_correlation_id) { - console.log("no repurchase: no correlation id"); - return {isRepurchase: false}; - } - let result: TransactionRecord|undefined = await ( - this.q() - .getIndexed(Stores.transactions.repurchaseIndex, - [ - contract.merchant_pub, - contract.repurchase_correlation_id - ])); - - if (result) { - console.assert(result.contract.repurchase_correlation_id == contract.repurchase_correlation_id); - return { - isRepurchase: true, - existingContractHash: result.contractHash, - existingFulfillmentUrl: result.contract.fulfillment_url, - }; - } else { - return {isRepurchase: false}; - } - } - /** * Generate a nonce in form of an EdDSA public key. diff --git a/src/wxBackend.ts b/src/wxBackend.ts index cdc8f4392..5957e1e1b 100644 --- a/src/wxBackend.ts +++ b/src/wxBackend.ts @@ -35,7 +35,7 @@ import * as logging from "./logging"; "use strict"; const DB_NAME = "taler"; -const DB_VERSION = 14; +const DB_VERSION = 15; import {Stores} from "./wallet"; import {Store, Index} from "./query"; @@ -194,10 +194,6 @@ function makeHandlers(db: IDBDatabase, let amount = AmountJson.checked(detail.amount); return wallet.getReserveCreationInfo(detail.baseUrl, amount); }, - ["check-repurchase"]: function (detail, sender) { - let contract = Contract.checked(detail.contract); - return wallet.checkRepurchase(contract); - }, ["get-history"]: function (detail, sender) { // TODO: limit history length return wallet.getHistory(); -- cgit v1.2.3