Skip to content

Commit 6a9cee4

Browse files
committed
add subscribe flag to contract requests and responses
1 parent 1c4d616 commit 6a9cee4

File tree

82 files changed

+944
-1022
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+944
-1022
lines changed

rust/src/client_api/client_events.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,14 @@ impl ClientRequest<'_> {
264264
contract,
265265
state,
266266
related_contracts,
267+
subscribe,
267268
} => {
268269
let related_contracts = related_contracts.into_owned();
269270
ContractRequest::Put {
270271
contract,
271272
state,
272273
related_contracts,
274+
subscribe,
273275
}
274276
}
275277
ContractRequest::Update { key, data } => {
@@ -279,9 +281,11 @@ impl ClientRequest<'_> {
279281
ContractRequest::Get {
280282
key,
281283
return_contract_code,
284+
subscribe,
282285
} => ContractRequest::Get {
283286
key,
284287
return_contract_code,
288+
subscribe,
285289
},
286290
ContractRequest::Subscribe { key, summary } => ContractRequest::Subscribe {
287291
key,
@@ -357,6 +361,8 @@ pub enum ContractRequest<'a> {
357361
/// Related contracts.
358362
#[serde(borrow)]
359363
related_contracts: RelatedContracts<'a>,
364+
/// If this flag is set then subscribe to updates for this contract.
365+
subscribe: bool,
360366
},
361367
/// Update an existing contract corresponding with the provided key.
362368
Update {
@@ -370,6 +376,8 @@ pub enum ContractRequest<'a> {
370376
key: ContractKey,
371377
/// If this flag is set then fetch also the contract itself.
372378
return_contract_code: bool,
379+
/// If this flag is set then subscribe to updates for this contract.
380+
subscribe: bool,
373381
},
374382
/// Subscribe to the changes in a given contract. Implicitly starts a get operation
375383
/// if the contract is not present yet.
@@ -386,10 +394,12 @@ impl ContractRequest<'_> {
386394
contract,
387395
state,
388396
related_contracts,
397+
subscribe,
389398
} => ContractRequest::Put {
390399
contract,
391400
state,
392401
related_contracts: related_contracts.into_owned(),
402+
subscribe,
393403
},
394404
Self::Update { key, data } => ContractRequest::Update {
395405
key,
@@ -398,9 +408,11 @@ impl ContractRequest<'_> {
398408
Self::Get {
399409
key,
400410
return_contract_code: fetch_contract,
411+
subscribe,
401412
} => ContractRequest::Get {
402413
key,
403414
return_contract_code: fetch_contract,
415+
subscribe,
404416
},
405417
Self::Subscribe { key, summary } => ContractRequest::Subscribe {
406418
key,
@@ -425,9 +437,11 @@ impl<'a> TryFromFbs<&FbsContractRequest<'a>> for ContractRequest<'a> {
425437
let get = request.contract_request_as_get().unwrap();
426438
let key = ContractKey::try_decode_fbs(&get.key())?;
427439
let fetch_contract = get.fetch_contract();
440+
let subscribe = get.subscribe();
428441
ContractRequest::Get {
429442
key,
430443
return_contract_code: fetch_contract,
444+
subscribe,
431445
}
432446
}
433447
ContractRequestType::Put => {
@@ -436,10 +450,12 @@ impl<'a> TryFromFbs<&FbsContractRequest<'a>> for ContractRequest<'a> {
436450
let state = WrappedState::new(put.wrapped_state().bytes().to_vec());
437451
let related_contracts =
438452
RelatedContracts::try_decode_fbs(&put.related_contracts())?.into_owned();
453+
let subscribe = put.subscribe();
439454
ContractRequest::Put {
440455
contract,
441456
state,
442457
related_contracts,
458+
subscribe,
443459
}
444460
}
445461
ContractRequestType::Update => {
@@ -1431,13 +1447,15 @@ mod client_request_test {
14311447
contract,
14321448
state,
14331449
related_contracts: _,
1450+
subscribe,
14341451
} => {
14351452
assert_eq!(
14361453
contract.to_string(),
14371454
"WasmContainer([api=0.0.1](D8fdVLbRyMLw5mZtPRpWMFcrXGN2z8Nq8UGcLGPFBg2W))"
14381455
);
14391456
assert_eq!(contract.unwrap_v1().data.data(), &[1, 2, 3, 4, 5, 6, 7, 8]);
14401457
assert_eq!(state.to_vec(), &[1, 2, 3, 4, 5, 6, 7, 8]);
1458+
assert_eq!(subscribe, false);
14411459
}
14421460
_ => panic!("wrong contract request type"),
14431461
}
@@ -1465,9 +1483,11 @@ mod client_request_test {
14651483
ContractRequest::Get {
14661484
key,
14671485
return_contract_code: fetch_contract,
1486+
subscribe,
14681487
} => {
14691488
assert_eq!(key.encoded_contract_id(), EXPECTED_ENCODED_CONTRACT_ID);
14701489
assert!(!fetch_contract);
1490+
assert_eq!(subscribe, false);
14711491
}
14721492
_ => panic!("wrong contract request type"),
14731493
}

0 commit comments

Comments
 (0)