Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No ternary #2

Merged
merged 2 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ path = "src/lib.rs"

[dependencies]
anyhow = { version = "1.0", default-features = false }
iota-streams = { git = "https://github.com/iotaledger/streams", rev = "456347a"}
iota-streams = { git = "https://github.com/iotaledger/streams", rev = "04cfe80"}
iota-core = { git = "https://github.com/iotaledger/iota.rs", rev = "74fa529" }
iota-conversion = { git = "https://github.com/iotaledger/iota.rs", rev = "03cf531" }
tokio = { version = "^0.2", features = ["full"] }
async-trait = "0.1.30"
chrono = "0.4"
Expand Down
23 changes: 15 additions & 8 deletions examples/test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
use gateway_core::gateway::publisher::Channel;
use serde::Deserialize;
use serde::Serialize;
use serde_json::Value;

#[derive(serde::Serialize)]
struct Data {
hello: String,
world: String,
#[derive(Serialize, Deserialize, Debug)]
pub struct SensorData {
pub iot2tangle: Vec<SensorType>,
pub device: String,
pub timestamp: serde_json::Value,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SensorType {
pub sensor: String,
pub data: Vec<Value>,
}

///
Expand All @@ -15,10 +25,7 @@ fn main() {
let (address, msg_id) = channel.open().unwrap();
println!("Channel Address: {}", format!("{}:{}", address, msg_id));

let data = Data {
hello: String::from("Hello"),
world: String::from("World!"),
};
let data: SensorData = serde_json::from_str("{\"iot2tangle\":[{\"sensor\": \"Environmental\",\"data\":[{\"Pressure\":\"102033\"},{\"Temp\":\"26160\"},{\"Humidity\":\"33\"}]}],\"device\": \"DEVICE_ID_1\",\"timestamp\": \"1601653408\"}").unwrap();

match channel.write_signed(data) {
Ok(_) => {
Expand Down
18 changes: 12 additions & 6 deletions src/gateway/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ use crate::{
};

use anyhow::Result;
use iota_streams::app::transport::tangle::client::Client;
use iota_streams::app::transport::tangle::{client::SendTrytesOptions, PAYLOAD_BYTES};
use iota_streams::app_channels::api::tangle::{Address, Author};
use iota_streams::{
app::transport::tangle::{
client::{Client as StreamsClient, SendTrytesOptions},
PAYLOAD_BYTES,
},
app_channels::api::tangle::{Address, Author},
};

use iota::client as iota_client;
use std::string::ToString;

///
/// Channel
///
pub struct Channel {
author: Author<Client>,
author: Author<StreamsClient>,
channel_address: String,
announcement_id: String,
previous_msg_tag: String,
Expand All @@ -35,9 +41,9 @@ impl Channel {
send_opt.min_weight_magnitude = mwm;
send_opt.local_pow = local_pow;

let client: Client = Client::new(
let client: StreamsClient = StreamsClient::new(
send_opt,
iota::client::ClientBuilder::new()
iota_client::ClientBuilder::new()
.node(&node)
.unwrap()
.build()
Expand Down
7 changes: 3 additions & 4 deletions src/payload/payload_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//! Payload Module
//!
use base64::{decode_config, encode_config, URL_SAFE_NO_PAD};
use iota_conversion::trytes_converter::{to_string as trytes_to_string, to_trytes};
use iota_streams::ddml::types::Bytes;
use serde::{de::DeserializeOwned, Serialize};
use std::marker::PhantomData;
Expand Down Expand Up @@ -57,7 +56,7 @@ where
if data_str.len() == 0 {
return Ok(None);
}
let raw = trytes_to_string(&data.to_string())?;
let raw = &data.to_string();
let decode_data = decode_config(&raw, URL_SAFE_NO_PAD)?;
Ok(Some(String::from_utf8(decode_data).unwrap()))
}
Expand Down Expand Up @@ -105,7 +104,7 @@ where
{
// let json_payload = serde_json::to_string(data).unwrap();
let payload_str = S::serialize_data(data)?;
self.p_data = to_trytes(&encode_config(&payload_str, URL_SAFE_NO_PAD))?;
self.p_data = encode_config(&payload_str, URL_SAFE_NO_PAD);
Ok(self)
}

Expand All @@ -118,7 +117,7 @@ where
{
// let json_payload = serde_json::to_string(data).unwrap();
let payload_str = S::serialize_data(data)?;
self.m_data = to_trytes(&encode_config(&payload_str, URL_SAFE_NO_PAD))?;
self.m_data = encode_config(&payload_str, URL_SAFE_NO_PAD);
Ok(self)
}

Expand Down