remove repurchase correlation id
This commit is contained in:
parent
af6843a2aa
commit
93e3d52735
@ -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> {
|
function queryPayment(query: any): Promise<any> {
|
||||||
// current URL without fragment
|
// current URL without fragment
|
||||||
const walletMsg = {
|
const walletMsg = {
|
||||||
@ -239,22 +225,6 @@ namespace TalerNotify {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let resp = await checkRepurchase(proposal.data);
|
|
||||||
|
|
||||||
if (resp.error) {
|
|
||||||
console.error("wallet backend error", resp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)";
|
let merchantName = "(unknown)";
|
||||||
try {
|
try {
|
||||||
merchantName = proposal.data.merchant.name;
|
merchantName = proposal.data.merchant.name;
|
||||||
@ -282,7 +252,6 @@ namespace TalerNotify {
|
|||||||
const target = uri.query(params).href();
|
const target = uri.query(params).href();
|
||||||
document.location.replace(target);
|
document.location.replace(target);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function registerHandlers() {
|
function registerHandlers() {
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +53,6 @@ test("contract validation", (t: TestLib) => {
|
|||||||
timestamp: "Date(12345)",
|
timestamp: "Date(12345)",
|
||||||
transaction_id: 1234,
|
transaction_id: 1234,
|
||||||
fulfillment_url: "foo",
|
fulfillment_url: "foo",
|
||||||
repurchase_correlation_id: "blabla",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
types.Contract.checked(c);
|
types.Contract.checked(c);
|
||||||
|
13
src/types.ts
13
src/types.ts
@ -486,12 +486,6 @@ export class Contract {
|
|||||||
@Checkable.String
|
@Checkable.String
|
||||||
fulfillment_url: string;
|
fulfillment_url: string;
|
||||||
|
|
||||||
@Checkable.Optional(Checkable.String)
|
|
||||||
repurchase_correlation_id: string;
|
|
||||||
|
|
||||||
@Checkable.Optional(Checkable.String)
|
|
||||||
instance: string;
|
|
||||||
|
|
||||||
@Checkable.Any
|
@Checkable.Any
|
||||||
extra: any;
|
extra: any;
|
||||||
|
|
||||||
@ -614,13 +608,6 @@ export namespace Amounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface CheckRepurchaseResult {
|
|
||||||
isRepurchase: boolean;
|
|
||||||
existingContractHash?: string;
|
|
||||||
existingFulfillmentUrl?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export interface Notifier {
|
export interface Notifier {
|
||||||
notify(): void;
|
notify(): void;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
import {
|
import {
|
||||||
AmountJson,
|
AmountJson,
|
||||||
Amounts,
|
Amounts,
|
||||||
CheckRepurchaseResult,
|
|
||||||
CoinRecord,
|
CoinRecord,
|
||||||
CoinPaySig,
|
CoinPaySig,
|
||||||
Contract,
|
Contract,
|
||||||
@ -349,10 +348,6 @@ export namespace Stores {
|
|||||||
super("transactions", {keyPath: "contractHash"});
|
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");
|
fulfillmentUrlIndex = new Index<string,TransactionRecord>(this, "fulfillment_url", "contract.fulfillment_url");
|
||||||
orderIdIndex = new Index<string,TransactionRecord>(this, "order_id", "contract.order_id");
|
orderIdIndex = new Index<string,TransactionRecord>(this, "order_id", "contract.order_id");
|
||||||
}
|
}
|
||||||
@ -1691,34 +1686,6 @@ export class Wallet {
|
|||||||
return this.cryptoApi.hashString(canonicalJson(contract));
|
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.
|
* Generate a nonce in form of an EdDSA public key.
|
||||||
|
@ -35,7 +35,7 @@ import * as logging from "./logging";
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const DB_NAME = "taler";
|
const DB_NAME = "taler";
|
||||||
const DB_VERSION = 14;
|
const DB_VERSION = 15;
|
||||||
|
|
||||||
import {Stores} from "./wallet";
|
import {Stores} from "./wallet";
|
||||||
import {Store, Index} from "./query";
|
import {Store, Index} from "./query";
|
||||||
@ -194,10 +194,6 @@ function makeHandlers(db: IDBDatabase,
|
|||||||
let amount = AmountJson.checked(detail.amount);
|
let amount = AmountJson.checked(detail.amount);
|
||||||
return wallet.getReserveCreationInfo(detail.baseUrl, 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) {
|
["get-history"]: function (detail, sender) {
|
||||||
// TODO: limit history length
|
// TODO: limit history length
|
||||||
return wallet.getHistory();
|
return wallet.getHistory();
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
"noImplicitAny": true
|
"noImplicitAny": true,
|
||||||
|
"alwaysStrict": true
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"decl/chrome/chrome.d.ts",
|
"decl/chrome/chrome.d.ts",
|
||||||
|
Loading…
Reference in New Issue
Block a user