diff --git a/Dockerfile b/Dockerfile index a7e266e6..57df1080 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,25 @@ # Stage 1: Build the binary -FROM rust:slim-bullseye as builder +FROM rust:slim-bookworm AS builder WORKDIR /app COPY --link . /app -RUN for i in 1 2 3; do apt-get update && apt-get install --fix-missing -y cmake curl clang git pkg-config libssl-dev libdw-dev libpq-dev lld && break || sleep 10; done +RUN apt-get update \ + && apt-get install --no-install-recommends --fix-missing -y \ + cmake \ + curl \ + clang \ + make \ + git \ + pkg-config \ + libssl-dev \ + libdw-dev \ + libpq-dev \ + lld \ + && rm -rf /var/lib/apt/lists/* ENV CARGO_NET_GIT_FETCH_WITH_CLI true # TODO: Fix this with real processors. RUN cargo build --locked --release -p processor && ls -lah target/release/ @@ -24,19 +36,19 @@ ENV GIT_SHA ${GIT_SHA} # Stage 2: Create the final image -FROM debian:bullseye-slim +FROM debian:bookworm-slim COPY --from=builder /usr/local/bin/processor /usr/local/bin RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ apt-get update && apt-get install --no-install-recommends --fix-missing -y \ - libssl1.1 \ + libssl3 \ ca-certificates \ net-tools \ tcpdump \ iproute2 \ - netcat \ + netcat-openbsd \ libdw-dev \ libpq-dev \ curl diff --git a/Dockerfile.address-reputation-api b/Dockerfile.address-reputation-api index 5be4c111..488d8ed5 100644 --- a/Dockerfile.address-reputation-api +++ b/Dockerfile.address-reputation-api @@ -2,13 +2,25 @@ # Stage 1: Build the binary -FROM rust:slim-bullseye as builder +FROM rust:slim-bookworm AS builder WORKDIR /app COPY --link . /app -RUN for i in 1 2 3; do apt-get update && apt-get install --fix-missing -y cmake curl clang git pkg-config libssl-dev libdw-dev libpq-dev lld && break || sleep 10; done +RUN apt-get update \ + && apt-get install --no-install-recommends --fix-missing -y \ + cmake \ + curl \ + clang \ + make \ + git \ + pkg-config \ + libssl-dev \ + libdw-dev \ + libpq-dev \ + lld \ + && rm -rf /var/lib/apt/lists/* ENV CARGO_NET_GIT_FETCH_WITH_CLI true RUN cargo build --locked --release -p address-reputation-api && ls -lah target/release/ RUN cp target/release/address-reputation-api /usr/local/bin @@ -23,19 +35,19 @@ ENV GIT_SHA ${GIT_SHA} # Stage 2: Create the final image -FROM debian:bullseye-slim +FROM debian:bookworm-slim COPY --from=builder /usr/local/bin/address-reputation-api /usr/local/bin RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ apt-get update && apt-get install --no-install-recommends --fix-missing -y \ - libssl1.1 \ + libssl3 \ ca-certificates \ net-tools \ tcpdump \ iproute2 \ - netcat \ + netcat-openbsd \ libdw-dev \ libpq-dev \ curl diff --git a/processor/src/processors/token_v2/token_v2_models/v2_token_activities.rs b/processor/src/processors/token_v2/token_v2_models/v2_token_activities.rs index 5ea0d503..5d219647 100644 --- a/processor/src/processors/token_v2/token_v2_models/v2_token_activities.rs +++ b/processor/src/processors/token_v2/token_v2_models/v2_token_activities.rs @@ -123,12 +123,13 @@ impl TokenActivityV2 { event_type: event_type.clone(), }, V2TokenEvent::TokenMutation(inner) => TokenActivityHelperV2 { - from_address: Some(inner.token_address.clone()), + // whoever submitted the mutation event is the from address + from_address: Some(sender.to_owned()), to_address: None, token_amount: BigDecimal::zero(), before_value: Some(inner.old_value.clone()), after_value: Some(inner.new_value.clone()), - event_type: "0x4::collection::MutationEvent".to_string(), + event_type: "0x4::token::MutationEvent".to_string(), }, V2TokenEvent::BurnEvent(_) => TokenActivityHelperV2 { from_address: Some(object_core.get_owner_address()), @@ -486,3 +487,54 @@ impl From for PostgresTokenActivityV2 { } } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::processors::objects::v2_object_utils::ObjectAggregatedData; + use aptos_indexer_processor_sdk::aptos_protos::transaction::v1::EventKey; + use chrono::DateTime; + + #[tokio::test] + async fn token_mutation_v2_uses_sender_not_token_address() { + let token_address = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + let sender = "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; + + let event = Event { + key: Some(EventKey { + creation_number: 0, + account_address: token_address.to_string(), + }), + sequence_number: 0, + r#type: None, + type_str: "0x4::token::Mutation".to_string(), + data: serde_json::json!({ + "token_address": token_address, + "mutated_field_name": "uri", + "old_value": "old", + "new_value": "new", + }) + .to_string(), + }; + + let mut metadata = ObjectAggregatedDataMapping::new(); + metadata.insert(token_address.to_string(), ObjectAggregatedData::default()); + + let ts = DateTime::from_timestamp(1_700_000_000, 0) + .unwrap() + .naive_utc(); + + let activity = TokenActivityV2::get_nft_v2_from_parsed_event( + &event, 1, ts, 0, &None, &metadata, sender, + ) + .await + .unwrap() + .expect("module Mutation event should produce an activity row"); + + assert_eq!(activity.from_address.as_deref(), Some(sender)); + assert_eq!(activity.type_, "0x4::token::MutationEvent"); + assert_eq!(activity.token_data_id, token_address); + assert_eq!(activity.before_value.as_deref(), Some("old")); + assert_eq!(activity.after_value.as_deref(), Some("new")); + } +} diff --git a/scripts/rust_lint.sh b/scripts/rust_lint.sh index 261c1aa9..32a48f2b 100755 --- a/scripts/rust_lint.sh +++ b/scripts/rust_lint.sh @@ -25,7 +25,10 @@ fi set -e set -x -cargo +nightly xclippy +# Run clippy on the pinned STABLE toolchain (from rust-toolchain.toml), NOT +# nightly. Latest nightly makes Infallible an alias of !, which breaks +# allocative (impl Allocative for both). Stable clippy matches the build toolchain. +cargo xclippy # We require the nightly build of cargo fmt # to provide stricter rust formatting.