Skip to content

Commit

Permalink
chore: versioned storage (#96)
Browse files Browse the repository at this point in the history
* chore: added profile address to the kujira config file.
* chore: versioned storage for trades and offers.
  • Loading branch information
desamtralized authored Oct 17, 2022
1 parent 2c2cfdd commit 096f5dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/src/network/cosmos/config/kujira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const KUJIRA_TESTNET_HUB_INFO: HubInfo = {
hubConfig: {
offer_addr: 'kujira17yfjhj4adsqlsm452a4hawp6lgtzd2lyrqnmfe057vd5pcpd8rwsykv8na',
trade_addr: 'kujira1kd0uf7za28hslrlz4ag82kyyaucmd8mzukut44p8nlnrkj4mps0sgxzuck',
profile_addr: '',
profile_addr: 'kujira1at4ls9w65hcpgk4jnzssdczyky2339h3apszcysh6xq9vx77mf8sdszr0s',
trading_incentives_addr: 'kujira1lzsuzy7485zzyze0tla55vn4ddwxa2flwhws9mrwfxftmhzmnwuslxv6z2',
local_market_addr: 'kujira1chejx4qqtvwxy6684yrsmf6pylancxqhk3vsmtleg5ta3zrffljq4xf685',
local_denom: {
Expand Down
1 change: 0 additions & 1 deletion contracts/packages/protocol/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub const OFFERS_KEY: &str = "offers";
pub const REQUEST_TIMEOUT: u64 = 20 * 60; // 20 mins
pub const FUNDING_TIMEOUT: u64 = 140 * 60; // 2hrs 20 mins
pub const LOCAL_FEE: u128 = 100;
Expand Down
12 changes: 8 additions & 4 deletions contracts/packages/protocol/src/offer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use super::constants::OFFERS_KEY;
use crate::currencies::FiatCurrency;
use crate::denom_utils::denom_to_string;
use crate::hub_utils::get_hub_config;
Expand Down Expand Up @@ -28,8 +27,13 @@ impl<'a> IndexList<Offer> for OfferIndexes<'a> {
}

pub fn offers<'a>() -> IndexedMap<'a, String, Offer, OfferIndexes<'a>> {
let offers_pk_namespace = "offers_v0_3_0";
let indexes = OfferIndexes {
owner: MultiIndex::new(|d| d.owner.clone().to_string(), "offers", "offers__owner"),
owner: MultiIndex::new(
|d| d.owner.clone().to_string(),
offers_pk_namespace,
"offers__owner",
),
filter: MultiIndex::new(
|offer: &Offer| {
offer
Expand All @@ -39,11 +43,11 @@ pub fn offers<'a>() -> IndexedMap<'a, String, Offer, OfferIndexes<'a>> {
.add(denom_to_string(&offer.denom).as_str())
.add(&offer.state.to_string())
},
"offers",
offers_pk_namespace,
"offers__filter",
),
};
IndexedMap::new(OFFERS_KEY, indexes)
IndexedMap::new(offers_pk_namespace, indexes)
}

// pub const OFFERS : IndexedMap<&str, Offer, OfferIndexes> = create_offers_indexedmap();
Expand Down
16 changes: 9 additions & 7 deletions contracts/packages/protocol/src/trade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,17 @@ impl<'a> IndexList<Trade> for TradeIndexes<'a> {
}

pub fn trades<'a>() -> IndexedMap<'a, String, Trade, TradeIndexes<'a>> {
let pk_namespace = "trades_v0_3_0";
let indexes = TradeIndexes {
buyer: MultiIndex::new(|t| t.buyer.to_string(), "trades", "trades__buyer"),
seller: MultiIndex::new(|t| t.seller.to_string(), "trades", "trades__seller"),
buyer: MultiIndex::new(|t| t.buyer.to_string(), pk_namespace, "trades__buyer"),
seller: MultiIndex::new(|t| t.seller.to_string(), pk_namespace, "trades__seller"),
arbitrator: MultiIndex::new(
|t| t.arbitrator.clone().to_string(),
"trades",
pk_namespace,
"trades__arbitrator",
),
};
IndexedMap::new("trades", indexes)
IndexedMap::new(pk_namespace, indexes)
}

// Arbitrator
Expand Down Expand Up @@ -537,19 +538,20 @@ impl ArbitratorModel {
}

pub fn arbitrators<'a>() -> IndexedMap<'a, &'a str, Arbitrator, ArbitratorIndexes<'a>> {
let arbitrators_pk_namespace = "arbitrators_v0_3_0";
let indexes = ArbitratorIndexes {
arbitrator: MultiIndex::new(
|d: &Arbitrator| d.arbitrator.clone(),
"arbitrators",
arbitrators_pk_namespace,
"arbitrators__arbitrator",
),
fiat: MultiIndex::new(
|d: &Arbitrator| d.fiat.clone().to_string(),
"arbitrators",
arbitrators_pk_namespace,
"arbitrators__asset",
),
};
IndexedMap::new("arbitrators", indexes)
IndexedMap::new(&arbitrators_pk_namespace, indexes)
}

pub struct ArbitratorIndexes<'a> {
Expand Down

0 comments on commit 096f5dc

Please sign in to comment.