Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change output of events in logs from Rust debug to JSON #1600

Merged
merged 4 commits into from
Sep 18, 2024

Conversation

leighmcculloch
Copy link
Member

@leighmcculloch leighmcculloch commented Sep 12, 2024

What

Change the output of contract events in logs from successful invocations from Rust debug to XDR and JSON.

Before

❯ stellar contract invoke --id $(stellar contract asset id --asset native) -- transfer --from me --to you --amount 1
2024-09-11T23:51:12.556972Z  INFO contract_event: soroban_cli::log::event: 1: DiagnosticEvent {
    in_successful_contract_call: true,
    event: ContractEvent {
        ext: V0,
        contract_id: Some(
            Hash(d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61),
        ),
        type_: Contract,
        body: V0(
            ContractEventV0 {
                topics: VecM(
                    [
                        Symbol(
                            ScSymbol(
                                StringM(transfer),
                            ),
                        ),
                        Address(
                            Account(
                                AccountId(
                                    PublicKeyTypeEd25519(
                                        Uint256(309d08c0d6e866993dfb33067291149d652b1ca75b690853b52a042b2947b1f5),
                                    ),
                                ),
                            ),
                        ),
                        Address(
                            Account(
                                AccountId(
                                    PublicKeyTypeEd25519(
                                        Uint256(7ac81d6ba7f93d9d17f226499d7df794f9ecd45c842f1e045aff9591e61c46d9),
                                    ),
                                ),
                            ),
                        ),
                        String(
                            ScString(
                                StringM(native),
                            ),
                        ),
                    ],
                ),
                data: I128(
                    Int128Parts {
                        hi: 0,
                        lo: 1,
                    },
                ),
            },
        ),
    },
}

After

❯ stellar contract invoke --id $(stellar contract asset id --asset native) -- transfer --from me --to you --amount 1
2024-09-12T00:00:01.671960Z INFO contract_event: soroban_cli::log::event: 1: AAAAAQAAAAAAAAAB15KLcsJwPM/q9+uf9O9NUEpVqLl5/JtFDqLIQrTRzmEAAAABAAAAAAAAAAQAAAAPAAAACHRyYW5zZmVyAAAAEgAAAAAAAAAAMJ0IwNboZpk9+zMGcpEUnWUrHKdbaQhTtSoEKylHsfUAAAASAAAAAAAAAAB6yB1rp/k9nRfyJkmdffeU+ezUXIQvHgRa/5WR5hxG2QAAAA4AAAAGbmF0aXZlAAAAAAAKAAAAAAAAAAAAAAAAAAAAAQ== {"in_successful_contract_call":true,"event":{"ext":"v0","contract_id":"d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61","type_":"contract","body":{"v0":{"topics":[{"symbol":"transfer"},{"address":"GAYJ2CGA23UGNGJ57MZQM4URCSOWKKY4U5NWSCCTWUVAIKZJI6Y7KL63"},{"address":"GB5MQHLLU74T3HIX6ITETHL566KPT3GULSCC6HQELL7ZLEPGDRDNS5OC"},{"string":"native"}],"data":{"i128":{"hi":0,"lo":1}}}}}}

Why

The rust debug is less human readable than JSON, because the Rust debug representation of the XDR types outputs values like the contract ID Hash, instead of the C string.

The output format has attempted to be as similar as possible to the output that @BlaineHeffron is using in:

Close #1447

@leighmcculloch leighmcculloch enabled auto-merge (squash) September 18, 2024 11:34
@leighmcculloch leighmcculloch merged commit 0a0cac0 into main Sep 18, 2024
25 checks passed
@leighmcculloch leighmcculloch deleted the jsonevents branch September 18, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Decode diagnostic events in logs
2 participants