Skip to content

Commit

Permalink
added env balance variables (#864)
Browse files Browse the repository at this point in the history
Signed-off-by: artembuslaev <buslaew.ar@mail.ru>
  • Loading branch information
artembuslaev authored and anvabr committed May 13, 2022
1 parent 7fbda5f commit 0a7d070
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions guardian-service/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ MQ_ADDRESS="localhost"
SERVICE_CHANNEL="guardian.1"
DB_HOST="localhost"
DB_DATABASE="guardian_db"
MAX_TRANSACTION_FEE="10"
INITIAL_BALANCE="30"
OPERATOR_ID="..."
OPERATOR_KEY="..."
2 changes: 2 additions & 0 deletions guardian-service/.env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ MQ_ADDRESS="message-broker"
SERVICE_CHANNEL="guardian.1"
DB_HOST="mongo"
DB_DATABASE="guardian_db"
MAX_TRANSACTION_FEE="10"
INITIAL_BALANCE="30"
OPERATOR_ID="..."
OPERATOR_KEY="..."
4 changes: 2 additions & 2 deletions guardian-service/src/api/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const demoAPI = async function (
const OPERATOR_ID = operatorId?.value || process.env.OPERATOR_ID;
const OPERATOR_KEY = operatorKey?.value || process.env.OPERATOR_KEY;
const client = new HederaSDKHelper(OPERATOR_ID, OPERATOR_KEY);
const treasury = await client.newAccount(30);
return new MessageResponse({
const treasury = await client.newAccount();
res.send(new MessageResponse({
id: treasury.id.toString(),
key: treasury.key.toString()
});
Expand Down
2 changes: 1 addition & 1 deletion guardian-service/src/api/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const tokenAPI = async function (
const root = await users.getHederaAccount(owner);

const client = new HederaSDKHelper(root.hederaAccountId, root.hederaAccountKey);
const treasury = await client.newAccount(2);
const treasury = await client.newAccount();
const treasuryId = treasury.id;
const treasuryKey = treasury.key;
const adminKey = enableAdmin ? treasuryKey : null;
Expand Down
9 changes: 5 additions & 4 deletions guardian-service/src/hedera-modules/hedera-sdk-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import axios from "axios";
import { Environment } from './environment';

export const MAX_FEE = 10;
export const INITIAL_BALANCE = 30;

/**
* Contains methods to simplify work with hashgraph sdk
Expand Down Expand Up @@ -89,7 +90,7 @@ export class HederaSDKHelper {
.setTreasuryAccountId(treasury.id)
.setDecimals(decimals)
.setInitialSupply(initialSupply)
.setMaxTransactionFee(new Hbar(MAX_FEE))
.setMaxTransactionFee(new Hbar(process.env.MAX_TRANSACTION_FEE || MAX_FEE))
.setTokenMemo(tokenMemo);

if (adminKey) {
Expand Down Expand Up @@ -495,12 +496,12 @@ export class HederaSDKHelper {
* @returns {any} - Account Id and Account Private Key
*/
@timeout(HederaSDKHelper.MAX_TIMEOUT)
public async newAccount(initialBalance: number): Promise<{ id: AccountId; key: PrivateKey; }> {
public async newAccount(): Promise<{ id: AccountId; key: PrivateKey; }> {
const client = this.client;
const newPrivateKey = PrivateKey.generate();
const transaction = new AccountCreateTransaction()
.setKey(newPrivateKey.publicKey)
.setInitialBalance(new Hbar(initialBalance));
.setInitialBalance(new Hbar(process.env.INITIAL_BALANCE || INITIAL_BALANCE));
const txResponse = await transaction.execute(client);
const receipt = await txResponse.getReceipt(client);
const newAccountId = receipt.accountId;
Expand All @@ -526,7 +527,7 @@ export class HederaSDKHelper {
const client = this.client;

let transaction: any = new TopicCreateTransaction()
.setMaxTransactionFee(new Hbar(MAX_FEE));
.setMaxTransactionFee(new Hbar(process.env.MAX_TRANSACTION_FEE || MAX_FEE));

if (topicMemo) {
transaction = transaction.setTopicMemo(topicMemo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class PolicyImportExportHelper {
const client = new HederaSDKHelper(root.hederaAccountId, root.hederaAccountKey);
const tokenRepository = getMongoRepository(Token);
for (const token of tokens) {
const treasury = await client.newAccount(2);
const treasury = await client.newAccount();
const treasuryId = treasury.id;
const treasuryKey = treasury.key;
const tokenName = token.tokenName;
Expand Down

0 comments on commit 0a7d070

Please sign in to comment.