Skip to content

Commit

Permalink
fix: renamed seller to sellers
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Dec 1, 2023
1 parent 3cea8b0 commit 94b3932
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
12 changes: 6 additions & 6 deletions src/deferred/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Deferred {
incr_by: u64,
installments: u64,
) -> DeferredResult<()> {
let contract_sellers = Inspect::inspect_is_seller(caller(), contract_id.clone())?.seller;
let contract_sellers = Inspect::inspect_is_seller(caller(), contract_id.clone())?.sellers;

// mint new tokens
let (tokens, _) =
Expand Down Expand Up @@ -126,7 +126,7 @@ impl Deferred {
caller(),
&data.id,
data.value,
&data.seller,
&data.sellers,
data.installments,
)?;

Expand All @@ -140,7 +140,7 @@ impl Deferred {
installments: data.installments,
is_signed: false,
r#type: data.r#type,
seller: data.seller,
sellers: data.sellers,
tokens: vec![],
value: data.value,
};
Expand Down Expand Up @@ -169,7 +169,7 @@ impl Deferred {
// mint new tokens
let (tokens, _) = Minter::mint(
&contract_id,
contract.seller,
contract.sellers,
contract.installments,
contract.value,
)
Expand Down Expand Up @@ -591,7 +591,7 @@ mod test {
installments: 10,
properties: vec![],
r#type: did::deferred::ContractType::Financing,
seller: vec![Seller {
sellers: vec![Seller {
principal: caller(),
quota: 100,
}],
Expand All @@ -616,7 +616,7 @@ mod test {
installments: 10,
properties: vec![],
r#type: did::deferred::ContractType::Financing,
seller: vec![Seller {
sellers: vec![Seller {
principal: caller(),
quota: 100,
}],
Expand Down
12 changes: 6 additions & 6 deletions src/deferred/src/app/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ impl Inspect {
caller: Principal,
id: &ID,
value: u64,
seller: &[Seller],
sellers: &[Seller],
installments: u64,
) -> DeferredResult<()> {
if !Self::inspect_is_custodian(caller) && !Self::inspect_is_agent(caller) {
return Err(DeferredError::Unauthorized);
}

if seller
if sellers
.iter()
.any(|seller| seller.principal == Principal::anonymous())
{
Expand All @@ -154,7 +154,7 @@ impl Inspect {
));
}

let total_quota = seller.iter().map(|seller| seller.quota).sum::<u8>();
let total_quota = sellers.iter().map(|seller| seller.quota).sum::<u8>();
if total_quota != 100 {
return Err(DeferredError::Token(
TokenError::ContractSellerQuotaIsNot100,
Expand Down Expand Up @@ -377,7 +377,7 @@ mod test {
&[3],
3,
|contract| {
contract.seller = vec![Seller {
contract.sellers = vec![Seller {
principal: Principal::management_canister(),
quota: 100,
}];
Expand All @@ -395,7 +395,7 @@ mod test {
&[4],
4,
|contract| {
contract.seller = vec![Seller {
contract.sellers = vec![Seller {
principal: Principal::management_canister(),
quota: 100,
}];
Expand Down Expand Up @@ -426,7 +426,7 @@ mod test {
&[6],
6,
|contract| {
contract.seller = vec![Seller {
contract.sellers = vec![Seller {
principal: Principal::management_canister(),
quota: 100,
}];
Expand Down
34 changes: 17 additions & 17 deletions src/deferred/src/app/storage/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl ContractStorage {
}

if contract
.seller
.sellers
.iter()
.any(|seller| seller.principal == Principal::anonymous())
{
Expand Down Expand Up @@ -73,7 +73,7 @@ impl ContractStorage {
.map(|t| t.id.clone())
.collect::<Vec<TokenIdentifier>>();

let seller = with_contract_mut(contract_id, |contract| {
let sellers = with_contract_mut(contract_id, |contract| {
if contract.is_signed {
return Err(DeferredError::Token(TokenError::ContractAlreadySigned(
contract.id.clone(),
Expand All @@ -88,10 +88,10 @@ impl ContractStorage {
contract.is_signed = true;
contract.tokens = token_ids;

Ok(contract.seller.clone())
Ok(contract.sellers.clone())
})?;

Self::mint_tokens(contract_id, &seller, tokens)?;
Self::mint_tokens(contract_id, &sellers, tokens)?;

Ok(())
}
Expand All @@ -117,7 +117,7 @@ impl ContractStorage {
.map(|t| t.id.clone())
.collect::<Vec<TokenIdentifier>>();

Self::mint_tokens(contract_id, &contract.seller, tokens)?;
Self::mint_tokens(contract_id, &contract.sellers, tokens)?;

// update contract value and ids
contract.value = new_value;
Expand Down Expand Up @@ -441,7 +441,7 @@ mod test {
});

let contract = with_mock_contract(1, 2, |contract| {
contract.seller = seller;
contract.sellers = seller;
});

assert!(ContractStorage::get_contract(&contract.id).is_none());
Expand Down Expand Up @@ -479,7 +479,7 @@ mod test {
});

let contract = with_mock_contract(1, 2, |contract| {
contract.seller = seller;
contract.sellers = seller;
contract.buyers = vec![];
});

Expand All @@ -502,7 +502,7 @@ mod test {
#[test]
fn test_should_not_allow_duped_contract() {
let contract = with_mock_contract(1, 2, |contract| {
contract.seller = vec![Seller {
contract.sellers = vec![Seller {
principal: Principal::anonymous(),
quota: 100,
}];
Expand Down Expand Up @@ -581,7 +581,7 @@ mod test {
});

let contract = with_mock_contract(1, 2, |contract| {
contract.seller = seller;
contract.sellers = seller;
});

assert!(ContractStorage::insert_contract(contract.clone()).is_ok());
Expand Down Expand Up @@ -620,7 +620,7 @@ mod test {
});

let contract = with_mock_contract(1, 1, |contract| {
contract.seller = vec![Seller {
contract.sellers = vec![Seller {
principal: owner,
quota: 100,
}];
Expand Down Expand Up @@ -675,7 +675,7 @@ mod test {
});

let contract = with_mock_contract(1, 1, |contract| {
contract.seller = vec![Seller {
contract.sellers = vec![Seller {
principal: Principal::management_canister(),
quota: 100,
}];
Expand Down Expand Up @@ -714,7 +714,7 @@ mod test {
let token_1 = mock_token(1, 1);
let token_2 = mock_token(2, 1);
let contract = with_mock_contract(1, 2, |contract| {
contract.seller = seller;
contract.sellers = seller;
});

assert!(ContractStorage::insert_contract(contract.clone(),).is_ok());
Expand All @@ -728,7 +728,7 @@ mod test {

#[test]
fn test_should_update_token_operator() {
let seller = vec![Seller {
let sellers = vec![Seller {
principal: caller(),
quota: 100,
}];
Expand All @@ -738,7 +738,7 @@ mod test {
let contract = Contract {
id: contract_id.clone(),
r#type: did::deferred::ContractType::Financing,
seller,
sellers,
buyers: vec![Principal::anonymous()],
tokens: vec![],
installments: 2,
Expand Down Expand Up @@ -775,7 +775,7 @@ mod test {
assert_eq!(next_token_id, Nat::from(0));
let token_1 = mock_token(next_token_id, 1);
let contract = with_mock_contract(1, 1, |contract| {
contract.seller = vec![Seller {
contract.sellers = vec![Seller {
principal: seller,
quota: 51,
}];
Expand Down Expand Up @@ -808,7 +808,7 @@ mod test {
assert_eq!(next_token_id, Nat::from(0));
let token_1 = mock_token(next_token_id, 1);
let contract = with_mock_contract(1, 1, |contract| {
contract.seller = seller;
contract.sellers = seller;
contract.value = 100;
});

Expand Down Expand Up @@ -839,7 +839,7 @@ mod test {
let next_token_id = ContractStorage::total_supply();
assert_eq!(next_token_id, Nat::from(0));
let contract = with_mock_contract(1, 2, |contract| {
contract.seller = seller;
contract.sellers = seller;
});

assert!(ContractStorage::insert_contract(contract.clone()).is_ok());
Expand Down
2 changes: 1 addition & 1 deletion src/deferred/src/app/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn mock_contract(id: u64, installments: u64) -> Contract {
Contract {
id: id.into(),
r#type: did::deferred::ContractType::Financing,
seller: vec![Seller {
sellers: vec![Seller {
principal: caller(),
quota: 100,
}],
Expand Down
2 changes: 1 addition & 1 deletion src/deferred/src/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn inspect_message_impl() {
caller(),
&data.id,
data.value,
&data.seller,
&data.sellers,
data.installments,
)
.is_ok()
Expand Down
4 changes: 2 additions & 2 deletions src/did/src/deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod test {
let contract = Contract {
id: ID::from(1),
r#type: ContractType::Sell,
seller: vec![
sellers: vec![
Seller {
principal: Principal::from_text(
"zrrb4-gyxmq-nx67d-wmbky-k6xyt-byhmw-tr5ct-vsxu4-nuv2g-6rr65-aae",
Expand Down Expand Up @@ -97,7 +97,7 @@ mod test {
let decoded_contract = Decode!(&data, Contract).unwrap();

assert_eq!(contract.id, decoded_contract.id);
assert_eq!(contract.seller, decoded_contract.seller);
assert_eq!(contract.sellers, decoded_contract.sellers);
assert_eq!(contract.buyers, decoded_contract.buyers);
assert_eq!(contract.tokens, decoded_contract.tokens);
assert_eq!(contract.properties, decoded_contract.properties);
Expand Down
6 changes: 3 additions & 3 deletions src/did/src/deferred/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Contract {
/// Contract type
pub r#type: ContractType,
/// The contractors selling the building with their quota
pub seller: Vec<Seller>,
pub sellers: Vec<Seller>,
/// Contract buyers. Those who must pay
pub buyers: Vec<Principal>,
/// Tokens associated to the contract, by id
Expand All @@ -38,7 +38,7 @@ pub struct Contract {

impl Contract {
pub fn is_seller(&self, principal: &Principal) -> bool {
self.seller.iter().any(|s| &s.principal == principal)
self.sellers.iter().any(|s| &s.principal == principal)
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ pub struct Seller {
pub struct ContractRegistration {
pub id: ID,
pub r#type: ContractType,
pub seller: Vec<Seller>,
pub sellers: Vec<Seller>,
pub buyers: Vec<Principal>,
pub value: u64,
pub currency: String,
Expand Down

0 comments on commit 94b3932

Please sign in to comment.