diff --git a/src/oracle/oracle_store.cairo b/src/oracle/oracle_store.cairo index ebaab1a2..b724023d 100644 --- a/src/oracle/oracle_store.cairo +++ b/src/oracle/oracle_store.cairo @@ -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 + signers: List, + signers_indexes: LegacyMap } // ************************************************************************* @@ -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 { // TODO - ArrayTrait::new() + fn get_signers(self: @ContractState, start: u128, end: u128) -> Array { + let mut signers_subset: Array = 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 } } }