-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Transaction Debugger - 提案エンジン実装
概要
トランザクション失敗原因に基づいて、解決方法を提案する
実装内容
# lib/transaction_debugger/suggestions_engine.rb
module TransactionDebugger
class SuggestionsEngine
def generate(transaction, receipt, revert_reason)
suggestions = []
# Analyze revert reason
suggestions += analyze_revert_reason(revert_reason) if revert_reason
# Analyze gas
suggestions += analyze_gas(transaction, receipt)
# Analyze nonce
suggestions += analyze_nonce(transaction)
suggestions
end
private
def analyze_revert_reason(reason)
suggestions = []
case reason
when /insufficient balance/i
suggestions << {
title: "Insufficient Balance",
description: "The sender doesn't have enough ETH",
actions: [
"Check balance: eth.getBalance(address)",
"Send more ETH to the address",
"Reduce the transfer amount"
]
}
when /allowance|approved/i
suggestions << {
title: "Insufficient Allowance",
description: "The contract doesn't have permission to spend tokens",
actions: [
"Call token.approve(spender, amount)",
"Check current allowance: token.allowance(owner, spender)",
"Increase allowance to required amount"
]
}
when /out of gas/i
suggestions << {
title: "Out of Gas",
description: "Transaction ran out of gas during execution",
actions: [
"Increase gas limit (current was likely too low)",
"Optimize contract code if possible",
"Break operation into smaller transactions"
]
}
end
suggestions
end
def analyze_gas(transaction, receipt)
suggestions = []
# Check if gas was almost exhausted
usage = (receipt.gas_used.to_f / transaction.gas * 100)
if usage > 95
suggestions << {
title: "High Gas Usage",
description: "Transaction used #{usage.round(1)}% of gas limit",
actions: [
"Increase gas limit to avoid potential failures",
"Current limit: #{transaction.gas}"
]
}
end
suggestions
end
def analyze_nonce(transaction)
# TODO: Check for nonce issues
[]
end
end
end完了条件
- 主要なエラーパターンに対して提案を生成できる
- 提案にタイトル・説明・アクションが含まれる
- CLIで見やすく表示される
- テストが全てパスする
Phase
Phase 3 - 高度な機能
Dependencies
- Issue [Feature] Improve error message formatting #12: [Feature] Improve error message formatting
Metadata
Metadata
Assignees
Labels
No labels