Skip to content

Commit

Permalink
add consume_random_for_caller
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Oct 1, 2024
1 parent 22be9aa commit 04ad0ec
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions contracts/src/vrf_consumer/vrf_consumer_component.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ pub mod VrfConsumerComponent {

#[embeddable_as(VrfConsumerImpl)]
impl VrfConsumer<
TContractState,
+Drop<TContractState>,
+HasComponent<TContractState>,
TContractState, +Drop<TContractState>, +HasComponent<TContractState>,
> of super::IVrfConsumer<ComponentState<TContractState>> {
fn get_vrf_provider(self: @ComponentState<TContractState>) -> ContractAddress {
self.VrfConsumer_vrf_provider.read()
Expand All @@ -58,7 +56,6 @@ pub mod VrfConsumerComponent {
IVrfProviderDispatcher { contract_address: self.VrfConsumer_vrf_provider.read() }
.get_public_key()
}

}

#[generate_trait]
Expand Down Expand Up @@ -89,6 +86,16 @@ pub mod VrfConsumerComponent {

fn consume_random<T, +Drop<T>, +Serde<T>>(
self: @ComponentState<TContractState>, entrypoint: felt252, calldata: @T
) -> (felt252, felt252) {
let caller = get_caller_address();
self.consume_random_for_caller(entrypoint, calldata, caller)
}

fn consume_random_for_caller<T, +Drop<T>, +Serde<T>>(
self: @ComponentState<TContractState>,
entrypoint: felt252,
calldata: @T,
caller: ContractAddress
) -> (felt252, felt252) {
let mut serialized = array![];
calldata.serialize(ref serialized);
Expand All @@ -102,8 +109,6 @@ pub mod VrfConsumerComponent {
// check call matches commit
assert(seed == committed, Errors::COMMIT_MISMATCH);

let caller = get_caller_address();

// consume random & uncommit caller
let random = self.vrf_provider_disp().consume_random(caller, seed);

Expand Down

0 comments on commit 04ad0ec

Please sign in to comment.