opportunity-service 0.0.651 → 0.0.655

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,26 +7,52 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Contract } from 'ethers';
10
+ import { Contract, ethers } from 'ethers';
11
11
  import opportunityService from '../../OpportunityService';
12
12
  import { Contracts } from '../../constants';
13
13
  import addressMap from '../../blockchain/addresses.json';
14
14
  import abiMap from '../../blockchain/abi.json';
15
15
  function registerNewUser() {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
- try {
18
- const msgSender = yield opportunityService.getSignersInterface()._address;
19
- console.log('Registering new user: ' + msgSender);
20
- if (typeof msgSender == 'undefined')
21
- throw new Error('Message sender is undefined');
22
- const txResult = new Contract(addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION], abiMap[Contracts.USER_REGISTRATION]).connect(opportunityService.getSignersInterface())
23
- .registerNewUser({
24
- from: msgSender
25
- });
26
- }
27
- catch (error) {
28
- console.log(error);
29
- }
17
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
18
+ try {
19
+ const userRegistrationAddress = addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION];
20
+ const userRegistrationInterface = abiMap[Contracts.USER_REGISTRATION];
21
+ const msgSender = yield opportunityService.getSignersInterface()._address;
22
+ if (typeof msgSender == 'undefined')
23
+ throw new Error('Message sender is undefined');
24
+ const userRegistrationInstance = new ethers.Contract(userRegistrationAddress, userRegistrationInterface, opportunityService.getProviderInterface());
25
+ console.log('Checking true identificaiton of msgSender: ' + msgSender);
26
+ const id = yield userRegistrationInstance.getTrueIdentification(msgSender);
27
+ console.log('The true identificaiton is: ' + id);
28
+ if (id == '0x0000000000000000000000000000000000000000') {
29
+ console.log('Registering new user: ' + msgSender);
30
+ const tx = new Contract(addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION], abiMap[Contracts.USER_REGISTRATION]).connect(opportunityService.getSignersInterface())
31
+ .registerNewUser({
32
+ from: msgSender
33
+ });
34
+ const receipt = yield tx.wait();
35
+ console.log('the receipt');
36
+ console.log(receipt);
37
+ if (Number(receipt.status) === 1) {
38
+ console.log('transaction succeeded');
39
+ resolve(true);
40
+ }
41
+ else {
42
+ console.log('Transaction failed');
43
+ resolve(false);
44
+ }
45
+ }
46
+ else {
47
+ console.log('User already registered');
48
+ resolve(false);
49
+ }
50
+ }
51
+ catch (error) {
52
+ console.log(error);
53
+ reject('An error occurred while trying to complete the registration.');
54
+ }
55
+ }));
30
56
  });
31
57
  }
32
58
  export default registerNewUser;
@@ -1 +1 @@
1
- {"version":3,"file":"register-new-user.js","sourceRoot":"","sources":["../../../src/api/identity/register-new-user.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAe,MAAM,QAAQ,CAAC;AAC/C,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,UAAU,MAAM,iCAAiC,CAAA;AACxD,OAAO,MAAM,MAAM,2BAA2B,CAAA;AAG9C,SAAe,eAAe;;QAC1B,IAAI;YACR,MAAM,SAAS,GAAG,MAAM,kBAAkB,CAAC,mBAAmB,EAAE,CAAC,QAAQ,CAAA;YACzE,OAAO,CAAC,GAAG,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAAA;YAEjD,IAAI,OAAO,SAAS,IAAI,WAAW;gBAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;YAEnF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CACzB,UAAU,CAAC,kBAAkB,CAAC,aAAa,EAAE,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAC3E,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAClC,CAAC,OAA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AAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opportunity-service",
3
- "version": "0.0.651",
3
+ "version": "0.0.655",
4
4
  "description": "A service layer that connects all services between the blockchain and ui.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,4 @@
1
- import { Contract, Transaction } from 'ethers';
1
+ import { Contract, ethers, Transaction } from 'ethers';
2
2
  import opportunityService from '../../OpportunityService';
3
3
  import { Contracts } from '../../constants';
4
4
 
@@ -7,22 +7,52 @@ import abiMap from '../../blockchain/abi.json'
7
7
  import { Result } from 'ethers/lib/utils';
8
8
 
9
9
  async function registerNewUser() {
10
- try {
11
- const msgSender = await opportunityService.getSignersInterface()._address
12
- console.log('Registering new user: ' + msgSender)
13
-
14
- if (typeof msgSender == 'undefined') throw new Error('Message sender is undefined')
15
-
16
- const txResult = new Contract(
17
- addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION],
18
- abiMap[Contracts.USER_REGISTRATION]
19
- ).connect(opportunityService.getSignersInterface())
20
- .registerNewUser({
21
- from: msgSender
10
+ return new Promise(async (resolve, reject) => {
11
+ try {
12
+ const userRegistrationAddress = addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION]
13
+ const userRegistrationInterface = abiMap[Contracts.USER_REGISTRATION]
14
+ const msgSender = await opportunityService.getSignersInterface()._address
15
+
16
+ if (typeof msgSender == 'undefined') throw new Error('Message sender is undefined')
17
+
18
+ const userRegistrationInstance = new ethers.Contract(userRegistrationAddress, userRegistrationInterface, opportunityService.getProviderInterface())
19
+
20
+ console.log('Checking true identificaiton of msgSender: ' + msgSender)
21
+ const id = await userRegistrationInstance.getTrueIdentification(msgSender)
22
+ console.log('The true identificaiton is: ' + id)
23
+
24
+ if (id == '0x0000000000000000000000000000000000000000')
25
+ {
26
+ console.log('Registering new user: ' + msgSender)
27
+ const tx = new Contract(
28
+ addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION],
29
+ abiMap[Contracts.USER_REGISTRATION]).connect(opportunityService.getSignersInterface())
30
+ .registerNewUser({
31
+ from: msgSender
32
+ })
33
+
34
+ const receipt = await tx.wait()
35
+ console.log('the receipt')
36
+ console.log(receipt)
37
+
38
+ if (Number(receipt.status) === 1) {
39
+ console.log('transaction succeeded')
40
+ resolve(true);
41
+ } else {
42
+ console.log('Transaction failed')
43
+ resolve(false)
44
+ }
45
+ } else {
46
+ console.log('User already registered')
47
+ resolve(false)
48
+ }
49
+
50
+
51
+ } catch(error) {
52
+ console.log(error)
53
+ reject('An error occurred while trying to complete the registration.')
54
+ }
22
55
  })
23
- } catch(error) {
24
- console.log(error)
25
- }
26
56
  }
27
57
 
28
58
  export default registerNewUser;