Skip to content

Commit

Permalink
feat(connector-tcs-huawei): add initial version
Browse files Browse the repository at this point in the history
Signed-off-by: wangyinglun <wangyinglun3@huawei.com>
  • Loading branch information
wangyinglun committed Jun 23, 2023
1 parent 48a4133 commit 0465c13
Show file tree
Hide file tree
Showing 52 changed files with 2,789 additions and 0 deletions.
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

0 comments on commit 0465c13

Please sign in to comment.