Skip to content

Commit

Permalink
Signing added to iOS LocationShare example app
Browse files Browse the repository at this point in the history
  • Loading branch information
SanttuRantanen committed Oct 21, 2024
1 parent 5b861ca commit fd80ae9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
filePath = "LocationShare/LocationShareViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "88"
endingLineNumber = "88"
startingLineNumber = "98"
endingLineNumber = "98"
landmarkName = "buttonClicked()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -46,8 +46,8 @@
filePath = "LocationShare/LocationShareViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "77"
endingLineNumber = "77"
startingLineNumber = "87"
endingLineNumber = "87"
landmarkName = "longitude"
landmarkType = "24">
</BreakpointContent>
Expand All @@ -62,8 +62,8 @@
filePath = "LocationShare/LocationShareViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "83"
endingLineNumber = "83"
startingLineNumber = "93"
endingLineNumber = "93"
landmarkName = "buttonClicked()"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -94,8 +94,8 @@
filePath = "LocationShare/LocationShareViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "49"
endingLineNumber = "49"
startingLineNumber = "59"
endingLineNumber = "59"
landmarkName = "publishingIntervalInSeconds"
landmarkType = "24">
</BreakpointContent>
Expand All @@ -110,8 +110,8 @@
filePath = "LocationShare/LocationShareViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "52"
endingLineNumber = "52"
startingLineNumber = "62"
endingLineNumber = "62"
landmarkName = "publishingIntervalInSeconds"
landmarkType = "24">
</BreakpointContent>
Expand Down Expand Up @@ -158,8 +158,8 @@
filePath = "LocationShare/LocationShareViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "40"
endingLineNumber = "40"
startingLineNumber = "50"
endingLineNumber = "50"
landmarkName = "proxyId"
landmarkType = "24">
</BreakpointContent>
Expand Down Expand Up @@ -224,7 +224,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "41"
endingLineNumber = "41"
landmarkName = "ProxyClient::publish(proxyClientHandle, data)"
landmarkName = "ProxyClient::publish(proxyClientHandle, data, ethereumPrivateKey)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ struct LocationShareView: View {
"Enter proxy ID",
text: $viewModel.proxyId
)
SecureField(
"Enter Ethereum Private Key",
text: $viewModel.ethereumPrivateKey
)
Text(viewModel.status)
}
Section(header: Text("Publishing Interval")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ struct LocationShareViewModel {
}
}

@MainActor
var ethereumPrivateKey: String {
get {
streamrProxyClient.ethereumPrivateKey
}
set(newEthereumPrivateKey) {
streamrProxyClient.ethereumPrivateKey = newEthereumPrivateKey
}
}

@MainActor
var proxyId: String {
get {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ Result ProxyClient::deleteClient(uint64_t proxyClientHandle) const {
return Result{Result::ResultCode::Ok, ""};
}

Result ProxyClient::publish(uint64_t proxyClientHandle, std::string data) const {
Result ProxyClient::publish(uint64_t proxyClientHandle, std::string data, std::string ethereumPrivateKey) const {
Error* errors = nullptr;
uint64_t numErrors = 0;
proxyClientPublish(&errors, &numErrors, proxyClientHandle, data.c_str(), data.length());
proxyClientPublish(&errors, &numErrors, proxyClientHandle, data.c_str(), data.length(), ethereumPrivateKey.c_str());
std::this_thread::sleep_for(1s);
return Result{Result::ResultCode::Ok, ""};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef ProxyClient_hpp
#define ProxyClient_hpp

#define GLOG_USE_GLOG_EXPORT
//#define GLOG_USE_GLOG_EXPORT

#include <string>
#include "Result.hpp"
Expand All @@ -21,7 +21,7 @@ class ProxyClient {
ProxyClient() { }
uint64_t newClient(std::string ownEthereumAddress, std::string streamPartId) const;
Result deleteClient(uint64_t proxyClientHandle) const;
Result publish(uint64_t proxyClientHandle, std::string data) const;
Result publish(uint64_t proxyClientHandle, std::string data, std::string ethereumPrivateKey) const;
uint64_t connect(uint64_t proxyClientHandle, std::string websocketUrl,
std::string ethereumAddress) const;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Combine

@Observable
class StreamrProxyClient {
@MainActor var proxyInfo: PeerDesc = PeerDesc(peerId: "ws://127.0.0.1:44211", peerAddress: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
@MainActor var proxyInfo: PeerDesc = PeerDesc(peerId: "ws://127.0.0.1:44211", peerAddress: "0x2ee615edd5d13310f83d8125ff4f0960a7475e33")
@MainActor var ethereumPrivateKey = "23bead9b499af21c4c16e4511b3b6b08c3e22e76e0591f5ab5ba8d4c3a5b1820"
@MainActor var publishingIntervalInSeconds: TimeInterval = defaultPublishingIntervalInSeconds
var status: Status = .stopped
private let locationManager: LocationManager
Expand All @@ -31,7 +32,7 @@ class StreamrProxyClient {

init(locationManager: LocationManager) {
self.locationManager = locationManager
proxyClientHandle = self.proxyClient.newClient("0x1234567890123456789012345678901234567890", "0xa000000000000000000000000000000000000000#01")
proxyClientHandle = self.proxyClient.newClient("0xa5374e3c19f15e1847881979dd0c6c9ffe846bd5", "0xd7278f1e4a946fa7838b5d1e0fe50c5725fb23de/nativesdktest#01")
}

@MainActor
Expand All @@ -52,9 +53,10 @@ class StreamrProxyClient {
print("Publish start")
let latitude = locationManager.location?.latitude ?? 0
let longitude = locationManager.location?.longitude ?? 0
let stdPrivateKey = std.string(ethereumPrivateKey)
self.status = .publishing
let result = await Task.detached {
self.proxyClient.publish(self.proxyClientHandle, std.string("\(latitude) \(longitude)"))
self.proxyClient.publish(self.proxyClientHandle, std.string("\(latitude) \(longitude)"), stdPrivateKey)
}.value
print("Publish end")
return result
Expand Down

0 comments on commit fd80ae9

Please sign in to comment.