Skip to content

Commit

Permalink
fix: save amount in hex format (#483)
Browse files Browse the repository at this point in the history
## Description

Use hex format to save `amount` in the `token_event` table

## What type of PR is this? (check all applicable)

- [X] 🐛 Bug Fix (`fix:`)
  • Loading branch information
remiroyc authored Oct 9, 2024
1 parent 3fe519b commit 4a33a1f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/pontos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl<S: Storage, C: StarknetClient, E: EventHandler + Send + Sync> Pontos<S, C,
) -> Result<()> {
let mut token_sale_event = self
.event_manager
.format_element_sale_event(&event, block_timestamp)
.format_element_sale_event(&event, block_timestamp, chain_id)
.await?;

let contract_addr = FieldElement::from_hex_be(
Expand Down Expand Up @@ -430,7 +430,7 @@ impl<S: Storage, C: StarknetClient, E: EventHandler + Send + Sync> Pontos<S, C,

let mut token_sale_event = self
.event_manager
.format_ventory_sale_or_accepted_offer_event(&event, block_timestamp)
.format_ventory_sale_or_accepted_offer_event(&event, block_timestamp, chain_id)
.await?;

let contract_addr = FieldElement::from_hex_be(
Expand Down
8 changes: 6 additions & 2 deletions crates/pontos/src/managers/event_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl<S: Storage> EventManager<S> {
&self,
event: &EmittedEvent,
block_timestamp: u64,
chain_id: &str,
) -> Result<TokenSaleEvent> {
let _listing_counter = event
.data
Expand Down Expand Up @@ -120,14 +121,16 @@ impl<S: Storage> EventManager<S> {
currency_address: None,
marketplace_contract_address: to_hex_str(&event.from_address),
marketplace_name: "Ventory".to_string(),
price: price.to_big_decimal(0).to_string(),
price: to_hex_str(price),
chain_id: chain_id.to_string(),
})
}

pub async fn format_element_sale_event(
&self,
event: &EmittedEvent,
block_timestamp: u64,
chain_id: &str,
) -> Result<TokenSaleEvent> {
if event.keys.len() < 4 {
return Err(anyhow!("Can't find event data into this event"));
Expand Down Expand Up @@ -231,7 +234,8 @@ impl<S: Storage> EventManager<S> {
currency_address: Some(to_hex_str(currency_address)),
marketplace_contract_address: to_hex_str(&event.from_address),
marketplace_name: "Element".to_string(),
price: price.to_big_decimal(0).to_string(),
price: to_hex_str(price),
chain_id: chain_id.to_string(),
})
}

Expand Down
5 changes: 3 additions & 2 deletions crates/pontos/src/storage/sqlx/default_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,14 @@ impl Storage for DefaultSqlxStorage {
)));
}

let q = "INSERT INTO token_event (block_timestamp, contract_address, from_address, to_address, transaction_hash, token_id, contract_type, event_type, event_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)";
let q = "INSERT INTO token_event (block_timestamp, contract_address, chain_id, from_address, to_address, transaction_hash, token_id, contract_type, event_type, event_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)";

let _r = sqlx::query(q)
.bind(event.timestamp.to_string())
.bind(event.contract_address.clone())
.bind(event.chain_id.clone())
.bind(event.from_address.clone())
.bind(event.to_address.clone())
.bind(event.contract_address.clone())
.bind(event.transaction_hash.clone())
.bind(event.token_id.clone())
.bind(event.contract_type.clone())
Expand Down
1 change: 1 addition & 0 deletions crates/pontos/src/storage/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub struct TokenSaleEvent {
pub quantity: u64,
pub currency_address: Option<String>,
pub price: String,
pub chain_id: String,
}

impl Default for TokenTransferEvent {
Expand Down
2 changes: 1 addition & 1 deletion crates/sana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl<S: Storage, C: StarknetClient, E: EventHandler + Send + Sync> Sana<S, C, E>

let mut token_sale_event = self
.event_manager
.format_ventory_sale_event(&event, block_timestamp)
.format_ventory_sale_event(&event, block_timestamp, chain_id)
.await?;

let contract_addr = FieldElement::from_hex_be(
Expand Down
7 changes: 4 additions & 3 deletions crates/sana/src/managers/event_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl<S: Storage> EventManager<S> {
&self,
event: &EmittedEvent,
block_timestamp: u64,
chain_id: &str,
) -> Result<TokenSaleEvent> {
let _listing_counter = event
.data
Expand Down Expand Up @@ -113,8 +114,8 @@ impl<S: Storage> EventManager<S> {
currency_address: None,
marketplace_contract_address: to_hex_str(&event.from_address),
marketplace_name: "Ventory".to_string(),
price: price.to_big_decimal(0).to_string(),
chain_id: "0x534e5f4d41494e".to_string(),
price: to_hex_str(price),
chain_id: chain_id.to_string(),
})
}

Expand Down Expand Up @@ -226,7 +227,7 @@ impl<S: Storage> EventManager<S> {
currency_address: Some(to_hex_str(currency_address)),
marketplace_contract_address: to_hex_str(&event.from_address),
marketplace_name: "Element".to_string(),
price: price.to_big_decimal(0).to_string(),
price: to_hex_str(price),
chain_id: chain_id.to_string(),
})
}
Expand Down

0 comments on commit 4a33a1f

Please sign in to comment.