Skip to content

Commit 395dada

Browse files
author
nieznany.sprawiciel
committed
Yarapi compiles with event-api/master on ya-client
1 parent 50ad8bd commit 395dada

8 files changed

Lines changed: 52 additions & 28 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
target
3+
tests/test-workdir/*

Cargo.lock

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ keywords=["golem", "yagna"]
1212

1313

1414
[dependencies]
15-
ya-client = { git = "https://github.com/golemfactory/ya-client.git", rev = "cf9838499aaeb2a54c4ad56d1601c4579a66e7cc", features = ["sgx"] }
15+
ya-client = { git = "https://github.com/golemfactory/ya-client.git", rev = "29f9b7a60044d56c6665b5d236696bf1830aacdd", features = ["sgx"] }
1616
gftp = "0.1"
1717
ya-agreement-utils = "0.1"
1818

examples/low_level.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ async fn do_init(activity: impl rest::Activity) -> anyhow::Result<()> {
7979
"aea5db67524e02a263b9339fe6667d6b577f3d4c".to_string(),
8080
"1".to_string(),
8181
],
82+
capture: None,
8283
},
8384
])
8485
.await?;

src/requestor.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use ya_client::{
3131
AgreementProposal, NewDemand, RequestorEvent,
3232
},
3333
},
34-
payment::PaymentRequestorApi,
34+
payment::PaymentApi,
3535
web::WebClient,
3636
};
3737

@@ -167,7 +167,7 @@ impl Requestor {
167167
let client = WebClient::builder().auth_token(&app_key).build();
168168
let market_api: MarketRequestorApi = client.interface()?;
169169
let activity_api: ActivityRequestorApi = client.interface()?;
170-
let payment_api: PaymentRequestorApi = client.interface()?;
170+
let payment_api: PaymentApi = client.interface()?;
171171

172172
let demand = self.create_demand().await?;
173173
log::debug!("demand: {}", serde_json::to_string_pretty(&demand)?);
@@ -411,14 +411,8 @@ async fn create_agreement(market_api: MarketRequestorApi, proposal: Proposal) ->
411411
let _ = market_api.confirm_agreement(&id, None).await?;
412412
log::info!("waiting for approval of agreement [{}]", agreement_id);
413413

414-
let response = market_api.wait_for_approval(&id, Some(10.0)).await?;
415-
match response.trim().to_lowercase().as_str() {
416-
"approved" => Ok(agreement_id),
417-
res => Err(anyhow::anyhow!(
418-
"expected agreement approval, got {} instead",
419-
res
420-
)),
421-
}
414+
market_api.wait_for_approval(&id, Some(10.0)).await?;
415+
Ok(agreement_id)
422416
}
423417

424418
async fn monitor_activity(

src/requestor/activity.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(dead_code)]
22

33
use crate::requestor::command::{CommandList, ExeScript};
4-
use anyhow::{Context, Result};
4+
use anyhow::{anyhow, Context, Result};
55
use ya_client::activity::{ActivityRequestorApi, SecureActivityRequestorApi};
66
use ya_client::model::activity::{ActivityState, ExeScriptCommandResult};
77

@@ -100,6 +100,12 @@ impl Activity {
100100
}
101101

102102
pub async fn get_usage(&self) -> Result<Vec<f64>> {
103-
Ok(self.api.state().get_usage(&self.activity_id).await?)
103+
Ok(self
104+
.api
105+
.state()
106+
.get_usage(&self.activity_id)
107+
.await?
108+
.current_usage
109+
.ok_or(anyhow!("None usage vector"))?)
104110
}
105111
}

src/requestor/payment_manager.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
use actix::prelude::*;
44
use bigdecimal::BigDecimal;
55
use chrono::{DateTime, Utc};
6-
use futures::TryFutureExt;
76
use std::collections::HashSet;
87
use std::time::Duration;
9-
use ya_client::{model, payment::requestor::PaymentRequestorApi};
8+
use ya_client::{model, payment::PaymentApi};
109

1110
pub struct PaymentManager {
12-
payment_api: PaymentRequestorApi,
11+
payment_api: PaymentApi,
1312
allocation_id: String,
1413
total_amount: BigDecimal,
1514
amount_paid: BigDecimal,
@@ -28,7 +27,7 @@ impl Actor for PaymentManager {
2827
}
2928

3029
impl PaymentManager {
31-
pub fn new(payment_api: PaymentRequestorApi, allocation: model::payment::Allocation) -> Self {
30+
pub fn new(payment_api: PaymentApi, allocation: model::payment::Allocation) -> Self {
3231
let now = Utc::now();
3332
PaymentManager {
3433
payment_api,
@@ -47,11 +46,11 @@ impl PaymentManager {
4746

4847
let f = async move {
4948
let events = api
50-
.get_debit_note_events(Some(&ts), Some(Duration::from_secs(60)))
49+
.get_debit_note_events(Some(&ts), Some(Duration::from_secs(60)), None, None)
5150
.await?;
5251
for event in events {
5352
log::debug!("got debit note: {:?}", event);
54-
ts = event.timestamp;
53+
ts = event.event_date;
5554
}
5655
Ok::<_, anyhow::Error>(ts)
5756
}
@@ -78,16 +77,16 @@ impl PaymentManager {
7877

7978
let f = async move {
8079
let events = api
81-
.get_invoice_events(Some(&ts), Some(Duration::from_secs(60)))
80+
.get_invoice_events(Some(&ts), Some(Duration::from_secs(60)), None, None)
8281
.await?;
8382
let mut new_invoices = Vec::new();
8483
for event in events {
8584
log::debug!("Got invoice: {:?}", event);
86-
if event.event_type == model::payment::EventType::Received {
85+
if event.event_type == model::payment::InvoiceEventType::InvoiceReceivedEvent {
8786
let invoice = api.get_invoice(&event.invoice_id).await?;
8887
new_invoices.push(invoice);
8988
}
90-
ts = event.timestamp;
89+
ts = event.event_date;
9190
}
9291
Ok::<_, anyhow::Error>((ts, new_invoices))
9392
}
@@ -200,8 +199,8 @@ impl Handler<ReleaseAllocation> for PaymentManager {
200199
async move {
201200
payment_api
202201
.release_allocation(&allocation_id)
203-
.map_err(anyhow::Error::from)
204202
.await
203+
.map_err(anyhow::Error::from)
205204
}
206205
.into_actor(self),
207206
)

src/rest/market.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ impl Proposal {
168168
let _ = self
169169
.subscription
170170
.api
171-
.reject_proposal_with_reason(
171+
.reject_proposal(
172172
self.subscription.id.as_ref(),
173173
self.proposal_id.as_str(),
174-
Option::<Reason>::None,
174+
&Option::<Reason>::None,
175175
)
176176
.await?;
177177
Ok(())
@@ -216,7 +216,7 @@ impl Drop for AgreementInner {
216216
let api = self.api.clone();
217217
let agreement_id = self.agreement_id.clone();
218218
self.drop_list.async_drop(async move {
219-
api.terminate_agreement(&agreement_id, Option::<Reason>::None)
219+
api.terminate_agreement(&agreement_id, &Option::<Reason>::None)
220220
.await
221221
.with_context(|| format!("Failed to auto destroy Agreement: {:?}", agreement_id))?;
222222
log::debug!(target:"yarapi::drop", "Agreement {:?} terminated", agreement_id);

0 commit comments

Comments
 (0)