Skip to content

Commit

Permalink
Added set repair streak token identifier endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbucur1 committed Feb 7, 2024
1 parent 242dd90 commit e2f3a46
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 10 deletions.
52 changes: 52 additions & 0 deletions contracts/on-chain-claim/interaction/mainnet.snippets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
WALLET="${PWD}/wallet.pem"
PROJECT="${PWD}"
PROXY=https://gateway.multiversx.com
CHAINID=D

DEPLOY_GAS="30000000"
SFT_IDENTIFIER=0x585354525245504149522d653162363733 #XSTRREPAIR-e1b673

CONTRACT_ADDRESS="erd1qqqqqqqqqqqqqpgqkm3wla3wk0yqk7lk725wee8yh0e2zeru76ls3gr0nj"

deploy() {
mxpy --verbose contract deploy \
--bytecode="output/on-chain-claim.wasm" \
--arguments ${SFT_IDENTIFIER} \
--pem=${WALLET} \
--gas-limit=${DEPLOY_GAS} \
--proxy=${PROXY} \
--chain=${CHAINID} \
--recall-nonce \
--send \
--outfile="deploy-mainnet.interaction.json" || return

TRANSACTION=$(mxpy data parse --file="deploy-mainnet.interaction.json" --expression="data['emittedTransactionHash']")
ADDRESS=$(mxpy data parse --file="deploy-mainnet.interaction.json" --expression="data['contractAddress']")

mxpy data store --key=address-mainnet --value=${ADDRESS}
mxpy data store --key=deployTransaction-mainnet --value=${TRANSACTION}

echo ""
echo "Smart contract address: ${ADDRESS}"
}

upgrade() {
mxpy --verbose contract upgrade ${CONTRACT_ADDRESS} \
--bytecode="output/on-chain-claim.wasm" \
--pem=${WALLET} \
--gas-limit=${DEPLOY_GAS} \
--proxy=${PROXY} \
--chain=${CHAINID} \
--recall-nonce \
--send \
--outfile="upgrade-mainnet.interaction.json" || return

TRANSACTION=$(mxpy data parse --file="upgrade-mainnet.interaction.json" --expression="data['emittedTransactionHash']")
ADDRESS=$(mxpy data parse --file="upgrade-mainnet.interaction.json" --expression="data['contractAddress']")

mxpy data store --key=address-mainnet --value=${ADDRESS}
mxpy data store --key=upgradeTransaction-mainnet --value=${TRANSACTION}

echo ""
echo "Smart contract address: ${ADDRESS}"
}
4 changes: 2 additions & 2 deletions contracts/on-chain-claim/interaction/testnet.snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ PROJECT="${PWD}"
PROXY=https://testnet-gateway.multiversx.com
CHAINID=D

DEPLOY_GAS="25000000"
SFT_IDENTIFIER=0x585354525245504149522d653162363733 #XSTRREPAIR-e1b673
DEPLOY_GAS="30000000"
SFT_IDENTIFIER=0x54525245504149522d626435323730 #XSTRREPAIR-e1b673
deploy() {
mxpy --verbose contract deploy \
--bytecode="output/on-chain-claim.wasm" \
Expand Down
24 changes: 18 additions & 6 deletions contracts/on-chain-claim/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ use multiversx_sc_modules::only_admin;
pub trait OnChainClaimContract: config::ConfigModule + only_admin::OnlyAdminModule {
#[init]
fn init(&self, repair_streak_token_id: TokenIdentifier) {
require!(
repair_streak_token_id.is_valid_esdt_identifier(),
"Invalid token ID"
);
self.repair_streak_token_identifier()
.set(repair_streak_token_id);
self.internal_set_repair_streak_token_id(repair_streak_token_id);

let caller = self.blockchain().get_caller();
self.add_admin(caller);
}
Expand Down Expand Up @@ -138,4 +134,20 @@ pub trait OnChainClaimContract: config::ConfigModule + only_admin::OnlyAdminModu
);
self.address_info(address).set(address_info);
}

#[endpoint(setRepairStreakTokenId)]
fn set_repair_streak_token_id(&self, repair_streak_token_id: TokenIdentifier) {
self.require_caller_is_admin();

self.internal_set_repair_streak_token_id(repair_streak_token_id);
}

fn internal_set_repair_streak_token_id(&self, repair_streak_token_id: TokenIdentifier) {
require!(
repair_streak_token_id.is_valid_esdt_identifier(),
"Invalid token ID"
);
self.repair_streak_token_identifier()
.set(repair_streak_token_id);
}
}
5 changes: 3 additions & 2 deletions contracts/on-chain-claim/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 11
// Endpoints: 12
// Async Callback (empty): 1
// Total number of exported functions: 13
// Total number of exported functions: 14

#![no_std]
#![allow(internal_features)]
Expand All @@ -24,6 +24,7 @@ multiversx_sc_wasm_adapter::endpoints! {
claim => claim
claimAndRepair => claim_and_repair
updateState => update_state
setRepairStreakTokenId => set_repair_streak_token_id
getAddressInfo => get_address_info
canBeRepaired => can_be_repaired
getRepairStreakTokenIdentifier => repair_streak_token_identifier
Expand Down

0 comments on commit e2f3a46

Please sign in to comment.