|
|
@@ -19,8 +19,9 @@ export class BcInfoService {
|
|
|
commandService: CommandService;
|
|
|
queryService: QueryService;
|
|
|
user = 'kunickyd@test';
|
|
|
- userPrivateKey = 'ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8';
|
|
|
+ // userPrivateKey = 'ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8';
|
|
|
userBalance = -1;
|
|
|
+ paymentHash = ""
|
|
|
private _requestInProcess = false;
|
|
|
|
|
|
constructor(public httpClient: HttpClient) {
|
|
|
@@ -33,16 +34,19 @@ export class BcInfoService {
|
|
|
if (this._requestInProcess) {
|
|
|
return;
|
|
|
}
|
|
|
- this.userBalance = await this.getUserBalanceFromIroha()
|
|
|
- await this.transferAssets();
|
|
|
+ this.userBalance = await this.getUserBalanceFromIroha(this.user, "ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8", this.ASSET );
|
|
|
}
|
|
|
|
|
|
- async getUserBalanceFromIroha(): Promise<number> {
|
|
|
+ async pay(): Promise<any>{
|
|
|
+ this.paymentHash = await this.transferAssets(this.user, "ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8", this.ASSET, "extent + data source", 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ async getUserBalanceFromIroha(user: string, userPrivateKey: string, assetId: string): Promise<number> {
|
|
|
|
|
|
this._requestInProcess = true;
|
|
|
let queryOptions = {
|
|
|
- privateKey: this.userPrivateKey,
|
|
|
- creatorAccountId: this.user,
|
|
|
+ privateKey: userPrivateKey,
|
|
|
+ creatorAccountId: user,
|
|
|
queryService: this.queryService,
|
|
|
timeoutLimit: 10000
|
|
|
};
|
|
|
@@ -56,8 +60,8 @@ export class BcInfoService {
|
|
|
});*/
|
|
|
|
|
|
let data = await queries.getAccountAssets(queryOptions, {
|
|
|
- accountId: this.user,
|
|
|
- firstAssetId: this.ASSET,
|
|
|
+ accountId: user,
|
|
|
+ firstAssetId: assetId,
|
|
|
pageSize: 10
|
|
|
});
|
|
|
|
|
|
@@ -76,11 +80,11 @@ export class BcInfoService {
|
|
|
this._requestInProcess = false
|
|
|
}
|
|
|
|
|
|
- async transferAssets(): Promise<string> {
|
|
|
+ async transferAssets(user: string, userPrivateKey: string, assetId: string, description: string, amount: number): Promise<string> {
|
|
|
|
|
|
let commandOptions = {
|
|
|
- privateKeys: [this.userPrivateKey], // Array of private keys in hex format
|
|
|
- creatorAccountId: this.user, // Account id, ex. admin@test
|
|
|
+ privateKeys: [ userPrivateKey ], // Array of private keys in hex format
|
|
|
+ creatorAccountId: user, // Account id, ex. admin@test
|
|
|
quorum: 1,
|
|
|
commandService: this.commandService,
|
|
|
timeoutLimit: 5000 // Set timeout limit
|
|
|
@@ -89,17 +93,16 @@ export class BcInfoService {
|
|
|
try {
|
|
|
|
|
|
let response = await commands.transferAsset(commandOptions, {
|
|
|
- srcAccountId: this.user,
|
|
|
+ srcAccountId: user,
|
|
|
destAccountId: this.ADMIN_USER,
|
|
|
- assetId: this.ASSET,
|
|
|
- description: "test",
|
|
|
- amount: "10",
|
|
|
+ assetId,
|
|
|
+ description,
|
|
|
+ amount: String(amount),
|
|
|
});
|
|
|
|
|
|
console.debug(response);
|
|
|
-
|
|
|
- return "bla";
|
|
|
-
|
|
|
+
|
|
|
+ return response["txHash"][0];
|
|
|
|
|
|
} catch (err) {
|
|
|
console.error(err)
|