-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from hollow-leaf/feat/addReset
feat: add reset & remove access
- Loading branch information
Showing
3 changed files
with
50 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,64 @@ | ||
import { TezosToolkit } from '@taquito/taquito'; | ||
import { InMemorySigner, importKey } from '@taquito/signer'; | ||
import { InMemorySigner } from '@taquito/signer'; | ||
|
||
const Tezos = new TezosToolkit('https://ghostnet.tezos.marigold.dev'); | ||
|
||
Tezos.setProvider({ | ||
signer: new InMemorySigner('edskS1zsQPHwdhuQQ9dcvtmrgSC1f7pqMZMrst4xzB4hMgkmAzgnDHbRhHGckG7RXN6yoed1PE31S63z2Y7Pa13kvZcQgcQ8bU'), | ||
}); | ||
|
||
interface ProposalType { | ||
[index: number]: string; | ||
} | ||
|
||
const proposal: ProposalType = { | ||
1: 'KT1ExMeV39XPUEyARJYwjUMfC1Lq1PLwo8bh', | ||
2: 'KT1KnNfPjgnn7jznstBZ7FXvwBEH5RwjLafK', | ||
3: 'KT1S9iHKShcrkJLZMTeeEcqgKZ3gQQgmcKBg' | ||
} | ||
|
||
export const accessProposal = async () => { | ||
export const voteProposal = async (proposalNumber: number, vote: number) => { | ||
if(proposalNumber > 3 || proposalNumber < 1) { | ||
return Error | ||
} | ||
|
||
await Tezos.contract | ||
.at('KT1KqDtnTZMYiEpe81f6u24Jnmq5Hg2h9z5v') | ||
.at(proposal[proposalNumber]) | ||
.then((contract) => { | ||
console.log('Access proposal...') | ||
return contract.methods.access().send(); | ||
console.log('Vote proposal...') | ||
return contract.methods.vote(vote).send(); | ||
}) | ||
.then((op) => { | ||
const result: any = op.results[0] | ||
console.log(`Waiting for ${op.hash} to be confirmed...`); | ||
return op.confirmation(1).then(() => op.hash); | ||
}) | ||
.then((hash) => { | ||
console.log(`Access operation finished: https://better-call.dev/ghostnet/opg/${hash}`) | ||
console.log(`Vote finished: https://better-call.dev/ghostnet/opg/${hash}`) | ||
}) | ||
.catch((error) => { | ||
console.log(`Access error: ${JSON.stringify(error, null, 2)}`) | ||
}) | ||
} | ||
console.log(`Vote error: ${JSON.stringify(error, null, 2)}`) | ||
}); | ||
} | ||
|
||
export const resetProposal = async (proposalNumber: number) => { | ||
if(proposalNumber > 3 || proposalNumber < 1) { | ||
return Error | ||
} | ||
|
||
export const voteProposal = async (vote: number) => { | ||
await Tezos.contract | ||
.at('KT1KqDtnTZMYiEpe81f6u24Jnmq5Hg2h9z5v') | ||
.at(proposal[proposalNumber]) | ||
.then((contract) => { | ||
console.log('Vote proposal...') | ||
return contract.methods.vote(vote).send(); | ||
console.log('Reset proposal...') | ||
return contract.methods.reset().send(); | ||
}) | ||
.then((op) => { | ||
console.log(`Waiting for ${op.hash} to be confirmed...`); | ||
return op.confirmation(1).then(() => op.hash); | ||
}) | ||
.then((hash) => { | ||
console.log(`Vote finished: https://better-call.dev/ghostnet/opg/${hash}`) | ||
console.log(`Reset operation finished: https://better-call.dev/ghostnet/opg/${hash}`) | ||
}) | ||
.catch((error) => { | ||
console.log(`Vote error: ${JSON.stringify(error, null, 2)}`) | ||
}); | ||
} | ||
|
||
export const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)) | ||
|
||
const main = async () => { | ||
// await voteProposal(1) | ||
// sleep(15000) | ||
// await accessProposal() | ||
console.log(`Reset error: ${JSON.stringify(error, null, 2)}`) | ||
}) | ||
} | ||
|
||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { voteProposal, accessProposal } from './index'; | ||
import { voteProposal, resetProposal } from './index'; | ||
|
||
const main = async () => { | ||
await voteProposal(1) | ||
await accessProposal() | ||
await voteProposal(1, 1) | ||
await resetProposal(1) | ||
} | ||
|
||
main() |