Skip to content

Commit

Permalink
Make owner_address null too
Browse files Browse the repository at this point in the history
  • Loading branch information
rtso committed Jul 10, 2024
1 parent 6654a71 commit e95eb6e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub type EventToCoinType = AHashMap<EventGuidResource, CoinType>;
pub struct FungibleAssetActivity {
pub transaction_version: i64,
pub event_index: i64,
pub owner_address: String,
pub owner_address: Option<String>,
pub storage_id: String,
pub asset_type: Option<String>,
pub is_frozen: Option<bool>,
Expand Down Expand Up @@ -105,32 +105,34 @@ impl FungibleAssetActivity {

// The event account address will also help us find fungible store which tells us where to find
// the metadata
if let Some(object_metadata) = object_aggregated_data_mapping.get(&storage_id) {
let object_core = &object_metadata.object.object_core;
// The FungibleStore might not exist in the transaction if it's a secondary store that got burnt
let maybe_fungible_asset = object_metadata.fungible_asset_store.as_ref();
let maybe_asset_type =
maybe_fungible_asset.map(|fa| fa.metadata.get_reference_address());
let maybe_object_metadata = object_aggregated_data_mapping.get(&storage_id);
// The ObjectCore might not exist in the transaction if the object got deleted
let maybe_owner_address = maybe_object_metadata
.map(|metadata| &metadata.object.object_core)
.map(|object_core| object_core.get_owner_address());
// The FungibleStore might not exist in the transaction if it's a secondary store that got burnt
let maybe_asset_type = maybe_object_metadata
.and_then(|metadata| metadata.fungible_asset_store.as_ref())
.map(|fa| fa.metadata.get_reference_address());

return Ok(Some(Self {
transaction_version: txn_version,
event_index,
owner_address: object_core.get_owner_address(),
storage_id: storage_id.clone(),
asset_type: maybe_asset_type,
is_frozen,
amount,
type_: event_type.clone(),
is_gas_fee: false,
gas_fee_payer_address: None,
is_transaction_success: true,
entry_function_id_str: entry_function_id_str.clone(),
block_height,
token_standard: TokenStandard::V2.to_string(),
transaction_timestamp: txn_timestamp,
storage_refund_amount: BigDecimal::zero(),
}));
}
return Ok(Some(Self {
transaction_version: txn_version,
event_index,
owner_address: maybe_owner_address,
storage_id: storage_id.clone(),
asset_type: maybe_asset_type,
is_frozen,
amount,
type_: event_type.clone(),
is_gas_fee: false,
gas_fee_payer_address: None,
is_transaction_success: true,
entry_function_id_str: entry_function_id_str.clone(),
block_height,
token_standard: TokenStandard::V2.to_string(),
transaction_timestamp: txn_timestamp,
storage_refund_amount: BigDecimal::zero(),
}));
}
Ok(None)
}
Expand Down Expand Up @@ -187,7 +189,7 @@ impl FungibleAssetActivity {
Ok(Some(Self {
transaction_version: txn_version,
event_index,
owner_address,
owner_address: Some(owner_address),
storage_id,
asset_type: Some(coin_type),
is_frozen: None,
Expand Down Expand Up @@ -234,7 +236,7 @@ impl FungibleAssetActivity {
Self {
transaction_version,
event_index: v1_activity.event_index.unwrap(),
owner_address: v1_activity.owner_address,
owner_address: Some(v1_activity.owner_address),
storage_id,
asset_type: Some(v1_activity.coin_type),
is_frozen: None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-- This file should undo anything in `up.sql`
ALTER TABLE IF EXISTS fungible_asset_activities ALTER COLUMN asset_type SET NOT NULL;
ALTER TABLE IF EXISTS fungible_asset_activities ALTER COLUMN asset_type SET NOT NULL;
ALTER TABLE IF EXISTS fungible_asset_activities ALTER COLUMN owner_address SET NOT NULL;
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-- Your SQL goes here
ALTER TABLE IF EXISTS fungible_asset_activities ALTER COLUMN asset_type DROP NOT NULL;
ALTER TABLE IF EXISTS fungible_asset_activities ALTER COLUMN asset_type DROP NOT NULL;
ALTER TABLE IF EXISTS fungible_asset_activities ALTER COLUMN owner_address DROP NOT NULL;
2 changes: 1 addition & 1 deletion rust/processor/src/db/postgres/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ diesel::table! {
transaction_version -> Int8,
event_index -> Int8,
#[max_length = 66]
owner_address -> Varchar,
owner_address -> Nullable<Varchar>,
#[max_length = 66]
storage_id -> Varchar,
#[max_length = 1000]
Expand Down

0 comments on commit e95eb6e

Please sign in to comment.