opportunity-service 0.0.536 → 0.0.538
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/OpportunityService.js +16 -20
- package/dist/OpportunityService.js.map +1 -1
- package/dist/api/dispute/check-vote-results.js +33 -0
- package/dist/api/dispute/check-vote-results.js.map +1 -0
- package/dist/api/dispute/connect.js +39 -0
- package/dist/api/dispute/connect.js.map +1 -0
- package/dist/api/dispute/ensure-entity-metadata.js +39 -0
- package/dist/api/dispute/ensure-entity-metadata.js.map +1 -0
- package/dist/api/dispute/launch-new-vote.js +94 -0
- package/dist/api/dispute/launch-new-vote.js.map +1 -0
- package/dist/api/dispute/submit-vote.js +41 -0
- package/dist/api/dispute/submit-vote.js.map +1 -0
- package/dist/api/dispute/util/wait-until-present.js +27 -0
- package/dist/api/dispute/util/wait-until-present.js.map +1 -0
- package/dist/api/{voting/connect.js → dispute/util/wait-until-started.js} +11 -21
- package/dist/api/dispute/util/wait-until-started.js.map +1 -0
- package/dist/api/exchange/create-dispute.js +1 -2
- package/dist/api/exchange/create-dispute.js.map +1 -1
- package/dist/api/exchange/create-task.js +1 -1
- package/dist/api/exchange/create-task.js.map +1 -1
- package/dist/api/identity/register-new-user.js +1 -1
- package/dist/api/identity/register-new-user.js.map +1 -1
- package/dist/api/index.js +31 -12
- package/dist/api/index.js.map +1 -1
- package/dist/api/internal/abis.js +2 -1
- package/dist/api/internal/abis.js.map +1 -1
- package/dist/api/internal/addresses.js +21 -4
- package/dist/api/internal/addresses.js.map +1 -1
- package/dist/api/other/create-eth-crypto-creds.js +20 -0
- package/dist/api/other/create-eth-crypto-creds.js.map +1 -0
- package/dist/api/provider/decrypt.js +18 -0
- package/dist/api/provider/decrypt.js.map +1 -0
- package/dist/api/provider/encrypt.js +18 -0
- package/dist/api/provider/encrypt.js.map +1 -0
- package/dist/api/util/encrypt-by-public-key.js +52 -0
- package/dist/api/util/encrypt-by-public-key.js.map +1 -0
- package/dist/api/util/parse-cipher.js +11 -0
- package/dist/api/util/parse-cipher.js.map +1 -0
- package/dist/api/util/stringify-cipher.js +5 -0
- package/dist/api/util/stringify-cipher.js.map +1 -0
- package/dist/blockchain/abi.json +779 -1
- package/dist/blockchain/addresses.json +15 -5
- package/dist/blockchain/bytecode.json +2 -2
- package/dist/constants.js +0 -1
- package/dist/constants.js.map +1 -1
- package/dist/modules/storage/OpportunityStorageProvider.js +65 -41
- package/dist/modules/storage/OpportunityStorageProvider.js.map +1 -1
- package/dist/sync/sync-markets.js +1 -1
- package/dist/sync/sync-markets.js.map +1 -1
- package/package.json +13 -2
- package/src/OpportunityService.ts +22 -24
- package/src/api/dispute/check-vote-results.ts +30 -0
- package/src/api/dispute/connect.ts +36 -0
- package/src/api/dispute/ensure-entity-metadata.ts +34 -0
- package/src/api/dispute/launch-new-vote.ts +116 -0
- package/src/api/dispute/submit-vote.ts +59 -0
- package/src/api/dispute/util/wait-until-present.ts +19 -0
- package/src/api/dispute/util/wait-until-started.ts +14 -0
- package/src/api/exchange/create-dispute.ts +1 -1
- package/src/api/exchange/create-task.ts +1 -1
- package/src/api/identity/register-new-user.ts +1 -1
- package/src/api/index.ts +31 -12
- package/src/api/internal/abis.ts +2 -1
- package/src/api/internal/addresses.ts +21 -4
- package/src/api/other/create-eth-crypto-creds.ts +14 -0
- package/src/api/provider/decrypt.ts +9 -0
- package/src/api/provider/encrypt.ts +9 -0
- package/src/api/util/encrypt-by-public-key.ts +47 -0
- package/src/api/util/parse-cipher.ts +11 -0
- package/src/api/util/stringify-cipher.ts +5 -0
- package/src/blockchain/abi.json +779 -1
- package/src/blockchain/addresses.json +17 -5
- package/src/blockchain/bytecode.json +2 -2
- package/src/constants.ts +0 -1
- package/src/modules/storage/OpportunityStorageProvider.ts +75 -23
- package/src/sync/sync-markets.ts +1 -1
- package/src/types.ts +21 -1
- package/dist/api/voting/census.js +0 -38
- package/dist/api/voting/census.js.map +0 -1
- package/dist/api/voting/connect.js.map +0 -1
- package/dist/api/voting/entity.js +0 -39
- package/dist/api/voting/entity.js.map +0 -1
- package/dist/api/voting/process.js +0 -101
- package/dist/api/voting/process.js.map +0 -1
- package/src/api/voting/census.ts +0 -39
- package/src/api/voting/connect.ts +0 -34
- package/src/api/voting/entity.ts +0 -33
- package/src/api/voting/process.ts +0 -119
@@ -1,119 +0,0 @@
|
|
1
|
-
import * as assert from "assert"
|
2
|
-
import { ProcessMetadata, VochainWaiter, CensusOffChainApi, EntityApi, ProcessMetadataTemplate, INewProcessParams, ProcessMode, VotingApi, ProcessEnvelopeType, ProcessCensusOrigin, Voting, } from "dvote-js"
|
3
|
-
import { providers } from "ethers"
|
4
|
-
import gwPool from "./connect"
|
5
|
-
|
6
|
-
import { CensusOffChain } from "dvote-js/dist/api/census"
|
7
|
-
import opportunityService from "../../OpportunityService"
|
8
|
-
|
9
|
-
/**
|
10
|
-
* As it happened before, the JSON metadata is pinned on IPFS and pointed to from the process smart contract. In addition, some metadata fields are also stored on the smart contract so they can be accessed on-chain.
|
11
|
-
* The contract flags define how the process will behave, whereas the metadata is used to store the human readable content.
|
12
|
-
* In about 2-3 minutes, the Ethereum transaction will be relayed to the voting blockchain as well. When the block number reaches startBlock, the process will become open to those who are part of the census. The startBlock value should be at least 25 blocks ahead of the current value.
|
13
|
-
*
|
14
|
-
* @param censusRoot
|
15
|
-
* @param censusUri
|
16
|
-
* @param details
|
17
|
-
* @param entityWallet
|
18
|
-
*/
|
19
|
-
export async function createVotingProcess(
|
20
|
-
censusRoot,
|
21
|
-
censusUri,
|
22
|
-
details : ProcessMetadata,
|
23
|
-
entityWallet : providers.JsonRpcSigner
|
24
|
-
) {
|
25
|
-
console.log("Preparing the new vote metadata")
|
26
|
-
console.log("Getting the block height")
|
27
|
-
const currentBlock = await VotingApi.getBlockHeight(gwPool)
|
28
|
-
const startBlock = currentBlock + 25
|
29
|
-
const blockCount = 60480
|
30
|
-
|
31
|
-
const processParamsPre: INewProcessParams = {
|
32
|
-
|
33
|
-
mode: ProcessMode.make({ autoStart: true, interruptible: true }), // helper
|
34
|
-
envelopeType: ProcessEnvelopeType.ENCRYPTED_VOTES, // bit mask
|
35
|
-
censusOrigin: ProcessCensusOrigin.OFF_CHAIN_TREE,
|
36
|
-
metadata: details,
|
37
|
-
censusRoot: censusRoot,
|
38
|
-
censusUri: censusUri,
|
39
|
-
startBlock,
|
40
|
-
blockCount,
|
41
|
-
maxCount: 1,
|
42
|
-
maxValue: 3,
|
43
|
-
maxTotalCost: 0,
|
44
|
-
costExponent: 10000,
|
45
|
-
maxVoteOverwrites: 1,
|
46
|
-
paramsSignature: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
47
|
-
}
|
48
|
-
|
49
|
-
console.log("Creating the process")
|
50
|
-
|
51
|
-
const processId = await VotingApi.newProcess(processParamsPre, entityWallet, gwPool)
|
52
|
-
//assert(processId)
|
53
|
-
|
54
|
-
//processMetadata = processParamsPre.metadata
|
55
|
-
|
56
|
-
// Reading back
|
57
|
-
//processParams = await VotingApi.getProcessContractParameters(processId, gwPool)
|
58
|
-
//assert.strictEqual(processParams.entityAddress.toLowerCase(), entityAddr.toLowerCase())
|
59
|
-
//assert.strictEqual(processParams.startBlock, processParamsPre.startBlock, "SENT " + JSON.stringify(processParamsPre) + " GOT " + JSON.stringify(processParams))
|
60
|
-
//assert.strictEqual(processParams.blockCount, processParamsPre.blockCount)
|
61
|
-
//assert.strictEqual(processParams.censusRoot, processParamsPre.censusRoot)
|
62
|
-
//assert.strictEqual(processParams.censusUri, processParamsPre.censusUri)
|
63
|
-
}
|
64
|
-
|
65
|
-
async function vote(processId, choices, publicKey) {
|
66
|
-
// Fetch the metadata
|
67
|
-
const processMeta = await VotingApi.getProcessMetadata(processId, gwPool)
|
68
|
-
const processParams = await VotingApi.getProcessContractParameters(processId, gwPool)
|
69
|
-
|
70
|
-
console.log("- Starting:", await VotingApi.estimateDateAtBlock(processMeta.startBlock, gwPool))
|
71
|
-
console.log("- Ending:", await VotingApi.estimateDateAtBlock(processMeta.startBlock + processMeta.numberOfBlocks, gwPool))
|
72
|
-
console.log("- Census size:", await CensusOffChainApi.getSize(processMeta.census.merkleRoot, gwPool))
|
73
|
-
console.log("- Current block:", await VotingApi.getBlockHeight(gwPool))
|
74
|
-
console.log("- Current votes:", await VotingApi.getEnvelopeHeight(processId, gwPool))
|
75
|
-
|
76
|
-
await VochainWaiter.waitUntil(processParams.startBlock, gwPool, { verbose: true })
|
77
|
-
//await waitUntilVochainBlock(processMeta.startBlock, gwPool, { verbose: true })
|
78
|
-
|
79
|
-
console.log("Submitting vote envelopes")
|
80
|
-
|
81
|
-
// Hash the voter's public key
|
82
|
-
const publicKeyHash = CensusOffChain.Public.encodePublicKey(publicKey) //supposed to be digestPublicKey(x, y)?
|
83
|
-
|
84
|
-
// Generate the census proof
|
85
|
-
const merkleProof = await CensusOffChainApi.generateProof(
|
86
|
-
processParams.censusRoot,
|
87
|
-
{ key: Buffer.from(String(publicKey), "hex").toString("base64"), value: 0 },
|
88
|
-
true,
|
89
|
-
gwPool
|
90
|
-
)
|
91
|
-
|
92
|
-
// Sign the vote envelope with our choices
|
93
|
-
const voteEnvelope = await VotingApi.packageSignedEnvelope({ votes: choices, censusOrigin: 0, censusProof: merkleProof, processLeys: processId, walletOrSigner: opportunityService.getSignersInterface() })
|
94
|
-
|
95
|
-
// If the process had encrypted votes:
|
96
|
-
// const voteEnvelope = await packagePollEnvelope({ votes, merkleProof, processId, walletOrSigner: wallet, encryptionPubKeys: ["..."] })
|
97
|
-
|
98
|
-
await VotingApi.submitEnvelope(voteEnvelope, opportunityService.getSignersInterface(), gwPool)
|
99
|
-
console.log("Envelope submitted")
|
100
|
-
}
|
101
|
-
|
102
|
-
/*
|
103
|
-
async function checkVoteStatus() {
|
104
|
-
// Compute our deterministic nullifier to check the status of our vote
|
105
|
-
const nullifier = await getPollNullifier(wallet.address, processId)
|
106
|
-
const status = await VotingApi.getEnvelopeStatus(processId, nullifier, pool)
|
107
|
-
|
108
|
-
console.log("- Registered: ", status.registered)
|
109
|
-
console.log("- Block: ", status.block)
|
110
|
-
console.log("- Date: ", status.date)
|
111
|
-
}*/
|
112
|
-
|
113
|
-
|
114
|
-
async function fetchResults(processId) {
|
115
|
-
const { results, status } = await VotingApi.getResults(processId, gwPool)
|
116
|
-
console.log("Process results", results)
|
117
|
-
}
|
118
|
-
|
119
|
-
|