Skip to content

Commit 44699b7

Browse files
committed
Refactor: extract do_price_upd into seperate method
1 parent 7911477 commit 44699b7

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

program/src/oracle/oracle.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,24 @@ static bool is_valid_price_upd( cmd_upd_price_t *cptr, SolAccountInfo *price_acc
515515
return true;
516516
}
517517

518+
static void do_price_upd( cmd_upd_price_t *cptr, SolAccountInfo *clock_account, SolAccountInfo *price_account, uint32_t comp_idx ) {
519+
// update aggregate price as necessary
520+
pc_price_t *pptr = (pc_price_t*)price_account->data;
521+
sysvar_clock_t *sptr = (sysvar_clock_t*)clock_account->data;
522+
if ( sptr->slot_ > pptr->agg_.pub_slot_ ) {
523+
upd_aggregate( pptr, sptr->slot_ );
524+
}
525+
526+
// update component price if required
527+
pc_price_info_t *fptr = &pptr->comp_[comp_idx].latest_;
528+
if ( cptr->cmd_ == e_cmd_upd_price ) {
529+
fptr->price_ = cptr->price_;
530+
fptr->conf_ = cptr->conf_;
531+
fptr->status_ = cptr->status_;
532+
fptr->pub_slot_ = cptr->pub_slot_;
533+
}
534+
}
535+
518536
static uint64_t upd_price( SolParameters *prm, SolAccountInfo *ka )
519537
{
520538
// Validate command parameters
@@ -547,19 +565,8 @@ static uint64_t upd_price( SolParameters *prm, SolAccountInfo *ka )
547565
return ERROR_INVALID_ARGUMENT;
548566
}
549567

550-
// update aggregate price as necessary
551-
sysvar_clock_t *sptr = (sysvar_clock_t*)clock_account->data;
552-
if ( sptr->slot_ > pptr->agg_.pub_slot_ ) {
553-
upd_aggregate( pptr, sptr->slot_ );
554-
}
555-
556-
// update component price if required
557-
if ( cptr->cmd_ == e_cmd_upd_price ) {
558-
fptr->price_ = cptr->price_;
559-
fptr->conf_ = cptr->conf_;
560-
fptr->status_ = cptr->status_;
561-
fptr->pub_slot_ = cptr->pub_slot_;
562-
}
568+
// Update the price
569+
do_price_upd( cptr, clock_account, price_account, comp_idx );
563570
return SUCCESS;
564571
}
565572

0 commit comments

Comments
 (0)