|
@@ -12,6 +12,7 @@ import { queries, commands } from 'iroha-helpers'
|
|
|
export class BcInfoService {
|
|
export class BcInfoService {
|
|
|
|
|
|
|
|
BASE_URL = 'https://chain4all.lesprojekt.cz' as const;
|
|
BASE_URL = 'https://chain4all.lesprojekt.cz' as const;
|
|
|
|
|
+ CHAIN4ALL_SERVICE_URL = 'http://localhost:3000' as const;
|
|
|
IROHA_ADDRESS = "http://localhost:8080" as const;
|
|
IROHA_ADDRESS = "http://localhost:8080" as const;
|
|
|
ASSET = "testcoin#test" as const;
|
|
ASSET = "testcoin#test" as const;
|
|
|
ADMIN_USER = "admin@test" as const;
|
|
ADMIN_USER = "admin@test" as const;
|
|
@@ -21,24 +22,34 @@ export class BcInfoService {
|
|
|
user = 'kunickyd@test';
|
|
user = 'kunickyd@test';
|
|
|
// userPrivateKey = 'ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8';
|
|
// userPrivateKey = 'ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8';
|
|
|
userBalance = -1;
|
|
userBalance = -1;
|
|
|
- paymentHash = ""
|
|
|
|
|
|
|
+ price = -1;
|
|
|
|
|
+ paymentHash = "";
|
|
|
|
|
+ dataUrl = "";
|
|
|
|
|
+ extent = [ //bottom left and top right point should be enough
|
|
|
|
|
+ [48.5, 17],
|
|
|
|
|
+ [49, 17],
|
|
|
|
|
+ [49, 16.5],
|
|
|
|
|
+ [48.5, 16.5]
|
|
|
|
|
+ ];
|
|
|
private _requestInProcess = false;
|
|
private _requestInProcess = false;
|
|
|
|
|
|
|
|
constructor(public httpClient: HttpClient) {
|
|
constructor(public httpClient: HttpClient) {
|
|
|
this.commandService = new CommandService(this.IROHA_ADDRESS);
|
|
this.commandService = new CommandService(this.IROHA_ADDRESS);
|
|
|
this.queryService = new QueryService(this.IROHA_ADDRESS);
|
|
this.queryService = new QueryService(this.IROHA_ADDRESS);
|
|
|
this.getUserBalance();
|
|
this.getUserBalance();
|
|
|
|
|
+ this.getPrice(this.extent).then(price => this.price = price);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async getUserBalance(): Promise<any> {
|
|
async getUserBalance(): Promise<any> {
|
|
|
if (this._requestInProcess) {
|
|
if (this._requestInProcess) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- this.userBalance = await this.getUserBalanceFromIroha(this.user, "ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8", this.ASSET );
|
|
|
|
|
|
|
+ this.userBalance = await this.getUserBalanceFromIroha(this.user, "ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8", this.ASSET);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async pay(): Promise<any>{
|
|
|
|
|
- this.paymentHash = await this.transferAssets(this.user, "ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8", this.ASSET, "extent + data source", 1);
|
|
|
|
|
|
|
+ async pay(): Promise<any> {
|
|
|
|
|
+ this.paymentHash = await this.transferAssets(this.user, "ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8", this.ASSET, JSON.stringify({ extent: this.extent }), this.price);
|
|
|
|
|
+ this.dataUrl = await this.requestData(this.paymentHash, this.user);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async getUserBalanceFromIroha(user: string, userPrivateKey: string, assetId: string): Promise<number> {
|
|
async getUserBalanceFromIroha(user: string, userPrivateKey: string, assetId: string): Promise<number> {
|
|
@@ -83,7 +94,7 @@ export class BcInfoService {
|
|
|
async transferAssets(user: string, userPrivateKey: string, assetId: string, description: string, amount: number): Promise<string> {
|
|
async transferAssets(user: string, userPrivateKey: string, assetId: string, description: string, amount: number): Promise<string> {
|
|
|
|
|
|
|
|
let commandOptions = {
|
|
let commandOptions = {
|
|
|
- privateKeys: [ userPrivateKey ], // Array of private keys in hex format
|
|
|
|
|
|
|
+ privateKeys: [userPrivateKey], // Array of private keys in hex format
|
|
|
creatorAccountId: user, // Account id, ex. admin@test
|
|
creatorAccountId: user, // Account id, ex. admin@test
|
|
|
quorum: 1,
|
|
quorum: 1,
|
|
|
commandService: this.commandService,
|
|
commandService: this.commandService,
|
|
@@ -101,11 +112,25 @@ export class BcInfoService {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
console.debug(response);
|
|
console.debug(response);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return response["txHash"][0];
|
|
return response["txHash"][0];
|
|
|
|
|
|
|
|
- } catch (err) {
|
|
|
|
|
|
|
+ } catch (err) {
|
|
|
console.error(err)
|
|
console.error(err)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ async getPrice(extent: Array<Array<number>>) : Promise<number>{
|
|
|
|
|
+ let response = await this.httpClient.post(this.CHAIN4ALL_SERVICE_URL + '/price', { extent: extent }).toPromise();
|
|
|
|
|
+
|
|
|
|
|
+ console.debug(response);
|
|
|
|
|
+ return response["price"];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async requestData(paymentHash: string, user: string) : Promise<string>{
|
|
|
|
|
+ let response = await this.httpClient.post(this.CHAIN4ALL_SERVICE_URL + '/buy', { txHash: paymentHash, user }).toPromise();
|
|
|
|
|
+
|
|
|
|
|
+ console.debug(response);
|
|
|
|
|
+ return response["dataUrl"];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|