forked from DAVFoundation/dav-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBid.js.map
1 lines (1 loc) · 13.6 KB
/
Bid.js.map
1
{"version":3,"sources":["../src/Bid.ts"],"names":[],"mappings":";;AAAA,iDAAgD;AAIhD,6EAAgE;AAEhE,uCAAgC;AAChC,uCAAgC;AAChC,mCAA4B;AAC5B,2CAAoC;AAEpC,iFAA0E;AAC1E,2DAAoD;AACpD,qEAA8D;AAC9D,uEAAgE;AAChE,+DAA+E;AAC/E,6EAAsE;AACtE;;GAEG;AACH;IAaE,YACU,OAAW,EACX,OAAU,EACV,OAAgB,EAChB,kBAAuC;QAHvC,YAAO,GAAP,OAAO,CAAI;QACX,YAAO,GAAP,OAAO,CAAG;QACV,YAAO,GAAP,OAAO,CAAS;QAChB,uBAAkB,GAAlB,kBAAkB,CAAqB;QAE/C,IAAI,CAAC,mBAAmB,GAAG,kBAAkB,CAAC;IAChD,CAAC;IAfD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAWO,KAAK,CAAC,qBAAqB;QACjC,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAC7B,IAAI,CAAC,mBAAmB,GAAG,MAAM,eAAK,CAAC,QAAQ,CAC7C,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,OAAO,CACb,CAAC;SACH;QACD,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAEM,KAAK,CAAC,iBAAiB;QAC5B,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE;YAC5B,OAAO,IAAI,gCAAsB,CAC/B,IAAI,sCAA4B,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAC7D,CAAC;SACH;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CA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CAAC,OAAO,EACZ,uBAAuB,EACvB,IAAI,CAAC,OAAO,CACb,CACJ,CAAC;QACF,OAAO,yBAAU,CAAC,cAAc,CAAC,uBAAuB,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1E,CAAC;CACF;AAvMD,sBAuMC","file":"Bid.js","sourcesContent":["import { ID, Observable } from './common-types';\nimport IConfig from './IConfig';\nimport BidParams from './BidParams';\nimport MissionParams from './MissionParams';\nimport GeneralMessageParams from './MissionPeerIdMessageParams';\nimport MessageParams from './MessageParams';\nimport Message from './Message';\nimport Mission from './Mission';\nimport Kafka from './Kafka';\nimport Contracts from './Contracts';\nimport KafkaMessageStream from './KafkaMessageStream';\nimport CommitmentConfirmationParams from './CommitmentConfirmationParams';\nimport CommitmentRequest from './CommitmentRequest';\nimport CommitmentConfirmation from './CommitmentConfirmation';\nimport CommitmentRequestParams from './CommitmentRequestParams';\nimport KafkaMessageFactory, { MessageCategories } from './KafkaMessageFactory';\nimport MissionPeerIdMessageParams from './MissionPeerIdMessageParams';\n/**\n * @class Bid class represent a bid for service request.\n */\nexport default class Bid<T extends BidParams> {\n private _missionId: ID;\n // DON'T USE THIS MEMBER BUT ONLY VIA ITS GETTER!\n private _kafkaMessageStream: KafkaMessageStream;\n\n get params(): T {\n return this._params;\n }\n\n get id(): ID {\n return this._selfId;\n }\n\n constructor(\n private _selfId: ID,\n private _params: T,\n private _config: IConfig,\n private kafkaMessageStream?: KafkaMessageStream,\n ) {\n this._kafkaMessageStream = kafkaMessageStream;\n }\n\n private async getKafkaMessageStream(): Promise<KafkaMessageStream> {\n if (!this._kafkaMessageStream) {\n this._kafkaMessageStream = await Kafka.messages(\n this._selfId,\n this._config,\n );\n }\n return this._kafkaMessageStream;\n }\n\n public async requestCommitment(): Promise<CommitmentConfirmation> {\n if (this._params.isCommitted) {\n return new CommitmentConfirmation(\n new CommitmentConfirmationParams({ bidId: this._params.id }),\n );\n }\n const bidderId = this._params.id; // Channel#6\n const commitmentRequestParams = new CommitmentRequestParams({\n neederId: this._selfId,\n });\n const kafkaMessageStream: KafkaMessageStream = await this.getKafkaMessageStream(); // Channel#3\n const commitmentConfirmationParamsStream = kafkaMessageStream.filterType([\n CommitmentConfirmationParams._messageType,\n ]);\n const commitmentConfirmation = commitmentConfirmationParamsStream\n .filter(\n (commitmentConfirmationParams: CommitmentConfirmationParams) =>\n commitmentConfirmationParams.bidId === this._params.id,\n )\n .map((commitmentParams: CommitmentConfirmationParams) => {\n this._params.isCommitted = true;\n return new CommitmentConfirmation(commitmentParams);\n })\n .first()\n .toPromise();\n await Kafka.sendParams(bidderId, commitmentRequestParams, this._config);\n return commitmentConfirmation;\n }\n\n /**\n * @method accept Used to accept a bid and create a new mission, the mission will sent to the bid provider.\n * @param missionParams the mission parameters.\n * @param walletPrivateKey Ethereum wallet private key, to charge for the mission.\n * @returns the created mission.\n */\n // TODO: think why do mission params is a parameter of this method? does mission params have another source of information except bid params?\n public async accept<V extends MissionParams>(\n missionParams: V,\n walletPrivateKey: string,\n ): Promise<Mission<V>> {\n if (!this._params.isCommitted) {\n throw new Error(\n `Bidder hasn't confirmed commitment to this bid! please get commitment confirmation first.`,\n );\n }\n const bidderId = this._params.id; // Channel#6\n missionParams.id = Contracts.generateMissionId(this._config); // Channel#4\n missionParams.price = this._params.price;\n missionParams.neederDavId = this._params.neederDavId;\n missionParams.vehicleId = this._params.vehicleId;\n this._missionId = missionParams.id;\n try {\n await Contracts.approveMission(\n missionParams.neederDavId,\n walletPrivateKey,\n this._config,\n );\n } catch (err) {\n throw new Error(\n `Fail to approve mission, you might not have enough DAV Tokens: ${err}`,\n );\n }\n try {\n await Kafka.createTopic(missionParams.id, this._config);\n } catch (err) {\n // TODO: move this general message to kafka.createTopic\n throw new Error(`Fail to create a topic: ${err}`);\n }\n const messageStream = await Kafka.messages(missionParams.id, this._config);\n const peerIdPromise = new Promise<string>((resolve, reject) => {\n messageStream\n .filterType([MissionPeerIdMessageParams._messageType])\n .take(1)\n .subscribe((m: MissionPeerIdMessageParams) => {\n resolve(m.senderId);\n }, reject);\n });\n await Kafka.sendParams(bidderId, missionParams, this._config);\n const peerId = await peerIdPromise;\n const mission = new Mission<V>(\n this._missionId,\n peerId,\n missionParams,\n this._config,\n );\n return mission;\n }\n /**\n * @method sendMessage Used to send a message to the bid provider.\n * @param messageParams the message parameters.\n */\n public async sendMessage(messageParams: MessageParams): Promise<void> {\n if (this._selfId === this._params.id) {\n throw new Error(`You cannot send message to your own channel`);\n }\n messageParams.senderId = this._selfId; // Channel#3\n return await Kafka.sendParams(this._params.id, messageParams, this._config); // Channel#6\n }\n /**\n * @method messages Used to subscribe for messages for the current bid.\n * @param filterTypes (optional) array of the expected message params object type.\n * @returns Observable for messages subscription.\n */\n public async messages<U extends MessageParams>(\n filterTypes?: string[],\n ): Promise<Observable<Message<U>>> {\n const kafkaMessageStream: KafkaMessageStream = await this.getKafkaMessageStream(); // Channel#6 or Channel#3\n const messageParamsStream: Observable<U> = kafkaMessageStream.filterType(\n filterTypes ||\n KafkaMessageFactory.instance.getMessageTypes(\n this._params.protocol,\n MessageCategories.Message,\n ),\n );\n const messageStream = messageParamsStream.map(\n (params: U) => new Message<U>(this._selfId, params, this._config),\n );\n return Observable.fromObservable(messageStream, messageParamsStream.topic);\n }\n /**\n * @method missions Used to subscribe for missions.\n * @returns Observable for missions subscription.\n */\n public async missions<V extends MissionParams>(): Promise<\n Observable<Mission<V>>\n > {\n const kafkaMessageStream: KafkaMessageStream = await this.getKafkaMessageStream(); // Channel#6\n const missionParamsStream: Observable<V> = kafkaMessageStream.filterType(\n KafkaMessageFactory.instance.getMessageTypes(\n this._params.protocol,\n MessageCategories.Mission,\n ),\n );\n const missionStream = missionParamsStream\n .map(async (params: V) => {\n this._missionId = Kafka.generateTopicId();\n await Kafka.createTopic(this._missionId, this._config); // Channel #5\n return new Mission<V>(this._missionId, params.id, params, this._config);\n })\n .map(promise => Observable.fromPromise(promise))\n .mergeAll()\n .do(mission => {\n const message = new GeneralMessageParams({ senderId: this._missionId });\n mission.sendMessage(message);\n });\n return Observable.fromObservable(missionStream, missionParamsStream.topic);\n }\n\n /**\n * @method commitmentRequests Used to subscribe for commitmentRequests for current bid.\n * @returns Observable of commitmentRequests.\n */\n public async commitmentRequests(): Promise<Observable<CommitmentRequest>> {\n const kafkaMessageStream: KafkaMessageStream = await this.getKafkaMessageStream(); // Channel#6\n const commitmentRequestParamsStream: Observable<\n CommitmentRequestParams\n > = kafkaMessageStream.filterType([CommitmentRequestParams._messageType]);\n const commitmentRequestStream = commitmentRequestParamsStream.map(\n commitmentRequestParams =>\n new CommitmentRequest(\n this._selfId,\n commitmentRequestParams,\n this._config,\n ),\n );\n return Observable.fromObservable(commitmentRequestStream, this._selfId);\n }\n}\n"]}