Skip to content

Commit

Permalink
refactor: merged views
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid committed Jul 30, 2024
1 parent 052766c commit cd89d22
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 24 deletions.
21 changes: 2 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
path = "src/lib.rs"

[dependencies]
core-mx-liveliness-stake = {path="/Users/bucurdavid/dev/itheum/core-mx-liveliness-stake"}
core-mx-liveliness-stake = {git ="https://github.com/Itheum/core-mx-liveliness-stake.git",branch = "main"}

[dependencies.multiversx-sc]
version = "0.51.0"
Expand Down
53 changes: 53 additions & 0 deletions src/life_bonding_sc_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ where
.original_result()
}

pub fn top_up_address_vault<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<TokenIdentifier<Env::Api>>,
Arg2: ProxyArg<u64>,
>(
self,
address: Arg0,
token_identifier: Arg1,
nonce: Arg2,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("topUpAddressVault")
.argument(&address)
.argument(&token_identifier)
.argument(&nonce)
.original_result()
}

pub fn stake_rewards<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<TokenIdentifier<Env::Api>>,
Expand Down Expand Up @@ -409,6 +427,19 @@ where
.original_result()
}

pub fn get_address_bonds_info<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, (BigUint<Env::Api>, BigUint<Env::Api>, BigUint<Env::Api>)> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getAddressBondsInfo")
.argument(&address)
.original_result()
}

pub fn get_all_bonds(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ManagedVec<Env::Api, Bond<Env::Api>>> {
Expand Down Expand Up @@ -713,6 +744,19 @@ where
.original_result()
}

pub fn set_top_up_administrator<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("setTopUpAdministrator")
.argument(&address)
.original_result()
}

pub fn set_administrator<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
Expand Down Expand Up @@ -744,6 +788,15 @@ where
.original_result()
}

pub fn top_up_administrator(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ManagedAddress<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getTopUpAdministrator")
.original_result()
}

pub fn accepted_callers(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, ManagedAddress<Env::Api>>> {
Expand Down
17 changes: 15 additions & 2 deletions src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,27 @@ pub trait ViewsModule:
}

#[view(getAddressBondsTotalValue)]
fn get_address_bonds_total_value(&self, address: ManagedAddress<Self::Api>) -> BigUint {
self.address_bonds(&address)
fn get_address_bonds_total_value(&self, address: &ManagedAddress<Self::Api>) -> BigUint {
self.address_bonds(address)
.into_iter()
.fold(BigUint::zero(), |acc, bond_id| {
acc + self.remaining_amount(bond_id).get()
})
}

#[view(getAddressBondsInfo)]
fn get_address_bonds_info(&self, address: ManagedAddress) -> (BigUint, BigUint, BigUint) {
let address_bonds_value = self.get_address_bonds_total_value(&address);
let address_bonds_avg_score = self.get_address_bonds_avg_score(address);
let total_bond_amount = self.total_bond_amount().get();

(
total_bond_amount,
address_bonds_value,
address_bonds_avg_score,
)
}

#[view(getAllBonds)]
fn get_all_bonds(&self) -> ManagedVec<Bond<Self::Api>> {
self.bonds()
Expand Down
5 changes: 3 additions & 2 deletions wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 59
// Endpoints: 60
// Async Callback (empty): 1
// Total number of exported functions: 62
// Total number of exported functions: 63

#![no_std]

Expand Down Expand Up @@ -44,6 +44,7 @@ multiversx_sc_wasm_adapter::endpoints! {
getAddressBonds => get_address_bonds
getAddressBondsAvgScore => get_address_bonds_avg_score
getAddressBondsTotalValue => get_address_bonds_total_value
getAddressBondsInfo => get_address_bonds_info
getAllBonds => get_all_bonds
getPagedBonds => get_paged_bonds
getBondsLen => get_bonds_len
Expand Down

0 comments on commit cd89d22

Please sign in to comment.