Skip to content

Commit a707a2d

Browse files
authored
Merge pull request #288 from Ejirowebfi/feat/issue-235-smart-contract-analytics
feat: wire on-chain analytics hooks for issue #235
2 parents 1629030 + e876759 commit a707a2d

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

contract/src/lib.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ impl StellarEscrowContract {
543543
save_trade(&env, trade_id, &trade);
544544
events::emit_trade_created(&env, trade_id, seller.clone(), buyer.clone(), amount);
545545
events::emit_compliance_passed(&env, trade_id, seller, buyer, amount);
546+
analytics::on_trade_created(&env, amount, &trade.seller, &trade.buyer);
546547
Ok(trade_id)
547548
}
548549

@@ -829,8 +830,19 @@ impl StellarEscrowContract {
829830
}
830831
save_arbitrator_reputation(&env, arbitrator, &rep);
831832
events::emit_arb_rep_updated(&env, arbitrator.clone(), rep.resolved_count, rep.rating_sum, rep.rating_count);
833+
let resolution_code: u8 = match resolution {
834+
DisputeResolution::ReleaseToBuyer => 0,
835+
DisputeResolution::ReleaseToSeller => 1,
836+
DisputeResolution::Partial { .. } => 2,
837+
};
838+
analytics::on_dispute_resolved(&env, arbitrator, resolution_code);
832839
}
833840
Some(ArbitrationConfig::MultiSig(config)) => {
841+
let resolution_code: u8 = match resolution {
842+
DisputeResolution::ReleaseToBuyer => 0,
843+
DisputeResolution::ReleaseToSeller => 1,
844+
DisputeResolution::Partial { .. } => 2,
845+
};
834846
for i in 0..config.arbitrators.len() {
835847
let arb = config.arbitrators.get(i).unwrap();
836848
let mut rep = storage::get_arbitrator_reputation(&env, arb);
@@ -842,28 +854,17 @@ impl StellarEscrowContract {
842854
}
843855
save_arbitrator_reputation(&env, arb, &rep);
844856
events::emit_arb_rep_updated(&env, arb.clone(), rep.resolved_count, rep.rating_sum, rep.rating_count);
857+
analytics::on_dispute_resolved(&env, &arb, resolution_code);
845858
}
846859
// Clear votes after resolution
847860
storage::clear_votes_for_trade(&env, trade_id, &config.arbitrators);
848861
}
849862
None => {}
850863
}
851-
save_arbitrator_reputation(&env, &arbitrator, &rep);
852-
events::emit_arb_rep_updated(&env, arbitrator.clone(), rep.resolved_count, rep.rating_sum, rep.rating_count);
853-
set_currency_fees(&env, &trade.currency, new_fees);
854-
let token = get_usdc_token(&env)?;
855-
let token_client = TokenClient::new(&env, &token);
856-
token_client.transfer(&env.current_contract_address(), &recipient, &(payout as i128));
857-
// Single read-modify-write for fees
858-
add_accumulated_fees(&env, trade.fee)?;
859-
let resolution_code: u8 = match resolution {
860-
DisputeResolution::ReleaseToBuyer => 0,
861-
DisputeResolution::ReleaseToSeller => 1,
862-
DisputeResolution::Partial { .. } => 2,
863-
};
864-
analytics::on_dispute_resolved(&env, &arbitrator, resolution_code);
865-
events::emit_dispute_resolved(&env, trade_id, resolution, recipient);
866-
Ok(()) for the arbitrator of a resolved dispute.
864+
Ok(())
865+
}
866+
867+
/// Rate the arbitrator of a resolved dispute.
867868
/// Only the buyer or seller of the trade may rate, once each.
868869
pub fn rate_arbitrator(env: Env, trade_id: u64, rater: Address, stars: u32) -> Result<(), ContractError> {
869870
if !is_initialized(&env) {

0 commit comments

Comments
 (0)