opportunity-service 0.0.629 → 0.0.633

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opportunity-service",
3
- "version": "0.0.629",
3
+ "version": "0.0.633",
4
4
  "description": "A service layer that connects all services between the blockchain and ui.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,6 +13,7 @@ import opportunityStorageProvider from "./modules/storage/OpportunityStorageProv
13
13
  import { EthNetworkID } from "dvote-js";
14
14
  import Web3 from 'web3';
15
15
  import OpportunityStorageProvider from "./modules/storage/OpportunityStorageProvider";
16
+ import { createAlchemyWeb3 } from "@alch/alchemy-web3"
16
17
 
17
18
  import { Shh } from 'web3-shh'
18
19
 
@@ -20,6 +21,7 @@ class OpportunityService {
20
21
  private eventEmitter = opportunityEventEmitter;
21
22
  private running: boolean = false;
22
23
  private syncing: boolean = false;
24
+ private opportunityProvider : providers.JsonRpcProvider;
23
25
  private ethersProvider : providers.JsonRpcProvider = ethers.getDefaultProvider('http://localhost:8545');
24
26
  private ethersSigner : providers.JsonRpcSigner = null;
25
27
  private static defaultProvider = new Web3('http://localhost:8545')
@@ -39,7 +41,11 @@ class OpportunityService {
39
41
  * construction calls with the `new` operator.
40
42
  */
41
43
  private constructor() {
44
+ const web3 = createAlchemyWeb3(process.env.NODE_ENV == 'dev' ? "https://eth-mainnet.alchemyapi.io/v2/JKVeBInuvm4wq9_8fECUmazLbm7Vpv5V" : "https://eth-mainnet.alchemyapi.io/v2/7d2CRio84usjQwU8tRPG75rqV1wJmX_W");
42
45
  this.ethNetwork = 'rinkeby'
46
+
47
+ this.opportunityProvider = new ethers.providers.JsonRpcProvider(process.env.NODE_ENV == 'dev' ? "https://eth-mainnet.alchemyapi.io/v2/JKVeBInuvm4wq9_8fECUmazLbm7Vpv5V" : "https://eth-mainnet.alchemyapi.io/v2/7d2CRio84usjQwU8tRPG75rqV1wJmX_W")
48
+ console.log(this.opportunityProvider)
43
49
  }
44
50
 
45
51
  /**
@@ -145,6 +151,14 @@ class OpportunityService {
145
151
  }
146
152
 
147
153
  getProviderInterface() : providers.JsonRpcProvider {
154
+ if (this.opportunityProvider) {
155
+ console.log('Provider is not null')
156
+ console.log(this.opportunityProvider)
157
+ return this.opportunityProvider
158
+ } else {
159
+ console.log('provider is null')
160
+ }
161
+
148
162
  return this.ethersProvider;
149
163
  }
150
164
 
package/src/api/index.ts CHANGED
@@ -7,7 +7,7 @@ import { enterWorkRelationship } from "./exchange/enter-work-relationship";
7
7
  import registerNewUser from "./identity/register-new-user";
8
8
  import { createMarket } from "./market/create-market";
9
9
 
10
- import { abis, events, getContractAddress} from './internal/index';
10
+ import { abis, events, getContractAddress, getContractInterface} from './internal/index';
11
11
 
12
12
  import { sendAsync } from './ethereum/sendAsync'
13
13
  import { parseCypher } from "./util/parse-cipher";
@@ -29,6 +29,7 @@ function generateAPI() {
29
29
  internal: {
30
30
  abis: abis,
31
31
  getContractAddress,
32
+ getContractInterface
32
33
  },
33
34
  exchange: {
34
35
  completeRelationship,
@@ -1,5 +1,12 @@
1
1
 
2
- import * as abiMap from '../../blockchain/abi.json';
2
+ import abiMap from '../../blockchain/abi.json';
3
+
4
+ function getContractInterface(contract: string) {
5
+ console.log(abiMap)
6
+ return abiMap[contract]
7
+ }
8
+
9
+ export { getContractInterface }
3
10
 
4
11
  export default {
5
12
  'MarketFactory': abiMap['MarketFactory'],
@@ -4,8 +4,5 @@ import { EthNetworkID } from 'dvote-js';
4
4
  import { Contracts } from '../../constants';
5
5
 
6
6
  export default function getContractAddress(network: EthNetworkID, contractName: Contracts): string {
7
- console.log(network)
8
- console.log(contractName)
9
- console.log(addressMap)
10
7
  return addressMap[network][contractName]
11
8
  }
@@ -1,5 +1,5 @@
1
- import abis from "./abis";
1
+ import abis, { getContractInterface } from "./abis";
2
2
  import getContractAddress from "./addresses";
3
3
  import events from "./events";
4
4
 
5
- export { abis, getContractAddress, events};
5
+ export { abis, getContractAddress, getContractInterface, events};