-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(VerifierFactory): add connection feature to both of socket.io-ty…
…pe Validator and http-type Validator Signed-off-by: Takuma TAKEUCHI <takeuchi.takuma@fujitsu.com>
- Loading branch information
Showing
63 changed files
with
1,313 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright 2020-2021 Hyperledger Cactus Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* AssetManagement.ts | ||
*/ | ||
|
||
import { LPInfoHolder } from '../../packages/routing-interface/util/LPInfoHolder'; | ||
import { VerifierBase } from '../../packages/ledger-plugin/VerifierBase'; | ||
import { ContractInfoHolder } from '../../packages/routing-interface/util/ContractInfoHolder'; | ||
import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const config: any = ConfigUtil.getConfig(); | ||
import { getLogger } from "log4js"; | ||
const moduleName = 'AssetManagement'; | ||
const logger = getLogger(`${moduleName}`); | ||
logger.level = config.logLevel; | ||
|
||
export class AssetManagement { | ||
private connectInfo: LPInfoHolder = null; // connection information | ||
private contractInfoholder: ContractInfoHolder = null; // contract information | ||
private verifierEthereum: VerifierBase = null; | ||
|
||
constructor() { | ||
this.connectInfo = new LPInfoHolder(); | ||
this.contractInfoholder = new ContractInfoHolder(); | ||
} | ||
|
||
addAsset(amount: string): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
if (this.verifierEthereum === null) { | ||
logger.debug("create verifierEthereum"); | ||
const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("84jUisrs"); | ||
this.verifierEthereum = new VerifierBase(ledgerPluginInfo); | ||
} | ||
|
||
// for Neo | ||
const contractInfo: string = this.contractInfoholder.getContractInfo("AssetContract"); | ||
const contractInfoObj: {} = JSON.parse(contractInfo); | ||
const coinbase = contractInfoObj['_eth']['coinbase']; | ||
const address = contractInfoObj['address']; | ||
const abi = contractInfoObj['abi']; | ||
const contract = { | ||
"address": address, | ||
"abi": abi | ||
}; | ||
const method = {type: "contract", command: "addAsset", function: "sendTransaction"}; | ||
const args = {"args": [amount, {from: coinbase}]}; | ||
|
||
this.verifierEthereum.execSyncFunctionNeo(contract, method, args).then(result => { | ||
const response = { | ||
"status": result.status, | ||
"Transaction hash": result.data | ||
} | ||
resolve(response); | ||
}).catch((err) => { | ||
logger.error(err); | ||
reject(err); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
getAsset(): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
if (this.verifierEthereum === null) { | ||
logger.debug("create verifierEthereum"); | ||
const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("84jUisrs"); | ||
this.verifierEthereum = new VerifierBase(ledgerPluginInfo); | ||
} | ||
|
||
// for Neo | ||
const contractInfo: string = this.contractInfoholder.getContractInfo("AssetContract"); | ||
const contractInfoObj: {} = JSON.parse(contractInfo); | ||
const address = contractInfoObj['address']; | ||
const abi = contractInfoObj['abi']; | ||
const contract = { | ||
"address": address, | ||
"abi": abi | ||
}; | ||
const method = {type: "contract", command: "getAsset", function: "call"}; | ||
const args = {"args": []}; | ||
|
||
this.verifierEthereum.execSyncFunctionNeo(contract, method, args).then(result => { | ||
const response = { | ||
"status": result.status, | ||
"asset": parseFloat(result.data) | ||
} | ||
resolve(response); | ||
}).catch((err) => { | ||
logger.error(err); | ||
reject(err); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2020-2021 Hyperledger Cactus Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* BalanceManagement.ts | ||
*/ | ||
|
||
import { LPInfoHolder } from '../../packages/routing-interface/util/LPInfoHolder'; | ||
import { VerifierBase } from '../../packages/ledger-plugin/VerifierBase'; | ||
import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
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 verifierEthereum: VerifierBase = null; | ||
|
||
constructor() { | ||
this.connectInfo = new LPInfoHolder(); | ||
} | ||
|
||
getBalance(account: string): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
if (this.verifierEthereum === null) { | ||
logger.debug("create verifierEthereum"); | ||
const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("84jUisrs"); | ||
this.verifierEthereum = new VerifierBase(ledgerPluginInfo); | ||
} | ||
|
||
// 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 args = {"args": [account]}; | ||
|
||
this.verifierEthereum.execSyncFunctionNeo(contract, method, args).then(result => { | ||
const response = { | ||
"status": result.status, | ||
"amount": parseFloat(result.data) | ||
} | ||
resolve(response); | ||
}).catch((err) => { | ||
logger.error(err); | ||
reject(err); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2020-2021 Hyperledger Cactus Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* CarsManagement.ts | ||
*/ | ||
|
||
import { LPInfoHolder } from '../../packages/routing-interface/util/LPInfoHolder'; | ||
import { VerifierBase } from '../../packages/ledger-plugin/VerifierBase'; | ||
import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const config: any = ConfigUtil.getConfig(); | ||
import { getLogger } from "log4js"; | ||
const moduleName = 'CarsManagement'; | ||
const logger = getLogger(`${moduleName}`); | ||
logger.level = config.logLevel; | ||
|
||
export class CarsManagement { | ||
private connectInfo: LPInfoHolder = null; // connection information | ||
private verifierFabric: VerifierBase = null; | ||
|
||
constructor() { | ||
this.connectInfo = new LPInfoHolder(); | ||
} | ||
|
||
queryCar(carID: string): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
if (this.verifierFabric === null) { | ||
logger.debug("create verifierFabric"); | ||
const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("r9IS4dDf"); | ||
this.verifierFabric = new VerifierBase(ledgerPluginInfo); | ||
} | ||
|
||
const contract = {"channelName": "mychannel", "contractName": "fabcar"}; | ||
const method = {type: "evaluateTransaction", command: "queryCar"}; | ||
const args = {"args": [carID]}; | ||
|
||
this.verifierFabric.execSyncFunctionNeo(contract, method, args).then(result => { | ||
resolve(result); | ||
}).catch((err) => { | ||
logger.error(err); | ||
reject(err); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
queryAllCars(): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
if (this.verifierFabric === null) { | ||
logger.debug("create verifierFabric"); | ||
const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("r9IS4dDf"); | ||
this.verifierFabric = new VerifierBase(ledgerPluginInfo); | ||
} | ||
|
||
const contract = {"channelName": "mychannel", "contractName": "fabcar"}; | ||
const method = {type: "evaluateTransaction", command: "queryAllCars"}; | ||
const args = {"args": []}; | ||
|
||
this.verifierFabric.execSyncFunctionNeo(contract, method, args).then(result => { | ||
resolve(result); | ||
}).catch((err) => { | ||
logger.error(err); | ||
reject(err); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.