浏览代码

getUserBalance WIP

kunickyd 3 年之前
父节点
当前提交
2c22acb13c
共有 2 个文件被更改,包括 42 次插入8 次删除
  1. 2 1
      src/app/bc-info/bc-info.module.ts
  2. 40 7
      src/app/bc-info/bc-info.service.ts

+ 2 - 1
src/app/bc-info/bc-info.module.ts

@@ -1,9 +1,10 @@
 import {NgModule} from '@angular/core';
+import {CommonModule} from '@angular/common'
 
 import {BcInfoComponent} from './bc-info.component';
 
 @NgModule({
-  imports: [],
+  imports: [CommonModule],
   exports: [BcInfoComponent],
   declarations: [BcInfoComponent],
   providers: [],

+ 40 - 7
src/app/bc-info/bc-info.service.ts

@@ -1,14 +1,47 @@
-import {Injectable} from '@angular/core';
-import {HttpClient} from '@angular/common/http';
+import { Injectable } from '@angular/core';
+import { HttpClient } from '@angular/common/http';
+import {
+  CommandService_v1Client as CommandService,
+  QueryService_v1Client as QueryService
+} from 'iroha-helpers/lib/proto/endpoint_pb_service'
+import { queries } from 'iroha-helpers'
 
-@Injectable({providedIn: 'root'})
+@Injectable({ providedIn: 'root' })
 export class BcInfoService {
+
   BASE_URL = 'https://chain4all.lesprojekt.cz' as const;
+  IROHA_ADDRESS = "localhost:50051" as const;
+  ASSET = "testcoin#test" as const;
+
   user = 'jmacura';
+  userPrivateKey = 'test';
   user_balance = -1;
-  constructor(public httpClient: HttpClient) {}
-  
-  getUserBalance() {
-    //TODO:
+
+  commandService: CommandService;
+  queryService: QueryService;
+
+  constructor(public httpClient: HttpClient) { 
+    this.commandService = new CommandService(this.IROHA_ADDRESS);
+    this.queryService = new QueryService(this.IROHA_ADDRESS);
+  }
+
+  getUserBalance() : any{
+    let queryOptions = {
+      privateKey: this.userPrivateKey,
+      creatorAccountId: this.user,
+      queryService: this.queryService,
+      timeoutLimit: 5000
+    };
+    
+    queries.getAccountAssets(queryOptions, {
+      accountId: this.user,
+      firstAssetId: undefined,
+      pageSize: 10
+    })
+    .then((data) => console.log(data))
+    .catch((err) => console.error(err));
+
+    return "test";
+
   }
 }