-
Notifications
You must be signed in to change notification settings - Fork 1
Added TonCenter API key support #81
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,14 +26,25 @@ export class TON extends DefaultChain { | |||||||||||||||||||||||||||||||||||||
| this.name = "ton" | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private _apiKey?: string | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| override setRpc(rpc_url: string): void { | ||||||||||||||||||||||||||||||||||||||
| this.rpc_url = rpc_url | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| this.provider = new TonClient({ | ||||||||||||||||||||||||||||||||||||||
| endpoint: this.rpc_url, | ||||||||||||||||||||||||||||||||||||||
| ...(this._apiKey && { apiKey: this._apiKey }), | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| setApiKey(apiKey: string): void { | ||||||||||||||||||||||||||||||||||||||
| this._apiKey = apiKey | ||||||||||||||||||||||||||||||||||||||
| // Recreate provider with the API key | ||||||||||||||||||||||||||||||||||||||
| if (this.rpc_url) { | ||||||||||||||||||||||||||||||||||||||
| this.setRpc(this.rpc_url) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+46
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. 2. Setapikey doesn’t reconnect TON.setApiKey rebuilds the TonClient provider but never re-runs connect() or resets connected, so the instance can report an outdated connection state after changing auth configuration. This is especially problematic with DefaultChain.create() which immediately calls connect() after setRpc(), giving no opportunity to set the API key before the initial connection attempt. Agent Prompt
Comment on lines
+40
to
+46
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. Add JSDoc for the new public The method introduced at Line 40 is public API and should include JSDoc in this repository. Proposed fix+ /**
+ * Set TonCenter API key and recreate the RPC provider when an endpoint is already configured.
+ * `@param` apiKey TonCenter API key.
+ */
setApiKey(apiKey: string): void {As per coding guidelines, "Use JSDoc format for all new methods and functions". 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
On Line 40-45, recreating the provider can leave Proposed fix- setApiKey(apiKey: string): void {
- this._apiKey = apiKey
- // Recreate provider with the API key
- if (this.rpc_url) {
- this.setRpc(this.rpc_url)
- }
- }
+ setApiKey(apiKey: string): void {
+ const normalizedApiKey = apiKey.trim()
+ if (!normalizedApiKey) {
+ throw new Error("TON API key must be a non-empty string")
+ }
+
+ this._apiKey = normalizedApiKey
+
+ if (this.rpc_url) {
+ this.setRpc(this.rpc_url)
+ this.connected = false
+ }
+ }As per coding guidelines, "Provide clear, actionable error messages". 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| async connect() { | ||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| const info = await this.provider.getMasterchainInfo() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
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.
1. Bad apikey spread operand
🐞 Bug✓ CorrectnessTON.setRpc conditionally spreads this._apiKey && { apiKey: this._apiKey }, but if setApiKey("") is used (allowed by the current signature), the && expression evaluates to a string and is spread into the options object, producing an invalid configuration and omitting apiKey. This makes API-key configuration fail in a hard-to-debug way when the key is empty/missing (e.g., env var defaulting to "").Agent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools