Skip to content

Instantly share code, notes, and snippets.

@fortmarek
Last active February 28, 2020 16:17
Show Gist options
  • Save fortmarek/632ecee9a96921d948fdab65c9e3f67a to your computer and use it in GitHub Desktop.
Save fortmarek/632ecee9a96921d948fdab65c9e3f67a to your computer and use it in GitHub Desktop.
Vote function
private func vote(votes: [Candidate.ID: Int], contractAddress: String) {
#1
guard let wallet = userRepository.state.value.wallet else { return }
let nonZeroVotes = votes.filter { $0.value != 0 }
#2
tezosClient
.rateContract(at: contractAddress)
.vote(nonZeroVotes)
.callPublisher(from: wallet, amount: Tez(0))
.handleEvents(receiveOutput: { [weak self] output in
print(output)
self?.addVotes(votes, for: contractAddress)
}, receiveCompletion: { completion in
print(completion)
})
.startAndStore(in: &cancellables)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment