opportunity-service 0.0.614 → 0.0.618

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/dist/OpportunityService.js +0 -5
  2. package/dist/OpportunityService.js.map +1 -1
  3. package/dist/api/index.js +6 -11
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/modules/storage/OpportunityStorageProvider.js +1 -20
  6. package/dist/modules/storage/OpportunityStorageProvider.js.map +1 -1
  7. package/dist/modules/whisper/ChatHandler.js +0 -77
  8. package/dist/modules/whisper/ChatHandler.js.map +1 -1
  9. package/package.json +4 -11
  10. package/src/OpportunityService.ts +3 -8
  11. package/src/api/index.ts +6 -12
  12. package/src/modules/storage/OpportunityStorageProvider.ts +1 -122
  13. package/src/modules/whisper/ChatHandler.ts +0 -78
  14. package/dist/api/dispute/check-vote-results.js +0 -33
  15. package/dist/api/dispute/check-vote-results.js.map +0 -1
  16. package/dist/api/dispute/connect.js +0 -39
  17. package/dist/api/dispute/connect.js.map +0 -1
  18. package/dist/api/dispute/ensure-entity-metadata.js +0 -39
  19. package/dist/api/dispute/ensure-entity-metadata.js.map +0 -1
  20. package/dist/api/dispute/launch-new-vote.js +0 -94
  21. package/dist/api/dispute/launch-new-vote.js.map +0 -1
  22. package/dist/api/dispute/submit-vote.js +0 -41
  23. package/dist/api/dispute/submit-vote.js.map +0 -1
  24. package/dist/api/dispute/util/wait-until-present.js +0 -27
  25. package/dist/api/dispute/util/wait-until-present.js.map +0 -1
  26. package/dist/api/dispute/util/wait-until-started.js +0 -23
  27. package/dist/api/dispute/util/wait-until-started.js.map +0 -1
  28. package/src/api/dispute/check-vote-results.ts +0 -30
  29. package/src/api/dispute/connect.ts +0 -36
  30. package/src/api/dispute/ensure-entity-metadata.ts +0 -34
  31. package/src/api/dispute/launch-new-vote.ts +0 -116
  32. package/src/api/dispute/submit-vote.ts +0 -59
  33. package/src/api/dispute/util/wait-until-present.ts +0 -19
  34. package/src/api/dispute/util/wait-until-started.ts +0 -14
  35. package/test/voting.test.ts +0 -20
@@ -14,7 +14,6 @@ import { ethers } from "ethers";
14
14
  import { startEventListeners } from "./events/start-event-listeners";
15
15
  import opportunityAPI from './api/index';
16
16
  import Web3 from 'web3';
17
- import WhisperHandler from "./modules/whisper/ChatHandler";
18
17
  class OpportunityService {
19
18
  /**
20
19
  * The Singleton's constructor should always be private to prevent direct
@@ -50,10 +49,6 @@ class OpportunityService {
50
49
  assignDefaultProvider(provider) {
51
50
  return __awaiter(this, void 0, void 0, function* () {
52
51
  OpportunityService.defaultProvider = provider;
53
- const shhProvider = provider;
54
- shhProvider.setProvider(new Web3.providers.WebsocketProvider("ws://localhost:8545", { headers: { Origin: "mychat" } }));
55
- yield shhProvider.eth.net.isListening();
56
- this.whisperProvider = new WhisperHandler(shhProvider);
57
52
  });
58
53
  }
59
54
  assignProvider(provider) {
@@ -1 +1 @@
1
- {"version":3,"file":"OpportunityService.js","sourceRoot":"","sources":["../src/OpportunityService.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAA6B,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,uBAAuB,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAKxE,OAAO,EAAE,MAAM,EAAa,MAAM,QAAQ,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,cAAc,MAAM,aAAa,CAAC;AAGzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,cAAc,MAAM,+BAA+B,CAAC;AAE3D,MAAM,kBAAkB;IAkBpB;;;OAGG;IACH;QArBQ,iBAAY,GAAG,uBAAuB,CAAC;QACvC,YAAO,GAAY,KAAK,CAAC;QACzB,YAAO,GAAY,KAAK,CAAC;QACzB,mBAAc,GAA+B,MAAM,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,CAAC;QAChG,iBAAY,GAA6B,IAAI,CAAC;QAE9C,sBAAiB,GAAG,IAAI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I,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QAC/C,oBAAoB,EAAE;aACjB,IAAI,CAAC,GAAG,EAAE;YACP,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;YAC9C,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAA;YAC9C,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACzB,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,CAAC,EAAE;YACT,OAAO,CAAC,GAAG,CAAC,qCAAqC,GAAG,GAAG,CAAC,CAAA;YACxD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACzB,CAAC,CAAC,CAAA;IACV,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,2BAA2B;QACvB,OAAO,kBAAkB,CAAC,eAAe,CAAC;IAC9C,CAAC;IAED,oBAAoB;QAChB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED,mBAAmB;QACf,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,kBAAkB;QACd,OAAO,IAAI,CAAC,eAAe,CAAA;IAC/B,CAAC;;AApIc,kCAAe,GAAG,IAAI,IAAI,CAAC,uBAAuB,CAAC,CAAA;AAuItE,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;AAC5D,eAAe,kBAAkB,CAAC"}
package/dist/api/index.js CHANGED
@@ -14,11 +14,6 @@ import { decryptByPrivateKey, encryptByPublicKey } from "./util/encrypt-by-publi
14
14
  import { createEthCryptoCreds } from "./other/create-eth-crypto-creds";
15
15
  import { encrypt } from "./provider/encrypt";
16
16
  import { decrypt } from "./provider/decrypt";
17
- import { connectGateways, getOracleClient } from "./dispute/connect";
18
- import { checkVoteResults } from "./dispute/check-vote-results";
19
- import { ensureEntityMetadata } from "./dispute/ensure-entity-metadata";
20
- import { launchNewVote } from "./dispute/launch-new-vote";
21
- import { submitVote } from "./dispute/submit-vote";
22
17
  import syncCreatedDisputes from "../sync/sync-disputes";
23
18
  import syncMarketDisputes from "../sync/sync-market-disputes";
24
19
  function generateAPI() {
@@ -38,12 +33,12 @@ function generateAPI() {
38
33
  enterWorkRelationship
39
34
  },
40
35
  dispute: {
41
- connectGateways: connectGateways,
42
- getOracleClient: getOracleClient,
43
- checkVoteResults: checkVoteResults,
44
- ensureEntityMetadata: ensureEntityMetadata,
45
- launchNewVote: launchNewVote,
46
- submitVote: submitVote
36
+ connectGateways: () => { },
37
+ getOracleClient: () => { },
38
+ checkVoteResults: () => { },
39
+ ensureEntityMetadata: () => { },
40
+ launchNewVote: () => { },
41
+ submitVote: () => { }
47
42
  },
48
43
  identity: {
49
44
  registerNewUser
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,IAAI,EAAU,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,k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QAAQ,EAAE;YACN,oBAAoB;YACpB,UAAU;YACV,qBAAqB;SACxB;QACD,OAAO,EAAE;YACL,eAAe,EAAE,GAAG,EAAE,GAAE,CAAC;YACzB,eAAe,EAAE,GAAG,EAAE,GAAE,CAAC;YACzB,gBAAgB,EAAE,GAAG,EAAE,GAAE,CAAC;YAC1B,oBAAoB,EAAE,GAAG,EAAE,GAAE,CAAC;YAC9B,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;YACvB,UAAU,EAAE,GAAG,EAAE,GAAE,CAAC;SACvB;QACD,QAAQ,EAAE;YACN,eAAe;SAClB;QACD,OAAO,EAAE;YACL,YAAY;SACf;QACD,OAAO,EAAE;YACL,IAAI,EAAE;gBACF,gBAAgB,EAAE,oBAAoB;gBACtC,WAAW;gBACX,QAAQ;gBACR,mBAAmB;gBACnB,kBAAkB;aACrB;SACJ;QACD,QAAQ,EAAE;YACN,SAAS;YACT,OAAO;YACP,OAAO;SACV;QACD,IAAI,EAAE;YACF,WAAW;YACX,eAAe;SAClB;KACJ,CAAA;AACL,CAAC;AAED,MAAM,cAAc,GAAG,WAAW,EAAE,CAAC;AAErC,eAAe,cAAc,CAAC"}
@@ -1,21 +1,2 @@
1
- const IPFS = require('ipfs');
2
- const OrbitDB = require('orbit-db');
3
- const operations = ['>', '<', '==', '>=', '<='];
4
- const optionsToWrite = {
5
- // Give write access to the creator of the database
6
- accessController: {
7
- type: 'orbitdb',
8
- create: 'true',
9
- admin: ['*'],
10
- write: ['*'],
11
- },
12
- indexBy: 'collection'
13
- };
14
- class OpportunityStorageProvider {
15
- constructor(address) {
16
- // this.initIPFSInstance()
17
- //this.listen(address)
18
- }
19
- }
20
- export default OpportunityStorageProvider;
1
+ export default function OpportunityStorageProvider() { }
21
2
  //# sourceMappingURL=OpportunityStorageProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"OpportunityStorageProvider.js","sourceRoot":"","sources":["../../../src/modules/storage/OpportunityStorageProvider.ts"],"names":[],"mappings":"AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAQnC,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;AAE/C,MAAM,cAAc,GAAG;IACnB,mDAAmD;IACnD,gBAAgB,EAAE;QAChB,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,KAAK,EAAE,CAAC,GAAG,CAAC;KACb;IACD,OAAO,EAAE,YAAY;CACxB,CAAA;AAGD,MAAM,0BAA0B;IAG5B,YAAY,OAAe;QACxB,0BAA0B;QACzB,sBAAsB;IAC1B,CAAC;CA0FJ;AAED,eAAe,0BAA0B,CAAA"}
1
+ {"version":3,"file":"OpportunityStorageProvider.js","sourceRoot":"","sources":["../../../src/modules/storage/OpportunityStorageProvider.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,0BAA0B,KAAI,CAAC"}
@@ -1,78 +1 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import opportunityEventEmitter from "../../events/OpportunityEventEmitter";
11
- const POW_TIME = 100;
12
- const TTL = 20;
13
- const POW_TARGET = 2;
14
- class WhisperHandler {
15
- constructor(web3) {
16
- this.web3 = web3;
17
- this.generateKeypair();
18
- }
19
- generateKeypair() {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const keyPair = yield this.web3.shh.newKeyPair();
22
- this.keypair = keyPair;
23
- // Obtain public key
24
- const pubKey = yield this.web3.shh.getPublicKey(keyPair);
25
- this.pubKey = pubKey;
26
- });
27
- }
28
- getWhisperPubKey() {
29
- return this.pubKey;
30
- }
31
- sendPrivateMessage(toPubKey, msg, topic) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- // Send private message
34
- this.web3.shh.post({
35
- pubKey: toPubKey,
36
- sig: this.keypair,
37
- ttl: TTL,
38
- topic,
39
- payload: this.web3.utils.fromAscii(msg),
40
- powTime: POW_TIME,
41
- powTarget: POW_TARGET
42
- });
43
- });
44
- }
45
- subscribeToTopic(topic) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- // Subscribe to private messages
48
- const subscribe = (topic) => __awaiter(this, void 0, void 0, function* () {
49
- this.web3.shh.subscribe("messages", {
50
- minPow: POW_TARGET,
51
- privateKeyID: this.keypair,
52
- topics: [topic]
53
- }).on('data', (data) => {
54
- console.log('Receieved data: ');
55
- console.log(data);
56
- console.log(this.web3.utils.toAscii(data.payload));
57
- opportunityEventEmitter.emit('WHISPER_RECEIVED', data);
58
- }).on('error', (err) => {
59
- console.log('Couldnt decode message');
60
- console.log(err);
61
- });
62
- });
63
- const receivedWhisper = (data) => {
64
- console.log(data);
65
- };
66
- yield subscribe(topic)
67
- .then(() => {
68
- opportunityEventEmitter.subscribeToEvent('WHISPER_RECEIVED', receivedWhisper);
69
- })
70
- .catch(error => {
71
- console.log('Error trying to subscribe to topic');
72
- console.log(error);
73
- });
74
- });
75
- }
76
- }
77
- export default WhisperHandler;
78
1
  //# sourceMappingURL=ChatHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ChatHandler.js","sourceRoot":"","sources":["../../../src/modules/whisper/ChatHandler.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,uBAAuB,MAAM,sCAAsC,CAAC;AAG3E,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,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CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;oBACnB,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;oBAC/B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;oBACjB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;oBAClD,uBAAuB,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAA;gBAC1D,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;oBACnB,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;oBACrC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;gBACpB,CAAC,CAAC,CAAC;YACP,CAAC,CAAA,CAAA;YAED,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,EAAE;gBAC7B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YACrB,CAAC,CAAA;YAED,MAAM,SAAS,CAAC,KAAK,CAAC;iBACrB,IAAI,CAAC,GAAG,EAAE;gBACP,uBAAuB,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAA;YACjF,CAAC,CAAC;iBACD,KAAK,CAAC,KAAK,CAAC,EAAE;gBACX,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAA;gBACjD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;YACtB,CAAC,CAAC,CAAA;QACN,CAAC;KAAA;CACJ;AAED,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"ChatHandler.js","sourceRoot":"","sources":["../../../src/modules/whisper/ChatHandler.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opportunity-service",
3
- "version": "0.0.614",
3
+ "version": "0.0.618",
4
4
  "description": "A service layer that connects all services between the blockchain and ui.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -44,17 +44,11 @@
44
44
  "@toruslabs/torus-embed": "^1.10.14",
45
45
  "@types/sqlite3": "^3.1.7",
46
46
  "@types/web3": "^1.2.2",
47
- "@vocdoni/census": "^1.14.1",
48
- "@vocdoni/client": "^1.14.2",
49
- "@vocdoni/contract-wrappers": "^1.14.1",
50
- "@vocdoni/data-models": "^1.14.2",
51
- "@vocdoni/voting": "^1.14.0",
52
47
  "assert": "^2.0.0",
53
- "bluebird": "^3.7.2",
54
48
  "compression": "^1.7.4",
55
49
  "cors": "^2.8.5",
56
50
  "dotenv": "^8.2.0",
57
- "dvote-js": "^1.13.3",
51
+ "dvote-js": "^1.15.2",
58
52
  "eth-crypto": "^2.1.0",
59
53
  "ethereumjs-tx": "^2.1.2",
60
54
  "ethereumjs-wallet": "^1.0.2",
@@ -68,9 +62,8 @@
68
62
  "ipfs-http-client": "^49.0.4",
69
63
  "keythereum": "^1.2.0",
70
64
  "md5": "^2.3.0",
71
- "orbit-db": "^0.28.0",
72
- "orbit-db-identity-provider": "^0.4.0",
73
65
  "secp256k1": "^3.6.2",
74
- "web3": "^1.3.5"
66
+ "web3": "^1.3.5",
67
+ "web3-shh": "^1.6.1"
75
68
  }
76
69
  }
@@ -10,11 +10,11 @@ import { EventCallbackDictionary } from "./types";
10
10
  import { startEventListeners } from "./events/start-event-listeners";
11
11
  import opportunityAPI from './api/index';
12
12
  import opportunityStorageProvider from "./modules/storage/OpportunityStorageProvider";
13
-
13
+ import { EthNetworkID } from "dvote-js";
14
14
  import Web3 from 'web3';
15
15
  import OpportunityStorageProvider from "./modules/storage/OpportunityStorageProvider";
16
- import { EthNetworkID } from "dvote-js";
17
- import WhisperHandler from "./modules/whisper/ChatHandler";
16
+
17
+ import { Shh } from 'web3-shh'
18
18
 
19
19
  class OpportunityService {
20
20
  private eventEmitter = opportunityEventEmitter;
@@ -58,11 +58,6 @@ class OpportunityService {
58
58
 
59
59
  async assignDefaultProvider(provider : Web3) {
60
60
  OpportunityService.defaultProvider = provider;
61
- const shhProvider = provider;
62
- shhProvider.setProvider(new Web3.providers.WebsocketProvider("ws://localhost:8545", {headers: {Origin: "mychat"}}));
63
- await shhProvider.eth.net.isListening();
64
-
65
- this.whisperProvider = new WhisperHandler(shhProvider);
66
61
  }
67
62
 
68
63
  assignProvider(provider : any) {
package/src/api/index.ts CHANGED
@@ -16,12 +16,6 @@ import { decryptByPrivateKey, encryptByPublicKey } from "./util/encrypt-by-publi
16
16
  import { createEthCryptoCreds } from "./other/create-eth-crypto-creds";
17
17
  import { encrypt } from "./provider/encrypt";
18
18
  import { decrypt } from "./provider/decrypt";
19
- import { connectGateways, getOracleClient } from "./dispute/connect";
20
- import { checkVoteResults } from "./dispute/check-vote-results";
21
- import { ensureEntityMetadata } from "./dispute/ensure-entity-metadata";
22
- import { launchNewVote } from "./dispute/launch-new-vote";
23
- import { submitVote } from "./dispute/submit-vote";
24
-
25
19
  import syncCreatedDisputes from "../sync/sync-disputes";
26
20
  import syncMarketDisputes from "../sync/sync-market-disputes";
27
21
 
@@ -42,12 +36,12 @@ function generateAPI() {
42
36
  enterWorkRelationship
43
37
  },
44
38
  dispute: {
45
- connectGateways: connectGateways,
46
- getOracleClient: getOracleClient,
47
- checkVoteResults: checkVoteResults,
48
- ensureEntityMetadata: ensureEntityMetadata,
49
- launchNewVote: launchNewVote,
50
- submitVote: submitVote
39
+ connectGateways: () => {},
40
+ getOracleClient: () => {},
41
+ checkVoteResults: () => {},
42
+ ensureEntityMetadata: () => {},
43
+ launchNewVote: () => {},
44
+ submitVote: () => {}
51
45
  },
52
46
  identity: {
53
47
  registerNewUser
@@ -1,122 +1 @@
1
- const IPFS = require('ipfs')
2
- const OrbitDB = require('orbit-db')
3
-
4
- import {
5
- DisputeDoc,
6
- WorkRelationshipDoc,
7
- UserSummaryDoc
8
- } from '../../types'
9
-
10
- const operations = ['>', '<', '==', '>=', '<=']
11
-
12
- const optionsToWrite = {
13
- // Give write access to the creator of the database
14
- accessController: {
15
- type: 'orbitdb', //OrbitDBAccessController
16
- create: 'true',
17
- admin: ['*'],
18
- write: ['*'],
19
- },
20
- indexBy: 'collection'
21
- }
22
-
23
-
24
- class OpportunityStorageProvider {
25
- private db: any
26
-
27
- constructor(address: string) {
28
- // this.initIPFSInstance()
29
- //this.listen(address)
30
- }
31
- /*
32
-
33
- // Create IPFS instance
34
- initIPFSInstance = async () => {
35
- return await IPFS.create({
36
- repo: Math.random().toString(),
37
- start: true,
38
- preload: {
39
- enabled: false,
40
- },
41
- EXPERIMENTAL: { pubsub: true },
42
- });
43
- };
44
-
45
- listen(address = '') {
46
- this.initIPFSInstance().then(async ipfs => {
47
- const orbitdb = await OrbitDB.createInstance(ipfs);
48
-
49
- // Create / Open a database
50
- if (address == '') {
51
- this.db = await orbitdb.docs('database.default');
52
- console.log(this.db)
53
- console.log(this.db.address)
54
- } else {
55
-
56
- if (!this.db?.dbname || this.db?.dbname == '') {
57
- console.log('Connecting orbitdb to: ' + address)
58
-
59
- this.db = await orbitdb.docs(address, {
60
- type: 'docstore',
61
- accessController: {
62
- admin: ['*'],
63
- write: ['*']
64
- },
65
- //indexBy: 'collection'
66
- })
67
-
68
- //await this.db.load();
69
- }
70
- console.log(this.db)
71
- }
72
-
73
- // Listen for updates from peers
74
- this.db.events.on("replicated", address => {
75
- console.log(this.db.iterator({ limit: -1 }).collect());
76
- });
77
-
78
- // Add an entry
79
- const hash = await this.db.put({ _id: 0, collection: "hmm"});
80
- console.log(hash);
81
-
82
- // Query
83
- const result = this.db.iterator({ limit: -1 }).collect();
84
- console.log(JSON.stringify(result, null, 2));
85
- });
86
- }
87
-
88
-
89
-
90
- async store(doc: DisputeDoc | WorkRelationshipDoc | UserSummaryDoc): Promise<string> {
91
- try {
92
- const hash = await this.db.put(doc).then(hash => {
93
- return hash;
94
- })
95
-
96
- return hash;
97
- } catch(error) {
98
- console.log(error)
99
- return ''
100
- }
101
- }
102
-
103
- async retrieveDoc(key: string = '', collection: string): Promise<DisputeDoc> | Promise<WorkRelationshipDoc> | Promise<UserSummaryDoc> {
104
- try {
105
- const docs = await this.db.get(key)
106
- return docs
107
- } catch(error) {
108
- console.log(error)
109
- return []
110
- }
111
- }
112
-
113
- async retrieveDocsByCollection(collection: string) {
114
- return await this.db.query((doc) => doc[collection] == collection)
115
- }
116
-
117
- async deleteDoc(key: string) {
118
- const hash = await this.db.del(key)
119
- }*/
120
- }
121
-
122
- export default OpportunityStorageProvider
1
+ export default function OpportunityStorageProvider() {}
@@ -1,78 +0,0 @@
1
- import opportunityEventEmitter from "../../events/OpportunityEventEmitter";
2
- import Web3 from "web3";
3
-
4
- const POW_TIME = 100;
5
- const TTL = 20;
6
- const POW_TARGET = 2;
7
-
8
- class WhisperHandler {
9
- private web3;
10
- private keypair;
11
- private pubKey;
12
-
13
- constructor(web3: Web3) {
14
- this.web3 = web3;
15
- this.generateKeypair()
16
- }
17
-
18
- async generateKeypair() {
19
- const keyPair = await this.web3.shh.newKeyPair();
20
- this.keypair = keyPair;
21
-
22
- // Obtain public key
23
- const pubKey = await this.web3.shh.getPublicKey(keyPair);
24
- this.pubKey = pubKey;
25
- }
26
-
27
-
28
- getWhisperPubKey() {
29
- return this.pubKey;
30
- }
31
-
32
- async sendPrivateMessage(toPubKey: string, msg: string, topic: string) {
33
- // Send private message
34
- this.web3.shh.post({
35
- pubKey: toPubKey,
36
- sig: this.keypair,
37
- ttl: TTL,
38
- topic,
39
- payload: this.web3.utils.fromAscii(msg),
40
- powTime: POW_TIME,
41
- powTarget: POW_TARGET
42
- });
43
- }
44
-
45
- async subscribeToTopic(topic: string) {
46
- // Subscribe to private messages
47
- const subscribe = async (topic: string) => {
48
- this.web3.shh.subscribe("messages", {
49
- minPow: POW_TARGET,
50
- privateKeyID: this.keypair,
51
- topics: [topic]
52
- }).on('data', (data) => {
53
- console.log('Receieved data: ')
54
- console.log(data)
55
- console.log(this.web3.utils.toAscii(data.payload))
56
- opportunityEventEmitter.emit('WHISPER_RECEIVED', data)
57
- }).on('error', (err) => {
58
- console.log('Couldnt decode message')
59
- console.log(err)
60
- });
61
- }
62
-
63
- const receivedWhisper = (data) => {
64
- console.log(data)
65
- }
66
-
67
- await subscribe(topic)
68
- .then(() => {
69
- opportunityEventEmitter.subscribeToEvent('WHISPER_RECEIVED', receivedWhisper)
70
- })
71
- .catch(error => {
72
- console.log('Error trying to subscribe to topic')
73
- console.log(error)
74
- })
75
- }
76
- }
77
-
78
- export default WhisperHandler;
@@ -1,33 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import * as assert from 'assert';
11
- import { VotingApi, VochainWaiter } from '@vocdoni/voting';
12
- export function checkVoteResults(processId, gwPool) {
13
- return __awaiter(this, void 0, void 0, function* () {
14
- assert.strictEqual(typeof processId, "string");
15
- console.log("Waiting a bit for the votes to be received", processId);
16
- const nextBlock = 2 + (yield VotingApi.getBlockHeight(gwPool));
17
- yield VochainWaiter.waitUntil(nextBlock, gwPool, { verbose: true });
18
- console.log("Fetching the number of votes for", processId);
19
- const envelopeHeight = yield VotingApi.getEnvelopeHeight(processId, gwPool);
20
- console.log('Votes submitted: ' + envelopeHeight);
21
- const processState = yield VotingApi.getProcessState(processId, gwPool);
22
- console.log("Waiting for the process to end", processId);
23
- yield VochainWaiter.waitUntil(processState.endBlock, gwPool, { verbose: true });
24
- console.log("Waiting a bit for the results to be ready", processId);
25
- yield VochainWaiter.wait(2, gwPool, { verbose: true });
26
- console.log("Fetching the vote results for", processId);
27
- const rawResults = yield VotingApi.getResults(processId, gwPool);
28
- const totalVotes = yield VotingApi.getEnvelopeHeight(processId, gwPool);
29
- console.log('Raw voting results: ' + rawResults);
30
- console.log('Total votes: ' + totalVotes);
31
- });
32
- }
33
- //# sourceMappingURL=check-vote-results.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check-vote-results.js","sourceRoot":"","sources":["../../../src/api/dispute/check-vote-results.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAG1D,MAAM,UAAgB,gBAAgB,CAAC,SAAiB,EAAE,MAAmB;;QACzE,MAAM,CAAC,WAAW,CAAC,OAAO,SAAS,EAAE,QAAQ,CAAC,CAAA;QAE9C,OAAO,CAAC,GAAG,CAAC,4CAA4C,EAAE,SAAS,CAAC,CAAA;QACpE,MAAM,SAAS,GAAG,CAAC,IAAG,MAAM,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA,CAAA;QAC5D,MAAM,aAAa,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;QAEnE,OAAO,CAAC,GAAG,CAAC,kCAAkC,EAAE,SAAS,CAAC,CAAA;QAC1D,MAAM,cAAc,GAAG,MAAM,SAAS,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAC3E,OAAO,CAAC,GAAG,CAAC,mBAAmB,GAAG,cAAc,CAAC,CAAA;QAEjD,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAEvE,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,SAAS,CAAC,CAAA;QACxD,MAAM,aAAa,CAAC,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;QAE/E,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,SAAS,CAAC,CAAA;QACnE,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;QAEtD,OAAO,CAAC,GAAG,CAAC,+BAA+B,EAAE,SAAS,CAAC,CAAA;QACvD,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAChE,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAEvE,OAAO,CAAC,GAAG,CAAC,sBAAsB,GAAG,UAAU,CAAC,CAAA;QAChD,OAAO,CAAC,GAAG,CAAC,eAAe,GAAG,UAAU,CAAC,CAAA;IAC7C,CAAC;CAAA"}
@@ -1,39 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { GatewayPool, DVoteGateway } from "@vocdoni/client";
11
- export function connectGateways(networkId, environment, bootnodeContentUri) {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- console.log("Connecting to the gateways");
14
- const options = {
15
- networkId: networkId,
16
- environment: environment,
17
- bootnodesContentUri: bootnodeContentUri
18
- };
19
- const pool = yield GatewayPool.discover(options);
20
- console.log("Connected to", pool.dvoteUri);
21
- console.log("Connected to", pool.provider["connection"].url);
22
- return pool;
23
- });
24
- }
25
- export function getOracleClient() {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- console.log('Creating oracle instance...');
28
- const oracleClient = new DVoteGateway({
29
- uri: 'https://signaling-oracle.dev.vocdoni.net/dvote',
30
- supportedApis: ["oracle"]
31
- });
32
- console.log('Initiating oracle...');
33
- yield oracleClient.init();
34
- console.log('Oracle status: ' + oracleClient.isReady);
35
- console.log('Oracle health: ' + oracleClient.health);
36
- return oracleClient;
37
- });
38
- }
39
- //# sourceMappingURL=connect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connect.js","sourceRoot":"","sources":["../../../src/api/dispute/connect.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAA+B,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAIxF,MAAM,UAAgB,eAAe,CAAC,SAAuB,EAAE,WAA+B,EAAE,kBAA0B;;QACtH,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;QAEzC,MAAM,OAAO,GAAiC;YAC1C,SAAS,EAAE,SAAS;YACpB,WAAW,EAAE,WAAW;YACxB,mBAAmB,EAAE,kBAAkB;SAC1C,CAAA;QAED,MAAM,IAAI,GAAG,MAAO,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QAEjD,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC1C,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAA;QAE5D,OAAO,IAAI,CAAA;IACf,CAAC;CAAA;AAED,MAAM,UAAgB,eAAe;;QACjC,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAA;QAC1C,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC;YAClC,GAAG,EAAE,gDAAgD;YACrD,aAAa,EAAE,CAAC,QAAQ,CAAC;SAC5B,CAAC,CAAA;QAEF,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;QACnC,MAAM,YAAY,CAAC,IAAI,EAAE,CAAA;QAEzB,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;QACrD,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,YAAY,CAAC,MAAM,CAAC,CAAA;QAEpD,OAAO,YAAY,CAAA;IACvB,CAAC;CAAA"}
@@ -1,39 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { EntityMetadataTemplate } from '@vocdoni/data-models';
11
- import { EntityApi } from '@vocdoni/voting';
12
- import * as assert from 'assert';
13
- export function ensureEntityMetadata(creatorWallet, gwPool) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- console.log("Making sure metadata doesn't already exist...");
16
- const meta = yield EntityApi.getMetadata(creatorWallet.address, gwPool).catch(err => console.log(err));
17
- if (!meta)
18
- return false;
19
- console.log("Setting Metadata for entity", creatorWallet.address);
20
- const metadata = JSON.parse(JSON.stringify(EntityMetadataTemplate));
21
- metadata.name = { default: "Opportunity" };
22
- metadata.description = { default: "Opportunity, decentralized job markets" };
23
- metadata.media = {
24
- avatar: "https://picsum.photos/200/300",
25
- header: "Opportunity, decentralized job markets",
26
- logo: "https://picsum.photos/200/300"
27
- };
28
- yield EntityApi.setMetadata(creatorWallet.address, metadata, creatorWallet, gwPool);
29
- console.log('Entity metadata set');
30
- // Read back
31
- const entityMetaPost = yield EntityApi.getMetadata(creatorWallet.address, gwPool);
32
- if (!entityMetaPost)
33
- return false;
34
- assert.strictEqual(entityMetaPost.name.default, metadata.name.default);
35
- assert.strictEqual(entityMetaPost.description.default, metadata.description.default);
36
- return true;
37
- });
38
- }
39
- //# sourceMappingURL=ensure-entity-metadata.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ensure-entity-metadata.js","sourceRoot":"","sources":["../../../src/api/dispute/ensure-entity-metadata.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAEhC,MAAM,UAAgB,oBAAoB,CAAC,aAAqB,EAAE,MAAmB;;QACjF,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAA;QAC5D,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QACtG,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAA;QAEvB,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;QACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC,CAAA;QAEnE,QAAQ,CAAC,IAAI,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,CAAA;QAC1C,QAAQ,CAAC,WAAW,GAAG,EAAE,OAAO,EAAE,wCAAwC,EAAE,CAAA;QAC5E,QAAQ,CAAC,KAAK,GAAG;YACb,MAAM,EAAE,+BAA+B;YACvC,MAAM,EAAE,wCAAwC;YAChD,IAAI,EAAE,+BAA+B;SACxC,CAAA;QAED,MAAM,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,CAAC,CAAA;QACnF,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;QAElC,YAAY;QACZ,MAAM,cAAc,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACjF,IAAI,CAAC,cAAc;YAAE,OAAO,KAAK,CAAA;QAEjC,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACtE,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAEpF,OAAO,IAAI,CAAA;IACf,CAAC;CAAA"}
@@ -1,94 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { CensusErc20Api } from "@vocdoni/census";
11
- import { VotingApi, VotingOracleApi } from "@vocdoni/voting";
12
- import { Erc20TokensApi } from "@vocdoni/client";
13
- import { ProcessMetadataTemplate } from "@vocdoni/data-models";
14
- import { ProcessMode, ProcessEnvelopeType } from '@vocdoni/contract-wrappers';
15
- import * as assert from 'assert';
16
- import { waitUntilPresent } from "./util/wait-until-present";
17
- export function launchNewVote(creatorWallet, tokenAddress, gwPool, oracleClient, disputeId, employer, worker) {
18
- var _a;
19
- return __awaiter(this, void 0, void 0, function* () {
20
- console.log('Launching new vote...');
21
- if (!(yield Erc20TokensApi.isRegistered(tokenAddress, gwPool))) {
22
- yield CensusErc20Api.registerTokenAuto(tokenAddress, creatorWallet, gwPool);
23
- assert(yield Erc20TokensApi.isRegistered(tokenAddress, gwPool));
24
- }
25
- const sourceBlockHeight = (yield gwPool.provider.getBlockNumber()) - 1;
26
- const tokenInfo = yield CensusErc20Api.getTokenInfo(tokenAddress, gwPool);
27
- const proof = yield CensusErc20Api.generateProof(tokenAddress, creatorWallet.address, tokenInfo.balanceMappingPosition, sourceBlockHeight, gwPool.provider);
28
- if (!((_a = proof === null || proof === void 0 ? void 0 : proof.storageProof) === null || _a === void 0 ? void 0 : _a.length))
29
- throw new Error("Invalid storage proof");
30
- console.log("Preparing the new vote metadata");
31
- const processMetadataPre = JSON.parse(JSON.stringify(ProcessMetadataTemplate)); // make a copy of the template
32
- processMetadataPre.title.default = disputeId,
33
- processMetadataPre.description.default = `Dispute: ${disputeId}`,
34
- processMetadataPre.questions = [
35
- {
36
- title: { default: "Contract Dispute" },
37
- description: { default: "Please choose one of the two participants" },
38
- choices: [
39
- { title: { default: employer }, value: 0 },
40
- { title: { default: worker }, value: 1 },
41
- ]
42
- }
43
- ];
44
- processMetadataPre.meta.disputeId = disputeId;
45
- const maxValue = processMetadataPre.questions.reduce((prev, cur) => {
46
- const localMax = cur.choices.reduce((prev, cur) => prev > cur.value ? prev : cur.value, 0);
47
- return localMax > prev ? localMax : prev;
48
- }, 0);
49
- console.log("Getting the block height");
50
- const currentBlock = yield VotingApi.getBlockHeight(gwPool);
51
- const startBlock = currentBlock + 15; //start after 15 blocks
52
- const blockCount = 6 * 4; // 4m
53
- const processParamsPre = {
54
- mode: ProcessMode.make({ autoStart: true }),
55
- envelopeType: ProcessEnvelopeType.make({}),
56
- metadata: processMetadataPre,
57
- startBlock,
58
- blockCount,
59
- maxCount: 1,
60
- maxValue,
61
- maxTotalCost: 0,
62
- costExponent: 10000,
63
- maxVoteOverwrites: 1,
64
- sourceBlockHeight,
65
- tokenAddress,
66
- paramsSignature: "0x0000000000000000000000000000000000000000000000000000000000000000"
67
- };
68
- const tokenDetails = {
69
- balanceMappingPosition: tokenInfo.balanceMappingPosition,
70
- storageHash: proof.storageHash,
71
- storageProof: {
72
- key: proof.storageProof[0].key,
73
- value: proof.storageProof[0].value,
74
- proof: proof.storageProof[0].proof
75
- }
76
- };
77
- console.log("Creating the process");
78
- const processId = yield VotingOracleApi.newProcessErc20(processParamsPre, tokenDetails, creatorWallet, gwPool, oracleClient);
79
- assert(processId);
80
- console.log("Created process with process id: ", processId);
81
- yield waitUntilPresent(processId, gwPool);
82
- console.log('Checking process params to ensure process was created...');
83
- const processParams = yield VotingApi.getProcessState(processId, gwPool);
84
- assert.strictEqual(processParams === null || processParams === void 0 ? void 0 : processParams.entityAddress.toLowerCase(), creatorWallet.address.toLowerCase());
85
- assert.strictEqual(processParams === null || processParams === void 0 ? void 0 : processParams.startBlock, processParamsPre === null || processParamsPre === void 0 ? void 0 : processParamsPre.startBlock, "SENT " + JSON.stringify(processParamsPre) + " GOT " + JSON.stringify(processParams));
86
- assert.strictEqual(processParams === null || processParams === void 0 ? void 0 : processParams.blockCount, processParamsPre === null || processParamsPre === void 0 ? void 0 : processParamsPre.blockCount);
87
- assert.strictEqual(processParams === null || processParams === void 0 ? void 0 : processParams.censusUri, processParamsPre === null || processParamsPre === void 0 ? void 0 : processParamsPre.censusUri);
88
- const processMetadata = yield VotingApi.getProcessMetadata(processId, gwPool);
89
- console.log('Process created with metadata: ');
90
- console.log(processMetadata);
91
- return { processId, processParams, processMetadata };
92
- });
93
- }
94
- //# sourceMappingURL=launch-new-vote.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"launch-new-vote.js","sourceRoot":"","sources":["../../../src/api/dispute/launch-new-vote.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAgB,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAi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AAA;QACvE,MAAM,aAAa,GAAiB,MAAM,SAAS,CAAC,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAEtF,MAAM,CAAC,WAAW,CAAC,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,aAAa,CAAC,WAAW,EAAE,EAAE,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;QACnG,MAAM,CAAC,WAAW,CAAC,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,UAAU,EAAE,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;QACjK,MAAM,CAAC,WAAW,CAAC,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,UAAU,EAAE,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,UAAU,CAAC,CAAA;QAC3E,MAAM,CAAC,WAAW,CAAC,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,SAAS,EAAE,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,SAAS,CAAC,CAAA;QAEzE,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC,kBAAkB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAC7E,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAA;QAC9C,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;QAE5B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,CAAA;;CACvD"}
@@ -1,41 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { CensusErc20Api } from "@vocdoni/census";
11
- import { VotingApi } from "@vocdoni/voting";
12
- export function submitVote(processId, processParams, processMetadata, accounts, tokenAddress, voter, voterChoice, gwPool) {
13
- return __awaiter(this, void 0, void 0, function* () {
14
- console.log("Launching votes");
15
- const processKeys = processParams.envelopeType.hasEncryptedVotes ? yield VotingApi.getProcessKeys(processId, gwPool) : null;
16
- const balanceMappingPosition = (yield CensusErc20Api.getTokenInfo(tokenAddress, gwPool)).balanceMappingPosition;
17
- const voterAddress = yield voter.getAddress();
18
- const result = yield CensusErc20Api.generateProof(tokenAddress, voterAddress, balanceMappingPosition, processParams.sourceBlockHeight, gwPool.provider);
19
- const censusProof = result.storageProof[0];
20
- console.log('Creating voter envelope');
21
- const envelope = processParams.envelopeType.encryptedVotes ?
22
- yield VotingApi.packageSignedEnvelope({ censusOrigin: processParams.censusOrigin, votes: voterChoice, censusProof, processId, walletOrSigner: voter, processKeys }) :
23
- yield VotingApi.packageSignedEnvelope({ censusOrigin: processParams.censusOrigin, votes: voterChoice, censusProof, processId, walletOrSigner: voter });
24
- console.log('Attempting to submit voter envelope: ' + voter);
25
- yield VotingApi.submitEnvelope(envelope, voter, gwPool);
26
- // wait a bit
27
- yield new Promise(resolve => setTimeout(resolve, 11000));
28
- const nullifier = VotingApi.getSignedVoteNullifier(voterAddress, processId);
29
- const { block, date, registered } = yield VotingApi.getEnvelopeStatus(processId, nullifier, gwPool);
30
- if (!registered) {
31
- console.log('Vote not submitted.. voter not registered...');
32
- return false;
33
- }
34
- console.log('Voter envelope successfully submitted');
35
- console.log('Block: ' + block);
36
- console.log('Date: ' + date);
37
- console.log('Registered: ' + registered);
38
- return true;
39
- });
40
- }
41
- //# sourceMappingURL=submit-vote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AAE,CAAC,CAAC,CAAC;YACrK,MAAM,SAAS,CAAC,qBAAqB,CAAC,EAAE,YAAY,EAAE,aAAa,CAAC,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAA;QAEtJ,OAAO,CAAC,GAAG,CAAC,uCAAuC,GAAG,KAAK,CAAC,CAAA;QAC5D,MAAM,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;QAEvD,aAAa;QACb,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;QAExD,MAAM,SAAS,GAAG,SAAS,CAAC,sBAAsB,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;QAC3E,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,SAAS,CAAC,iBAAiB,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAA;QAEnG,IAAI,CAAC,UAAU,EAAE;YACb,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAA;YAC3D,OAAO,KAAK,CAAC;SAChB;QAED,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAA;QACpD,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC,CAAA;QAC9B,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;QAC5B,OAAO,CAAC,GAAG,CAAC,cAAc,GAAG,UAAU,CAAC,CAAA;QACxC,OAAO,IAAI,CAAA;IACf,CAAC;CAAA"}
@@ -1,27 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { VotingApi, VochainWaiter } from '@vocdoni/voting';
11
- export function waitUntilPresent(processId, gwPool) {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- let attempts = 10;
14
- while (attempts >= 0) {
15
- console.log("Waiting for process", processId, "to be created");
16
- yield VochainWaiter.wait(1, gwPool);
17
- const state = yield VotingApi.getProcessState(processId, gwPool).catch(error => console.log(error));
18
- console.log('Attempted to get process state: ' + state);
19
- if (state === null || state === void 0 ? void 0 : state.entityId)
20
- break;
21
- attempts--;
22
- }
23
- if (attempts < 0)
24
- throw new Error("The process still does not exist on the Vochain after 10 blocks");
25
- });
26
- }
27
- //# sourceMappingURL=wait-until-present.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wait-until-present.js","sourceRoot":"","sources":["../../../../src/api/dispute/util/wait-until-present.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAgB,MAAM,iBAAiB,CAAA;AAIxE,MAAM,UAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM;;QACpD,IAAI,QAAQ,GAAG,EAAE,CAAA;QACjB,OAAO,QAAQ,IAAI,CAAC,EAAE;YAClB,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,SAAS,EAAE,eAAe,CAAC,CAAA;YAC9D,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;YAEnC,MAAM,KAAK,GAAwB,MAAM,SAAS,CAAC,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;YACxH,OAAO,CAAC,GAAG,CAAC,kCAAkC,GAAG,KAAK,CAAC,CAAA;YACvD,IAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ;gBAAE,MAAK;YAE1B,QAAQ,EAAE,CAAA;SACb;QAED,IAAI,QAAQ,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;IACxG,CAAC;CAAA"}
@@ -1,23 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { VotingApi, VochainWaiter } from '@vocdoni/voting';
11
- import * as assert from 'assert';
12
- import { ProcessStatus } from 'dvote-solidity';
13
- export function waitUntilStarted(processId, startBlock, gwPool) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- console.log('Waiting until block: ' + startBlock);
16
- // start block
17
- yield VochainWaiter.waitUntil(startBlock, gwPool, { verbose: true });
18
- console.log("Waiting for the process to be ready");
19
- const state = yield VotingApi.getProcessState(processId, gwPool);
20
- assert.strictEqual(state.status, ProcessStatus.READY, "Should be ready but is not");
21
- });
22
- }
23
- //# sourceMappingURL=wait-until-started.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wait-until-started.js","sourceRoot":"","sources":["../../../../src/api/dispute/util/wait-until-started.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,MAAM,UAAgB,gBAAgB,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM;;QAChE,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,UAAU,CAAC,CAAA;QAEjD,cAAc;QACd,MAAM,aAAa,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;QAEpE,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;QAClD,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAChE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,EAAE,aAAa,CAAC,KAAK,EAAE,4BAA4B,CAAC,CAAA;IACvF,CAAC;CAAA"}
@@ -1,30 +0,0 @@
1
- import * as assert from 'assert'
2
- import { VotingApi, VochainWaiter } from '@vocdoni/voting'
3
- import { GatewayPool } from '@vocdoni/client'
4
-
5
- export async function checkVoteResults(processId: string, gwPool: GatewayPool) {
6
- assert.strictEqual(typeof processId, "string")
7
-
8
- console.log("Waiting a bit for the votes to be received", processId)
9
- const nextBlock = 2 + await VotingApi.getBlockHeight(gwPool)
10
- await VochainWaiter.waitUntil(nextBlock, gwPool, { verbose: true })
11
-
12
- console.log("Fetching the number of votes for", processId)
13
- const envelopeHeight = await VotingApi.getEnvelopeHeight(processId, gwPool)
14
- console.log('Votes submitted: ' + envelopeHeight)
15
-
16
- const processState = await VotingApi.getProcessState(processId, gwPool)
17
-
18
- console.log("Waiting for the process to end", processId)
19
- await VochainWaiter.waitUntil(processState.endBlock, gwPool, { verbose: true })
20
-
21
- console.log("Waiting a bit for the results to be ready", processId)
22
- await VochainWaiter.wait(2, gwPool, { verbose: true })
23
-
24
- console.log("Fetching the vote results for", processId)
25
- const rawResults = await VotingApi.getResults(processId, gwPool)
26
- const totalVotes = await VotingApi.getEnvelopeHeight(processId, gwPool)
27
-
28
- console.log('Raw voting results: ' + rawResults)
29
- console.log('Total votes: ' + totalVotes)
30
- }
@@ -1,36 +0,0 @@
1
- import { GatewayPool, IGatewayDiscoveryParameters, DVoteGateway } from "@vocdoni/client"
2
- import { EthNetworkID } from "@vocdoni/common"
3
- import { VocdoniEnvironment } from "dvote-js"
4
-
5
- export async function connectGateways(networkId: EthNetworkID, environment: VocdoniEnvironment, bootnodeContentUri: string){
6
- console.log("Connecting to the gateways")
7
-
8
- const options: IGatewayDiscoveryParameters = {
9
- networkId: networkId,
10
- environment: environment,
11
- bootnodesContentUri: bootnodeContentUri
12
- }
13
-
14
- const pool = await GatewayPool.discover(options)
15
-
16
- console.log("Connected to", pool.dvoteUri)
17
- console.log("Connected to", pool.provider["connection"].url)
18
-
19
- return pool
20
- }
21
-
22
- export async function getOracleClient() {
23
- console.log('Creating oracle instance...')
24
- const oracleClient = new DVoteGateway({
25
- uri: 'https://signaling-oracle.dev.vocdoni.net/dvote',
26
- supportedApis: ["oracle"]
27
- })
28
-
29
- console.log('Initiating oracle...')
30
- await oracleClient.init()
31
-
32
- console.log('Oracle status: ' + oracleClient.isReady)
33
- console.log('Oracle health: ' + oracleClient.health)
34
-
35
- return oracleClient
36
- }
@@ -1,34 +0,0 @@
1
- import { GatewayPool } from '@vocdoni/client'
2
- import { EntityMetadataTemplate } from '@vocdoni/data-models'
3
- import { EntityApi } from '@vocdoni/voting'
4
- import { Wallet } from 'ethers'
5
- import * as assert from 'assert'
6
-
7
- export async function ensureEntityMetadata(creatorWallet: Wallet, gwPool: GatewayPool) {
8
- console.log("Making sure metadata doesn't already exist...")
9
- const meta = await EntityApi.getMetadata(creatorWallet.address, gwPool).catch(err => console.log(err))
10
- if (!meta) return false
11
-
12
- console.log("Setting Metadata for entity", creatorWallet.address)
13
- const metadata = JSON.parse(JSON.stringify(EntityMetadataTemplate))
14
-
15
- metadata.name = { default: "Opportunity" }
16
- metadata.description = { default: "Opportunity, decentralized job markets" }
17
- metadata.media = {
18
- avatar: "https://picsum.photos/200/300",
19
- header: "Opportunity, decentralized job markets",
20
- logo: "https://picsum.photos/200/300"
21
- }
22
-
23
- await EntityApi.setMetadata(creatorWallet.address, metadata, creatorWallet, gwPool)
24
- console.log('Entity metadata set')
25
-
26
- // Read back
27
- const entityMetaPost = await EntityApi.getMetadata(creatorWallet.address, gwPool)
28
- if (!entityMetaPost) return false
29
-
30
- assert.strictEqual(entityMetaPost.name.default, metadata.name.default)
31
- assert.strictEqual(entityMetaPost.description.default, metadata.description.default)
32
-
33
- return true
34
- }
@@ -1,116 +0,0 @@
1
- import { Wallet } from "@ethersproject/wallet"
2
- import { CensusErc20Api } from "@vocdoni/census"
3
- import { ProcessState, VotingApi, VotingOracleApi } from "@vocdoni/voting"
4
- import { DVoteGateway, Erc20TokensApi, GatewayPool } from "@vocdoni/client"
5
- import { ProcessMetadataTemplate } from "@vocdoni/data-models"
6
- import { ProcessMode, ProcessContractParameters, ProcessEnvelopeType } from '@vocdoni/contract-wrappers'
7
- import * as assert from 'assert'
8
- import { waitUntilPresent } from "./util/wait-until-present"
9
-
10
- export async function launchNewVote(
11
- creatorWallet: Wallet,
12
- tokenAddress: string,
13
- gwPool: GatewayPool,
14
- oracleClient: DVoteGateway,
15
- disputeId: string,
16
- employer: string,
17
- worker: string
18
- ) {
19
- console.log('Launching new vote...')
20
-
21
- if (!await Erc20TokensApi.isRegistered(tokenAddress, gwPool)) {
22
- await CensusErc20Api.registerTokenAuto(
23
- tokenAddress,
24
- creatorWallet,
25
- gwPool
26
- )
27
-
28
- assert(await Erc20TokensApi.isRegistered(tokenAddress, gwPool))
29
- }
30
-
31
- const sourceBlockHeight = (await gwPool.provider.getBlockNumber()) - 1
32
- const tokenInfo = await CensusErc20Api.getTokenInfo(tokenAddress, gwPool)
33
- const proof = await CensusErc20Api.generateProof(tokenAddress, creatorWallet.address, tokenInfo.balanceMappingPosition, sourceBlockHeight, gwPool.provider)
34
-
35
- if (!proof?.storageProof?.length) throw new Error("Invalid storage proof")
36
-
37
- console.log("Preparing the new vote metadata")
38
- const processMetadataPre = JSON.parse(JSON.stringify(ProcessMetadataTemplate)) // make a copy of the template
39
- processMetadataPre.title.default = disputeId,
40
- processMetadataPre.description.default = `Dispute: ${disputeId}`,
41
- processMetadataPre.questions = [
42
- {
43
- title: { default: "Contract Dispute" },
44
- description: { default: "Please choose one of the two participants" },
45
- choices: [
46
- { title: { default: employer }, value: 0 },
47
- { title: { default: worker }, value: 1 },
48
- ]
49
- }
50
- ]
51
- processMetadataPre.meta.disputeId = disputeId;
52
-
53
- const maxValue = processMetadataPre.questions.reduce((prev, cur) => {
54
- const localMax = cur.choices.reduce((prev, cur) => prev > cur.value ? prev : cur.value, 0)
55
- return localMax > prev ? localMax : prev
56
- }, 0)
57
-
58
- console.log("Getting the block height")
59
- const currentBlock = await VotingApi.getBlockHeight(gwPool)
60
- const startBlock = currentBlock + 15 //start after 15 blocks
61
- const blockCount = 6 * 4 // 4m
62
-
63
- const processParamsPre = {
64
- mode: ProcessMode.make({ autoStart: true }),
65
- envelopeType: ProcessEnvelopeType.make({}), // bit mask
66
- metadata: processMetadataPre,
67
- startBlock,
68
- blockCount,
69
- maxCount: 1,
70
- maxValue,
71
- maxTotalCost: 0,
72
- costExponent: 10000, // 1.0000
73
- maxVoteOverwrites: 1,
74
- sourceBlockHeight,
75
- tokenAddress,
76
- paramsSignature: "0x0000000000000000000000000000000000000000000000000000000000000000"
77
- }
78
-
79
- const tokenDetails = {
80
- balanceMappingPosition: tokenInfo.balanceMappingPosition,
81
- storageHash: proof.storageHash,
82
- storageProof: {
83
- key: proof.storageProof[0].key,
84
- value: proof.storageProof[0].value,
85
- proof: proof.storageProof[0].proof
86
- }
87
- }
88
-
89
- console.log("Creating the process")
90
- const processId = await VotingOracleApi.newProcessErc20(
91
- processParamsPre,
92
- tokenDetails,
93
- creatorWallet,
94
- gwPool,
95
- oracleClient
96
- )
97
-
98
- assert(processId)
99
- console.log("Created process with process id: ", processId)
100
-
101
- await waitUntilPresent(processId, gwPool)
102
-
103
- console.log('Checking process params to ensure process was created...')
104
- const processParams: ProcessState = await VotingApi.getProcessState(processId, gwPool)
105
-
106
- assert.strictEqual(processParams?.entityAddress.toLowerCase(), creatorWallet.address.toLowerCase())
107
- assert.strictEqual(processParams?.startBlock, processParamsPre?.startBlock, "SENT " + JSON.stringify(processParamsPre) + " GOT " + JSON.stringify(processParams))
108
- assert.strictEqual(processParams?.blockCount, processParamsPre?.blockCount)
109
- assert.strictEqual(processParams?.censusUri, processParamsPre?.censusUri)
110
-
111
- const processMetadata = await VotingApi.getProcessMetadata(processId, gwPool)
112
- console.log('Process created with metadata: ')
113
- console.log(processMetadata)
114
-
115
- return { processId, processParams, processMetadata }
116
- }
@@ -1,59 +0,0 @@
1
- import { Wallet } from "@ethersproject/wallet"
2
- import { CensusErc20Api } from "@vocdoni/census"
3
- import { ProcessState, VotingApi, VotingOracleApi } from "@vocdoni/voting"
4
- import { DVoteGateway, Erc20TokensApi, GatewayPool } from "@vocdoni/client"
5
- import { ProcessMetadata } from "@vocdoni/data-models"
6
- import { Signer } from "@ethersproject/abstract-signer"
7
- import { JsonRpcProvider } from "@ethersproject/providers"
8
- import { assert } from "console"
9
-
10
- export async function submitVote(
11
- processId: string,
12
- processParams: ProcessState,
13
- processMetadata: ProcessMetadata,
14
- accounts,
15
- tokenAddress: string,
16
- voter: Signer,
17
- voterChoice: number[],
18
- gwPool: GatewayPool) {
19
- console.log("Launching votes")
20
-
21
- const processKeys = processParams.envelopeType.hasEncryptedVotes ? await VotingApi.getProcessKeys(processId, gwPool) : null
22
- const balanceMappingPosition = (await CensusErc20Api.getTokenInfo(tokenAddress, gwPool)).balanceMappingPosition
23
- const voterAddress = await voter.getAddress()
24
-
25
- const result = await CensusErc20Api.generateProof(
26
- tokenAddress,
27
- voterAddress,
28
- balanceMappingPosition,
29
- processParams.sourceBlockHeight,
30
- gwPool.provider as JsonRpcProvider
31
- )
32
-
33
- const censusProof = result.storageProof[0]
34
-
35
- console.log('Creating voter envelope')
36
- const envelope = processParams.envelopeType.encryptedVotes ?
37
- await VotingApi.packageSignedEnvelope({ censusOrigin: processParams.censusOrigin, votes: voterChoice, censusProof, processId, walletOrSigner: voter, processKeys }) :
38
- await VotingApi.packageSignedEnvelope({ censusOrigin: processParams.censusOrigin, votes: voterChoice, censusProof, processId, walletOrSigner: voter })
39
-
40
- console.log('Attempting to submit voter envelope: ' + voter)
41
- await VotingApi.submitEnvelope(envelope, voter, gwPool)
42
-
43
- // wait a bit
44
- await new Promise(resolve => setTimeout(resolve, 11000))
45
-
46
- const nullifier = VotingApi.getSignedVoteNullifier(voterAddress, processId)
47
- const { block, date, registered } = await VotingApi.getEnvelopeStatus(processId, nullifier, gwPool)
48
-
49
- if (!registered) {
50
- console.log('Vote not submitted.. voter not registered...')
51
- return false;
52
- }
53
-
54
- console.log('Voter envelope successfully submitted')
55
- console.log('Block: ' + block)
56
- console.log('Date: ' + date)
57
- console.log('Registered: ' + registered)
58
- return true
59
- }
@@ -1,19 +0,0 @@
1
- import { VotingApi, VochainWaiter, ProcessState } from '@vocdoni/voting'
2
- import * as assert from 'assert'
3
- import { ProcessStatus } from 'dvote-solidity'
4
-
5
- export async function waitUntilPresent(processId, gwPool) {
6
- let attempts = 10
7
- while (attempts >= 0) {
8
- console.log("Waiting for process", processId, "to be created")
9
- await VochainWaiter.wait(1, gwPool)
10
-
11
- const state: ProcessState | void = await VotingApi.getProcessState(processId, gwPool).catch(error => console.log(error))
12
- console.log('Attempted to get process state: ' + state)
13
- if (state?.entityId) break
14
-
15
- attempts--
16
- }
17
-
18
- if (attempts < 0) throw new Error("The process still does not exist on the Vochain after 10 blocks")
19
- }
@@ -1,14 +0,0 @@
1
- import { VotingApi, VochainWaiter } from '@vocdoni/voting'
2
- import * as assert from 'assert'
3
- import { ProcessStatus } from 'dvote-solidity'
4
-
5
- export async function waitUntilStarted(processId, startBlock, gwPool) {
6
- console.log('Waiting until block: ' + startBlock)
7
-
8
- // start block
9
- await VochainWaiter.waitUntil(startBlock, gwPool, { verbose: true })
10
-
11
- console.log("Waiting for the process to be ready")
12
- const state = await VotingApi.getProcessState(processId, gwPool)
13
- assert.strictEqual(state.status, ProcessStatus.READY, "Should be ready but is not")
14
- }
@@ -1,20 +0,0 @@
1
-
2
-
3
- import { ethers } from "dvote-js/node_modules/ethers"
4
- import gwPool, { connectGateways } from "../src/api/voting/connect"
5
- import { registerEntity } from '../src/api/voting/entity'
6
-
7
- const ethNetworkId = 'mainnet'
8
- const environment = 'dev'
9
- const bootnodesContentUri = "https://bootnodes.vocdoni.net/gateways.dev.json"
10
-
11
- describe("Setting up a process", () => {
12
- it("Should connect gateways", async () => {
13
- expect(async () => await connectGateways(ethNetworkId, environment, bootnodesContentUri)).not.toThrow()
14
- const pool = await connectGateways(ethNetworkId, environment, bootnodesContentUri)
15
- console.log(pool)
16
- const wallet = ethers.Wallet.createRandom().connect(pool['provider'])
17
- const address = await wallet.getAddress()
18
- expect(() => registerEntity(pool, wallet, address)).not.toThrow()
19
- })
20
- })