-
Notifications
You must be signed in to change notification settings - Fork 118
four issues resolved: multi-currency contracts (37 tests passing), de… #153
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ struct PromptCreated { | |
| pub prompt_id: u128, | ||
| pub creator: Address, | ||
| pub price_stroops: i128, | ||
| pub asset: Address, | ||
| } | ||
|
Comment on lines
+9
to
10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify downstream PromptCreated handling is multi-asset aware
fd -i 'indexer.ts'
rg -n -C3 'PromptCreated|price_stroops|asset|10_000_000|10_000_0000' server/src/services/indexer.tsRepository: Obiajulu-gif/Prompt-Hash-Stellar Length of output: 954 🏁 Script executed: #!/bin/bash
set -euo pipefail
# 1) Inspect the PromptCreated event definition (asset field presence/types)
rg -n "PromptCreated" contracts/prompt-hash/src/events.rs
rg -n "asset" contracts/prompt-hash/src/events.rs
# Print the relevant sections around the matches (keep output small)
rg -n "PromptCreated" -n -C3 contracts/prompt-hash/src/events.rs
rg -n "asset" -n -C3 contracts/prompt-hash/src/events.rs
# 2) Inspect PromptCreated handling/normalization in the indexer
sed -n '1,160p' server/src/services/indexer.ts
# 3) Check whether asset/decimals is used anywhere near PromptCreated or price_stroops normalization
rg -n "price_stroops" server/src/services/indexer.ts
rg -n "asset" server/src/services/indexer.ts
rg -n "10_000_000" server/src/services/indexer.ts
# 4) Broader search: any other consumer of PromptCreated / price_stroops / asset decimals
rg -n "PromptCreated" server/src | head -n 50
rg -n "price_stroops" server/src | head -n 50
rg -n "\"PromptPriceUpdated\"" server/src | head -n 50
rg -n "10_000_000" server/src | head -n 50Repository: Obiajulu-gif/Prompt-Hash-Stellar Length of output: 4648 🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n "struct PromptPriceUpdated|PromptPriceUpdated" contracts/prompt-hash/src/events.rs
rg -n "PromptPriceUpdated" -n -C3 contracts/prompt-hash/src/events.rsRepository: Obiajulu-gif/Prompt-Hash-Stellar Length of output: 488 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Locate PromptCreated emission
rg -n "emit_prompt_created|PromptCreated \{" contracts/prompt-hash/src -S
rg -n "price_stroops|asset" contracts/prompt-hash/src -S
# Show surrounding code for the emission (limit output)
rg -n "emit_prompt_created" -n -C5 contracts/prompt-hash/src
# If emit functions exist, inspect their definitions and any helpers that compute price
rg -n "fn emit_.*prompt.*" contracts/prompt-hash/src -SRepository: Obiajulu-gif/Prompt-Hash-Stellar Length of output: 10010 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect contract.rs around pricing/emit_prompt_created and decimals validation
sed -n '1,220p' contracts/prompt-hash/src/contract.rs
# Inspect server Prompt model to see if it stores asset/decimals
fd -i "*Prompt*" server/src -a
fd -i "prompt" server/src/models -a 2>/dev/null || true
ls -R server/src/models 2>/dev/null || true
rg -n "class Prompt|interface Prompt|mongoose.*Prompt|price|asset|decimals" server/src/models -S || true
# Inspect any DB update for asset during PromptCreated indexing
rg -n "asset" server/src/services/indexer.ts
rg -n "Prompt.findOneAndUpdate\\(" server/src/services/indexer.ts -nRepository: Obiajulu-gif/Prompt-Hash-Stellar Length of output: 7772 🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n "10_000_000" server/src
rg -n "asset" server/src/models server/src/services/indexer.ts
fd -i "Prompt*" server/src/models -t f || trueRepository: Obiajulu-gif/Prompt-Hash-Stellar Length of output: 265 🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n "10_000_000" server/src
fd -i "Prompt*" server/src/models -t f || true
rg -n "class Prompt|interface Prompt|mongoose.*Prompt|asset|decimals" server/src/models server/src -S
rg -n "price_stroops" server/src -SRepository: Obiajulu-gif/Prompt-Hash-Stellar Length of output: 1251 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '1,220p' server/src/models/Prompt.js
sed -n '1,120p' server/src/models/PromptVersion.ts
rg -n "asset|decimals|price_stroops|10_000_000" server/src/models/Prompt.js server/src/models/PromptVersion.ts server/src -SRepository: Obiajulu-gif/Prompt-Hash-Stellar Length of output: 2375 Fix indexer price normalization for
🤖 Prompt for AI Agents |
||
|
|
||
| #[contractevent] | ||
|
|
@@ -75,11 +76,18 @@ struct FeeWalletUpdated { | |
| pub struct Events; | ||
|
|
||
| impl Events { | ||
| pub fn emit_prompt_created(env: &Env, prompt_id: u128, creator: Address, price_stroops: i128) { | ||
| pub fn emit_prompt_created( | ||
| env: &Env, | ||
| prompt_id: u128, | ||
| creator: Address, | ||
| price_stroops: i128, | ||
| asset: Address, | ||
| ) { | ||
| PromptCreated { | ||
| prompt_id, | ||
| creator, | ||
| price_stroops, | ||
| asset, | ||
| } | ||
| .publish(env); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
For soroban_sdk token clients, what is the recommended way to validate a token/SAC contract address without trapping, and doestoken::StellarAssetClientexposetry_decimals()(or equivalent fallible APIs)?💡 Result:
Recommended validation approach (no trapping): don’t call the infallible metadata methods (e.g.,
decimals()), because they are specified to panic if the SAC/token contract “has not yet been initialized” [1]. Instead, for Soroban token/SAC clients, prefer the fallible API that returns aResult(or otherwise gate your call behind a pre-check), so you can handle “not initialized / wrong contract” as an error rather than allowing a trap. Fortoken::StellarAssetClient: yes—StellarAssetClientexposes a fallible equivalent ofdecimals()namedtry_decimals(&self) -> Result<..., Error>[2]. The docs also explicitly saydecimals()panics when the contract hasn’t been initialized [2]. Caveat/contract-shape expectation:decimals(env) -> u32is part of theStellarAssetInterface(CAP-46-6 functions) and is defined as panicking in that interface if the contract is not initialized [1][3]. Sotry_decimals()is the API you want when you need “validate that this address is a suitable SAC/token without trapping.”Citations:
Fix asset validation to return
Error::InvalidAssetvia fallibletry_decimals(no trapping)token::Client::new(&env, &pricing.asset).decimals()can panic/trap when the SAC/token contract isn’t initialized, soError::InvalidAssetisn’t reliably returned. Validate with the same client family used later for transfers (token::StellarAssetClient) and maptry_decimals()failure toError::InvalidAsset.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents