Skip to content

Commit

Permalink
fix invitatioin (#3146)
Browse files Browse the repository at this point in the history
* fix invitatioin

* release
  • Loading branch information
jolestar committed Jan 8, 2025
1 parent a159419 commit 2eb2c1b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Binary file added apps/gas_faucet/released/3/package.rpd
Binary file not shown.
9 changes: 7 additions & 2 deletions apps/gas_faucet/sources/gas_faucet.move
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,22 @@ module gas_faucet::gas_faucet {

/// Anyone can call this function to help the claimer claim the faucet
public entry fun claim(faucet_obj: &mut Object<RGasFaucet>, claimer: address, utxo_ids: vector<ObjectID>){
Self::do_claim(faucet_obj, claimer, utxo_ids);
}

/// Claim the faucet for the claimer, return true if it is the first time to claim
public fun do_claim(faucet_obj: &mut Object<RGasFaucet>, claimer: address, utxo_ids: vector<ObjectID>): bool{
let claim_rgas_amount = Self::check_claim(faucet_obj, claimer, utxo_ids);
let faucet = object::borrow_mut(faucet_obj);
let rgas_coin = coin_store::withdraw(&mut faucet.rgas_store, claim_rgas_amount);
account_coin_store::deposit<RGas>(claimer, rgas_coin);
let total_claim_amount = table::borrow_mut_with_default(&mut faucet.claim_records, claimer, 0u256);
let first_claim = *total_claim_amount == 0;
*total_claim_amount = *total_claim_amount + claim_rgas_amount;
first_claim
}




public entry fun deposit_rgas_coin(
account: &signer,
faucet_obj: &mut Object<RGasFaucet>,
Expand Down
Binary file added apps/invitation_record/released/4/package.rpd
Binary file not shown.
16 changes: 10 additions & 6 deletions apps/invitation_record/sources/invitation.move
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module invitation_record::invitation {
use rooch_framework::gas_coin::RGas;
use rooch_framework::coin_store::CoinStore;
use rooch_framework::coin_store;
use gas_faucet::gas_faucet::{RGasFaucet, claim};
use gas_faucet::gas_faucet::{RGasFaucet, do_claim};
use moveos_std::table;
use moveos_std::object;
use app_admin::admin::AdminCap;
Expand Down Expand Up @@ -153,11 +153,17 @@ module invitation_record::invitation {
let full_message = encode_full_message(MessagePrefix, message);
verify_btc_signature(bitcoin_address, public_key, signature, full_message);
let claimer = bitcoin_address::to_rooch_address(&bitcoin_address);
assert!(inviter != claimer, ErrorCannotInviteOneself);
//assert!(inviter != claimer, ErrorCannotInviteOneself);
let invitation_conf = object::borrow_mut(invitation_obj);
assert!(invitation_conf.is_open, ErrorFaucetNotOpen);
if (inviter == @rooch_framework){
claim(faucet_obj, claimer, utxo_ids);
//If the inviter is the rooch_framework or the claimer, we do not need to record the invitation relationship
if (inviter == @rooch_framework || inviter == claimer){
do_claim(faucet_obj, claimer, utxo_ids);
return
};
let first_claim = do_claim(faucet_obj, claimer, utxo_ids);
//If the claimer has claimed the faucet, we do not need to record the invitation relationship
if (!first_claim){
return
};
if (!table::contains(&invitation_conf.invitation_records, inviter)) {
Expand All @@ -181,8 +187,6 @@ module invitation_record::invitation {
user_invitation_records.remaining_luckey_ticket = user_invitation_records.remaining_luckey_ticket + 1u64;
let rgas_coin = coin_store::withdraw(&mut invitation_conf.rgas_store, invitation_conf.unit_invitation_amount);
account_coin_store::deposit<RGas>(inviter, rgas_coin);

claim(faucet_obj, claimer, utxo_ids);
}

public entry fun claim_from_twitter(
Expand Down

0 comments on commit 2eb2c1b

Please sign in to comment.