Skip to content

Commit a4eab37

Browse files
Merge pull request #1641 from multiversx/renames-crypto-zombies
Crypto Zombies renames & small fixes
2 parents dbee715 + fa76fc9 commit a4eab37

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use multiversx_sc::derive_imports::*;
2-
3-
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)]
2+
#[type_abi]
3+
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
44
pub struct Kitty {
55
pub genes: KittyGenes,
66
pub birth_time: u64, // timestamp
@@ -12,14 +12,16 @@ pub struct Kitty {
1212
pub generation: u16, // max(sire_gen, matron_gen) + 1. Generation also influences cooldown.
1313
}
1414

15-
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)]
15+
#[type_abi]
16+
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
1617
pub struct KittyGenes {
1718
pub fur_color: Color,
1819
pub eye_color: Color,
1920
pub meow_power: u8, // the higher the value, the louder the cat
2021
}
2122

22-
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)]
23+
#[type_abi]
24+
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
2325
pub struct Color {
2426
pub r: u8,
2527
pub g: u8,
@@ -28,13 +30,13 @@ pub struct Color {
2830

2931
impl KittyGenes {
3032
pub fn get_as_u64(&self) -> u64 {
31-
(self.fur_color.as_u64() << 12 | self.eye_color.as_u64()) << 4
33+
(self.fur_color.as_u64() << 24 | self.eye_color.as_u64()) << 8
3234
| self.meow_power.to_be() as u64
3335
}
3436
}
3537

3638
impl Color {
3739
pub fn as_u64(&self) -> u64 {
38-
((self.r.to_be() as u64) << 4 | self.r.to_be() as u64) << 4 | self.r.to_be() as u64
40+
((self.r.to_be() as u64) << 8 | self.r.to_be() as u64) << 8 | self.r.to_be() as u64
3941
}
4042
}

contracts/examples/crypto-zombies/src/proxy_crypto_zombies.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ where
154154
.original_result()
155155
}
156156

157-
pub fn zombies_count(
157+
pub fn zombie_last_index(
158158
self,
159159
) -> TxTypedCall<Env, From, To, NotPayable, Gas, usize> {
160160
self.wrapped_tx
161161
.payment(NotPayable)
162-
.raw_call("zombies_count")
162+
.raw_call("zombie_last_index")
163163
.original_result()
164164
}
165165

contracts/examples/crypto-zombies/src/storage.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@ use crate::zombie::Zombie;
55
#[multiversx_sc::module]
66
pub trait Storage {
77
#[view]
8-
#[storage_mapper("dna_digits")]
8+
#[storage_mapper("dnaDigits")]
99
fn dna_digits(&self) -> SingleValueMapper<u8>;
1010

1111
#[view]
12-
#[storage_mapper("zombies_count")]
13-
fn zombies_count(&self) -> SingleValueMapper<usize>;
12+
#[storage_mapper("zombieLastIndex")]
13+
fn zombie_last_index(&self) -> SingleValueMapper<usize>;
1414

1515
#[view]
1616
#[storage_mapper("zombies")]
1717
fn zombies(&self, id: &usize) -> SingleValueMapper<Zombie<Self::Api>>;
1818

1919
#[view]
20-
#[storage_mapper("zombie_owner")]
20+
#[storage_mapper("zombieOwner")]
2121
fn zombie_owner(&self, id: &usize) -> SingleValueMapper<ManagedAddress>;
2222

2323
#[view]
24-
#[storage_mapper("crypto_kitties_sc_address")]
24+
#[storage_mapper("cryptoKittiesScAddress")]
2525
fn crypto_kitties_sc_address(&self) -> SingleValueMapper<ManagedAddress>;
2626

2727
#[view]
28-
#[storage_mapper("cooldown_time")]
28+
#[storage_mapper("cooldownTime")]
2929
fn cooldown_time(&self) -> SingleValueMapper<u64>;
3030

3131
#[view]
32-
#[storage_mapper("owned_zombies")]
32+
#[storage_mapper("ownedZombies")]
3333
fn owned_zombies(&self, owner: &ManagedAddress) -> UnorderedSetMapper<usize>;
3434

35-
#[storage_mapper("attack_victory_probability")]
35+
#[storage_mapper("attackVictoryProbability")]
3636
fn attack_victory_probability(&self) -> SingleValueMapper<u8>;
3737

38-
#[storage_mapper("level_up_fee")]
38+
#[storage_mapper("levelUpFee")]
3939
fn level_up_fee(&self) -> SingleValueMapper<BigUint>;
4040

41-
#[storage_mapper("collected_fees")]
41+
#[storage_mapper("collectedFees")]
4242
fn collected_fees(&self) -> SingleValueMapper<BigUint>;
4343
}

contracts/examples/crypto-zombies/src/zombie_factory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{storage, zombie::Zombie};
55
#[multiversx_sc::module]
66
pub trait ZombieFactory: storage::Storage {
77
fn create_zombie(&self, owner: ManagedAddress, name: ManagedBuffer, dna: u64) {
8-
self.zombies_count().update(|id| {
8+
self.zombie_last_index().update(|id| {
99
self.new_zombie_event(*id, &name, dna);
1010
self.zombies(id).set(Zombie {
1111
name,
@@ -40,7 +40,7 @@ pub trait ZombieFactory: storage::Storage {
4040
self.create_zombie(caller, name, rand_dna);
4141
}
4242

43-
#[event("new_zombie_event")]
43+
#[event("newZombieEvent")]
4444
fn new_zombie_event(
4545
&self,
4646
#[indexed] zombie_id: usize,

contracts/examples/crypto-zombies/src/zombie_feeding.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use multiversx_sc::imports::*;
22

3-
use crate::{kitty_ownership_proxy, storage, zombie_factory, zombie_helper};
3+
use crate::{kitty_obj::Kitty, kitty_ownership_proxy, storage, zombie_factory, zombie_helper};
44

55
#[multiversx_sc::module]
66
pub trait ZombieFeeding:
@@ -38,7 +38,7 @@ pub trait ZombieFeeding:
3838
#[callback]
3939
fn get_kitty_callback(
4040
&self,
41-
#[call_result] result: ManagedAsyncCallResult<crate::kitty_obj::Kitty>,
41+
#[call_result] result: ManagedAsyncCallResult<Kitty>,
4242
zombie_id: usize,
4343
) {
4444
match result {

contracts/examples/crypto-zombies/wasm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ multiversx_sc_wasm_adapter::endpoints! {
2626
is_ready => is_ready
2727
feed_on_kitty => feed_on_kitty
2828
dna_digits => dna_digits
29-
zombies_count => zombies_count
29+
zombie_last_index => zombie_last_index
3030
zombies => zombies
3131
zombie_owner => zombie_owner
3232
crypto_kitties_sc_address => crypto_kitties_sc_address

0 commit comments

Comments
 (0)