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

feat: implement oracle_store #584

Merged
merged 2 commits into from
Nov 9, 2023
Merged
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
43 changes: 30 additions & 13 deletions src/oracle/oracle_store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ mod OracleStore {
/// Interface to interact with the `EventEmitter` contract.
event_emitter: IEventEmitterDispatcher,
// NOTE: temporarily implemented to complete oracle tests.
signers: List<ContractAddress>
signers: List<ContractAddress>,
signers_indexes: LegacyMap<ContractAddress, u32>
}

// *************************************************************************
Expand Down Expand Up @@ -125,29 +126,45 @@ mod OracleStore {
self.role_store.write(IRoleStoreDispatcher { contract_address: role_store_address });
}

fn add_signer(ref self: ContractState, account: ContractAddress) { // TODO
// NOTE: temporarily implemented to complete oracle tests.
fn add_signer(ref self: ContractState, account: ContractAddress) {
let mut signers = self.signers.read();
let index = signers.len();
signers.append(account);
self.signers_indexes.write(account, index);
}

fn remove_signer(ref self: ContractState, account: ContractAddress) { // TODO
fn remove_signer(ref self: ContractState, account: ContractAddress) {
let mut signers = self.signers.read();
let last_signer_index = signers.len();
let signer_to_remove_index = self.signers_indexes.read(account);
let last_signer = signers.get(last_signer_index).expect('failed to get last signer');
signers.set(signer_to_remove_index, last_signer);
self.signers_indexes.write(last_signer, signer_to_remove_index);
signers.len = signers.len() - 1;
}

fn get_signer_count(self: @ContractState) -> u128 { // TODO
0
fn get_signer_count(self: @ContractState) -> u128 {
self.signers.read().len().into()
}

fn get_signer(self: @ContractState, index: usize) -> ContractAddress { // TODO
fn get_signer(self: @ContractState, index: usize) -> ContractAddress {
// NOTE: temporarily implemented to complete oracle tests.
let mut signers = self.signers.read();
signers.get(index).expect('array get failed')
self.signers.read().get(index).expect('failed to get signer')
}

fn get_signers(
self: @ContractState, start: u128, end: u128
) -> Array<ContractAddress> { // TODO
ArrayTrait::new()
fn get_signers(self: @ContractState, start: u128, end: u128) -> Array<ContractAddress> {
let mut signers_subset: Array<ContractAddress> = ArrayTrait::new();
let signers = self.signers.read();

let mut index: u32 = start.try_into().expect('failed convertion u32 to u128');
loop {
if start == end {
break;
}
signers_subset.append(signers.get(index).expect('out of bound signer index'))
};

signers_subset
}
}
}
Loading