Skip to content

Commit

Permalink
Merge pull request #372 from Concordium/minor-contract-api-fixes
Browse files Browse the repository at this point in the history
Fix minor API changes
  • Loading branch information
limemloh authored Jan 9, 2025
2 parents e9afee3 + 9a14b87 commit eccb6c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions backend-rust/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ impl From<concordium_rust_sdk::types::Address> for Address {
}
}
}

impl From<concordium_rust_sdk::common::types::AccountAddress> for Address {
fn from(address: concordium_rust_sdk::common::types::AccountAddress) -> Self {
Address::AccountAddress(address.into())
}
}
10 changes: 6 additions & 4 deletions backend-rust/src/graphql_api/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,25 @@ impl Contract {
async fn contract_events(
&self,
ctx: &Context<'_>,
skip: u32,
take: u32,
skip: Option<u64>,
take: Option<u64>,
) -> ApiResult<ContractEventsCollectionSegment> {
let config = get_config(ctx)?;
let pool = get_pool(ctx)?;
let skip = skip.unwrap_or(0);
let take = take.unwrap_or(config.contract_events_collection_limit);

// If `skip` is 0 and at least one event is taken, include the
// `init_transaction_event`.
let include_initial_event = skip == 0 && take > 0;
// Adjust the `take` and `skip` values considering if the
// `init_transaction_event` is requested to be included or not.
let take_without_initial_event = take.saturating_sub(include_initial_event as u32);
let take_without_initial_event = take.saturating_sub(include_initial_event as u64);
let skip_without_initial_event = skip.saturating_sub(1);

// Limit the number of events to be fetched from the `contract_events` table.
let limit = std::cmp::min(
take_without_initial_event as u64,
take_without_initial_event,
config.contract_events_collection_limit.saturating_sub(include_initial_event as u64),
);

Expand Down
1 change: 1 addition & 0 deletions backend-rust/src/transaction_event/smart_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ pub struct ContractCall {
}

#[derive(SimpleObject, serde::Serialize, serde::Deserialize)]
#[graphql(complex)]
pub struct ContractInterrupted {
pub contract_address: ContractAddress,
// All logged events by the smart contract during this section of the transaction execution.
Expand Down
2 changes: 1 addition & 1 deletion backend-rust/src/transaction_event/transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing::error;
pub struct Transferred {
pub amount: Amount,
pub from: Address,
pub to: AccountAddress,
pub to: Address,
}

#[derive(SimpleObject, serde::Serialize, serde::Deserialize)]
Expand Down

0 comments on commit eccb6c9

Please sign in to comment.