opportunity-service 0.0.651 → 0.0.652
Sign up to get free protection for your applications and to get access to all the features.
@@ -7,26 +7,43 @@ 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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
+
if (userRegistrationInstance.getTrueIdentification(msgSender) == '0x0000000000000000000000000000000000000000') {
|
26
|
+
console.log('Registering new user: ' + msgSender);
|
27
|
+
const tx = new Contract(addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION], abiMap[Contracts.USER_REGISTRATION]).connect(opportunityService.getSignersInterface())
|
28
|
+
.registerNewUser({
|
29
|
+
from: msgSender
|
30
|
+
});
|
31
|
+
const receipt = yield tx.wait();
|
32
|
+
console.log('the receipt');
|
33
|
+
console.log(receipt);
|
34
|
+
if (Number(receipt.status) === 1) {
|
35
|
+
resolve(true);
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
resolve(false);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
catch (error) {
|
43
|
+
console.log(error);
|
44
|
+
reject('An error occurred while trying to complete the registration.');
|
45
|
+
}
|
46
|
+
}));
|
30
47
|
});
|
31
48
|
}
|
32
49
|
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;
|
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,EAAe,MAAM,QAAQ,CAAC;AACvD,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,OAAO,IAAI,OAAO,CAAC,CAAO,OAAO,EAAE,MAAM,EAAE,EAAE;YACzC,IAAI;gBACA,MAAM,uBAAuB,GAAG,UAAU,CAAC,kBAAkB,CAAC,aAAa,EAAE,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAA;gBAC3G,MAAM,yBAAyB,GAAG,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAA;gBACrE,MAAM,SAAS,GAAG,MAAM,kBAAkB,CAAC,mBAAmB,EAAE,CAAC,QAAQ,CAAA;gBAEzE,IAAI,OAAO,SAAS,IAAI,WAAW;oBAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;gBAEnF,MAAM,wBAAwB,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,uBAAuB,EAAE,yBAAyB,EAAE,kBAAkB,CAAC,oBAAoB,EAAE,CAAC,CAAA;gBACnJ,IAAI,wBAAwB,CAAC,qBAAqB,CAAC,SAAS,CAAC,IAAI,4CAA4C,EAC7G;oBACI,OAAO,CAAC,GAAG,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAAA;oBACjD,MAAM,EAAE,GAAG,IAAI,QAAQ,CACnB,UAAU,CAAC,kBAAkB,CAAC,aAAa,EAAE,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAC3E,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,EAAE,CAAC;yBACrF,eAAe,CAAC;wBACb,IAAI,EAAE,SAAS;qBACtB,CAAC,CAAA;oBAEF,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,IAAI,EAAE,CAAA;oBAC/B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;oBAC1B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;oBAEpB,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;wBAC9B,OAAO,CAAC,IAAI,CAAC,CAAC;qBACjB;yBAAM;wBACH,OAAO,CAAC,KAAK,CAAC,CAAA;qBACjB;iBACJ;aAGJ;YAAC,OAAM,KAAK,EAAE;gBACX,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;gBAClB,MAAM,CAAC,8DAA8D,CAAC,CAAA;aACzE;QACL,CAAC,CAAA,CAAC,CAAA;IACN,CAAC;CAAA;AAED,eAAe,eAAe,CAAC"}
|
package/package.json
CHANGED
@@ -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,42 @@ import abiMap from '../../blockchain/abi.json'
|
|
7
7
|
import { Result } from 'ethers/lib/utils';
|
8
8
|
|
9
9
|
async function registerNewUser() {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
+
if (userRegistrationInstance.getTrueIdentification(msgSender) == '0x0000000000000000000000000000000000000000')
|
20
|
+
{
|
21
|
+
console.log('Registering new user: ' + msgSender)
|
22
|
+
const tx = new Contract(
|
23
|
+
addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION],
|
24
|
+
abiMap[Contracts.USER_REGISTRATION]).connect(opportunityService.getSignersInterface())
|
25
|
+
.registerNewUser({
|
26
|
+
from: msgSender
|
27
|
+
})
|
28
|
+
|
29
|
+
const receipt = await tx.wait()
|
30
|
+
console.log('the receipt')
|
31
|
+
console.log(receipt)
|
32
|
+
|
33
|
+
if (Number(receipt.status) === 1) {
|
34
|
+
resolve(true);
|
35
|
+
} else {
|
36
|
+
resolve(false)
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
} catch(error) {
|
42
|
+
console.log(error)
|
43
|
+
reject('An error occurred while trying to complete the registration.')
|
44
|
+
}
|
22
45
|
})
|
23
|
-
} catch(error) {
|
24
|
-
console.log(error)
|
25
|
-
}
|
26
46
|
}
|
27
47
|
|
28
48
|
export default registerNewUser;
|