ソースを参照

transferAssets

kunickyd 3 年 前
コミット
0cbe443752
1 ファイル変更37 行追加4 行削除
  1. 37 4
      src/app/bc-info/bc-info.service.ts

+ 37 - 4
src/app/bc-info/bc-info.service.ts

@@ -4,7 +4,8 @@ import {
   CommandService_v1Client as CommandService,
   QueryService_v1Client as QueryService
 } from 'iroha-helpers/lib/proto/endpoint_pb_service'
-import { queries } from 'iroha-helpers'
+import { queries, commands } from 'iroha-helpers'
+
 
 
 @Injectable({ providedIn: 'root' })
@@ -13,11 +14,12 @@ export class BcInfoService {
   BASE_URL = 'https://chain4all.lesprojekt.cz' as const;
   IROHA_ADDRESS = "http://localhost:8080" as const;
   ASSET = "testcoin#test" as const;
+  ADMIN_USER = "admin@test" as const;
 
   commandService: CommandService;
   queryService: QueryService;
-  user = 'admin@test';
-  userPrivateKey = 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70';
+  user = 'kunickyd@test';
+  userPrivateKey = 'ecb7f22887b0b45d1923fcd147d34bb6fd79f56eb54ed5af42c9d70c7808a9d8';
   userBalance = -1;
   private _requestInProcess = false;
 
@@ -32,6 +34,7 @@ export class BcInfoService {
       return;
     }
     this.userBalance = await this.getUserBalanceFromIroha()
+    await this.transferAssets();
   }
 
   async getUserBalanceFromIroha(): Promise<number> {
@@ -42,7 +45,7 @@ export class BcInfoService {
       creatorAccountId: this.user,
       queryService: this.queryService,
       timeoutLimit: 10000
-    };    
+    };
 
     try {
       // For testing
@@ -72,4 +75,34 @@ export class BcInfoService {
 
     this._requestInProcess = false
   }
+
+  async transferAssets(): Promise<string> {
+
+    let commandOptions = {
+      privateKeys: [this.userPrivateKey], // Array of private keys in hex format
+      creatorAccountId: this.user, // Account id, ex. admin@test
+      quorum: 1,
+      commandService: this.commandService,
+      timeoutLimit: 5000 // Set timeout limit
+    };
+
+    try {
+
+      let response = await commands.transferAsset(commandOptions, {
+        srcAccountId: this.user,
+        destAccountId: this.ADMIN_USER,
+        assetId: this.ASSET,
+        description: "test",
+        amount: "10",
+      });
+
+      console.debug(response);
+
+      return "bla";
+
+
+    } catch (err) {     
+      console.error(err)
+    }
+  }
 }