remove repurchase correlation id

This commit is contained in:
Florian Dold 2017-02-14 19:45:22 +01:00
parent af6843a2aa
commit 93e3d52735
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
6 changed files with 25 additions and 106 deletions

View File

@ -76,20 +76,6 @@ namespace TalerNotify {
});
}
function checkRepurchase(contract: string): Promise<any> {
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<any> {
// 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() {

View File

@ -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);

View File

@ -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;
}

View File

@ -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<string,TransactionRecord>(this, "fulfillment_url", "contract.fulfillment_url");
orderIdIndex = new Index<string,TransactionRecord>(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<CheckRepurchaseResult> {
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.

View File

@ -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();

View File

@ -10,7 +10,8 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": true,
"noImplicitAny": true
"noImplicitAny": true,
"alwaysStrict": true
},
"files": [
"decl/chrome/chrome.d.ts",