Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(connector-tcs-huawei): add initial version #2417

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/cactus-example-tcs-huawei/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MeterInfo.json

# BLP artifacts
etc/

# don't commit package-lock
package-lock.json
65 changes: 65 additions & 0 deletions examples/cactus-example-tcs-huawei/BalanceManagement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2020-2021 Hyperledger Cactus Contributors
* SPDX-License-Identifier: Apache-2.0
*
* BalanceManagement.ts
*/

import {
LPInfoHolder,
ConfigUtil,
} from "@hyperledger/cactus-cmd-socketio-server";
import {
VerifierFactory,
VerifierFactoryConfig,
} from "@hyperledger/cactus-verifier-client";

const config: any = ConfigUtil.getConfig();
import { getLogger } from "log4js";
const moduleName = "BalanceManagement";
const logger = getLogger(`${moduleName}`);
logger.level = config.logLevel;

export class BalanceManagement {
private connectInfo: LPInfoHolder = null; // connection information
private readonly verifierFactory: VerifierFactory;

constructor() {
this.connectInfo = new LPInfoHolder();
this.verifierFactory = new VerifierFactory(
this.connectInfo.ledgerPluginInfo as VerifierFactoryConfig,
config.logLevel,
);
}

getBalance(account: string): Promise<any> {
return new Promise((resolve, reject) => {
// for LedgerOperation
// const execData = {"referedAddress": account};
// const ledgerOperation: LedgerOperation = new LedgerOperation("getNumericBalance", "", execData);

// for Neo
const contract = {}; // NOTE: Since contract does not need to be specified, specify an empty object.
const method = { type: "web3Eth", command: "getBalance" };
const template = "default";
const args = { args: [account] };
// const method = "default";
// const args = {"method": {type: "web3Eth", command: "getBalance"}, "args": {"args": [account]}};

this.verifierFactory
.getVerifier("84jUisrs")
.sendSyncRequest(contract, method, args)
.then((result) => {
const response = {
status: result.status,
amount: parseFloat(result.data),
};
resolve(response);
})
.catch((err) => {
logger.error(err);
reject(err);
});
});
}
}
Loading