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
private func endVote(_ contractAddress: String) { | |
guard let wallet = userRepository.state.value.wallet else { return } | |
tezosClient | |
.rateContract(at: contractAddress) | |
#1 | |
.end() | |
.callPublisher(from: wallet, amount: Tez(0)) | |
.handleEvents(receiveOutput: { [weak self] output in | |
print(output) | |
#2 |
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
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 |
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
@sp.entry_point | |
def end(self, params): | |
#1 | |
sp.verify(sp.sender == self.data.manager) | |
sp.verify(self.data.hasEnded == False) | |
sp.for candidate in self.data.ballot.keys(): | |
#2 | |
sp.if self.data.ballot[candidate].numberOfVotes != 0: | |
sp.send(candidate, sp.split_tokens(sp.balance, sp.as_nat(self.data.ballot[candidate].numberOfVotes), sp.as_nat(self.data.totalNumberOfVotes))) | |
self.data.hasEnded = True |
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
@sp.entry_point | |
def vote(self, params): | |
#1 | |
sp.verify(self.data.hasEnded == False) | |
#2 | |
sp.verify(self.data.voters.contains(sp.sender)) | |
#3 | |
sp.for vote in params.votes.items(): | |
sp.verify(self.data.voters[sp.sender] >= vote.value) | |
self.data.ballot[vote.key].numberOfVotes += vote.value |
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
import smartpy as sp | |
class Ballot(sp.Contract): | |
def __init__(self, name, manager, candidates, voters, numberOfVotes): | |
initialBallot = {} | |
for candidate in candidates: | |
# Initializing initialBallot where we save `candidateName` and set `numberOfVotes` to zero | |
initialBallot[candidate[0]] = sp.record(candidateName = candidate[1], numberOfVotes = 0) | |
initialVoters = { } | |
for voter in voters: |
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
// Closure-based function | |
func status(completion: @escaping RPCCompletion<RateContractStatus>) | |
// Combine counterpart | |
func statusPublisher() -> ContractPublisher<RateContractStatus> |
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
private var urlSession: URLSession? | |
private func upload() { | |
if urlSession == nil { | |
let config = URLSessionConfiguration.background(withIdentifier: (Bundle.main.bundleIdentifier ?? "") + UUID().uuidString) | |
urlSession = URLSession(configuration: config, delegate: self, delegateQueue: nil) | |
} | |
} | |
extension ViewController: URLSessionDelegate, URLSessionTaskDelegate, URLSessionDataDelegate { |
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
let testContractAddress = try! Address(describing: "0xb8f016F3529b198b4a06574f3E9BDc04948ad852") | |
query.helloContract(at: testContractAddress).testString(greetString: "Greetings!").send(using: key, amount: Wei(10)).startWithResult { result in | |
switch result { | |
case .success(let hash): | |
print(hash) | |
print("Test greetings succeeded!") | |
case .failure(let error): | |
print(error) | |
print("Test greetings failed.") | |
} |
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
let walletStorage = KeychainStorageStrategy(identifier: "cz.ackee.etherkit.example") | |
let key = HDKey.Private(walletStorage, network: .rinkeby, path: [ | |
KeyPathNode(at: 44, hardened: true), | |
KeyPathNode(at: 60, hardened: true), | |
KeyPathNode(at: 0, hardened: true), | |
KeyPathNode(at: 1), | |
]) |
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
HDKey.Private.create( | |
with: MnemonicStorageStrategy(walletStorage), | |
mnemonic: sentence, | |
network: .main, | |
path: [ | |
KeyPathNode(at: 44, hardened: true), | |
KeyPathNode(at: 60, hardened: true), | |
KeyPathNode(at: 0, hardened: true), | |
KeyPathNode(at: 0), | |
] |