Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump to testnet #60

Merged
merged 16 commits into from
May 29, 2024
Prev Previous commit
Next Next commit
fix
  • Loading branch information
sarahschwartz committed May 17, 2024
commit ae57f1fed4ed074d1ac40eec36ff4e97e493f484
3 changes: 1 addition & 2 deletions contract/src/abi_structs.sw
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ abi GameContract {
#[storage(read, write), payable]
fn buy_seeds(food_type: FoodType, amount: u64);

// plant any amount of 1 type of seed
#[storage(read, write)]
fn plant_seeds(food_type: FoodType, indexes: Vec<u64>);
fn plant_seed_at_index(food_type: FoodType, index: u64);

// harvest grown seeds at certain indexes
#[storage(read, write)]
Expand Down
30 changes: 8 additions & 22 deletions contract/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -144,40 +144,26 @@ impl GameContract for Contract {
}

#[storage(read, write)]
fn plant_seeds(food_type: FoodType, indexes: Vec<u64>) {
let amount = indexes.len();
fn plant_seed_at_index(food_type: FoodType, index: u64) {
// get the sender
let sender = msg_sender().unwrap();
// require player has this many seeds
let current_amount_option = storage.player_seeds.get((sender, food_type)).try_read();
let current_amount = current_amount_option.unwrap_or(0);
require(
current_amount >= amount,
InvalidError::NotEnoughSeeds(amount),
current_amount >= 1,
InvalidError::NotEnoughSeeds(current_amount),
);
let new_amount = current_amount - amount;

let new_amount = current_amount - 1;
// update amount from player_seeds
storage.player_seeds.insert((sender, food_type), new_amount);

let mut count = 0;
let mut vec = storage.planted_seeds.get(sender).try_read().unwrap();
let food = Food::new(food_type, Some(timestamp()));
vec.plant_at_index(food, index);

// add the amount of food structs to planted_seeds
let mut vec = GardenVector::new();
let time = timestamp();
while count < amount {
let food = Food::new(food_type, Some(time));
let index = indexes.get(count).unwrap();
vec.plant_at_index(food, index);
count += 1;
}
storage.planted_seeds.insert(sender, vec);

log(PlantSeeds {
address: sender,
food_type,
indexes,
timestamp: time,
});
}

#[storage(read, write)]
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Garden.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function Garden({
const { value } = await contract.functions
.get_garden_vec(id)
.get();
console.log("VALUE:", value)
// console.log("VALUE:", value)
setTileStates(value);
} catch (err) {
console.log('Error in Garden:', err);
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/modals/PlantModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export default function PlantModal({
setStatus('loading');
setCanMove(false);
const seedType: FoodTypeInput = FoodTypeInput.Tomatoes;
// console.log("TILE ARRAY:", tileArray)
await contract.functions
.plant_seeds(seedType, tileArray)
.plant_seed_at_index(seedType, tileArray[0])
.call();


updatePageNum();
setStatus('none');
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Vector3 } from 'three';

// import contractIds from './sway-api/contract-ids.json';

export const FUEL_PROVIDER_URL = 'https:/devnet.fuel.network/v1/graphql';
export const FUEL_PROVIDER_URL = 'https://devnet.fuel.network/v1/graphql';

export const TESTNET_FAUCET_URL = 'https://faucet-devnet.fuel.network/'

Expand All @@ -15,11 +15,11 @@ export const CONTRACT_ID =
// VERCEL_ENV === 'development'
// ? contractIds.contract
// :
'0xa53ec4582f372a093dbe529d52aafc236166e90a8484c58b636a91f1dbb2c8cc';
'0x581411452d062c3061e022cc5369a5e2881048bf482c67d151a716818c63a1c6';

export const FARM_COIN_ASSET_ID = VERCEL_ENV === 'development'
? null :
"0x0bc308adcb1573915e02c25217c0db637928e0bb0575bab549ec9471be2dbd4c";
"0xa37f6db10859078b39807b2585e83d6e1518a460541af9947f510268ce205286";

export const FARM_COIN_NETWORK_ASSET = {
/** type of network */
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/sway-api/contracts/ContractAbi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ export type LevelUpInput = { address: IdentityInput, player_info: PlayerInput };
export type LevelUpOutput = { address: IdentityOutput, player_info: PlayerOutput };
export type NewPlayerInput = { address: IdentityInput };
export type NewPlayerOutput = { address: IdentityOutput };
export type PlantSeedsInput = { address: IdentityInput, food_type: FoodTypeInput, indexes: Vec<BigNumberish>, timestamp: BigNumberish };
export type PlantSeedsOutput = { address: IdentityOutput, food_type: FoodTypeOutput, indexes: Vec<BN>, timestamp: BN };
export type PlayerInput = { farming_skill: BigNumberish, total_value_sold: BigNumberish };
export type PlayerOutput = { farming_skill: BN, total_value_sold: BN };
export type SellItemInput = { address: IdentityInput, food_type: FoodTypeInput, amount_sold: BigNumberish, value_sold: BigNumberish, player_info: PlayerInput };
Expand All @@ -67,7 +65,7 @@ interface ContractAbiInterface extends Interface {
harvest: FunctionFragment;
level_up: FunctionFragment;
new_player: FunctionFragment;
plant_seeds: FunctionFragment;
plant_seed_at_index: FunctionFragment;
sell_item: FunctionFragment;
};

Expand All @@ -82,7 +80,7 @@ interface ContractAbiInterface extends Interface {
encodeFunctionData(functionFragment: 'harvest', values: [Vec<BigNumberish>]): Uint8Array;
encodeFunctionData(functionFragment: 'level_up', values: []): Uint8Array;
encodeFunctionData(functionFragment: 'new_player', values: []): Uint8Array;
encodeFunctionData(functionFragment: 'plant_seeds', values: [FoodTypeInput, Vec<BigNumberish>]): Uint8Array;
encodeFunctionData(functionFragment: 'plant_seed_at_index', values: [FoodTypeInput, BigNumberish]): Uint8Array;
encodeFunctionData(functionFragment: 'sell_item', values: [FoodTypeInput, BigNumberish]): Uint8Array;

decodeFunctionData(functionFragment: 'buy_seeds', data: BytesLike): DecodedValue;
Expand All @@ -96,7 +94,7 @@ interface ContractAbiInterface extends Interface {
decodeFunctionData(functionFragment: 'harvest', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'level_up', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'new_player', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'plant_seeds', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'plant_seed_at_index', data: BytesLike): DecodedValue;
decodeFunctionData(functionFragment: 'sell_item', data: BytesLike): DecodedValue;
}

Expand All @@ -114,7 +112,7 @@ export class ContractAbi extends Contract {
harvest: InvokeFunction<[indexes: Vec<BigNumberish>], void>;
level_up: InvokeFunction<[], void>;
new_player: InvokeFunction<[], void>;
plant_seeds: InvokeFunction<[food_type: FoodTypeInput, indexes: Vec<BigNumberish>], void>;
plant_seed_at_index: InvokeFunction<[food_type: FoodTypeInput, index: BigNumberish], void>;
sell_item: InvokeFunction<[food_type: FoodTypeInput, amount: BigNumberish], void>;
};
}
2 changes: 1 addition & 1 deletion frontend/src/sway-api/contracts/ContractAbi.hex.ts

Large diffs are not rendered by default.

Loading
Loading