Skip to content

Commit

Permalink
Merge branch 'main' into feature-983
Browse files Browse the repository at this point in the history
  • Loading branch information
jagpreetsinghsasan authored Jul 28, 2021
2 parents 55d0c5c + 43be168 commit 10f5c73
Show file tree
Hide file tree
Showing 77 changed files with 5,667 additions and 32 deletions.
106 changes: 106 additions & 0 deletions examples/discounted-cartrade/AssetManagement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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 template = "default";
const args = {"args": [amount, {from: coinbase}]};
// const method = "default";
// const args = {"method": {type: "contract", command: "addAsset", function: "sendTransaction"}, "args": {"args": [amount, {from: coinbase}]}};

this.verifierEthereum.execSyncFunction(contract, method, template, 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 template = "default";
const args = {"args": []};
// const method = "default";
// const args = {"method": {type: "contract", command: "getAsset", function: "call"}, "args": {"args": []}};

this.verifierEthereum.execSyncFunction(contract, method, template, args).then(result => {
const response = {
"status": result.status,
"asset": parseFloat(result.data)
}
resolve(response);
}).catch((err) => {
logger.error(err);
reject(err);
});

});
}

}
49 changes: 49 additions & 0 deletions examples/discounted-cartrade/BLP_container/blp-env.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM ubuntu:xenial

RUN apt-get update && apt-get upgrade -y && apt-get install -y software-properties-common gnupg
#RUN gnupg1 gnupg2

RUN apt-get install -y \
apt-utils \
apt-transport-https \
software-properties-common \
wget \
curl \
telnet \
sudo \
build-essential \
libffi-dev \
libssl-dev \
zlib1g-dev \
liblzma-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
git \
gnupg

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CE7709D068DB5E88
RUN add-apt-repository "deb https://repo.sovrin.org/sdk/deb xenial stable"
RUN apt-get update
RUN apt-get install -y libindy libnullpay libvcx indy-cli

# install python 3.9.5
#RUN apt-get install -y python3 python3-pip
RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv
RUN echo 'export PATH="$HOME"/.pyenv/bin:$PATH' >> ~/.rc
RUN . ~/.rc && pyenv install 3.9.5
RUN echo 'eval "$(pyenv init -)"' >> ~/.rc
RUN echo 'eval "$(pyenv init --path)"' >> ~/.rc
RUN cat ~/.rc >> ~/.bashrc
RUN . ~/.rc && pyenv global 3.9.5

# indy wrapper for python3
RUN . ~/.rc && pip install python3-indy

RUN apt-get install -y nodejs npm
RUN npm install n -g
RUN n 12
RUN apt purge -y nodejs npm
RUN npm install indy-sdk

CMD [ "tail", "-f", "/dev/null" ]
36 changes: 36 additions & 0 deletions examples/discounted-cartrade/BLP_container/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "3"
services:
blp_container:
container_name: blp_container
image: blp_container
build:
context: ./
dockerfile: blp-env.dockerfile
args:
- HTTP_PROXY=$HTTP_PROXY
- http_proxy=$HTTP_PROXY
- HTTPS_PROXY=$HTTPS_PROXY
- https_proxy=$HTTP_PROXY
- FTP_PROXY=$HTTP_PROXY
- ftp_proxy=$HTTP_PROXY
- NO_PROXY=$NO_PROXY
- no_proxy=$NO_PROXY
volumes:
- type: bind
source: "../../../../BIF-trial/"
target: "/root/BIF-trial"
ports:
- "5034:5034"
environment:
- HTTP_PROXY=$HTTP_PROXY
- http_proxy=$HTTP_PROXY
- HTTPS_PROXY=$HTTPS_PROXY
- https_proxy=$HTTP_PROXY
- FTP_PROXY=$HTTP_PROXY
- ftp_proxy=$HTTP_PROXY
- NO_PROXY=$NO_PROXY
- no_proxy=$NO_PROXY
networks:
default:
external:
name: indy_net
62 changes: 62 additions & 0 deletions examples/discounted-cartrade/BalanceManagement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 template = "default";
const args = {"args": [account]};
// const method = "default";
// const args = {"method": {type: "web3Eth", command: "getBalance"},"args": {"args": [account]}};

this.verifierEthereum.execSyncFunction(contract, method, template, 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 10f5c73

Please sign in to comment.